Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/commands.ts')
| -rw-r--r-- | editors/code/src/commands.ts | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 2d5272d199..e5aa06025b 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -8,10 +8,11 @@ import { applySnippetWorkspaceEdit, applySnippetTextEdits } from "./snippets"; import { spawnSync } from "child_process"; import { RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run"; import { AstInspector } from "./ast_inspector"; -import { isRustDocument, isCargoTomlDocument, sleep, isRustEditor } from "./util"; +import { isRustDocument, isCargoTomlDocument, sleep, isRustEditor, RustEditor } from './util'; import { startDebugSession, makeDebugConfig } from "./debug"; import { LanguageClient } from "vscode-languageclient/node"; import { LINKED_COMMANDS } from "./client"; +import { DependencyId } from './dependencies_provider'; export * from "./ast_inspector"; export * from "./run"; @@ -266,6 +267,44 @@ export function openCargoToml(ctx: CtxInit): Cmd { }; } +export function openFile(_ctx: CtxInit): Cmd { + return async (uri: vscode.Uri) => { + try { + await vscode.window.showTextDocument(uri); + } catch (err) { + await vscode.window.showErrorMessage(err.message); + } + }; +} + +export function revealDependency(ctx: CtxInit): Cmd { + return async (editor: RustEditor) => { + const rootPath = vscode.workspace.workspaceFolders![0].uri.fsPath; + const documentPath = editor.document.uri.fsPath; + if (documentPath.startsWith(rootPath)) return; + const dep = ctx.dependencies.getDependency(documentPath); + if (dep) { + await ctx.treeView.reveal(dep, { select: true, expand: true }); + } else { + let documentPath = editor.document.uri.fsPath; + const parentChain: DependencyId[] = [{ id: documentPath.toLowerCase() }]; + do { + documentPath = path.dirname(documentPath); + parentChain.push({ id: documentPath.toLowerCase() }); + } + while (!ctx.dependencies.contains(documentPath)); + parentChain.reverse(); + for (const idx in parentChain) { + await ctx.treeView.reveal(parentChain[idx], { select: true, expand: true }); + } + } + }; +} + +export async function execRevealDependency(e: RustEditor): Promise<void> { + await vscode.commands.executeCommand('rust-analyzer.revealDependency', e); +} + export function ssr(ctx: CtxInit): Cmd { return async () => { const editor = vscode.window.activeTextEditor; |