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 16cba19ff3
commit 1201b156d8
4 changed files with 40 additions and 1 deletions

View File

@ -27,6 +27,21 @@ pub struct AnalyzerStatusParams {
pub text_document: Option<TextDocumentIdentifier>,
}
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 {

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

@ -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<Dependency[]> {
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);

View File

@ -70,6 +70,22 @@ export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>
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;