diff options
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 14 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_project_model/src/project_json.rs | 60 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 7 |
4 files changed, 48 insertions, 35 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 04f7eb741..4182ca156 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -24,7 +24,7 @@ use rustc_hash::FxHashMap; | |||
24 | /// | 24 | /// |
25 | /// We use absolute paths here, `cargo metadata` guarantees to always produce | 25 | /// We use absolute paths here, `cargo metadata` guarantees to always produce |
26 | /// abs paths. | 26 | /// abs paths. |
27 | #[derive(Debug, Clone)] | 27 | #[derive(Debug, Clone, Eq, PartialEq)] |
28 | pub struct CargoWorkspace { | 28 | pub struct CargoWorkspace { |
29 | packages: Arena<PackageData>, | 29 | packages: Arena<PackageData>, |
30 | targets: Arena<TargetData>, | 30 | targets: Arena<TargetData>, |
@@ -68,7 +68,7 @@ pub type Package = Idx<PackageData>; | |||
68 | 68 | ||
69 | pub type Target = Idx<TargetData>; | 69 | pub type Target = Idx<TargetData>; |
70 | 70 | ||
71 | #[derive(Debug, Clone)] | 71 | #[derive(Debug, Clone, Eq, PartialEq)] |
72 | pub struct PackageData { | 72 | pub struct PackageData { |
73 | pub version: String, | 73 | pub version: String, |
74 | pub name: String, | 74 | pub name: String, |
@@ -83,13 +83,13 @@ pub struct PackageData { | |||
83 | pub proc_macro_dylib_path: Option<AbsPathBuf>, | 83 | pub proc_macro_dylib_path: Option<AbsPathBuf>, |
84 | } | 84 | } |
85 | 85 | ||
86 | #[derive(Debug, Clone)] | 86 | #[derive(Debug, Clone, Eq, PartialEq)] |
87 | pub struct PackageDependency { | 87 | pub struct PackageDependency { |
88 | pub pkg: Package, | 88 | pub pkg: Package, |
89 | pub name: String, | 89 | pub name: String, |
90 | } | 90 | } |
91 | 91 | ||
92 | #[derive(Debug, Clone)] | 92 | #[derive(Debug, Clone, Eq, PartialEq)] |
93 | pub struct TargetData { | 93 | pub struct TargetData { |
94 | pub package: Package, | 94 | pub package: Package, |
95 | pub name: String, | 95 | pub name: String, |
@@ -155,7 +155,7 @@ impl CargoWorkspace { | |||
155 | if let Some(target) = cargo_features.target.as_ref() { | 155 | if let Some(target) = cargo_features.target.as_ref() { |
156 | meta.other_options(vec![String::from("--filter-platform"), target.clone()]); | 156 | meta.other_options(vec![String::from("--filter-platform"), target.clone()]); |
157 | } | 157 | } |
158 | let meta = meta.exec().with_context(|| { | 158 | let mut meta = meta.exec().with_context(|| { |
159 | format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) | 159 | format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) |
160 | })?; | 160 | })?; |
161 | 161 | ||
@@ -175,6 +175,7 @@ impl CargoWorkspace { | |||
175 | 175 | ||
176 | let ws_members = &meta.workspace_members; | 176 | let ws_members = &meta.workspace_members; |
177 | 177 | ||
178 | meta.packages.sort_by(|a, b| a.id.cmp(&b.id)); | ||
178 | for meta_pkg in meta.packages { | 179 | for meta_pkg in meta.packages { |
179 | let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } = | 180 | let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } = |
180 | meta_pkg; | 181 | meta_pkg; |
@@ -210,7 +211,7 @@ impl CargoWorkspace { | |||
210 | } | 211 | } |
211 | } | 212 | } |
212 | let resolve = meta.resolve.expect("metadata executed with deps"); | 213 | let resolve = meta.resolve.expect("metadata executed with deps"); |
213 | for node in resolve.nodes { | 214 | for mut node in resolve.nodes { |
214 | let source = match pkg_by_id.get(&node.id) { | 215 | let source = match pkg_by_id.get(&node.id) { |
215 | Some(&src) => src, | 216 | Some(&src) => src, |
216 | // FIXME: replace this and a similar branch below with `.unwrap`, once | 217 | // FIXME: replace this and a similar branch below with `.unwrap`, once |
@@ -221,6 +222,7 @@ impl CargoWorkspace { | |||
221 | continue; | 222 | continue; |
222 | } | 223 | } |
223 | }; | 224 | }; |
225 | node.deps.sort_by(|a, b| a.pkg.cmp(&b.pkg)); | ||
224 | for dep_node in node.deps { | 226 | for dep_node in node.deps { |
225 | let pkg = match pkg_by_id.get(&dep_node.pkg) { | 227 | let pkg = match pkg_by_id.get(&dep_node.pkg) { |
226 | Some(&pkg) => pkg, | 228 | Some(&pkg) => pkg, |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 5d1f871c4..b9c5424bf 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -24,7 +24,7 @@ pub use crate::{ | |||
24 | }; | 24 | }; |
25 | pub use ra_proc_macro::ProcMacroClient; | 25 | pub use ra_proc_macro::ProcMacroClient; |
26 | 26 | ||
27 | #[derive(Debug, Clone)] | 27 | #[derive(Debug, Clone, Eq, PartialEq)] |
28 | pub enum ProjectWorkspace { | 28 | pub enum ProjectWorkspace { |
29 | /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. | 29 | /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. |
30 | Cargo { cargo: CargoWorkspace, sysroot: Sysroot }, | 30 | Cargo { cargo: CargoWorkspace, sysroot: Sysroot }, |
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 | ||
39 | impl ProjectJson { | 40 | impl 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/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 943ff92df..68d134da4 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -3,19 +3,19 @@ | |||
3 | use std::{convert::TryFrom, env, ops, path::Path, process::Command}; | 3 | use std::{convert::TryFrom, env, ops, path::Path, process::Command}; |
4 | 4 | ||
5 | use anyhow::{bail, format_err, Result}; | 5 | use anyhow::{bail, format_err, Result}; |
6 | use paths::{AbsPath, AbsPathBuf}; | ||
6 | use ra_arena::{Arena, Idx}; | 7 | use ra_arena::{Arena, Idx}; |
7 | 8 | ||
8 | use crate::output; | 9 | use crate::output; |
9 | use paths::{AbsPath, AbsPathBuf}; | ||
10 | 10 | ||
11 | #[derive(Default, Debug, Clone)] | 11 | #[derive(Default, Debug, Clone, Eq, PartialEq)] |
12 | pub struct Sysroot { | 12 | pub struct Sysroot { |
13 | crates: Arena<SysrootCrateData>, | 13 | crates: Arena<SysrootCrateData>, |
14 | } | 14 | } |
15 | 15 | ||
16 | pub type SysrootCrate = Idx<SysrootCrateData>; | 16 | pub type SysrootCrate = Idx<SysrootCrateData>; |
17 | 17 | ||
18 | #[derive(Debug, Clone)] | 18 | #[derive(Debug, Clone, Eq, PartialEq)] |
19 | pub struct SysrootCrateData { | 19 | pub struct SysrootCrateData { |
20 | pub name: String, | 20 | pub name: String, |
21 | pub root: AbsPathBuf, | 21 | pub root: AbsPathBuf, |
@@ -126,7 +126,6 @@ core | |||
126 | alloc | 126 | alloc |
127 | collections | 127 | collections |
128 | libc | 128 | libc |
129 | panic_unwind | ||
130 | proc_macro | 129 | proc_macro |
131 | rustc_unicode | 130 | rustc_unicode |
132 | std_unicode | 131 | std_unicode |