aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/inlay_hints.ts
diff options
context:
space:
mode:
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}