Skip to content

Commit 995ad75

Browse files
author
Veetaha
committed
vscode: refresh all editors on text changes, simplify inlays api
1 parent e8be640 commit 995ad75

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

editors/code/src/inlay_hints.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export function activateInlayHints(ctx: Ctx) {
99
const hintsUpdater = new HintsUpdater(ctx.client);
1010

1111
vscode.window.onDidChangeVisibleTextEditors(
12-
visibleEditors => hintsUpdater.refreshVisibleRustEditors(
13-
visibleEditors.filter(isRustTextEditor)
14-
),
12+
() => hintsUpdater.refreshVisibleRustEditors(),
1513
null,
1614
ctx.subscriptions
1715
);
@@ -21,7 +19,7 @@ export function activateInlayHints(ctx: Ctx) {
2119
if (contentChanges.length === 0) return;
2220
if (!isRustTextDocument(document)) return;
2321

24-
hintsUpdater.refreshRustDocument(document);
22+
hintsUpdater.forceRefreshVisibleRustEditors();
2523
},
2624
null,
2725
ctx.subscriptions
@@ -92,7 +90,7 @@ class HintsUpdater {
9290
this.enabled = enabled;
9391

9492
if (this.enabled) {
95-
this.refreshVisibleRustEditors(vscode.window.visibleTextEditors.filter(isRustTextEditor));
93+
this.refreshVisibleRustEditors();
9694
} else {
9795
this.clearHints();
9896
}
@@ -105,20 +103,20 @@ class HintsUpdater {
105103
}
106104
}
107105

108-
refreshRustDocument(document: RustTextDocument) {
106+
forceRefreshVisibleRustEditors() {
109107
if (!this.enabled) return;
110108

111-
const file = this.sourceFiles.getSourceFile(document.uri.toString());
112-
113-
assert(!!file, "Document must be opened in some text editor!");
114-
115-
void file.fetchAndRenderHints(this.client);
109+
for (const file of this.sourceFiles) {
110+
void file.fetchAndRenderHints(this.client);
111+
}
116112
}
117113

118-
refreshVisibleRustEditors(visibleEditors: RustTextEditor[]) {
114+
refreshVisibleRustEditors() {
119115
if (!this.enabled) return;
120116

121-
const visibleSourceFiles = this.sourceFiles.drainEditors(visibleEditors);
117+
const visibleSourceFiles = this.sourceFiles.drainEditors(
118+
vscode.window.visibleTextEditors.filter(isRustTextEditor)
119+
);
122120

123121
// Cancel requests for source files whose editors were disposed (leftovers after drain).
124122
for (const { inlaysRequest } of this.sourceFiles) inlaysRequest?.cancel();

0 commit comments

Comments
 (0)