From 114d9c568a777b0ed762e8003a8d7d19b58db372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 3 Feb 2021 15:48:25 +0800 Subject: [PATCH] `didChangeVisibleRanges` checks workspace --- client/out/languageserver.js | 17 ++++++++++++++++- client/src/languageserver.ts | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/client/out/languageserver.js b/client/out/languageserver.js index 832ed79..b2a1802 100644 --- a/client/out/languageserver.js +++ b/client/out/languageserver.js @@ -122,9 +122,24 @@ function onCommand(client) { vscode_1.commands.executeCommand(params.command, params.data); }); } +function isDocumentInClient(textDocuments, client) { + let selectors = client.clientOptions.documentSelector; + if (!node_1.DocumentSelector.is(selectors)) { + { + return false; + } + } + if (vscode.languages.match(selectors, textDocuments)) { + return true; + } + return false; +} function onDecorations(client) { let textType = vscode_1.window.createTextEditorDecorationType({}); function notifyVisibleRanges(textEditor) { + if (!isDocumentInClient(textEditor.document, client)) { + return; + } let uri = client.code2ProtocolConverter.asUri(textEditor.document.uri); let ranges = []; for (let index = 0; index < textEditor.visibleRanges.length; index++) { @@ -154,7 +169,7 @@ function onDecorations(client) { let uri = params.uri; for (let index = 0; index < vscode_1.window.visibleTextEditors.length; index++) { const editor = vscode_1.window.visibleTextEditors[index]; - if (editor.document.uri.toString() == uri) { + if (editor.document.uri.toString() == uri && isDocumentInClient(editor.document, client)) { textEditor = editor; break; } diff --git a/client/src/languageserver.ts b/client/src/languageserver.ts index b968029..848520c 100644 --- a/client/src/languageserver.ts +++ b/client/src/languageserver.ts @@ -179,10 +179,24 @@ function onCommand(client: LanguageClient) { }); } +function isDocumentInClient(textDocuments: TextDocument, client: LanguageClient): boolean { + let selectors = client.clientOptions.documentSelector; + if (!DocumentSelector.is(selectors)) {{ + return false; + }} + if (vscode.languages.match(selectors, textDocuments)) { + return true; + } + return false; +} + function onDecorations(client: LanguageClient) { let textType = window.createTextEditorDecorationType({}) function notifyVisibleRanges(textEditor: TextEditor) { + if (!isDocumentInClient(textEditor.document, client)) { + return; + } let uri: types.DocumentUri = client.code2ProtocolConverter.asUri(textEditor.document.uri); let ranges: types.Range[] = []; for (let index = 0; index < textEditor.visibleRanges.length; index++) { @@ -222,7 +236,7 @@ function onDecorations(client: LanguageClient) { let uri: types.URI = params.uri; for (let index = 0; index < window.visibleTextEditors.length; index++) { const editor = window.visibleTextEditors[index]; - if (editor.document.uri.toString() == uri) { + if (editor.document.uri.toString() == uri && isDocumentInClient(editor.document, client)) { textEditor = editor; break; }