reveal only when tree is visible
This commit is contained in:
parent
a3081a6774
commit
fe7874af90
@ -15,7 +15,6 @@ import {
|
|||||||
isRustEditor,
|
isRustEditor,
|
||||||
RustEditor,
|
RustEditor,
|
||||||
RustDocument,
|
RustDocument,
|
||||||
closeDocument,
|
|
||||||
} from "./util";
|
} from "./util";
|
||||||
import { startDebugSession, makeDebugConfig } from "./debug";
|
import { startDebugSession, makeDebugConfig } from "./debug";
|
||||||
import { LanguageClient } from "vscode-languageclient/node";
|
import { LanguageClient } from "vscode-languageclient/node";
|
||||||
@ -324,7 +323,6 @@ async function revealParentChain(document: RustDocument, ctx: CtxInit) {
|
|||||||
if (parentChain.length >= maxDepth) {
|
if (parentChain.length >= maxDepth) {
|
||||||
// this is an odd case that can happen when we change a crate version but we'd still have
|
// this is an odd case that can happen when we change a crate version but we'd still have
|
||||||
// a open file referencing the old version
|
// a open file referencing the old version
|
||||||
await closeDocument(document);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (!ctx.dependencies?.contains(documentPath));
|
} while (!ctx.dependencies?.contains(documentPath));
|
||||||
|
@ -285,14 +285,38 @@ export class Ctx {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.pushExtCleanup(this._treeView);
|
this.pushExtCleanup(this._treeView);
|
||||||
vscode.window.onDidChangeActiveTextEditor((e) => {
|
vscode.window.onDidChangeActiveTextEditor(async (e) => {
|
||||||
// we should skip documents that belong to the current workspace
|
// we should skip documents that belong to the current workspace
|
||||||
if (e && isRustEditor(e) && !isDocumentInWorkspace(e.document)) {
|
if (this.shouldRevealDependency(e)) {
|
||||||
execRevealDependency(e).catch((reason) => {
|
try {
|
||||||
void vscode.window.showErrorMessage(`Dependency error: ${reason}`);
|
await execRevealDependency(e);
|
||||||
});
|
} catch (reason) {
|
||||||
|
await vscode.window.showErrorMessage(`Dependency error: ${reason}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.treeView?.onDidChangeVisibility(async (e) => {
|
||||||
|
if (e.visible) {
|
||||||
|
const activeEditor = vscode.window.activeTextEditor;
|
||||||
|
if (this.shouldRevealDependency(activeEditor)) {
|
||||||
|
try {
|
||||||
|
await execRevealDependency(activeEditor);
|
||||||
|
} catch (reason) {
|
||||||
|
await vscode.window.showErrorMessage(`Dependency error: ${reason}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private shouldRevealDependency(e: vscode.TextEditor | undefined): e is RustEditor {
|
||||||
|
return (
|
||||||
|
e !== undefined &&
|
||||||
|
isRustEditor(e) &&
|
||||||
|
!isDocumentInWorkspace(e.document) &&
|
||||||
|
(this.treeView?.visible || false)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async restart() {
|
async restart() {
|
||||||
|
@ -125,11 +125,6 @@ export function isDocumentInWorkspace(document: RustDocument): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function closeDocument(document: RustDocument) {
|
|
||||||
await vscode.window.showTextDocument(document, { preview: true, preserveFocus: false });
|
|
||||||
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isValidExecutable(path: string): boolean {
|
export function isValidExecutable(path: string): boolean {
|
||||||
log.debug("Checking availability of a binary at", path);
|
log.debug("Checking availability of a binary at", path);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user