diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 7a81a18f4a..5d3aca29b5 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::(handlers::handle_workspace_reload) .on_sync_mut::(handlers::handle_proc_macros_rebuild) .on_sync_mut::(handlers::handle_memory_usage) + .on_sync_mut::(handlers::fetch_dependency_graph) .on_sync_mut::(handlers::handle_shuffle_crate_graph) .on_sync::(handlers::handle_join_lines) .on_sync::(handlers::handle_on_enter) diff --git a/editors/code/src/dependencies_provider.ts b/editors/code/src/dependencies_provider.ts index 18a96be124..f2838af6e0 100644 --- a/editors/code/src/dependencies_provider.ts +++ b/editors/code/src/dependencies_provider.ts @@ -4,6 +4,9 @@ import * as fs from "fs"; import { CtxInit } from "./ctx"; import * as ra from "./lsp_ext"; import { FetchDependencyGraphResult } from "./lsp_ext"; +import { Ctx } from "./ctx"; +import { setFlagsFromString } from "v8"; +import * as ra from "./lsp_ext"; @@ -13,9 +16,8 @@ export class RustDependenciesProvider dependenciesMap: { [id: string]: Dependency | DependencyFile };ctx: CtxInit; - constructor( - private readonly workspaceRoot: string,ctx: CtxInit) { - this.dependenciesMap = {}; + constructor(private readonly workspaceRoot: string,ctx: CtxInit) { + this.dependenciesMap = {}; this.ctx = ctx; } @@ -78,6 +80,8 @@ export class RustDependenciesProvider } private async getRootDependencies(): Promise { + const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {}); + const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {}); const crates = dependenciesResult.crates; const deps = crates.map((crate) => { diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 1a887b3720..f066a1c654 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -86,6 +86,22 @@ export const fetchDependencyGraph = new lc.RequestType< void >("rust-analyzer/fetchDependencyGraph"); +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;