aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-10 21:34:29 +0000
committerFlorian Diebold <[email protected]>2019-02-13 19:10:46 +0000
commit3a9934e2c3280864877a90c5ced777bad898d73a (patch)
treeb37994dc169b216a2d11a11bbe91503526d9b2dd /crates/ra_project_model
parent1526eb25c98fd16a9c0d114d0ed44e8fec1cc19c (diff)
Keep track of crate edition
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs5
-rw-r--r--crates/ra_project_model/src/lib.rs12
2 files changed, 14 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 5866be519..e28aca259 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -35,6 +35,7 @@ struct PackageData {
35 targets: Vec<Target>, 35 targets: Vec<Target>,
36 is_member: bool, 36 is_member: bool,
37 dependencies: Vec<PackageDependency>, 37 dependencies: Vec<PackageDependency>,
38 edition: String,
38} 39}
39 40
40#[derive(Debug, Clone)] 41#[derive(Debug, Clone)]
@@ -84,6 +85,9 @@ impl Package {
84 pub fn root(self, ws: &CargoWorkspace) -> &Path { 85 pub fn root(self, ws: &CargoWorkspace) -> &Path {
85 ws.packages[self].manifest.parent().unwrap() 86 ws.packages[self].manifest.parent().unwrap()
86 } 87 }
88 pub fn edition(self, ws: &CargoWorkspace) -> &str {
89 &ws.packages[self].edition
90 }
87 pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a { 91 pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Target> + 'a {
88 ws.packages[self].targets.iter().cloned() 92 ws.packages[self].targets.iter().cloned()
89 } 93 }
@@ -135,6 +139,7 @@ impl CargoWorkspace {
135 manifest: meta_pkg.manifest_path.clone(), 139 manifest: meta_pkg.manifest_path.clone(),
136 targets: Vec::new(), 140 targets: Vec::new(),
137 is_member, 141 is_member,
142 edition: meta_pkg.edition,
138 dependencies: Vec::new(), 143 dependencies: Vec::new(),
139 }); 144 });
140 let pkg_data = &mut packages[pkg]; 145 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..e5c93fd85 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};
6use failure::bail; 6use failure::bail;
7use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
8 8
9use ra_db::{CrateGraph, FileId}; 9use ra_db::{CrateGraph, FileId, Edition};
10 10
11pub use crate::{ 11pub 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,12 @@ 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 = if pkg.edition(&self.cargo) == "2015" {
67 Edition::Edition2015
68 } else {
69 Edition::Edition2018
70 };
71 let crate_id = crate_graph.add_crate_root(file_id, edition);
66 if tgt.kind(&self.cargo) == TargetKind::Lib { 72 if tgt.kind(&self.cargo) == TargetKind::Lib {
67 lib_tgt = Some(crate_id); 73 lib_tgt = Some(crate_id);
68 pkg_to_lib_crate.insert(pkg, crate_id); 74 pkg_to_lib_crate.insert(pkg, crate_id);