aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-28 11:53:16 +0000
committerGitHub <[email protected]>2019-10-28 11:53:16 +0000
commit02828520a75f686d044cb9767572ea49e93c4828 (patch)
treec976d1e2346b59a4c7f29f673fc170196132afea /crates
parentd9cbffe8a0fa3c05763719f2b6a72fec119fd12e (diff)
parenta0d55edc3873c7788ab2f91e394e53a5a77c16b8 (diff)
Merge #2097
2097: Be more precise with function signatures r=matklad a=kjeremy Finds the closest call expr. Fixes #2093 Co-authored-by: Jeremy Kolb <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/call_info.rs40
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
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_syntax::{ 4use 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
83impl FnCallNode { 83impl 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
449impl Foo {
450 fn bar(&self, _: u32) { }
451}
452
453fn bar(_: u32) { }
454
455fn 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}