From cb13e4a2ca6d2f4c19b6a9959288142dffc4c32c Mon Sep 17 00:00:00 2001 From: Toby Fleming Date: Sat, 31 Jul 2021 15:26:59 -0700 Subject: [PATCH] Rust project supports proc-macro dependent crates --- crates/project_model/src/project_json.rs | 4 ++++ crates/project_model/src/workspace.rs | 12 +++++++++++- docs/user/manual.adoc | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index e8f1aca61b3..5db1aa1b4f3 100644 --- a/crates/project_model/src/project_json.rs +++ b/crates/project_model/src/project_json.rs @@ -37,6 +37,7 @@ pub struct Crate { pub(crate) is_workspace_member: bool, pub(crate) include: Vec, pub(crate) exclude: Vec, + pub(crate) is_proc_macro: bool, } impl ProjectJson { @@ -96,6 +97,7 @@ pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { is_workspace_member, include, exclude, + is_proc_macro: crate_data.is_proc_macro, } }) .collect::>(), @@ -135,6 +137,8 @@ struct CrateData { proc_macro_dylib_path: Option, is_workspace_member: Option, source: Option, + #[serde(default)] + is_proc_macro: bool, } #[derive(Deserialize, Debug, Clone)] diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 41bd668e476..bfc0f144aac 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -446,10 +446,20 @@ fn project_json_to_crate_graph( for (from, krate) in project.crates() { if let Some(&from) = crates.get(&from) { - if let Some((public_deps, _proc_macro)) = &sysroot_deps { + if let Some((public_deps, libproc_macro)) = &sysroot_deps { for (name, to) in public_deps.iter() { add_dep(&mut crate_graph, from, name.clone(), *to) } + if krate.is_proc_macro { + if let Some(proc_macro) = libproc_macro { + add_dep( + &mut crate_graph, + from, + CrateName::new("proc_macro").unwrap(), + *proc_macro, + ); + } + } } for dep in &krate.deps { diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 000a95b1003..6f00da3178a 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -578,6 +578,8 @@ interface Crate { /// the `env!` macro env: : { [key: string]: string; }, + /// Whether the crate is a proc-macro crate. + is_proc_macro: bool; /// For proc-macro crates, path to compiled /// proc-macro (.so file). proc_macro_dylib_path?: string; @@ -597,7 +599,7 @@ Specifically, the `roots` setup will be different eventually. There are three ways to feed `rust-project.json` to rust-analyzer: -* Place `rust-project.json` file at the root of the project, and rust-anlayzer will discover it. +* Place `rust-project.json` file at the root of the project, and rust-analyzer will discover it. * Specify `"rust-analyzer.linkedProjects": [ "path/to/rust-project.json" ]` in the settings (and make sure that your LSP client sends settings as a part of initialize request). * Specify `"rust-analyzer.linkedProjects": [ { "roots": [...], "crates": [...] }]` inline.