Add is_workspace_member for rust-project.json

It is currently unused, but, in the future, it will be used to:

* drive certain UX (symbols search by default will look only in the
members)
* improve performance (rust-analyzer will assume that non-members
change rarely)

If not specified, is_workspace member is inferred from the path
This commit is contained in:
Aleksey Kladov 2020-07-20 17:57:10 +02:00
parent c7ccfb072c
commit bc4d047267

View file

@ -34,6 +34,7 @@ pub struct Crate {
pub(crate) target: Option<String>,
pub(crate) out_dir: Option<AbsPathBuf>,
pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
pub(crate) is_workspace_member: bool,
}
impl ProjectJson {
@ -43,7 +44,13 @@ impl ProjectJson {
crates: data
.crates
.into_iter()
.map(|crate_data| Crate {
.map(|crate_data| {
let is_workspace_member = crate_data.is_workspace_member.unwrap_or_else(|| {
crate_data.root_module.is_relative()
&& !crate_data.root_module.starts_with("..")
|| crate_data.root_module.starts_with(base)
});
Crate {
root_module: base.join(crate_data.root_module),
edition: crate_data.edition.into(),
deps: crate_data
@ -68,7 +75,11 @@ impl ProjectJson {
},
target: crate_data.target,
out_dir: crate_data.out_dir.map(|it| base.join(it)),
proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)),
proc_macro_dylib_path: crate_data
.proc_macro_dylib_path
.map(|it| base.join(it)),
is_workspace_member,
}
})
.collect::<Vec<_>>(),
}
@ -91,6 +102,7 @@ struct CrateData {
target: Option<String>,
out_dir: Option<PathBuf>,
proc_macro_dylib_path: Option<PathBuf>,
is_workspace_member: Option<bool>,
}
#[derive(Deserialize)]