vscode: refresh all editors on text changes, simplify inlays api

This commit is contained in:
Veetaha 2020-02-29 23:19:58 +02:00
parent 057cd959da
commit 3d93e2108e

View File

@ -9,9 +9,7 @@ export function activateInlayHints(ctx: Ctx) {
const hintsUpdater = new HintsUpdater(ctx.client);
vscode.window.onDidChangeVisibleTextEditors(
visibleEditors => hintsUpdater.refreshVisibleRustEditors(
visibleEditors.filter(isRustTextEditor)
),
() => hintsUpdater.refreshVisibleRustEditors(),
null,
ctx.subscriptions
);
@ -21,7 +19,7 @@ export function activateInlayHints(ctx: Ctx) {
if (contentChanges.length === 0) return;
if (!isRustTextDocument(document)) return;
hintsUpdater.refreshRustDocument(document);
hintsUpdater.forceRefreshVisibleRustEditors();
},
null,
ctx.subscriptions
@ -92,7 +90,7 @@ class HintsUpdater {
this.enabled = enabled;
if (this.enabled) {
this.refreshVisibleRustEditors(vscode.window.visibleTextEditors.filter(isRustTextEditor));
this.refreshVisibleRustEditors();
} else {
this.clearHints();
}
@ -105,20 +103,20 @@ class HintsUpdater {
}
}
refreshRustDocument(document: RustTextDocument) {
forceRefreshVisibleRustEditors() {
if (!this.enabled) return;
const file = this.sourceFiles.getSourceFile(document.uri.toString());
assert(!!file, "Document must be opened in some text editor!");
void file.fetchAndRenderHints(this.client);
for (const file of this.sourceFiles) {
void file.fetchAndRenderHints(this.client);
}
}
refreshVisibleRustEditors(visibleEditors: RustTextEditor[]) {
refreshVisibleRustEditors() {
if (!this.enabled) return;
const visibleSourceFiles = this.sourceFiles.drainEditors(visibleEditors);
const visibleSourceFiles = this.sourceFiles.drainEditors(
vscode.window.visibleTextEditors.filter(isRustTextEditor)
);
// Cancel requests for source files whose editors were disposed (leftovers after drain).
for (const { inlaysRequest } of this.sourceFiles) inlaysRequest?.cancel();