aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/imp.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-20 20:29:26 +0100
committerAleksey Kladov <[email protected]>2018-10-20 20:29:26 +0100
commit71cbdddf1c6b6c34c05aea01b92bb8a105b32c71 (patch)
tree1b7a83d15a344afa81e3b1169ffcd10fe2defc92 /crates/ra_analysis/src/imp.rs
parente74bf6e56e45a26002ef2a77fb3ac27f523277fb (diff)
make file-symbols query cancelable
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r--crates/ra_analysis/src/imp.rs39
1 files changed, 23 insertions, 16 deletions
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();