WIP: Add lsp-ext scaffold

This commit is contained in:
Lukas Wirth 2022-07-17 18:05:55 +02:00 committed by Bruno Ortiz
parent 9533644ccf
commit 299382dacd
3 changed files with 24 additions and 3 deletions

View file

@ -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)

View file

@ -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) => {

View file

@ -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;