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