Skip to content

Commit

Permalink
Merge pull request #758 from ejgallego/client_dont_start_except_if_files
Browse files Browse the repository at this point in the history
[code] Don't start the language client unless there is an active editor for us
  • Loading branch information
ejgallego authored Jun 7, 2024
2 parents c3a5da6 + ce8393e commit dc81772
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
(@ejgallego, #762)
- [lsp] [definition] Try also to resolve and locate module imports
(@ejgallego, #764)
- [code] Don't start server on extension activation, unless an editor
we own is active. We also auto-start the server if a document that
we own is opened later (@ejgallego, #758, fixes #750)

# coq-lsp 0.1.10: Hasta el 40 de Mayo _en effect_...
----------------------------------------------------
Expand Down
20 changes: 18 additions & 2 deletions editor/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export function activateCoqLSP(
0
);
lspStatusItem.command = "coq-lsp.toggle";
lspStatusItem.text = "coq-lsp (activating)";
lspStatusItem.text = "coq-lsp (not active)";
lspStatusItem.show();
context.subscriptions.push(lspStatusItem);
};
Expand Down Expand Up @@ -521,7 +521,23 @@ export function activateCoqLSP(

createEnableButton();

start();
// Fix for bug #750
const active_editors_for_us = (editors: readonly TextEditor[]) =>
editors.some(
(editor) => languages.match(CoqSelector.all, editor.document) > 0
);

// We track when new buffers appear, and start the client if so. We
// dispose of the hook too.
if (active_editors_for_us(window.visibleTextEditors)) {
start();
} else {
window.onDidChangeVisibleTextEditors((editors) => {
if (!client || !client.isRunning()) {
if (active_editors_for_us(editors)) start();
}
}, context.subscriptions);
}

return {
goalsRequest: (params) => {
Expand Down

0 comments on commit dc81772

Please sign in to comment.