diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 24 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 39 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/roots.rs | 21 |
4 files changed, 48 insertions, 40 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index cce959669..d621b3b22 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs | |||
@@ -1,17 +1,19 @@ | |||
1 | use crate::{ | 1 | use std::{ |
2 | module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase}, | 2 | fmt, |
3 | symbol_index::SymbolIndex, | 3 | hash::{Hash, Hasher}, |
4 | FileId, FileResolverImp, | 4 | sync::Arc, |
5 | }; | 5 | }; |
6 | |||
6 | use ra_editor::LineIndex; | 7 | use ra_editor::LineIndex; |
7 | use ra_syntax::File; | 8 | use ra_syntax::File; |
8 | use rustc_hash::FxHashSet; | 9 | use rustc_hash::FxHashSet; |
9 | use salsa; | 10 | use salsa; |
10 | 11 | ||
11 | use std::{ | 12 | use crate::{ |
12 | fmt, | 13 | Cancelable, |
13 | hash::{Hash, Hasher}, | 14 | module_map::{ModuleDescriptorQuery, ModuleTreeQuery, ModulesDatabase}, |
14 | sync::Arc, | 15 | symbol_index::SymbolIndex, |
16 | FileId, FileResolverImp, | ||
15 | }; | 17 | }; |
16 | 18 | ||
17 | #[derive(Default)] | 19 | #[derive(Default)] |
@@ -98,7 +100,7 @@ salsa::query_group! { | |||
98 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { | 100 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { |
99 | type FileLinesQuery; | 101 | type FileLinesQuery; |
100 | } | 102 | } |
101 | fn file_symbols(file_id: FileId) -> Arc<SymbolIndex> { | 103 | fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { |
102 | type FileSymbolsQuery; | 104 | type FileSymbolsQuery; |
103 | } | 105 | } |
104 | } | 106 | } |
@@ -112,7 +114,7 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { | |||
112 | let text = db.file_text(file_id); | 114 | let text = db.file_text(file_id); |
113 | Arc::new(LineIndex::new(&*text)) | 115 | Arc::new(LineIndex::new(&*text)) |
114 | } | 116 | } |
115 | fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<SymbolIndex> { | 117 | fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { |
116 | let syntax = db.file_syntax(file_id); | 118 | let syntax = db.file_syntax(file_id); |
117 | Arc::new(SymbolIndex::for_file(file_id, syntax)) | 119 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) |
118 | } | 120 | } |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index df5aacb2d..32e9bb6d7 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -148,14 +148,16 @@ impl AnalysisImpl { | |||
148 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { | 148 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { |
149 | self.root(file_id).lines(file_id) | 149 | self.root(file_id).lines(file_id) |
150 | } | 150 | } |
151 | pub fn world_symbols(&self, query: Query) -> Vec<(FileId, FileSymbol)> { | 151 | pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
152 | let mut buf = Vec::new(); | 152 | let mut buf = Vec::new(); |
153 | if query.libs { | 153 | if query.libs { |
154 | self.data.libs.iter().for_each(|it| it.symbols(&mut buf)); | 154 | for lib in self.data.libs.iter() { |
155 | lib.symbols(&mut buf)?; | ||
156 | } | ||
155 | } else { | 157 | } else { |
156 | self.data.root.symbols(&mut buf); | 158 | self.data.root.symbols(&mut buf)?; |
157 | } | 159 | } |
158 | query.search(&buf) | 160 | Ok(query.search(&buf)) |
159 | } | 161 | } |
160 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 162 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
161 | let root = self.root(file_id); | 163 | let root = self.root(file_id); |
@@ -212,7 +214,7 @@ impl AnalysisImpl { | |||
212 | let syntax = file.syntax(); | 214 | let syntax = file.syntax(); |
213 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { | 215 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { |
214 | // First try to resolve the symbol locally | 216 | // First try to resolve the symbol locally |
215 | if let Some((name, range)) = resolve_local_name(&file, offset, name_ref) { | 217 | return if let Some((name, range)) = resolve_local_name(&file, offset, name_ref) { |
216 | let mut vec = vec![]; | 218 | let mut vec = vec![]; |
217 | vec.push(( | 219 | vec.push(( |
218 | file_id, | 220 | file_id, |
@@ -222,12 +224,11 @@ impl AnalysisImpl { | |||
222 | kind: NAME, | 224 | kind: NAME, |
223 | }, | 225 | }, |
224 | )); | 226 | )); |
225 | 227 | Ok(vec) | |
226 | return Ok(vec); | ||
227 | } else { | 228 | } else { |
228 | // If that fails try the index based approach. | 229 | // If that fails try the index based approach. |
229 | return Ok(self.index_resolve(name_ref)); | 230 | self.index_resolve(name_ref) |
230 | } | 231 | }; |
231 | } | 232 | } |
232 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { | 233 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { |
233 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 234 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
@@ -379,17 +380,23 @@ impl AnalysisImpl { | |||
379 | &self, | 380 | &self, |
380 | file_id: FileId, | 381 | file_id: FileId, |
381 | offset: TextUnit, | 382 | offset: TextUnit, |
382 | ) -> Option<(FnDescriptor, Option<usize>)> { | 383 | ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { |
383 | let root = self.root(file_id); | 384 | let root = self.root(file_id); |
384 | let file = root.syntax(file_id); | 385 | let file = root.syntax(file_id); |
385 | let syntax = file.syntax(); | 386 | let syntax = file.syntax(); |
386 | 387 | ||
387 | // Find the calling expression and it's NameRef | 388 | // Find the calling expression and it's NameRef |
388 | let calling_node = FnCallNode::with_node(syntax, offset)?; | 389 | let calling_node = match FnCallNode::with_node(syntax, offset) { |
389 | let name_ref = calling_node.name_ref()?; | 390 | Some(node) => node, |
391 | None => return Ok(None), | ||
392 | }; | ||
393 | let name_ref = match calling_node.name_ref() { | ||
394 | Some(name) => name, | ||
395 | None => return Ok(None), | ||
396 | }; | ||
390 | 397 | ||
391 | // Resolve the function's NameRef (NOTE: this isn't entirely accurate). | 398 | // Resolve the function's NameRef (NOTE: this isn't entirely accurate). |
392 | let file_symbols = self.index_resolve(name_ref); | 399 | let file_symbols = self.index_resolve(name_ref)?; |
393 | for (_, fs) in file_symbols { | 400 | for (_, fs) in file_symbols { |
394 | if fs.kind == FN_DEF { | 401 | if fs.kind == FN_DEF { |
395 | if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { | 402 | if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { |
@@ -431,16 +438,16 @@ impl AnalysisImpl { | |||
431 | } | 438 | } |
432 | } | 439 | } |
433 | 440 | ||
434 | return Some((descriptor, current_parameter)); | 441 | return Ok(Some((descriptor, current_parameter))); |
435 | } | 442 | } |
436 | } | 443 | } |
437 | } | 444 | } |
438 | } | 445 | } |
439 | 446 | ||
440 | None | 447 | Ok(None) |
441 | } | 448 | } |
442 | 449 | ||
443 | fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> { | 450 | fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
444 | let name = name_ref.text(); | 451 | let name = name_ref.text(); |
445 | let mut query = Query::new(name.to_string()); | 452 | let mut query = Query::new(name.to_string()); |
446 | query.exact(); | 453 | query.exact(); |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 6ce32894a..189dbd9c2 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -224,7 +224,7 @@ impl Analysis { | |||
224 | ra_editor::folding_ranges(&file) | 224 | ra_editor::folding_ranges(&file) |
225 | } | 225 | } |
226 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 226 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
227 | Ok(self.imp.world_symbols(query)) | 227 | self.imp.world_symbols(query) |
228 | } | 228 | } |
229 | pub fn approximately_resolve_symbol( | 229 | pub fn approximately_resolve_symbol( |
230 | &self, | 230 | &self, |
@@ -269,7 +269,7 @@ impl Analysis { | |||
269 | file_id: FileId, | 269 | file_id: FileId, |
270 | offset: TextUnit, | 270 | offset: TextUnit, |
271 | ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { | 271 | ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { |
272 | Ok(self.imp.resolve_callable(file_id, offset)) | 272 | self.imp.resolve_callable(file_id, offset) |
273 | } | 273 | } |
274 | } | 274 | } |
275 | 275 | ||
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index e950a75e2..123c4acfa 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs | |||
@@ -22,7 +22,7 @@ pub(crate) trait SourceRoot { | |||
22 | fn module_tree(&self) -> Cancelable<Arc<ModuleTreeDescriptor>>; | 22 | fn module_tree(&self) -> Cancelable<Arc<ModuleTreeDescriptor>>; |
23 | fn lines(&self, file_id: FileId) -> Arc<LineIndex>; | 23 | fn lines(&self, file_id: FileId) -> Arc<LineIndex>; |
24 | fn syntax(&self, file_id: FileId) -> File; | 24 | fn syntax(&self, file_id: FileId) -> File; |
25 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>); | 25 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>; |
26 | } | 26 | } |
27 | 27 | ||
28 | #[derive(Default, Debug, Clone)] | 28 | #[derive(Default, Debug, Clone)] |
@@ -77,14 +77,12 @@ impl SourceRoot for WritableSourceRoot { | |||
77 | fn syntax(&self, file_id: FileId) -> File { | 77 | fn syntax(&self, file_id: FileId) -> File { |
78 | self.db.file_syntax(file_id) | 78 | self.db.file_syntax(file_id) |
79 | } | 79 | } |
80 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { | 80 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> { |
81 | let db = &self.db; | 81 | for &file_id in self.db.file_set().files.iter() { |
82 | let symbols = db.file_set(); | 82 | let symbols = self.db.file_symbols(file_id)?; |
83 | let symbols = symbols | 83 | acc.push(symbols) |
84 | .files | 84 | } |
85 | .iter() | 85 | Ok(()) |
86 | .map(|&file_id| db.file_symbols(file_id)); | ||
87 | acc.extend(symbols); | ||
88 | } | 86 | } |
89 | } | 87 | } |
90 | 88 | ||
@@ -180,7 +178,8 @@ impl SourceRoot for ReadonlySourceRoot { | |||
180 | fn syntax(&self, file_id: FileId) -> File { | 178 | fn syntax(&self, file_id: FileId) -> File { |
181 | self.data(file_id).syntax().clone() | 179 | self.data(file_id).syntax().clone() |
182 | } | 180 | } |
183 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) { | 181 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> { |
184 | acc.push(Arc::clone(&self.symbol_index)) | 182 | acc.push(Arc::clone(&self.symbol_index)); |
183 | Ok(()) | ||
185 | } | 184 | } |
186 | } | 185 | } |