diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs index b962279496..778cc84ef9 100644 --- a/crates/ra_project_model/src/project_json.rs +++ b/crates/ra_project_model/src/project_json.rs @@ -34,6 +34,7 @@ pub struct Crate { pub(crate) target: Option, pub(crate) out_dir: Option, pub(crate) proc_macro_dylib_path: Option, + pub(crate) is_workspace_member: bool, } impl ProjectJson { @@ -43,32 +44,42 @@ impl ProjectJson { crates: data .crates .into_iter() - .map(|crate_data| Crate { - root_module: base.join(crate_data.root_module), - edition: crate_data.edition.into(), - deps: crate_data - .deps - .into_iter() - .map(|dep_data| Dependency { - crate_id: CrateId(dep_data.krate as u32), - name: dep_data.name, - }) - .collect::>(), - cfg: { - let mut cfg = CfgOptions::default(); - for entry in &crate_data.cfg { - match split_delim(entry, '=') { - Some((key, value)) => { - cfg.insert_key_value(key.into(), value.into()); + .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 + .deps + .into_iter() + .map(|dep_data| Dependency { + crate_id: CrateId(dep_data.krate as u32), + name: dep_data.name, + }) + .collect::>(), + cfg: { + let mut cfg = CfgOptions::default(); + for entry in &crate_data.cfg { + match split_delim(entry, '=') { + Some((key, value)) => { + cfg.insert_key_value(key.into(), value.into()); + } + None => cfg.insert_atom(entry.into()), } - None => cfg.insert_atom(entry.into()), } - } - cfg - }, - 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)), + cfg + }, + 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)), + is_workspace_member, + } }) .collect::>(), } @@ -91,6 +102,7 @@ struct CrateData { target: Option, out_dir: Option, proc_macro_dylib_path: Option, + is_workspace_member: Option, } #[derive(Deserialize)] diff --git a/crates/vfs/src/loader.rs b/crates/vfs/src/loader.rs index 9c6e4b6a7d..04e257f53f 100644 --- a/crates/vfs/src/loader.rs +++ b/crates/vfs/src/loader.rs @@ -83,11 +83,11 @@ impl Directories { self.includes_path(path) } fn includes_path(&self, path: &AbsPath) -> bool { - let mut include = None; + let mut include: Option<&AbsPathBuf> = None; for incl in &self.include { - if is_prefix(incl, path) { + if path.starts_with(incl) { include = Some(match include { - Some(prev) if is_prefix(incl, prev) => prev, + Some(prev) if prev.starts_with(incl) => prev, _ => incl, }) } @@ -97,15 +97,11 @@ impl Directories { None => return false, }; for excl in &self.exclude { - if is_prefix(excl, path) && is_prefix(include, excl) { + if path.starts_with(excl) && excl.starts_with(include) { return false; } } - return true; - - fn is_prefix(short: &AbsPath, long: &AbsPath) -> bool { - long.strip_prefix(short).is_some() - } + true } }