aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/imp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r--crates/ra_analysis/src/imp.rs84
1 files changed, 42 insertions, 42 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 5f67c95f6..7604c7def 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -360,52 +360,52 @@ impl db::RootDatabase {
360 // Resolve the function's NameRef (NOTE: this isn't entirely accurate). 360 // Resolve the function's NameRef (NOTE: this isn't entirely accurate).
361 let file_symbols = self.index_resolve(name_ref)?; 361 let file_symbols = self.index_resolve(name_ref)?;
362 for (fn_file_id, fs) in file_symbols { 362 for (fn_file_id, fs) in file_symbols {
363 if fs.kind == FN_DEF { 363 if fs.ptr.kind() == FN_DEF {
364 let fn_file = self.source_file(fn_file_id); 364 let fn_file = self.source_file(fn_file_id);
365 if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { 365 let fn_def = fs.ptr.resolve(&fn_file);
366 let descr = ctry!(source_binder::function_from_source( 366 let fn_def = ast::FnDef::cast(fn_def.borrowed()).unwrap();
367 self, fn_file_id, fn_def 367 let descr = ctry!(source_binder::function_from_source(
368 )?); 368 self, fn_file_id, fn_def
369 if let Some(descriptor) = descr.signature_info(self) { 369 )?);
370 // If we have a calling expression let's find which argument we are on 370 if let Some(descriptor) = descr.signature_info(self) {
371 let mut current_parameter = None; 371 // If we have a calling expression let's find which argument we are on
372 372 let mut current_parameter = None;
373 let num_params = descriptor.params.len(); 373
374 let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); 374 let num_params = descriptor.params.len();
375 375 let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
376 if num_params == 1 { 376
377 if !has_self { 377 if num_params == 1 {
378 current_parameter = Some(0); 378 if !has_self {
379 } 379 current_parameter = Some(0);
380 } else if num_params > 1 {
381 // Count how many parameters into the call we are.
382 // TODO: This is best effort for now and should be fixed at some point.
383 // It may be better to see where we are in the arg_list and then check
384 // where offset is in that list (or beyond).
385 // Revisit this after we get documentation comments in.
386 if let Some(ref arg_list) = calling_node.arg_list() {
387 let start = arg_list.syntax().range().start();
388
389 let range_search = TextRange::from_to(start, position.offset);
390 let mut commas: usize = arg_list
391 .syntax()
392 .text()
393 .slice(range_search)
394 .to_string()
395 .matches(',')
396 .count();
397
398 // If we have a method call eat the first param since it's just self.
399 if has_self {
400 commas += 1;
401 }
402
403 current_parameter = Some(commas);
404 }
405 } 380 }
381 } else if num_params > 1 {
382 // Count how many parameters into the call we are.
383 // TODO: This is best effort for now and should be fixed at some point.
384 // It may be better to see where we are in the arg_list and then check
385 // where offset is in that list (or beyond).
386 // Revisit this after we get documentation comments in.
387 if let Some(ref arg_list) = calling_node.arg_list() {
388 let start = arg_list.syntax().range().start();
389
390 let range_search = TextRange::from_to(start, position.offset);
391 let mut commas: usize = arg_list
392 .syntax()
393 .text()
394 .slice(range_search)
395 .to_string()
396 .matches(',')
397 .count();
398
399 // If we have a method call eat the first param since it's just self.
400 if has_self {
401 commas += 1;
402 }
406 403
407 return Ok(Some((descriptor, current_parameter))); 404 current_parameter = Some(commas);
405 }
408 } 406 }
407
408 return Ok(Some((descriptor, current_parameter)));
409 } 409 }
410 } 410 }
411 } 411 }