Unnamed repository; edit this file 'description' to name the repository.
WIP: Add lsp-ext scaffold
Lukas Wirth 2023-05-02
parent 9533644 · commit 299382d
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
-rw-r--r--editors/code/src/dependencies_provider.ts10
-rw-r--r--editors/code/src/lsp_ext.ts16
3 files changed, 24 insertions, 3 deletions
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::<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 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<Dependency[]> {
+ 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;