From 3a9934e2c3280864877a90c5ced777bad898d73a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 10 Feb 2019 22:34:29 +0100 Subject: Keep track of crate edition --- crates/ra_project_model/src/cargo_workspace.rs | 5 +++++ crates/ra_project_model/src/lib.rs | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'crates/ra_project_model/src') 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 { targets: Vec, is_member: bool, dependencies: Vec, + edition: String, } #[derive(Debug, Clone)] @@ -84,6 +85,9 @@ impl Package { pub fn root(self, ws: &CargoWorkspace) -> &Path { ws.packages[self].manifest.parent().unwrap() } + pub fn edition(self, ws: &CargoWorkspace) -> &str { + &ws.packages[self].edition + } pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator + 'a { ws.packages[self].targets.iter().cloned() } @@ -135,6 +139,7 @@ impl CargoWorkspace { manifest: meta_pkg.manifest_path.clone(), targets: Vec::new(), is_member, + edition: meta_pkg.edition, dependencies: Vec::new(), }); 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}; use failure::bail; use rustc_hash::FxHashMap; -use ra_db::{CrateGraph, FileId}; +use ra_db::{CrateGraph, FileId, Edition}; pub use crate::{ cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, @@ -36,7 +36,8 @@ impl ProjectWorkspace { let mut sysroot_crates = FxHashMap::default(); for krate in self.sysroot.crates() { if let Some(file_id) = load(krate.root(&self.sysroot)) { - sysroot_crates.insert(krate, crate_graph.add_crate_root(file_id)); + sysroot_crates + .insert(krate, crate_graph.add_crate_root(file_id, Edition::Edition2015)); } } for from in self.sysroot.crates() { @@ -62,7 +63,12 @@ impl ProjectWorkspace { for tgt in pkg.targets(&self.cargo) { let root = tgt.root(&self.cargo); if let Some(file_id) = load(root) { - let crate_id = crate_graph.add_crate_root(file_id); + let edition = if pkg.edition(&self.cargo) == "2015" { + Edition::Edition2015 + } else { + Edition::Edition2018 + }; + let crate_id = crate_graph.add_crate_root(file_id, edition); if tgt.kind(&self.cargo) == TargetKind::Lib { lib_tgt = Some(crate_id); pkg_to_lib_crate.insert(pkg, crate_id); -- cgit v1.2.3 From 70839b7ef8217fd019ce5bd3a643a8a16f5fa829 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 13 Feb 2019 20:31:27 +0100 Subject: Make edition handling a bit nicer and allow specifying edition in crate_graph macro --- crates/ra_project_model/src/cargo_workspace.rs | 9 +++++---- crates/ra_project_model/src/lib.rs | 6 +----- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'crates/ra_project_model/src') diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index e28aca259..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}; use ra_arena::{Arena, RawId, impl_arena_id}; use rustc_hash::FxHashMap; use failure::format_err; +use ra_db::Edition; use crate::Result; @@ -35,7 +36,7 @@ struct PackageData { targets: Vec, is_member: bool, dependencies: Vec, - edition: String, + edition: Edition, } #[derive(Debug, Clone)] @@ -85,8 +86,8 @@ impl Package { pub fn root(self, ws: &CargoWorkspace) -> &Path { ws.packages[self].manifest.parent().unwrap() } - pub fn edition(self, ws: &CargoWorkspace) -> &str { - &ws.packages[self].edition + pub fn edition(self, ws: &CargoWorkspace) -> Edition { + ws.packages[self].edition } pub fn targets<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator + 'a { ws.packages[self].targets.iter().cloned() @@ -139,7 +140,7 @@ impl CargoWorkspace { manifest: meta_pkg.manifest_path.clone(), targets: Vec::new(), is_member, - edition: meta_pkg.edition, + edition: Edition::from_string(&meta_pkg.edition), dependencies: Vec::new(), }); 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 e5c93fd85..1b18ac836 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -63,11 +63,7 @@ impl ProjectWorkspace { for tgt in pkg.targets(&self.cargo) { let root = tgt.root(&self.cargo); if let Some(file_id) = load(root) { - let edition = if pkg.edition(&self.cargo) == "2015" { - Edition::Edition2015 - } else { - Edition::Edition2018 - }; + let edition = pkg.edition(&self.cargo); let crate_id = crate_graph.add_crate_root(file_id, edition); if tgt.kind(&self.cargo) == TargetKind::Lib { lib_tgt = Some(crate_id); -- cgit v1.2.3