aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2019-08-04 22:23:58 +0100
committerKirill Bulatov <[email protected]>2019-08-04 22:23:58 +0100
commit2c02aebeb560b6c388a8b94723042b1e25eb49e9 (patch)
treef42d4c2093085856e4c2ac345ca4f70e08bf656f /editors/code
parent4912cc35afe96b1506e5cda1be34d3e2418bc702 (diff)
Query less hints on file open
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/commands/inlay_hints.ts52
1 files changed, 34 insertions, 18 deletions
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({
21 21
22export class HintsUpdater { 22export class HintsUpdater {
23 private displayHints = true; 23 private displayHints = true;
24 private drawnDecorations = new Map<string, vscode.DecorationOptions[]>();
24 25
25 public async loadHints( 26 public async loadHints(editor?: vscode.TextEditor): Promise<void> {
26 editor: vscode.TextEditor | undefined 27 if (this.displayHints) {
27 ): Promise<void> { 28 const documentUri = this.getEditorDocumentUri(editor);
28 if ( 29 if (documentUri !== null) {
29 this.displayHints && 30 const latestDecorations = this.drawnDecorations.get(documentUri);
30 editor !== undefined && 31 if (latestDecorations === undefined) {
31 this.isRustDocument(editor.document) 32 await this.updateDecorationsFromServer(
32 ) { 33 documentUri,
33 await this.updateDecorationsFromServer( 34 editor!
34 editor.document.uri.toString(), 35 );
35 editor 36 } else {
36 ); 37 await editor!.setDecorations(typeHintDecorationType, latestDecorations);
38 }
39 }
37 } 40 }
38 } 41 }
39 42
40 public async toggleHintsDisplay(displayHints: boolean): Promise<void> { 43 public async toggleHintsDisplay(displayHints: boolean): Promise<void> {
41 if (this.displayHints !== displayHints) { 44 if (this.displayHints !== displayHints) {
42 this.displayHints = displayHints; 45 this.displayHints = displayHints;
46 this.drawnDecorations.clear();
43 47
44 if (displayHints) { 48 if (displayHints) {
45 return this.updateHints(); 49 return this.updateHints();
46 } else { 50 } else {
47 const editor = vscode.window.activeTextEditor; 51 const editor = vscode.window.activeTextEditor;
48 if (editor != null) { 52 if (this.getEditorDocumentUri(editor) !== null) {
49 return editor.setDecorations(typeHintDecorationType, []); 53 return editor!.setDecorations(typeHintDecorationType, []);
50 } 54 }
51 } 55 }
52 } 56 }
@@ -85,10 +89,15 @@ export class HintsUpdater {
85 range: hint.range, 89 range: hint.range,
86 renderOptions: { after: { contentText: `: ${hint.label}` } } 90 renderOptions: { after: { contentText: `: ${hint.label}` } }
87 })); 91 }));
88 return editor.setDecorations( 92
89 typeHintDecorationType, 93 this.drawnDecorations.set(documentUri, newDecorations);
90 newDecorations 94
91 ); 95 if (this.getEditorDocumentUri(vscode.window.activeTextEditor) === documentUri) {
96 return editor.setDecorations(
97 typeHintDecorationType,
98 newDecorations
99 );
100 }
92 } 101 }
93 } 102 }
94 103
@@ -106,4 +115,11 @@ export class HintsUpdater {
106 ) 115 )
107 ); 116 );
108 } 117 }
118
119 private getEditorDocumentUri(editor?: vscode.TextEditor): string | null {
120 if (editor && this.isRustDocument(editor.document)) {
121 return editor.document.uri.toString();
122 }
123 return null;
124 }
109} 125}