Skip to content

Commit

Permalink
Mark all resolve calls as cancellable. (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumer authored Jan 27, 2023
1 parent e944e47 commit 9b74202
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
ImplementationRequest, SelectionRangeRequest, TypeDefinitionRequest, CallHierarchyPrepareRequest, SemanticTokensRegistrationType, LinkedEditingRangeRequest,
TypeHierarchyPrepareRequest, InlineValueRequest, InlayHintRequest, WorkspaceSymbolRequest, TextDocumentRegistrationOptions, FileOperationRegistrationOptions,
ConnectionOptions, PositionEncodingKind, DocumentDiagnosticRequest, NotebookDocumentSyncRegistrationType, NotebookDocumentSyncRegistrationOptions, ErrorCodes,
MessageStrategy, DidOpenTextDocumentParams
MessageStrategy, DidOpenTextDocumentParams, CodeLensResolveRequest, CompletionResolveRequest, CodeActionResolveRequest, InlayHintResolveRequest, DocumentLinkResolveRequest, WorkspaceSymbolResolveRequest
} from 'vscode-languageserver-protocol';

import * as c2p from './codeConverter';
Expand Down Expand Up @@ -1896,6 +1896,15 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
SemanticTokensRangeRequest.method,
SemanticTokensDeltaRequest.method
]);
private static CancellableResolveCalls: Set<string> = new Set([
CompletionResolveRequest.method,
CodeLensResolveRequest.method,
CodeActionResolveRequest.method,
InlayHintResolveRequest.method,
DocumentLinkResolveRequest.method,
WorkspaceSymbolResolveRequest.method
]);

public handleFailedRequest<T>(type: MessageSignature, token: CancellationToken | undefined, error: any, defaultValue: T, showNotification: boolean = true): T {
// If we get a request cancel or a content modified don't log anything.
if (error instanceof ResponseError) {
Expand All @@ -1915,7 +1924,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
}
}
} else if (error.code === LSPErrorCodes.ContentModified) {
if (BaseLanguageClient.RequestsToCancelOnContentModified.has(type.method)) {
if (BaseLanguageClient.RequestsToCancelOnContentModified.has(type.method) || BaseLanguageClient.CancellableResolveCalls.has(type.method)) {
throw new CancellationError();
} else {
return defaultValue;
Expand Down

0 comments on commit 9b74202

Please sign in to comment.