diff options
author | Jeremy A. Kolb <[email protected]> | 2018-10-12 12:54:57 +0100 |
---|---|---|
committer | Jeremy A. Kolb <[email protected]> | 2018-10-12 12:54:57 +0100 |
commit | c9909f42ba4adf55b1e73e7118b48f1b10c80ac6 (patch) | |
tree | 66f565a193434bb219bcd2bc55df5f8a198c0d90 /crates/ra_analysis/src/imp.rs | |
parent | 3ac51997558c1904a56b0992f8f37f30b3aee1ee (diff) |
A FnDescriptor shouldn't exist without a name
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 9e3ae2b03..aad54b977 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -321,47 +321,45 @@ impl AnalysisImpl { | |||
321 | for (_, fs) in file_symbols { | 321 | for (_, fs) in file_symbols { |
322 | if fs.kind == FN_DEF { | 322 | if fs.kind == FN_DEF { |
323 | if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { | 323 | if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { |
324 | let descriptor = FnDescriptor::new(fn_def); | 324 | if let Some(descriptor) = FnDescriptor::new(fn_def) { |
325 | 325 | // If we have a calling expression let's find which argument we are on | |
326 | // If we have a calling expression let's find which argument we are on | 326 | let mut current_parameter = None; |
327 | let mut current_parameter = None; | 327 | |
328 | 328 | let num_params = descriptor.params.len(); | |
329 | let num_params = descriptor.params.len(); | 329 | let has_self = fn_def.param_list() |
330 | let has_self = fn_def.param_list() | 330 | .and_then(|l| l.self_param()) |
331 | .and_then(|l| l.self_param()) | 331 | .is_some(); |
332 | .is_some(); | 332 | |
333 | 333 | if num_params == 1 { | |
334 | 334 | if !has_self { | |
335 | if num_params == 1 { | 335 | current_parameter = Some(1); |
336 | if !has_self { | 336 | } |
337 | current_parameter = Some(1); | 337 | } else if num_params > 1 { |
338 | } | 338 | // Count how many parameters into the call we are. |
339 | } | 339 | // TODO: This is best effort for now and should be fixed at some point. |
340 | else if num_params > 1 { | 340 | // It may be better to see where we are in the arg_list and then check |
341 | // Count how many parameters into the call we are. | 341 | // where offset is in that list (or beyond). |
342 | // TODO: This is best effort for now and should be fixed at some point. | 342 | // Revisit this after we get documentation comments in. |
343 | // It may be better to see where we are in the arg_list and then check | 343 | if let Some(ref arg_list) = calling_node.arg_list() { |
344 | // where offset is in that list (or beyond). | 344 | let start = arg_list.syntax().range().start(); |
345 | // Revisit this after we get documentation comments in. | 345 | |
346 | if let Some(ref arg_list) = calling_node.arg_list() { | 346 | let range_search = TextRange::from_to(start, offset); |
347 | let start = arg_list.syntax().range().start(); | 347 | let mut commas: usize = arg_list.syntax().text() |
348 | 348 | .slice(range_search).to_string() | |
349 | let range_search = TextRange::from_to(start, offset); | 349 | .matches(",") |
350 | let mut commas : usize = arg_list.syntax().text() | 350 | .count(); |
351 | .slice(range_search).to_string() | 351 | |
352 | .matches(",") | 352 | // If we have a method call eat the first param since it's just self. |
353 | .count(); | 353 | if has_self { |
354 | 354 | commas = commas + 1; | |
355 | // If we have a method call eat the first param since it's just self. | 355 | } |
356 | if has_self { | 356 | |
357 | commas = commas + 1; | 357 | current_parameter = Some(commas); |
358 | } | 358 | } |
359 | |||
360 | current_parameter = Some(commas); | ||
361 | } | 359 | } |
362 | } | ||
363 | 360 | ||
364 | return Some((descriptor, current_parameter)); | 361 | return Some((descriptor, current_parameter)); |
362 | } | ||
365 | } | 363 | } |
366 | } | 364 | } |
367 | } | 365 | } |