diff options
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 942b5b945..fe1dfefea 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -210,7 +210,7 @@ impl AnalysisImpl { | |||
210 | let syntax = file.syntax(); | 210 | let syntax = file.syntax(); |
211 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 211 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
212 | if let Some(fn_descr) = | 212 | if let Some(fn_descr) = |
213 | hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref) | 213 | hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref)? |
214 | { | 214 | { |
215 | let scope = fn_descr.scope(&*self.db); | 215 | let scope = fn_descr.scope(&*self.db); |
216 | // First try to resolve the symbol locally | 216 | // First try to resolve the symbol locally |
@@ -257,11 +257,11 @@ impl AnalysisImpl { | |||
257 | Ok(vec![]) | 257 | Ok(vec![]) |
258 | } | 258 | } |
259 | 259 | ||
260 | pub fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { | 260 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
261 | let file = self.db.source_file(position.file_id); | 261 | let file = self.db.source_file(position.file_id); |
262 | // Find the binding associated with the offset | 262 | // Find the binding associated with the offset |
263 | let (binding, descr) = match find_binding(&self.db, &file, position) { | 263 | let (binding, descr) = match find_binding(&self.db, &file, position)? { |
264 | None => return Vec::new(), | 264 | None => return Ok(Vec::new()), |
265 | Some(it) => it, | 265 | Some(it) => it, |
266 | }; | 266 | }; |
267 | 267 | ||
@@ -274,25 +274,36 @@ impl AnalysisImpl { | |||
274 | .map(|ref_desc| (position.file_id, ref_desc.range)), | 274 | .map(|ref_desc| (position.file_id, ref_desc.range)), |
275 | ); | 275 | ); |
276 | 276 | ||
277 | return ret; | 277 | return Ok(ret); |
278 | 278 | ||
279 | fn find_binding<'a>( | 279 | fn find_binding<'a>( |
280 | db: &db::RootDatabase, | 280 | db: &db::RootDatabase, |
281 | source_file: &'a SourceFileNode, | 281 | source_file: &'a SourceFileNode, |
282 | position: FilePosition, | 282 | position: FilePosition, |
283 | ) -> Option<(ast::BindPat<'a>, hir::Function)> { | 283 | ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { |
284 | let syntax = source_file.syntax(); | 284 | let syntax = source_file.syntax(); |
285 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | 285 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { |
286 | let descr = hir::Function::guess_for_bind_pat(db, position.file_id, binding)?; | 286 | let descr = ctry!(hir::Function::guess_for_bind_pat( |
287 | return Some((binding, descr)); | 287 | db, |
288 | position.file_id, | ||
289 | binding | ||
290 | )?); | ||
291 | return Ok(Some((binding, descr))); | ||
288 | }; | 292 | }; |
289 | let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?; | 293 | let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); |
290 | let descr = hir::Function::guess_for_name_ref(db, position.file_id, name_ref)?; | 294 | let descr = ctry!(hir::Function::guess_for_name_ref( |
295 | db, | ||
296 | position.file_id, | ||
297 | name_ref | ||
298 | )?); | ||
291 | let scope = descr.scope(db); | 299 | let scope = descr.scope(db); |
292 | let resolved = scope.resolve_local_name(name_ref)?; | 300 | let resolved = ctry!(scope.resolve_local_name(name_ref)); |
293 | let resolved = resolved.ptr().resolve(source_file); | 301 | let resolved = resolved.ptr().resolve(source_file); |
294 | let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?; | 302 | let binding = ctry!(find_node_at_offset::<ast::BindPat>( |
295 | Some((binding, descr)) | 303 | syntax, |
304 | resolved.range().end() | ||
305 | )); | ||
306 | Ok(Some((binding, descr))) | ||
296 | } | 307 | } |
297 | } | 308 | } |
298 | 309 | ||
@@ -408,7 +419,9 @@ impl AnalysisImpl { | |||
408 | if fs.kind == FN_DEF { | 419 | if fs.kind == FN_DEF { |
409 | let fn_file = self.db.source_file(fn_file_id); | 420 | let fn_file = self.db.source_file(fn_file_id); |
410 | if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { | 421 | if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { |
411 | let descr = hir::Function::guess_from_source(&*self.db, fn_file_id, fn_def); | 422 | let descr = ctry!(hir::Function::guess_from_source( |
423 | &*self.db, fn_file_id, fn_def | ||
424 | )?); | ||
412 | if let Some(descriptor) = descr.signature_info(&*self.db) { | 425 | if let Some(descriptor) = descr.signature_info(&*self.db) { |
413 | // If we have a calling expression let's find which argument we are on | 426 | // If we have a calling expression let's find which argument we are on |
414 | let mut current_parameter = None; | 427 | let mut current_parameter = None; |