Skip to content

Commit 1201b15

Browse files
Veykrilbruno-ortiz
authored andcommitted
WIP: Add lsp-ext scaffold
1 parent 16cba19 commit 1201b15

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ pub struct AnalyzerStatusParams {
2727
pub text_document: Option<TextDocumentIdentifier>,
2828
}
2929

30+
pub enum FetchDependencyGraph {}
31+
32+
impl Request for FetchDependencyGraph {
33+
type Params = FetchDependencyGraphParams;
34+
type Result = FetchDependencyGraphResult;
35+
const METHOD: &'static str = "rust-analyzer/fetchDependencyGraph";
36+
}
37+
38+
#[derive(Deserialize, Serialize, Debug)]
39+
#[serde(rename_all = "camelCase")]
40+
pub struct FetchDependencyGraphParams {}
41+
#[derive(Deserialize, Serialize, Debug)]
42+
#[serde(rename_all = "camelCase")]
43+
pub struct FetchDependencyGraphResult {}
44+
3045
pub enum MemoryUsage {}
3146

3247
impl Request for MemoryUsage {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ impl GlobalState {
655655
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
656656
.on_sync_mut::<lsp_ext::RebuildProcMacros>(handlers::handle_proc_macros_rebuild)
657657
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
658+
.on_sync_mut::<lsp_ext::FetchDependencyGraph>(handlers::fetch_dependency_graph)
658659
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
659660
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)
660661
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)

editors/code/src/dependencies_provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import * as fspath from "path";
33
import * as fs from "fs";
44
import * as os from "os";
55
import { activeToolchain, Cargo, Crate, getRustcVersion } from "./toolchain";
6+
import { Ctx } from "./ctx";
7+
import { setFlagsFromString } from "v8";
8+
import * as ra from "./lsp_ext";
69

710
const debugOutput = vscode.window.createOutputChannel("Debug");
811

@@ -11,10 +14,12 @@ export class RustDependenciesProvider
1114
{
1215
cargo: Cargo;
1316
dependenciesMap: { [id: string]: Dependency | DependencyFile };
17+
ctx: Ctx;
1418

15-
constructor(private readonly workspaceRoot: string) {
19+
constructor(private readonly workspaceRoot: string, ctx: Ctx) {
1620
this.cargo = new Cargo(this.workspaceRoot || ".", debugOutput);
1721
this.dependenciesMap = {};
22+
this.ctx = ctx;
1823
}
1924

2025
private _onDidChangeTreeData: vscode.EventEmitter<
@@ -76,6 +81,8 @@ export class RustDependenciesProvider
7681
}
7782

7883
private async getRootDependencies(): Promise<Dependency[]> {
84+
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
85+
7986
const registryDir = fspath.join(os.homedir(), ".cargo", "registry", "src");
8087
const basePath = fspath.join(registryDir, fs.readdirSync(registryDir)[0]);
8188
const deps = await this.getDepsInCartoTree(basePath);

editors/code/src/lsp_ext.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>
7070

7171
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
7272

73+
export interface FetchDependencyGraphParams {}
74+
75+
export interface FetchDependencyGraphResult {
76+
crates: {
77+
name: string;
78+
version: string;
79+
path: string;
80+
}[];
81+
}
82+
83+
export const fetchDependencyGraph = new lc.RequestType<
84+
FetchDependencyGraphParams,
85+
FetchDependencyGraphResult,
86+
void
87+
>("rust-analyzer/fetchDependencyGraph");
88+
7389
export type ExpandMacroParams = {
7490
textDocument: lc.TextDocumentIdentifier;
7591
position: lc.Position;

0 commit comments

Comments
 (0)