diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 18 | ||||
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 13 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 9 |
4 files changed, 24 insertions, 18 deletions
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml index 5d7915fa5..ff56a3c34 100644 --- a/crates/ra_analysis/Cargo.toml +++ b/crates/ra_analysis/Cargo.toml | |||
@@ -11,7 +11,7 @@ rayon = "1.0.2" | |||
11 | fst = "0.3.1" | 11 | fst = "0.3.1" |
12 | ra_syntax = { path = "../ra_syntax" } | 12 | ra_syntax = { path = "../ra_syntax" } |
13 | ra_editor = { path = "../ra_editor" } | 13 | ra_editor = { path = "../ra_editor" } |
14 | salsa = "0.6.2" | 14 | salsa = "0.6.1" |
15 | rustc-hash = "1.0" | 15 | rustc-hash = "1.0" |
16 | 16 | ||
17 | [dev-dependencies] | 17 | [dev-dependencies] |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 703938cf9..af7894cd0 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -15,9 +15,9 @@ mod completion; | |||
15 | use std::{ | 15 | use std::{ |
16 | fmt, | 16 | fmt, |
17 | sync::Arc, | 17 | sync::Arc, |
18 | collections::BTreeMap, | ||
19 | }; | 18 | }; |
20 | 19 | ||
20 | use rustc_hash::FxHashMap; | ||
21 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; | 21 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; |
22 | use relative_path::{RelativePath, RelativePathBuf}; | 22 | use relative_path::{RelativePath, RelativePathBuf}; |
23 | use rayon::prelude::*; | 23 | use rayon::prelude::*; |
@@ -55,9 +55,21 @@ pub struct FileId(pub u32); | |||
55 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 55 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
56 | pub struct CrateId(pub u32); | 56 | pub struct CrateId(pub u32); |
57 | 57 | ||
58 | #[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] | 58 | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
59 | pub struct CrateGraph { | 59 | pub struct CrateGraph { |
60 | pub crate_roots: BTreeMap<CrateId, FileId>, | 60 | crate_roots: FxHashMap<CrateId, FileId>, |
61 | } | ||
62 | |||
63 | impl CrateGraph { | ||
64 | pub fn new() -> CrateGraph { | ||
65 | CrateGraph::default() | ||
66 | } | ||
67 | pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{ | ||
68 | let crate_id = CrateId(self.crate_roots.len() as u32); | ||
69 | let prev = self.crate_roots.insert(crate_id, file_id); | ||
70 | assert!(prev.is_none()); | ||
71 | crate_id | ||
72 | } | ||
61 | } | 73 | } |
62 | 74 | ||
63 | pub trait FileResolver: fmt::Debug + Send + Sync + 'static { | 75 | pub trait FileResolver: fmt::Debug + Send + Sync + 'static { |
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 198d6a263..806e1fb34 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -7,7 +7,6 @@ extern crate test_utils; | |||
7 | 7 | ||
8 | use std::{ | 8 | use std::{ |
9 | sync::Arc, | 9 | sync::Arc, |
10 | collections::BTreeMap, | ||
11 | }; | 10 | }; |
12 | 11 | ||
13 | use ra_syntax::TextRange; | 12 | use ra_syntax::TextRange; |
@@ -130,19 +129,17 @@ fn test_resolve_crate_root() { | |||
130 | let snap = host.analysis(); | 129 | let snap = host.analysis(); |
131 | assert!(snap.crate_for(FileId(2)).unwrap().is_empty()); | 130 | assert!(snap.crate_for(FileId(2)).unwrap().is_empty()); |
132 | 131 | ||
133 | let crate_graph = CrateGraph { | 132 | let crate_graph = { |
134 | crate_roots: { | 133 | let mut g = CrateGraph::new(); |
135 | let mut m = BTreeMap::default(); | 134 | g.add_crate_root(FileId(1)); |
136 | m.insert(CrateId(1), FileId(1)); | 135 | g |
137 | m | ||
138 | }, | ||
139 | }; | 136 | }; |
140 | let mut change = AnalysisChange::new(); | 137 | let mut change = AnalysisChange::new(); |
141 | change.set_crate_graph(crate_graph); | 138 | change.set_crate_graph(crate_graph); |
142 | host.apply_change(change); | 139 | host.apply_change(change); |
143 | let snap = host.analysis(); | 140 | let snap = host.analysis(); |
144 | 141 | ||
145 | assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(1)],); | 142 | assert_eq!(snap.crate_for(FileId(2)).unwrap(), vec![CrateId(0)],); |
146 | } | 143 | } |
147 | 144 | ||
148 | #[test] | 145 | #[test] |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 555de66ff..25986e230 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -2,11 +2,10 @@ use std::{ | |||
2 | fs, | 2 | fs, |
3 | path::{Path, PathBuf}, | 3 | path::{Path, PathBuf}, |
4 | sync::Arc, | 4 | sync::Arc, |
5 | collections::BTreeMap, | ||
6 | }; | 5 | }; |
7 | 6 | ||
8 | use languageserver_types::Url; | 7 | use languageserver_types::Url; |
9 | use ra_analysis::{Analysis, AnalysisHost, AnalysisChange, CrateGraph, CrateId, FileId, FileResolver, LibraryData}; | 8 | use ra_analysis::{Analysis, AnalysisHost, AnalysisChange, CrateGraph, FileId, FileResolver, LibraryData}; |
10 | use rustc_hash::FxHashMap; | 9 | use rustc_hash::FxHashMap; |
11 | 10 | ||
12 | use crate::{ | 11 | use crate::{ |
@@ -149,7 +148,7 @@ impl ServerWorldState { | |||
149 | Ok(file_id) | 148 | Ok(file_id) |
150 | } | 149 | } |
151 | pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) { | 150 | pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) { |
152 | let mut crate_roots = BTreeMap::default(); | 151 | let mut crate_graph = CrateGraph::new(); |
153 | ws.iter() | 152 | ws.iter() |
154 | .flat_map(|ws| { | 153 | .flat_map(|ws| { |
155 | ws.packages() | 154 | ws.packages() |
@@ -158,11 +157,9 @@ impl ServerWorldState { | |||
158 | }) | 157 | }) |
159 | .for_each(|root| { | 158 | .for_each(|root| { |
160 | if let Some(file_id) = self.path_map.get_id(root) { | 159 | if let Some(file_id) = self.path_map.get_id(root) { |
161 | let crate_id = CrateId(crate_roots.len() as u32); | 160 | crate_graph.add_crate_root(file_id); |
162 | crate_roots.insert(crate_id, file_id); | ||
163 | } | 161 | } |
164 | }); | 162 | }); |
165 | let crate_graph = CrateGraph { crate_roots }; | ||
166 | self.workspaces = Arc::new(ws); | 163 | self.workspaces = Arc::new(ws); |
167 | let mut change = AnalysisChange::new(); | 164 | let mut change = AnalysisChange::new(); |
168 | change.set_crate_graph(crate_graph); | 165 | change.set_crate_graph(crate_graph); |