Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 61838af

Browse files
committed
Don't start servers for every already opened files
This models better what built-in TS/JS services do, in an attempt to be more lazy and less resource-intensive. This addresses a use case where the user may prefer to operate on a monorepo with lots of opened files but keep the sessions short-ish, where they don't touch every project in a single session.
1 parent e63d147 commit 61838af

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
### Unreleased
22

3+
* (!) Don't immediately start server instances for every already opened file
4+
* (!) Don't immediately start server instances for newly added workspace folders
35
* Dynamically show progress only for the active client workspace
46
* Correctly run tasks based on active text editor rather than last opened Rust file
5-
* (!) Don't immediately try to start server instance for newly added workspace folders
67
* Use smooth, universally supported spinner in the status bar ⚙️
78

89
### 0.7.3 - 2020-04-21

src/extension.ts

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
IndentAction,
1010
languages,
1111
RelativePattern,
12-
TextDocument,
1312
TextEditor,
1413
Uri,
1514
window,
@@ -50,15 +49,8 @@ export async function activate(context: ExtensionContext) {
5049
context.subscriptions.push(configureLanguage());
5150
context.subscriptions.push(...registerCommands());
5251

53-
workspace.onDidOpenTextDocument(doc => whenOpeningTextDocument(doc));
5452
workspace.onDidChangeWorkspaceFolders(whenChangingWorkspaceFolders);
5553
window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor);
56-
window.onDidChangeActiveTextEditor(
57-
ed => ed && whenOpeningTextDocument(ed.document),
58-
);
59-
// Installed listeners don't fire immediately for already opened files, so
60-
// trigger an open event manually to fire up RLS instances where needed
61-
workspace.textDocuments.forEach(whenOpeningTextDocument);
6254
// Trigger manually logic for opening the first active editor
6355
onDidChangeActiveTextEditor(window.activeTextEditor);
6456

@@ -94,24 +86,18 @@ export async function deactivate() {
9486
return Promise.all([...workspaces.values()].map(ws => ws.stop()));
9587
}
9688

97-
// Taken from https://github.com/Microsoft/vscode-extension-samples/blob/master/lsp-multi-server-sample/client/src/extension.ts
98-
function whenOpeningTextDocument(document: TextDocument) {
99-
if (document.languageId !== 'rust' && document.languageId !== 'toml') {
100-
return;
101-
}
102-
103-
clientWorkspaceForUri(document.uri, { startIfMissing: true });
104-
}
105-
10689
/** Tracks dynamically updated progress for the active client workspace for UI purposes. */
10790
const progressObserver: Observer<{ message: string } | null> = new Observer();
10891

10992
function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
110-
if (!editor) {
93+
if (!editor || !editor.document) {
11194
return;
11295
}
96+
const { languageId, uri } = editor.document;
11397

114-
const workspace = clientWorkspaceForUri(editor.document.uri);
98+
const workspace = clientWorkspaceForUri(uri, {
99+
startIfMissing: languageId === 'rust' || languageId === 'toml',
100+
});
115101
if (!workspace) {
116102
return;
117103
}

0 commit comments

Comments
 (0)