mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Don't request inline hints repeatedly
This commit is contained in:
parent
23bac12062
commit
cdd7118cbf
2 changed files with 26 additions and 10 deletions
|
@ -41,6 +41,7 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
|||
});
|
||||
|
||||
class HintsUpdater {
|
||||
private pending: Map<string, vscode.CancellationTokenSource> = new Map();
|
||||
private ctx: Ctx;
|
||||
private enabled = true;
|
||||
|
||||
|
@ -67,7 +68,8 @@ class HintsUpdater {
|
|||
|
||||
private async refreshEditor(editor: vscode.TextEditor): Promise<void> {
|
||||
const newHints = await this.queryHints(editor.document.uri.toString());
|
||||
const newDecorations = (newHints ? newHints : []).map(hint => ({
|
||||
if (newHints == null) return;
|
||||
const newDecorations = newHints.map(hint => ({
|
||||
range: hint.range,
|
||||
renderOptions: {
|
||||
after: {
|
||||
|
@ -98,9 +100,20 @@ class HintsUpdater {
|
|||
const request: InlayHintsParams = {
|
||||
textDocument: { uri: documentUri },
|
||||
};
|
||||
return this.ctx.sendRequestWithRetry<InlayHint[] | null>(
|
||||
'rust-analyzer/inlayHints',
|
||||
request,
|
||||
);
|
||||
let tokenSource = new vscode.CancellationTokenSource();
|
||||
let prev = this.pending.get(documentUri);
|
||||
if (prev) prev.cancel()
|
||||
this.pending.set(documentUri, tokenSource);
|
||||
try {
|
||||
return await this.ctx.sendRequestWithRetry<InlayHint[] | null>(
|
||||
'rust-analyzer/inlayHints',
|
||||
request,
|
||||
tokenSource.token,
|
||||
);
|
||||
} finally {
|
||||
if (!tokenSource.token.isCancellationRequested) {
|
||||
this.pending.delete(documentUri)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue