aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/inlay_hints.ts
diff options
context:
space:
mode:
authorJulien Roncaglia <[email protected]>2020-03-02 21:54:29 +0000
committerJulien Roncaglia <[email protected]>2020-03-02 21:54:29 +0000
commit2f54c1d653d46831eeb7d691c5f25b78ca63378a (patch)
tree0bd7b296defaab5bfd70b1c501ad7b3467b16230 /editors/code/src/inlay_hints.ts
parentb95756d21b7988f067d1d5d6448dbe46118f972f (diff)
Centralize the check for languageId on document
Also move visibleRustEditors to Ctx
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r--editors/code/src/inlay_hints.ts23
1 files changed, 4 insertions, 19 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 46e5f7c0d..08d3a64a7 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -2,9 +2,7 @@ import * as vscode from 'vscode';
2import * as ra from './rust-analyzer-api'; 2import * as ra from './rust-analyzer-api';
3 3
4import { Ctx } from './ctx'; 4import { Ctx } from './ctx';
5import { log, sendRequestWithRetry } from './util'; 5import { log, sendRequestWithRetry, isRustDocument } from './util';
6
7const noInlayUriSchemes = ['git', 'svn'];
8 6
9export function activateInlayHints(ctx: Ctx) { 7export function activateInlayHints(ctx: Ctx) {
10 const hintsUpdater = new HintsUpdater(ctx); 8 const hintsUpdater = new HintsUpdater(ctx);
@@ -17,7 +15,7 @@ export function activateInlayHints(ctx: Ctx) {
17 vscode.workspace.onDidChangeTextDocument( 15 vscode.workspace.onDidChangeTextDocument(
18 async event => { 16 async event => {
19 if (event.contentChanges.length === 0) return; 17 if (event.contentChanges.length === 0) return;
20 if (event.document.languageId !== 'rust') return; 18 if (!isRustDocument(event.document)) return;
21 await hintsUpdater.refresh(); 19 await hintsUpdater.refresh();
22 }, 20 },
23 null, 21 null,
@@ -79,7 +77,7 @@ class HintsUpdater {
79 } 77 }
80 78
81 clear() { 79 clear() {
82 this.allEditors.forEach(it => { 80 this.ctx.visibleRustEditors.forEach(it => {
83 this.setTypeDecorations(it, []); 81 this.setTypeDecorations(it, []);
84 this.setParameterDecorations(it, []); 82 this.setParameterDecorations(it, []);
85 }); 83 });
@@ -87,20 +85,7 @@ class HintsUpdater {
87 85
88 async refresh() { 86 async refresh() {
89 if (!this.enabled) return; 87 if (!this.enabled) return;
90 await Promise.all(this.allEditors.map(it => this.refreshEditor(it))); 88 await Promise.all(this.ctx.visibleRustEditors.map(it => this.refreshEditor(it)));
91 }
92
93 private get allEditors(): vscode.TextEditor[] {
94 return vscode.window.visibleTextEditors.filter(
95 editor => {
96 if (editor.document.languageId !== 'rust') {
97 return false;
98 }
99 const scheme = editor.document.uri.scheme;
100 const hasBlacklistedScheme = noInlayUriSchemes.some(s => s === scheme);
101 return !hasBlacklistedScheme;
102 },
103 );
104 } 89 }
105 90
106 private async refreshEditor(editor: vscode.TextEditor): Promise<void> { 91 private async refreshEditor(editor: vscode.TextEditor): Promise<void> {