diff options
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 8 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 8adf463a6..81cb506b7 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -4,6 +4,7 @@ use cargo_metadata::{MetadataCommand, CargoOpt}; | |||
4 | use ra_arena::{Arena, RawId, impl_arena_id}; | 4 | use ra_arena::{Arena, RawId, impl_arena_id}; |
5 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
6 | use failure::format_err; | 6 | use failure::format_err; |
7 | use ra_db::Edition; | ||
7 | 8 | ||
8 | use crate::Result; | 9 | use crate::Result; |
9 | 10 | ||
@@ -12,7 +13,7 @@ use crate::Result; | |||
12 | /// | 13 | /// |
13 | /// Note that internally, rust analyzer uses a different structure: | 14 | /// Note that internally, rust analyzer uses a different structure: |
14 | /// `CrateGraph`. `CrateGraph` is lower-level: it knows only about the crates, | 15 | /// `CrateGraph`. `CrateGraph` is lower-level: it knows only about the crates, |
15 | /// while this knows about `Pacakges` & `Targets`: purely cargo-related | 16 | /// while this knows about `Packages` & `Targets`: purely cargo-related |
16 | /// concepts. | 17 | /// concepts. |
17 | #[derive(Debug, Clone)] | 18 | #[derive(Debug, Clone)] |
18 | pub struct CargoWorkspace { | 19 | pub struct CargoWorkspace { |
@@ -35,6 +36,7 @@ struct PackageData { | |||
35 | targets: Vec<Target>, | 36 | targets: Vec<Target>, |
36 | is_member: bool, | 37 | is_member: bool, |
37 | dependencies: Vec<PackageDependency>, | 38 | dependencies: Vec<PackageDependency>, |
39 | edition: Edition, | ||
38 | } | 40 | } |
39 | 41 | ||
40 | #[derive(Debug, Clone)] | 42 | #[derive(Debug, Clone)] |
@@ -84,6 +86,9 @@ impl Package { | |||
84 | pub fn root(self, ws: &CargoWorkspace) -> &Path { | 86 | pub fn root(self, ws: &CargoWorkspace) -> &Path { |
85 | ws.packages[self].manifest.parent().unwrap() | 87 | ws.packages[self].manifest.parent().unwrap() |
86 | } | 88 | } |
89 | pub fn edition(self, ws: &CargoWorkspace) -> Edition { | ||
90 | ws.packages[self].edition | ||
91 | } | ||
87 | pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a { | 92 | pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a { |
88 | ws.packages[self].targets.iter().cloned() | 93 | ws.packages[self].targets.iter().cloned() |
89 | } | 94 | } |
@@ -135,6 +140,7 @@ impl CargoWorkspace { | |||
135 | manifest: meta_pkg.manifest_path.clone(), | 140 | manifest: meta_pkg.manifest_path.clone(), |
136 | targets: Vec::new(), | 141 | targets: Vec::new(), |
137 | is_member, | 142 | is_member, |
143 | edition: Edition::from_string(&meta_pkg.edition), | ||
138 | dependencies: Vec::new(), | 144 | dependencies: Vec::new(), |
139 | }); | 145 | }); |
140 | let pkg_data = &mut packages[pkg]; | 146 | let pkg_data = &mut packages[pkg]; |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 3b1e07149..1b18ac836 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; | |||
6 | use failure::bail; | 6 | use failure::bail; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | 8 | ||
9 | use ra_db::{CrateGraph, FileId}; | 9 | use ra_db::{CrateGraph, FileId, Edition}; |
10 | 10 | ||
11 | pub use crate::{ | 11 | pub use crate::{ |
12 | cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, | 12 | cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, |
@@ -36,7 +36,8 @@ impl ProjectWorkspace { | |||
36 | let mut sysroot_crates = FxHashMap::default(); | 36 | let mut sysroot_crates = FxHashMap::default(); |
37 | for krate in self.sysroot.crates() { | 37 | for krate in self.sysroot.crates() { |
38 | if let Some(file_id) = load(krate.root(&self.sysroot)) { | 38 | if let Some(file_id) = load(krate.root(&self.sysroot)) { |
39 | sysroot_crates.insert(krate, crate_graph.add_crate_root(file_id)); | 39 | sysroot_crates |
40 | .insert(krate, crate_graph.add_crate_root(file_id, Edition::Edition2015)); | ||
40 | } | 41 | } |
41 | } | 42 | } |
42 | for from in self.sysroot.crates() { | 43 | for from in self.sysroot.crates() { |
@@ -62,7 +63,8 @@ impl ProjectWorkspace { | |||
62 | for tgt in pkg.targets(&self.cargo) { | 63 | for tgt in pkg.targets(&self.cargo) { |
63 | let root = tgt.root(&self.cargo); | 64 | let root = tgt.root(&self.cargo); |
64 | if let Some(file_id) = load(root) { | 65 | if let Some(file_id) = load(root) { |
65 | let crate_id = crate_graph.add_crate_root(file_id); | 66 | let edition = pkg.edition(&self.cargo); |
67 | let crate_id = crate_graph.add_crate_root(file_id, edition); | ||
66 | if tgt.kind(&self.cargo) == TargetKind::Lib { | 68 | if tgt.kind(&self.cargo) == TargetKind::Lib { |
67 | lib_tgt = Some(crate_id); | 69 | lib_tgt = Some(crate_id); |
68 | pkg_to_lib_crate.insert(pkg, crate_id); | 70 | pkg_to_lib_crate.insert(pkg, crate_id); |