From 2c02aebeb560b6c388a8b94723042b1e25eb49e9 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 5 Aug 2019 00:23:58 +0300 Subject: Query less hints on file open --- editors/code/src/commands/inlay_hints.ts | 52 +++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 3ba9da48b..5af3a69bc 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -21,32 +21,36 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ export class HintsUpdater { private displayHints = true; + private drawnDecorations = new Map(); - public async loadHints( - editor: vscode.TextEditor | undefined - ): Promise { - if ( - this.displayHints && - editor !== undefined && - this.isRustDocument(editor.document) - ) { - await this.updateDecorationsFromServer( - editor.document.uri.toString(), - editor - ); + public async loadHints(editor?: vscode.TextEditor): Promise { + if (this.displayHints) { + const documentUri = this.getEditorDocumentUri(editor); + if (documentUri !== null) { + const latestDecorations = this.drawnDecorations.get(documentUri); + if (latestDecorations === undefined) { + await this.updateDecorationsFromServer( + documentUri, + editor! + ); + } else { + await editor!.setDecorations(typeHintDecorationType, latestDecorations); + } + } } } public async toggleHintsDisplay(displayHints: boolean): Promise { if (this.displayHints !== displayHints) { this.displayHints = displayHints; + this.drawnDecorations.clear(); if (displayHints) { return this.updateHints(); } else { const editor = vscode.window.activeTextEditor; - if (editor != null) { - return editor.setDecorations(typeHintDecorationType, []); + if (this.getEditorDocumentUri(editor) !== null) { + return editor!.setDecorations(typeHintDecorationType, []); } } } @@ -85,10 +89,15 @@ export class HintsUpdater { range: hint.range, renderOptions: { after: { contentText: `: ${hint.label}` } } })); - return editor.setDecorations( - typeHintDecorationType, - newDecorations - ); + + this.drawnDecorations.set(documentUri, newDecorations); + + if (this.getEditorDocumentUri(vscode.window.activeTextEditor) === documentUri) { + return editor.setDecorations( + typeHintDecorationType, + newDecorations + ); + } } } @@ -106,4 +115,11 @@ export class HintsUpdater { ) ); } + + private getEditorDocumentUri(editor?: vscode.TextEditor): string | null { + if (editor && this.isRustDocument(editor.document)) { + return editor.document.uri.toString(); + } + return null; + } } -- cgit v1.2.3