aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/inlay_hints.ts
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-02-22 18:58:00 +0000
committerVeetaha <[email protected]>2020-02-23 13:49:09 +0000
commit4cee7cddc84aa3769d5d3e87e5745f4c981bca28 (patch)
treef8b98268925cf01e2cc74a9e12fac81a460c1eff /editors/code/src/inlay_hints.ts
parent838ad6bcfb2a82c030e18d019b8a06752f0fc828 (diff)
vscode: gracefully handle cancellation errors
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r--editors/code/src/inlay_hints.ts40
1 files changed, 18 insertions, 22 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 7e6c310a9..5f9229efb 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -1,8 +1,8 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3 3
4import { Ctx, sendRequestWithRetry } from './ctx'; 4import { Ctx } from './ctx';
5import { log } from './util'; 5import { log, sendRequestWithRetry } from './util';
6 6
7export function activateInlayHints(ctx: Ctx) { 7export function activateInlayHints(ctx: Ctx) {
8 const hintsUpdater = new HintsUpdater(ctx); 8 const hintsUpdater = new HintsUpdater(ctx);
@@ -152,28 +152,24 @@ class HintsUpdater {
152 } 152 }
153 153
154 private async queryHints(documentUri: string): Promise<InlayHint[] | null> { 154 private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
155 const client = this.ctx.client; 155 this.pending.get(documentUri)?.cancel();
156 if (!client) return null;
157 156
158 const request: InlayHintsParams = {
159 textDocument: { uri: documentUri },
160 };
161 const tokenSource = new vscode.CancellationTokenSource(); 157 const tokenSource = new vscode.CancellationTokenSource();
162 const prevHintsRequest = this.pending.get(documentUri);
163 prevHintsRequest?.cancel();
164
165 this.pending.set(documentUri, tokenSource); 158 this.pending.set(documentUri, tokenSource);
166 try { 159
167 return await sendRequestWithRetry<InlayHint[] | null>( 160 const request: InlayHintsParams = { textDocument: { uri: documentUri } };
168 client, 161
169 'rust-analyzer/inlayHints', 162 return sendRequestWithRetry<InlayHint[]>(
170 request, 163 this.ctx.client,
171 tokenSource.token, 164 'rust-analyzer/inlayHints',
172 ); 165 request,
173 } finally { 166 tokenSource.token
174 if (!tokenSource.token.isCancellationRequested) { 167 )
175 this.pending.delete(documentUri); 168 .catch(_ => null)
176 } 169 .finally(() => {
177 } 170 if (!tokenSource.token.isCancellationRequested) {
171 this.pending.delete(documentUri);
172 }
173 });
178 } 174 }
179} 175}