From 1201b156d839ac5b5cc7bca1ea1c1f0cf6fbf6a9 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 17 Jul 2022 18:05:55 +0200 Subject: [PATCH] WIP: Add lsp-ext scaffold --- crates/rust-analyzer/src/lsp_ext.rs | 15 +++++++++++++++ crates/rust-analyzer/src/main_loop.rs | 1 + editors/code/src/dependencies_provider.ts | 9 ++++++++- editors/code/src/lsp_ext.ts | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) 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, } +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::(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 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 { + 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 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;