Skip to content

Commit 314e2e7

Browse files
bors[bot]tobywf
andauthored
Merge #9752
9752: feature: Declare proc-macro dependent crates in `rust-project.json` r=matklad a=tobywf This adds the `is_proc_macro` flag in `rust-project.json`. By default, this is `false` and not required, so existing projects won't break/have the same behavior as before this change. If the flag is true, a dependency to the `proc_macro` sysroot crate is added (if it exists), so that rust-analyzer can resolve those imports. This fixes #9726 . I've also added some tests in the second commit. The first is a smoke test for a basic, minimal `rust-project.json` file. The second is a more targeted test for the flag. Both tests depend on the fake sysroot (a bunch of directories in the correct layout with empty `lib.rs` files), and also on `env!("CARGO_MANIFEST_DIR")` being an absolute path. I'm not sure if the later assumption is valid on all platforms. I wanted to at least try and add tests, but I'm happy to rework them or remove them if you don't think that's the way to go. (You can license/relicense my contribution in any way you wish without contacting me.) Co-authored-by: Toby Fleming <[email protected]>
2 parents 0d56ff2 + d0b9806 commit 314e2e7

File tree

17 files changed

+569
-27
lines changed

17 files changed

+569
-27
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)]

0 commit comments

Comments
 (0)