aboutsummaryrefslogtreecommitdiff
path: root/crates
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
parent1526eb25c98fd16a9c0d114d0ed44e8fec1cc19c (diff)
Keep track of crate edition
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/input.rs31
-rw-r--r--crates/ra_db/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs5
-rw-r--r--crates/ra_ide_api/src/lib.rs3
-rw-r--r--crates/ra_ide_api/src/mock_analysis.rs6
-rw-r--r--crates/ra_ide_api/tests/test/main.rs4
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs5
-rw-r--r--crates/ra_project_model/src/lib.rs12
8 files changed, 44 insertions, 24 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 8decc65c5..76998ea30 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -56,15 +56,22 @@ pub struct CyclicDependencies;
56#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 56#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
57pub struct CrateId(pub u32); 57pub struct CrateId(pub u32);
58 58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
60pub enum Edition {
61 Edition2018,
62 Edition2015,
63}
64
59#[derive(Debug, Clone, PartialEq, Eq)] 65#[derive(Debug, Clone, PartialEq, Eq)]
60struct CrateData { 66struct CrateData {
61 file_id: FileId, 67 file_id: FileId,
68 edition: Edition,
62 dependencies: Vec<Dependency>, 69 dependencies: Vec<Dependency>,
63} 70}
64 71
65impl CrateData { 72impl CrateData {
66 fn new(file_id: FileId) -> CrateData { 73 fn new(file_id: FileId, edition: Edition) -> CrateData {
67 CrateData { file_id, dependencies: Vec::new() } 74 CrateData { file_id, edition, dependencies: Vec::new() }
68 } 75 }
69 76
70 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { 77 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
@@ -85,9 +92,9 @@ impl Dependency {
85} 92}
86 93
87impl CrateGraph { 94impl CrateGraph {
88 pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId { 95 pub fn add_crate_root(&mut self, file_id: FileId, edition: Edition) -> CrateId {
89 let crate_id = CrateId(self.arena.len() as u32); 96 let crate_id = CrateId(self.arena.len() as u32);
90 let prev = self.arena.insert(crate_id, CrateData::new(file_id)); 97 let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition));
91 assert!(prev.is_none()); 98 assert!(prev.is_none());
92 crate_id 99 crate_id
93 } 100 }
@@ -159,14 +166,14 @@ impl CrateGraph {
159 166
160#[cfg(test)] 167#[cfg(test)]
161mod tests { 168mod tests {
162 use super::{CrateGraph, FileId, SmolStr}; 169 use super::{CrateGraph, FileId, SmolStr, Edition::Edition2018};
163 170
164 #[test] 171 #[test]
165 fn it_should_painc_because_of_cycle_dependencies() { 172 fn it_should_panic_because_of_cycle_dependencies() {
166 let mut graph = CrateGraph::default(); 173 let mut graph = CrateGraph::default();
167 let crate1 = graph.add_crate_root(FileId(1u32)); 174 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018);
168 let crate2 = graph.add_crate_root(FileId(2u32)); 175 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018);
169 let crate3 = graph.add_crate_root(FileId(3u32)); 176 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018);
170 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); 177 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
171 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); 178 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
172 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err()); 179 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err());
@@ -175,9 +182,9 @@ mod tests {
175 #[test] 182 #[test]
176 fn it_works() { 183 fn it_works() {
177 let mut graph = CrateGraph::default(); 184 let mut graph = CrateGraph::default();
178 let crate1 = graph.add_crate_root(FileId(1u32)); 185 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018);
179 let crate2 = graph.add_crate_root(FileId(2u32)); 186 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018);
180 let crate3 = graph.add_crate_root(FileId(3u32)); 187 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018);
181 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); 188 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
182 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); 189 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
183 } 190 }
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index 31442713d..e006c6d27 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -14,7 +14,7 @@ pub use ::salsa as salsa;
14pub use crate::{ 14pub use crate::{
15 cancellation::Canceled, 15 cancellation::Canceled,
16 input::{ 16 input::{
17 FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, 17 FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, Edition,
18 }, 18 },
19 loc2id::LocationIntener, 19 loc2id::LocationIntener,
20}; 20};
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 5ca870867..145ed39a1 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -3,6 +3,7 @@ use std::{sync::Arc, panic};
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use ra_db::{ 4use ra_db::{
5 FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa, 5 FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa,
6 Edition,
6}; 7};
7use relative_path::RelativePathBuf; 8use relative_path::RelativePathBuf;
8use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; 9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
@@ -60,7 +61,7 @@ impl MockDatabase {
60 let mut crate_graph = CrateGraph::default(); 61 let mut crate_graph = CrateGraph::default();
61 for (crate_name, (crate_root, _)) in graph.0.iter() { 62 for (crate_name, (crate_root, _)) in graph.0.iter() {
62 let crate_root = self.file_id_of(&crate_root); 63 let crate_root = self.file_id_of(&crate_root);
63 let crate_id = crate_graph.add_crate_root(crate_root); 64 let crate_id = crate_graph.add_crate_root(crate_root, Edition::Edition2018);
64 ids.insert(crate_name, crate_id); 65 ids.insert(crate_name, crate_id);
65 } 66 }
66 for (crate_name, (_, deps)) in graph.0.iter() { 67 for (crate_name, (_, deps)) in graph.0.iter() {
@@ -144,7 +145,7 @@ impl MockDatabase {
144 145
145 if is_crate_root { 146 if is_crate_root {
146 let mut crate_graph = CrateGraph::default(); 147 let mut crate_graph = CrateGraph::default();
147 crate_graph.add_crate_root(file_id); 148 crate_graph.add_crate_root(file_id, Edition::Edition2018);
148 self.set_crate_graph(Arc::new(crate_graph)); 149 self.set_crate_graph(Arc::new(crate_graph));
149 } 150 }
150 file_id 151 file_id
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index de3ec4e0a..d77a56ce8 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -62,7 +62,8 @@ pub use ra_ide_api_light::{
62 LineIndex, LineCol, translate_offset_with_edit, 62 LineIndex, LineCol, translate_offset_with_edit,
63}; 63};
64pub use ra_db::{ 64pub use ra_db::{
65 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId 65 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId,
66 Edition
66}; 67};
67pub use hir::Documentation; 68pub use hir::Documentation;
68 69
diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs
index 017ac5de3..550d69641 100644
--- a/crates/ra_ide_api/src/mock_analysis.rs
+++ b/crates/ra_ide_api/src/mock_analysis.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3use relative_path::RelativePathBuf; 3use relative_path::RelativePathBuf;
4use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; 4use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
5 5
6use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId}; 6use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId, Edition::Edition2018};
7 7
8/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis 8/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
9/// from a set of in-memory files. 9/// from a set of in-memory files.
@@ -89,9 +89,9 @@ impl MockAnalysis {
89 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 89 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
90 let file_id = FileId(i as u32 + 1); 90 let file_id = FileId(i as u32 + 1);
91 if path == "/lib.rs" || path == "/main.rs" { 91 if path == "/lib.rs" || path == "/main.rs" {
92 root_crate = Some(crate_graph.add_crate_root(file_id)); 92 root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018));
93 } else if path.ends_with("/lib.rs") { 93 } else if path.ends_with("/lib.rs") {
94 let other_crate = crate_graph.add_crate_root(file_id); 94 let other_crate = crate_graph.add_crate_root(file_id, Edition2018);
95 let crate_name = path.parent().unwrap().file_name().unwrap(); 95 let crate_name = path.parent().unwrap().file_name().unwrap();
96 if let Some(root_crate) = root_crate { 96 if let Some(root_crate) = root_crate {
97 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); 97 crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap();
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs
index 4cf842452..0526f7584 100644
--- a/crates/ra_ide_api/tests/test/main.rs
+++ b/crates/ra_ide_api/tests/test/main.rs
@@ -1,7 +1,7 @@
1use insta::assert_debug_snapshot_matches; 1use insta::assert_debug_snapshot_matches;
2use ra_ide_api::{ 2use ra_ide_api::{
3 mock_analysis::{single_file, single_file_with_position, MockAnalysis}, 3 mock_analysis::{single_file, single_file_with_position, MockAnalysis},
4 AnalysisChange, CrateGraph, FileId, Query, NavigationTarget, 4 AnalysisChange, CrateGraph, Edition::Edition2018, FileId, Query, NavigationTarget
5}; 5};
6use ra_syntax::{TextRange, SmolStr}; 6use ra_syntax::{TextRange, SmolStr};
7 7
@@ -36,7 +36,7 @@ fn test_resolve_crate_root() {
36 assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); 36 assert!(host.analysis().crate_for(mod_file).unwrap().is_empty());
37 37
38 let mut crate_graph = CrateGraph::default(); 38 let mut crate_graph = CrateGraph::default();
39 let crate_id = crate_graph.add_crate_root(root_file); 39 let crate_id = crate_graph.add_crate_root(root_file, Edition2018);
40 let mut change = AnalysisChange::new(); 40 let mut change = AnalysisChange::new();
41 change.set_crate_graph(crate_graph); 41 change.set_crate_graph(crate_graph);
42 host.apply_change(change); 42 host.apply_change(change);
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);