From 53ac201a24ef4d6439b9fff7a3721d47c620066f Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Tue, 15 Jun 2021 15:11:04 +0200 Subject: [PATCH] Fixes #1283: Server should provide default result for code actions so that canceled requests can be removed from queue --- server/src/eslintServer.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/server/src/eslintServer.ts b/server/src/eslintServer.ts index 84ad2348..4ff77aee 100644 --- a/server/src/eslintServer.ts +++ b/server/src/eslintServer.ts @@ -10,7 +10,8 @@ import { TextDocumentIdentifier, Command, WorkspaceChange, CodeActionRequest, VersionedTextDocumentIdentifier, ExecuteCommandRequest, DidChangeWatchedFilesNotification, DidChangeConfigurationNotification, WorkspaceFolder, DidChangeWorkspaceFoldersNotification, CodeAction, CodeActionKind, Position, DocumentFormattingRequest, - DocumentFormattingRegistrationOptions, Disposable, DocumentFilter, TextDocumentEdit, LSPErrorCodes, DiagnosticTag, NotificationType0 + DocumentFormattingRegistrationOptions, Disposable, DocumentFilter, TextDocumentEdit, LSPErrorCodes, DiagnosticTag, NotificationType0, + Message as LMessage, RequestMessage as LRequestMessage, ResponseMessage as LResponseMessage } from 'vscode-languageserver/node'; import { @@ -659,7 +660,26 @@ process.on('uncaughtException', (error: any) => { } }); -const connection = createConnection(); + +function isRequestMessage(message: LMessage | undefined): message is LRequestMessage { + const candidate = message; + return candidate && typeof candidate.method === 'string' && (typeof candidate.id === 'string' || typeof candidate.id === 'number'); +} + +const connection = createConnection({ + cancelUndispatched: (message: LMessage) => { + // Code actions can savely be cancel on request. + if (isRequestMessage(message) && message.method === 'textDocument/codeAction') { + const response: LResponseMessage = { + jsonrpc: message.jsonrpc, + id: message.id, + result: null + }; + return response; + } + return undefined; + } +}); connection.console.info(`ESLint server running in node ${process.version}`); // Is instantiated in the initialize handle; let documents!: TextDocuments; @@ -1148,7 +1168,7 @@ function setupDocumentsListeners() { const uri = event.document.uri; codeActions.delete(uri); resolveSettings(event.document).then((settings) => { - if (settings.validate !== Validate.on|| settings.run !== 'onType') { + if (settings.validate !== Validate.on || settings.run !== 'onType') { return; } messageQueue.addNotificationMessage(ValidateNotification.type, event.document, event.document.version);