diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 26 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_analysis/src/module_map.rs | 15 | ||||
-rw-r--r-- | crates/ra_analysis/src/roots.rs | 9 |
4 files changed, 31 insertions, 29 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index d60fb8278..df5aacb2d 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -159,7 +159,7 @@ impl AnalysisImpl { | |||
159 | } | 159 | } |
160 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 160 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
161 | let root = self.root(file_id); | 161 | let root = self.root(file_id); |
162 | let module_tree = root.module_tree(); | 162 | let module_tree = root.module_tree()?; |
163 | let res = module_tree | 163 | let res = module_tree |
164 | .parent_modules(file_id) | 164 | .parent_modules(file_id) |
165 | .iter() | 165 | .iter() |
@@ -177,8 +177,8 @@ impl AnalysisImpl { | |||
177 | .collect(); | 177 | .collect(); |
178 | Ok(res) | 178 | Ok(res) |
179 | } | 179 | } |
180 | pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { | 180 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
181 | let module_tree = self.root(file_id).module_tree(); | 181 | let module_tree = self.root(file_id).module_tree()?; |
182 | let crate_graph = &self.data.crate_graph; | 182 | let crate_graph = &self.data.crate_graph; |
183 | let mut res = Vec::new(); | 183 | let mut res = Vec::new(); |
184 | let mut work = VecDeque::new(); | 184 | let mut work = VecDeque::new(); |
@@ -196,7 +196,7 @@ impl AnalysisImpl { | |||
196 | .filter(|&id| visited.insert(id)); | 196 | .filter(|&id| visited.insert(id)); |
197 | work.extend(parents); | 197 | work.extend(parents); |
198 | } | 198 | } |
199 | res | 199 | Ok(res) |
200 | } | 200 | } |
201 | pub fn crate_root(&self, crate_id: CrateId) -> FileId { | 201 | pub fn crate_root(&self, crate_id: CrateId) -> FileId { |
202 | self.data.crate_graph.crate_roots[&crate_id] | 202 | self.data.crate_graph.crate_roots[&crate_id] |
@@ -205,9 +205,9 @@ impl AnalysisImpl { | |||
205 | &self, | 205 | &self, |
206 | file_id: FileId, | 206 | file_id: FileId, |
207 | offset: TextUnit, | 207 | offset: TextUnit, |
208 | ) -> Vec<(FileId, FileSymbol)> { | 208 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
209 | let root = self.root(file_id); | 209 | let root = self.root(file_id); |
210 | let module_tree = root.module_tree(); | 210 | let module_tree = root.module_tree()?; |
211 | let file = root.syntax(file_id); | 211 | let file = root.syntax(file_id); |
212 | let syntax = file.syntax(); | 212 | let syntax = file.syntax(); |
213 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { | 213 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { |
@@ -223,10 +223,10 @@ impl AnalysisImpl { | |||
223 | }, | 223 | }, |
224 | )); | 224 | )); |
225 | 225 | ||
226 | return vec; | 226 | return Ok(vec); |
227 | } else { | 227 | } else { |
228 | // If that fails try the index based approach. | 228 | // If that fails try the index based approach. |
229 | return self.index_resolve(name_ref); | 229 | return Ok(self.index_resolve(name_ref)); |
230 | } | 230 | } |
231 | } | 231 | } |
232 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { | 232 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { |
@@ -250,11 +250,11 @@ impl AnalysisImpl { | |||
250 | }) | 250 | }) |
251 | .collect(); | 251 | .collect(); |
252 | 252 | ||
253 | return res; | 253 | return Ok(res); |
254 | } | 254 | } |
255 | } | 255 | } |
256 | } | 256 | } |
257 | vec![] | 257 | Ok(vec![]) |
258 | } | 258 | } |
259 | 259 | ||
260 | pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> { | 260 | pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> { |
@@ -289,9 +289,9 @@ impl AnalysisImpl { | |||
289 | ret | 289 | ret |
290 | } | 290 | } |
291 | 291 | ||
292 | pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { | 292 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
293 | let root = self.root(file_id); | 293 | let root = self.root(file_id); |
294 | let module_tree = root.module_tree(); | 294 | let module_tree = root.module_tree()?; |
295 | let syntax = root.syntax(file_id); | 295 | let syntax = root.syntax(file_id); |
296 | 296 | ||
297 | let mut res = ra_editor::diagnostics(&syntax) | 297 | let mut res = ra_editor::diagnostics(&syntax) |
@@ -346,7 +346,7 @@ impl AnalysisImpl { | |||
346 | }; | 346 | }; |
347 | res.push(diag) | 347 | res.push(diag) |
348 | } | 348 | } |
349 | res | 349 | Ok(res) |
350 | } | 350 | } |
351 | 351 | ||
352 | pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> { | 352 | pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> { |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 8595d7e03..6ce32894a 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -37,7 +37,7 @@ pub use ra_editor::{ | |||
37 | RunnableKind, StructureNode, | 37 | RunnableKind, StructureNode, |
38 | }; | 38 | }; |
39 | 39 | ||
40 | #[derive(Clone, Copy, Debug)] | 40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
41 | pub struct Cancel; | 41 | pub struct Cancel; |
42 | 42 | ||
43 | pub type Cancelable<T> = Result<T, Cancel>; | 43 | pub type Cancelable<T> = Result<T, Cancel>; |
@@ -231,8 +231,8 @@ impl Analysis { | |||
231 | file_id: FileId, | 231 | file_id: FileId, |
232 | offset: TextUnit | 232 | offset: TextUnit |
233 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 233 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
234 | Ok(self.imp | 234 | self.imp |
235 | .approximately_resolve_symbol(file_id, offset)) | 235 | .approximately_resolve_symbol(file_id, offset) |
236 | } | 236 | } |
237 | pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable<Vec<(FileId, TextRange)>> { | 237 | pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable<Vec<(FileId, TextRange)>> { |
238 | Ok(self.imp.find_all_refs(file_id, offset)) | 238 | Ok(self.imp.find_all_refs(file_id, offset)) |
@@ -241,7 +241,7 @@ impl Analysis { | |||
241 | self.imp.parent_module(file_id) | 241 | self.imp.parent_module(file_id) |
242 | } | 242 | } |
243 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 243 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
244 | Ok(self.imp.crate_for(file_id)) | 244 | self.imp.crate_for(file_id) |
245 | } | 245 | } |
246 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { | 246 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
247 | Ok(self.imp.crate_root(crate_id)) | 247 | Ok(self.imp.crate_root(crate_id)) |
@@ -262,7 +262,7 @@ impl Analysis { | |||
262 | Ok(self.imp.assists(file_id, range)) | 262 | Ok(self.imp.assists(file_id, range)) |
263 | } | 263 | } |
264 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 264 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { |
265 | Ok(self.imp.diagnostics(file_id)) | 265 | self.imp.diagnostics(file_id) |
266 | } | 266 | } |
267 | pub fn resolve_callable( | 267 | pub fn resolve_callable( |
268 | &self, | 268 | &self, |
diff --git a/crates/ra_analysis/src/module_map.rs b/crates/ra_analysis/src/module_map.rs index b15432498..0c413becd 100644 --- a/crates/ra_analysis/src/module_map.rs +++ b/crates/ra_analysis/src/module_map.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | Cancelable, | ||
2 | db::SyntaxDatabase, | 3 | db::SyntaxDatabase, |
3 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, | 4 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, |
4 | FileId, | 5 | FileId, |
@@ -8,30 +9,30 @@ use std::sync::Arc; | |||
8 | 9 | ||
9 | salsa::query_group! { | 10 | salsa::query_group! { |
10 | pub(crate) trait ModulesDatabase: SyntaxDatabase { | 11 | pub(crate) trait ModulesDatabase: SyntaxDatabase { |
11 | fn module_tree() -> Arc<ModuleTreeDescriptor> { | 12 | fn module_tree() -> Cancelable<Arc<ModuleTreeDescriptor>> { |
12 | type ModuleTreeQuery; | 13 | type ModuleTreeQuery; |
13 | } | 14 | } |
14 | fn module_descriptor(file_id: FileId) -> Arc<ModuleDescriptor> { | 15 | fn module_descriptor(file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> { |
15 | type ModuleDescriptorQuery; | 16 | type ModuleDescriptorQuery; |
16 | } | 17 | } |
17 | } | 18 | } |
18 | } | 19 | } |
19 | 20 | ||
20 | fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Arc<ModuleDescriptor> { | 21 | fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> { |
21 | let file = db.file_syntax(file_id); | 22 | let file = db.file_syntax(file_id); |
22 | Arc::new(ModuleDescriptor::new(file.ast())) | 23 | Ok(Arc::new(ModuleDescriptor::new(file.ast()))) |
23 | } | 24 | } |
24 | 25 | ||
25 | fn module_tree(db: &impl ModulesDatabase) -> Arc<ModuleTreeDescriptor> { | 26 | fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> { |
26 | let file_set = db.file_set(); | 27 | let file_set = db.file_set(); |
27 | let mut files = Vec::new(); | 28 | let mut files = Vec::new(); |
28 | for &file_id in file_set.files.iter() { | 29 | for &file_id in file_set.files.iter() { |
29 | let module_descr = db.module_descriptor(file_id); | 30 | let module_descr = db.module_descriptor(file_id)?; |
30 | files.push((file_id, module_descr)); | 31 | files.push((file_id, module_descr)); |
31 | } | 32 | } |
32 | let res = ModuleTreeDescriptor::new( | 33 | let res = ModuleTreeDescriptor::new( |
33 | files.iter().map(|(file_id, descr)| (*file_id, &**descr)), | 34 | files.iter().map(|(file_id, descr)| (*file_id, &**descr)), |
34 | &file_set.resolver, | 35 | &file_set.resolver, |
35 | ); | 36 | ); |
36 | Arc::new(res) | 37 | Ok(Arc::new(res)) |
37 | } | 38 | } |
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 19c84df65..e950a75e2 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs | |||
@@ -8,6 +8,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; | |||
8 | use salsa::Database; | 8 | use salsa::Database; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | Cancelable, | ||
11 | db::{self, FilesDatabase, SyntaxDatabase}, | 12 | db::{self, FilesDatabase, SyntaxDatabase}, |
12 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, | 13 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, |
13 | imp::FileResolverImp, | 14 | imp::FileResolverImp, |
@@ -18,7 +19,7 @@ use crate::{ | |||
18 | 19 | ||
19 | pub(crate) trait SourceRoot { | 20 | pub(crate) trait SourceRoot { |
20 | fn contains(&self, file_id: FileId) -> bool; | 21 | fn contains(&self, file_id: FileId) -> bool; |
21 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor>; | 22 | fn module_tree(&self) -> Cancelable<Arc<ModuleTreeDescriptor>>; |
22 | fn lines(&self, file_id: FileId) -> Arc<LineIndex>; | 23 | fn lines(&self, file_id: FileId) -> Arc<LineIndex>; |
23 | fn syntax(&self, file_id: FileId) -> File; | 24 | fn syntax(&self, file_id: FileId) -> File; |
24 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>); | 25 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>); |
@@ -64,7 +65,7 @@ impl WritableSourceRoot { | |||
64 | } | 65 | } |
65 | 66 | ||
66 | impl SourceRoot for WritableSourceRoot { | 67 | impl SourceRoot for WritableSourceRoot { |
67 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { | 68 | fn module_tree(&self) -> Cancelable<Arc<ModuleTreeDescriptor>> { |
68 | self.db.module_tree() | 69 | self.db.module_tree() |
69 | } | 70 | } |
70 | fn contains(&self, file_id: FileId) -> bool { | 71 | fn contains(&self, file_id: FileId) -> bool { |
@@ -167,8 +168,8 @@ impl ReadonlySourceRoot { | |||
167 | } | 168 | } |
168 | 169 | ||
169 | impl SourceRoot for ReadonlySourceRoot { | 170 | impl SourceRoot for ReadonlySourceRoot { |
170 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { | 171 | fn module_tree(&self) -> Cancelable<Arc<ModuleTreeDescriptor>> { |
171 | Arc::clone(&self.module_tree) | 172 | Ok(Arc::clone(&self.module_tree)) |
172 | } | 173 | } |
173 | fn contains(&self, file_id: FileId) -> bool { | 174 | fn contains(&self, file_id: FileId) -> bool { |
174 | self.file_map.contains_key(&file_id) | 175 | self.file_map.contains_key(&file_id) |