aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-20 17:13:18 +0100
committerGitHub <[email protected]>2020-07-20 17:13:18 +0100
commit7a089a7bab3779ad83719a91f0db6ec6ccf0175b (patch)
treedec88276e72c3e49f5946a16a1b01a163c34fe17 /crates
parent62735cf587c92d20d4a308f2dd22d798dcb0f177 (diff)
parent3e688d2a9340e8d8ca2da5bbdc441f2d6cce893c (diff)
Merge #5457
5457: Simplify r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_project_model/src/project_json.rs60
-rw-r--r--crates/vfs/src/loader.rs14
2 files changed, 41 insertions, 33 deletions
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs
index b96227949..778cc84ef 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 {
34 pub(crate) target: Option<String>, 34 pub(crate) target: Option<String>,
35 pub(crate) out_dir: Option<AbsPathBuf>, 35 pub(crate) out_dir: Option<AbsPathBuf>,
36 pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>, 36 pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
37 pub(crate) is_workspace_member: bool,
37} 38}
38 39
39impl ProjectJson { 40impl ProjectJson {
@@ -43,32 +44,42 @@ impl ProjectJson {
43 crates: data 44 crates: data
44 .crates 45 .crates
45 .into_iter() 46 .into_iter()
46 .map(|crate_data| Crate { 47 .map(|crate_data| {
47 root_module: base.join(crate_data.root_module), 48 let is_workspace_member = crate_data.is_workspace_member.unwrap_or_else(|| {
48 edition: crate_data.edition.into(), 49 crate_data.root_module.is_relative()
49 deps: crate_data 50 && !crate_data.root_module.starts_with("..")
50 .deps 51 || crate_data.root_module.starts_with(base)
51 .into_iter() 52 });
52 .map(|dep_data| Dependency { 53 Crate {
53 crate_id: CrateId(dep_data.krate as u32), 54 root_module: base.join(crate_data.root_module),
54 name: dep_data.name, 55 edition: crate_data.edition.into(),
55 }) 56 deps: crate_data
56 .collect::<Vec<_>>(), 57 .deps
57 cfg: { 58 .into_iter()
58 let mut cfg = CfgOptions::default(); 59 .map(|dep_data| Dependency {
59 for entry in &crate_data.cfg { 60 crate_id: CrateId(dep_data.krate as u32),
60 match split_delim(entry, '=') { 61 name: dep_data.name,
61 Some((key, value)) => { 62 })
62 cfg.insert_key_value(key.into(), value.into()); 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()),
63 } 72 }
64 None => cfg.insert_atom(entry.into()),
65 } 73 }
66 } 74 cfg
67 cfg 75 },
68 }, 76 target: crate_data.target,
69 target: crate_data.target, 77 out_dir: crate_data.out_dir.map(|it| base.join(it)),
70 out_dir: crate_data.out_dir.map(|it| base.join(it)), 78 proc_macro_dylib_path: crate_data
71 proc_macro_dylib_path: crate_data.proc_macro_dylib_path.map(|it| base.join(it)), 79 .proc_macro_dylib_path
80 .map(|it| base.join(it)),
81 is_workspace_member,
82 }
72 }) 83 })
73 .collect::<Vec<_>>(), 84 .collect::<Vec<_>>(),
74 } 85 }
@@ -91,6 +102,7 @@ struct CrateData {
91 target: Option<String>, 102 target: Option<String>,
92 out_dir: Option<PathBuf>, 103 out_dir: Option<PathBuf>,
93 proc_macro_dylib_path: Option<PathBuf>, 104 proc_macro_dylib_path: Option<PathBuf>,
105 is_workspace_member: Option<bool>,
94} 106}
95 107
96#[derive(Deserialize)] 108#[derive(Deserialize)]
diff --git a/crates/vfs/src/loader.rs b/crates/vfs/src/loader.rs
index 9c6e4b6a7..04e257f53 100644
--- a/crates/vfs/src/loader.rs
+++ b/crates/vfs/src/loader.rs
@@ -83,11 +83,11 @@ impl Directories {
83 self.includes_path(path) 83 self.includes_path(path)
84 } 84 }
85 fn includes_path(&self, path: &AbsPath) -> bool { 85 fn includes_path(&self, path: &AbsPath) -> bool {
86 let mut include = None; 86 let mut include: Option<&AbsPathBuf> = None;
87 for incl in &self.include { 87 for incl in &self.include {
88 if is_prefix(incl, path) { 88 if path.starts_with(incl) {
89 include = Some(match include { 89 include = Some(match include {
90 Some(prev) if is_prefix(incl, prev) => prev, 90 Some(prev) if prev.starts_with(incl) => prev,
91 _ => incl, 91 _ => incl,
92 }) 92 })
93 } 93 }
@@ -97,15 +97,11 @@ impl Directories {
97 None => return false, 97 None => return false,
98 }; 98 };
99 for excl in &self.exclude { 99 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) {
101 return false; 101 return false;
102 } 102 }
103 } 103 }
104 return true; 104 true
105
106 fn is_prefix(short: &AbsPath, long: &AbsPath) -> bool {
107 long.strip_prefix(short).is_some()
108 }
109 } 105 }
110} 106}
111 107