diff options
author | Jeremy Kolb <[email protected]> | 2019-10-27 16:26:44 +0000 |
---|---|---|
committer | Jeremy Kolb <[email protected]> | 2019-10-27 16:26:44 +0000 |
commit | a0d55edc3873c7788ab2f91e394e53a5a77c16b8 (patch) | |
tree | 31b7744dedb362eefe873d799c4c2a509c4324f9 | |
parent | ad950830d0902aaacfb5a76355a203626eb93b5f (diff) |
Be more precise with function signatures
Fixes #2093
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 7d18be483..c95133343 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use ra_db::SourceDatabase; | 3 | use ra_db::SourceDatabase; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | algo::find_node_at_offset, | 5 | algo::ancestors_at_offset, |
6 | ast::{self, ArgListOwner}, | 6 | ast::{self, ArgListOwner}, |
7 | AstNode, SyntaxNode, TextUnit, | 7 | AstNode, SyntaxNode, TextUnit, |
8 | }; | 8 | }; |
@@ -82,13 +82,15 @@ enum FnCallNode { | |||
82 | 82 | ||
83 | impl FnCallNode { | 83 | impl FnCallNode { |
84 | fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option<FnCallNode> { | 84 | fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option<FnCallNode> { |
85 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { | 85 | ancestors_at_offset(syntax, offset).find_map(|node| { |
86 | return Some(FnCallNode::CallExpr(expr)); | 86 | if let Some(expr) = ast::CallExpr::cast(node.clone()) { |
87 | } | 87 | Some(FnCallNode::CallExpr(expr)) |
88 | if let Some(expr) = find_node_at_offset::<ast::MethodCallExpr>(syntax, offset) { | 88 | } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { |
89 | return Some(FnCallNode::MethodCallExpr(expr)); | 89 | Some(FnCallNode::MethodCallExpr(expr)) |
90 | } | 90 | } else { |
91 | None | 91 | None |
92 | } | ||
93 | }) | ||
92 | } | 94 | } |
93 | 95 | ||
94 | fn name_ref(&self) -> Option<ast::NameRef> { | 96 | fn name_ref(&self) -> Option<ast::NameRef> { |
@@ -438,4 +440,26 @@ By default this method stops actor's `Context`."# | |||
438 | let call_info = analysis.call_info(position).unwrap(); | 440 | let call_info = analysis.call_info(position).unwrap(); |
439 | assert!(call_info.is_none()); | 441 | assert!(call_info.is_none()); |
440 | } | 442 | } |
443 | |||
444 | #[test] | ||
445 | fn test_nested_method_in_lamba() { | ||
446 | let info = call_info( | ||
447 | r#"struct Foo; | ||
448 | |||
449 | impl Foo { | ||
450 | fn bar(&self, _: u32) { } | ||
451 | } | ||
452 | |||
453 | fn bar(_: u32) { } | ||
454 | |||
455 | fn main() { | ||
456 | let foo = Foo; | ||
457 | std::thread::spawn(move || foo.bar(<|>)); | ||
458 | }"#, | ||
459 | ); | ||
460 | |||
461 | assert_eq!(info.parameters(), ["&self", "_: u32"]); | ||
462 | assert_eq!(info.active_parameter, Some(1)); | ||
463 | assert_eq!(info.label(), "fn bar(&self, _: u32)"); | ||
464 | } | ||
441 | } | 465 | } |