Skip to content

Commit

Permalink
Fixes #1283: Server should provide default result for code actions so…
Browse files Browse the repository at this point in the history
… that canceled requests can be removed from queue
  • Loading branch information
dbaeumer committed Jun 15, 2021
1 parent 9d60c17 commit 53ac201
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions server/src/eslintServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -659,7 +660,26 @@ process.on('uncaughtException', (error: any) => {
}
});

const connection = createConnection();

function isRequestMessage(message: LMessage | undefined): message is LRequestMessage {
const candidate = <LRequestMessage>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<TextDocument>;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 53ac201

Please sign in to comment.