Skip to content

Commit 7a089a7

Browse files
bors[bot]matklad
andauthored
Merge #5457
5457: Simplify r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 62735cf + 3e688d2 commit 7a089a7

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

crates/ra_project_model/src/project_json.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct Crate {
3434
pub(crate) target: Option<String>,
3535
pub(crate) out_dir: Option<AbsPathBuf>,
3636
pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
37+
pub(crate) is_workspace_member: bool,
3738
}
3839

3940
impl ProjectJson {
@@ -43,32 +44,42 @@ impl ProjectJson {
4344
crates: data
4445
.crates
4546
.into_iter()
46-
.map(|crate_data| Crate {
47-
root_module: base.join(crate_data.root_module),
48-
edition: crate_data.edition.into(),
49-
deps: crate_data
50-
.deps
51-
.into_iter()
52-
.map(|dep_data| Dependency {
53-
crate_id: CrateId(dep_data.krate as u32),
54-
name: dep_data.name,
55-
})
56-
.collect::<Vec<_>>(),
57-
cfg: {
58-
let mut cfg = CfgOptions::default();
59-
for entry in &crate_data.cfg {
60-
match split_delim(entry, '=') {
61-
Some((key, value)) => {
62-
cfg.insert_key_value(key.into(), value.into());
47+
.map(|crate_data| {
48+
let is_workspace_member = crate_data.is_workspace_member.unwrap_or_else(|| {
49+
crate_data.root_module.is_relative()
50+
&& !crate_data.root_module.starts_with("..")
51+
|| crate_data.root_module.starts_with(base)
52+
});
53+
Crate {
54+
root_module: base.join(crate_data.root_module),
55+
edition: crate_data.edition.into(),
56+
deps: crate_data
57+
.deps
58+
.into_iter()
59+
.map(|dep_data| Dependency {
60+
crate_id: CrateId(dep_data.krate as u32),
61+
name: dep_data.name,
62+
})
63+
.collect::<Vec<_>>(),
64+
cfg: {
65+
let mut cfg = CfgOptions::default();
66+
for entry in &crate_data.cfg {
67+
match split_delim(entry, '=') {
68+
Some((key, value)) => {
69+
cfg.insert_key_value(key.into(), value.into());
70+
}
71+
None => cfg.insert_atom(entry.into()),
6372
}
64-
None => cfg.insert_atom(entry.into()),
6573
}
66-
}
67-
cfg
68-
},
69-
target: crate_data.target,
70-
out_dir: crate_data.out_dir.map(|it| base.join(it)),
71-
proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)),
74+
cfg
75+
},
76+
target: crate_data.target,
77+
out_dir: crate_data.out_dir.map(|it| base.join(it)),
78+
proc_macro_dylib_path: crate_data
79+
.proc_macro_dylib_path
80+
.map(|it| base.join(it)),
81+
is_workspace_member,
82+
}
7283
})
7384
.collect::<Vec<_>>(),
7485
}
@@ -91,6 +102,7 @@ struct CrateData {
91102
target: Option<String>,
92103
out_dir: Option<PathBuf>,
93104
proc_macro_dylib_path: Option<PathBuf>,
105+
is_workspace_member: Option<bool>,
94106
}
95107

96108
#[derive(Deserialize)]

crates/vfs/src/loader.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ impl Directories {
8383
self.includes_path(path)
8484
}
8585
fn includes_path(&self, path: &AbsPath) -> bool {
86-
let mut include = None;
86+
let mut include: Option<&AbsPathBuf> = None;
8787
for incl in &self.include {
88-
if is_prefix(incl, path) {
88+
if path.starts_with(incl) {
8989
include = Some(match include {
90-
Some(prev) if is_prefix(incl, prev) => prev,
90+
Some(prev) if prev.starts_with(incl) => prev,
9191
_ => incl,
9292
})
9393
}
@@ -97,15 +97,11 @@ impl Directories {
9797
None => return false,
9898
};
9999
for excl in &self.exclude {
100-
if is_prefix(excl, path) && is_prefix(include, excl) {
100+
if path.starts_with(excl) && excl.starts_with(include) {
101101
return false;
102102
}
103103
}
104-
return true;
105-
106-
fn is_prefix(short: &AbsPath, long: &AbsPath) -> bool {
107-
long.strip_prefix(short).is_some()
108-
}
104+
true
109105
}
110106
}
111107

0 commit comments

Comments
 (0)