about summary refs log tree commit diff
path: root/editors/code/src/commands.ts
diff options
context:
space:
mode:
authorbruno-ortiz <brunortiz11@gmail.com>2022-02-25 21:37:55 -0300
committerBruno Ortiz <brunortiz11@gmail.com>2023-05-02 10:48:33 -0300
commit795a1cbe89bc2428937aec828963fe64a2c8d4d9 (patch)
tree0e07a8bfd2c0cef3e401bad15755a425528916cb /editors/code/src/commands.ts
parentcffc402c058f9d4d0675ed20bd920fa700c361ec (diff)
downloadrust-795a1cbe89bc2428937aec828963fe64a2c8d4d9.tar.gz
rust-795a1cbe89bc2428937aec828963fe64a2c8d4d9.zip
Creating rust dependencies tree view
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r--editors/code/src/commands.ts41
1 files changed, 40 insertions, 1 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 2d5272d199d..e5aa06025b2 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;