Skip to content

Commit fe7874a

Browse files
committed
reveal only when tree is visible
1 parent a3081a6 commit fe7874a

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

editors/code/src/commands.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
isRustEditor,
1616
RustEditor,
1717
RustDocument,
18-
closeDocument,
1918
} from "./util";
2019
import { startDebugSession, makeDebugConfig } from "./debug";
2120
import { LanguageClient } from "vscode-languageclient/node";
@@ -324,7 +323,6 @@ async function revealParentChain(document: RustDocument, ctx: CtxInit) {
324323
if (parentChain.length >= maxDepth) {
325324
// this is an odd case that can happen when we change a crate version but we'd still have
326325
// a open file referencing the old version
327-
await closeDocument(document);
328326
return;
329327
}
330328
} while (!ctx.dependencies?.contains(documentPath));

editors/code/src/ctx.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,38 @@ export class Ctx {
285285
});
286286

287287
this.pushExtCleanup(this._treeView);
288-
vscode.window.onDidChangeActiveTextEditor((e) => {
288+
vscode.window.onDidChangeActiveTextEditor(async (e) => {
289289
// we should skip documents that belong to the current workspace
290-
if (e && isRustEditor(e) && !isDocumentInWorkspace(e.document)) {
291-
execRevealDependency(e).catch((reason) => {
292-
void vscode.window.showErrorMessage(`Dependency error: ${reason}`);
293-
});
290+
if (this.shouldRevealDependency(e)) {
291+
try {
292+
await execRevealDependency(e);
293+
} catch (reason) {
294+
await vscode.window.showErrorMessage(`Dependency error: ${reason}`);
295+
}
294296
}
295297
});
298+
299+
this.treeView?.onDidChangeVisibility(async (e) => {
300+
if (e.visible) {
301+
const activeEditor = vscode.window.activeTextEditor;
302+
if (this.shouldRevealDependency(activeEditor)) {
303+
try {
304+
await execRevealDependency(activeEditor);
305+
} catch (reason) {
306+
await vscode.window.showErrorMessage(`Dependency error: ${reason}`);
307+
}
308+
}
309+
}
310+
});
311+
}
312+
313+
private shouldRevealDependency(e: vscode.TextEditor | undefined): e is RustEditor {
314+
return (
315+
e !== undefined &&
316+
isRustEditor(e) &&
317+
!isDocumentInWorkspace(e.document) &&
318+
(this.treeView?.visible || false)
319+
);
296320
}
297321

298322
async restart() {

editors/code/src/util.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ export function isDocumentInWorkspace(document: RustDocument): boolean {
125125
return false;
126126
}
127127

128-
export async function closeDocument(document: RustDocument) {
129-
await vscode.window.showTextDocument(document, { preview: true, preserveFocus: false });
130-
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
131-
}
132-
133128
export function isValidExecutable(path: string): boolean {
134129
log.debug("Checking availability of a binary at", path);
135130

0 commit comments

Comments
 (0)