aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands/inlay_hints.ts41
1 files changed, 21 insertions, 20 deletions
diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts
index aad28d564..d6d1f61f9 100644
--- a/editors/code/src/commands/inlay_hints.ts
+++ b/editors/code/src/commands/inlay_hints.ts
@@ -21,8 +21,8 @@ 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 WeakMap< 24 private decorationsSinceLastChange = new Map<
25 vscode.Uri, 25 string,
26 vscode.DecorationOptions[] 26 vscode.DecorationOptions[]
27 >(); 27 >();
28 28
@@ -30,8 +30,8 @@ export class HintsUpdater {
30 if (this.displayHints) { 30 if (this.displayHints) {
31 const documentUri = this.getEditorDocumentUri(editor); 31 const documentUri = this.getEditorDocumentUri(editor);
32 if (documentUri !== null) { 32 if (documentUri !== null) {
33 const latestDecorations = this.drawnDecorations.get( 33 const latestDecorations = this.decorationsSinceLastChange.get(
34 documentUri 34 documentUri.toString()
35 ); 35 );
36 if (latestDecorations === undefined) { 36 if (latestDecorations === undefined) {
37 await this.updateDecorationsFromServer( 37 await this.updateDecorationsFromServer(
@@ -51,7 +51,7 @@ export class HintsUpdater {
51 public async toggleHintsDisplay(displayHints: boolean): Promise<void> { 51 public async toggleHintsDisplay(displayHints: boolean): Promise<void> {
52 if (this.displayHints !== displayHints) { 52 if (this.displayHints !== displayHints) {
53 this.displayHints = displayHints; 53 this.displayHints = displayHints;
54 this.drawnDecorations = new WeakMap(); 54 this.decorationsSinceLastChange.clear();
55 55
56 if (displayHints) { 56 if (displayHints) {
57 return this.updateHints(); 57 return this.updateHints();
@@ -72,14 +72,15 @@ export class HintsUpdater {
72 return; 72 return;
73 } 73 }
74 const editor = vscode.window.activeTextEditor; 74 const editor = vscode.window.activeTextEditor;
75 if (editor == null) { 75 if (editor === undefined) {
76 return; 76 return;
77 } 77 }
78 const document = cause == null ? editor.document : cause.document; 78 const document = cause === undefined ? editor.document : cause.document;
79 if (!this.isRustDocument(document)) { 79 if (!this.isRustDocument(document)) {
80 return; 80 return;
81 } 81 }
82 82
83 this.decorationsSinceLastChange.clear();
83 return await this.updateDecorationsFromServer(document.uri, editor); 84 return await this.updateDecorationsFromServer(document.uri, editor);
84 } 85 }
85 86
@@ -92,23 +93,23 @@ export class HintsUpdater {
92 editor: TextEditor 93 editor: TextEditor
93 ): Promise<void> { 94 ): Promise<void> {
94 const newHints = await this.queryHints(documentUri.toString()); 95 const newHints = await this.queryHints(documentUri.toString());
95 if (newHints != null) { 96 if (
97 newHints !== null &&
98 this.getEditorDocumentUri(vscode.window.activeTextEditor) ===
99 documentUri
100 ) {
96 const newDecorations = newHints.map(hint => ({ 101 const newDecorations = newHints.map(hint => ({
97 range: hint.range, 102 range: hint.range,
98 renderOptions: { after: { contentText: `: ${hint.label}` } } 103 renderOptions: { after: { contentText: `: ${hint.label}` } }
99 })); 104 }));
100 105 this.decorationsSinceLastChange.set(
101 this.drawnDecorations.set(documentUri, newDecorations); 106 documentUri.toString(),
102 107 newDecorations
103 if ( 108 );
104 this.getEditorDocumentUri(vscode.window.activeTextEditor) === 109 return editor.setDecorations(
105 documentUri 110 typeHintDecorationType,
106 ) { 111 newDecorations
107 return editor.setDecorations( 112 );
108 typeHintDecorationType,
109 newDecorations
110 );
111 }
112 } 113 }
113 } 114 }
114 115