|
9 | 9 | IndentAction,
|
10 | 10 | languages,
|
11 | 11 | RelativePattern,
|
12 |
| - TextDocument, |
13 | 12 | TextEditor,
|
14 | 13 | Uri,
|
15 | 14 | window,
|
@@ -50,15 +49,8 @@ export async function activate(context: ExtensionContext) {
|
50 | 49 | context.subscriptions.push(configureLanguage());
|
51 | 50 | context.subscriptions.push(...registerCommands());
|
52 | 51 |
|
53 |
| - workspace.onDidOpenTextDocument(doc => whenOpeningTextDocument(doc)); |
54 | 52 | workspace.onDidChangeWorkspaceFolders(whenChangingWorkspaceFolders);
|
55 | 53 | 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); |
62 | 54 | // Trigger manually logic for opening the first active editor
|
63 | 55 | onDidChangeActiveTextEditor(window.activeTextEditor);
|
64 | 56 |
|
@@ -94,24 +86,18 @@ export async function deactivate() {
|
94 | 86 | return Promise.all([...workspaces.values()].map(ws => ws.stop()));
|
95 | 87 | }
|
96 | 88 |
|
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 |
| - |
106 | 89 | /** Tracks dynamically updated progress for the active client workspace for UI purposes. */
|
107 | 90 | const progressObserver: Observer<{ message: string } | null> = new Observer();
|
108 | 91 |
|
109 | 92 | function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
|
110 |
| - if (!editor) { |
| 93 | + if (!editor || !editor.document) { |
111 | 94 | return;
|
112 | 95 | }
|
| 96 | + const { languageId, uri } = editor.document; |
113 | 97 |
|
114 |
| - const workspace = clientWorkspaceForUri(editor.document.uri); |
| 98 | + const workspace = clientWorkspaceForUri(uri, { |
| 99 | + startIfMissing: languageId === 'rust' || languageId === 'toml', |
| 100 | + }); |
115 | 101 | if (!workspace) {
|
116 | 102 | return;
|
117 | 103 | }
|
|
0 commit comments