Skip to content

Commit

Permalink
feat: support for canceling LSP requests (#672)
Browse files Browse the repository at this point in the history
Allows client to send `$/cancelRequest` request to cancel any previously
triggered request. Previously that did nothing.
  • Loading branch information
rchl committed Jan 27, 2023
1 parent 7dda79a commit 1daf209
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 135 deletions.
3 changes: 2 additions & 1 deletion src/features/inlay-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class TypeScriptInlayHintsProvider {
tspClient: TspClient,
lspClient: LspClient,
configurationManager: ConfigurationManager,
token?: lsp.CancellationToken,
): Promise<lsp.InlayHint[]> {
if (tspClient.apiVersion.lt(TypeScriptInlayHintsProvider.minVersion)) {
lspClient.showErrorMessage('Inlay Hints request failed. Requires TypeScript 4.4+.');
Expand Down Expand Up @@ -59,7 +60,7 @@ export class TypeScriptInlayHintsProvider {
const start = document.offsetAt(range.start);
const length = document.offsetAt(range.end) - start;

const response = await tspClient.request(CommandTypes.ProvideInlayHints, { file, start, length });
const response = await tspClient.request(CommandTypes.ProvideInlayHints, { file, start, length }, token);
if (response.type !== 'response' || !response.success || !response.body) {
return [];
}
Expand Down
3 changes: 2 additions & 1 deletion src/features/source-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class SourceDefinitionCommand {
tspClient: TspClient,
lspClient: LspClient,
reporter: lsp.WorkDoneProgressReporter,
token?: lsp.CancellationToken,
): Promise<lsp.Location[] | void> {
if (tspClient.apiVersion.lt(SourceDefinitionCommand.minVersion)) {
lspClient.showErrorMessage('Go to Source Definition failed. Requires TypeScript 4.7+.');
Expand Down Expand Up @@ -59,7 +60,7 @@ export class SourceDefinitionCommand {
message: 'Finding source definitions…',
reporter,
}, async () => {
const response = await tspClient.request(CommandTypes.FindSourceDefinition, args);
const response = await tspClient.request(CommandTypes.FindSourceDefinition, args, token);
if (response.type !== 'response' || !response.body) {
lspClient.showErrorMessage('No source definitions found.');
return;
Expand Down

0 comments on commit 1daf209

Please sign in to comment.