Skip to content

Commit cb13e4a

Browse files
committed
Rust project supports proc-macro dependent crates
1 parent df0936b commit cb13e4a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

crates/project_model/src/project_json.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct Crate {
3737
pub(crate) is_workspace_member: bool,
3838
pub(crate) include: Vec<AbsPathBuf>,
3939
pub(crate) exclude: Vec<AbsPathBuf>,
40+
pub(crate) is_proc_macro: bool,
4041
}
4142

4243
impl ProjectJson {
@@ -96,6 +97,7 @@ impl ProjectJson {
9697
is_workspace_member,
9798
include,
9899
exclude,
100+
is_proc_macro: crate_data.is_proc_macro,
99101
}
100102
})
101103
.collect::<Vec<_>>(),
@@ -135,6 +137,8 @@ struct CrateData {
135137
proc_macro_dylib_path: Option<PathBuf>,
136138
is_workspace_member: Option<bool>,
137139
source: Option<CrateSource>,
140+
#[serde(default)]
141+
is_proc_macro: bool,
138142
}
139143

140144
#[derive(Deserialize, Debug, Clone)]

crates/project_model/src/workspace.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,20 @@ fn project_json_to_crate_graph(
446446

447447
for (from, krate) in project.crates() {
448448
if let Some(&from) = crates.get(&from) {
449-
if let Some((public_deps, _proc_macro)) = &sysroot_deps {
449+
if let Some((public_deps, libproc_macro)) = &sysroot_deps {
450450
for (name, to) in public_deps.iter() {
451451
add_dep(&mut crate_graph, from, name.clone(), *to)
452452
}
453+
if krate.is_proc_macro {
454+
if let Some(proc_macro) = libproc_macro {
455+
add_dep(
456+
&mut crate_graph,
457+
from,
458+
CrateName::new("proc_macro").unwrap(),
459+
*proc_macro,
460+
);
461+
}
462+
}
453463
}
454464

455465
for dep in &krate.deps {

docs/user/manual.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ interface Crate {
578578
/// the `env!` macro
579579
env: : { [key: string]: string; },
580580
581+
/// Whether the crate is a proc-macro crate.
582+
is_proc_macro: bool;
581583
/// For proc-macro crates, path to compiled
582584
/// proc-macro (.so file).
583585
proc_macro_dylib_path?: string;
@@ -597,7 +599,7 @@ Specifically, the `roots` setup will be different eventually.
597599

598600
There are three ways to feed `rust-project.json` to rust-analyzer:
599601

600-
* Place `rust-project.json` file at the root of the project, and rust-anlayzer will discover it.
602+
* Place `rust-project.json` file at the root of the project, and rust-analyzer will discover it.
601603
* 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).
602604
* Specify `"rust-analyzer.linkedProjects": [ { "roots": [...], "crates": [...] }]` inline.
603605

0 commit comments

Comments
 (0)