about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs15
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
-rw-r--r--editors/code/src/dependencies_provider.ts9
-rw-r--r--editors/code/src/lsp_ext.ts16
4 files changed, 40 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index 625ffe0763c..420118ad68b 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -27,6 +27,21 @@ pub struct AnalyzerStatusParams {
     pub text_document: Option<TextDocumentIdentifier>,
 }
 
+pub enum FetchDependencyGraph {}
+
+impl Request for FetchDependencyGraph {
+    type Params = FetchDependencyGraphParams;
+    type Result = FetchDependencyGraphResult;
+    const METHOD: &'static str = "rust-analyzer/fetchDependencyGraph";
+}
+
+#[derive(Deserialize, Serialize, Debug)]
+#[serde(rename_all = "camelCase")]
+pub struct FetchDependencyGraphParams {}
+#[derive(Deserialize, Serialize, Debug)]
+#[serde(rename_all = "camelCase")]
+pub struct FetchDependencyGraphResult {}
+
 pub enum MemoryUsage {}
 
 impl Request for MemoryUsage {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index dc0ea0b17e0..72fc1f1e250 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -655,6 +655,7 @@ impl GlobalState {
             .on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
             .on_sync_mut::<lsp_ext::RebuildProcMacros>(handlers::handle_proc_macros_rebuild)
             .on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
+            .on_sync_mut::<lsp_ext::FetchDependencyGraph>(handlers::fetch_dependency_graph)
             .on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
             .on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)
             .on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
diff --git a/editors/code/src/dependencies_provider.ts b/editors/code/src/dependencies_provider.ts
index 777cb0d33a7..48d51523e86 100644
--- a/editors/code/src/dependencies_provider.ts
+++ b/editors/code/src/dependencies_provider.ts
@@ -3,6 +3,9 @@ import * as fspath from "path";
 import * as fs from "fs";
 import * as os from "os";
 import { activeToolchain, Cargo, Crate, getRustcVersion } from "./toolchain";
+import { Ctx } from "./ctx";
+import { setFlagsFromString } from "v8";
+import * as ra from "./lsp_ext";
 
 const debugOutput = vscode.window.createOutputChannel("Debug");
 
@@ -11,10 +14,12 @@ export class RustDependenciesProvider
 {
     cargo: Cargo;
     dependenciesMap: { [id: string]: Dependency | DependencyFile };
+    ctx: Ctx;
 
-    constructor(private readonly workspaceRoot: string) {
+    constructor(private readonly workspaceRoot: string, ctx: Ctx) {
         this.cargo = new Cargo(this.workspaceRoot || ".", debugOutput);
         this.dependenciesMap = {};
+        this.ctx = ctx;
     }
 
     private _onDidChangeTreeData: vscode.EventEmitter<
@@ -76,6 +81,8 @@ export class RustDependenciesProvider
     }
 
     private async getRootDependencies(): Promise<Dependency[]> {
+        const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
+
         const registryDir = fspath.join(os.homedir(), ".cargo", "registry", "src");
         const basePath = fspath.join(registryDir, fs.readdirSync(registryDir)[0]);
         const deps = await this.getDepsInCartoTree(basePath);
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index 82955acf25e..1a887b37201 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -70,6 +70,22 @@ export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>
 
 export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
 
+export interface FetchDependencyGraphParams {}
+
+export interface FetchDependencyGraphResult {
+    crates: {
+        name: string;
+        version: string;
+        path: string;
+    }[];
+}
+
+export const fetchDependencyGraph = new lc.RequestType<
+    FetchDependencyGraphParams,
+    FetchDependencyGraphResult,
+    void
+>("rust-analyzer/fetchDependencyGraph");
+
 export type ExpandMacroParams = {
     textDocument: lc.TextDocumentIdentifier;
     position: lc.Position;