about summary refs log tree commit diff
diff options
context:
space:
mode:
authoriDawer <ilnur.iskhakov.oss@outlook.com>2022-04-29 23:26:54 +0500
committeriDawer <ilnur.iskhakov.oss@outlook.com>2022-04-29 23:26:54 +0500
commitdffbab45f4c57868e914ea9eafa0d847220e2330 (patch)
treeb1b556a4ea013c40eff88a924ad8de31067724a1
parentd382e24a11c8706b201c8437894506d191691334 (diff)
downloadrust-dffbab45f4c57868e914ea9eafa0d847220e2330.tar.gz
rust-dffbab45f4c57868e914ea9eafa0d847220e2330.zip
Don't show signature help after closing bracket
-rw-r--r--crates/ide/src/signature_help.rs56
1 files changed, 46 insertions, 10 deletions
diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs
index 50187c933d3..57b0305fb35 100644
--- a/crates/ide/src/signature_help.rs
+++ b/crates/ide/src/signature_help.rs
@@ -8,7 +8,7 @@ use stdx::format_to;
 use syntax::{
     algo,
     ast::{self, HasArgList},
-    AstNode, Direction, SyntaxToken, TextRange, TextSize,
+    match_ast, AstNode, Direction, SyntaxToken, TextRange, TextSize,
 };
 
 use crate::RootDatabase;
@@ -66,12 +66,26 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio
         .and_then(|tok| algo::skip_trivia_token(tok, Direction::Prev))?;
     let token = sema.descend_into_macros_single(token);
 
-    if let Some(help) = signature_help_for_call(&sema, &token) {
-        return Some(help);
-    }
-
-    if let Some(help) = signature_help_for_generics(&sema, &token) {
-        return Some(help);
+    for node in token.ancestors() {
+        match_ast! {
+            match node {
+                ast::ArgList(arg_list) => {
+                    let cursor_outside = arg_list.r_paren_token().as_ref() == Some(&token);
+                    if cursor_outside {
+                        return None;
+                    }
+                    return signature_help_for_call(&sema, token);
+                },
+                ast::GenericArgList(garg_list) => {
+                    let cursor_outside = garg_list.r_angle_token().as_ref() == Some(&token);
+                    if cursor_outside {
+                        return None;
+                    }
+                    return signature_help_for_generics(&sema, token);
+                },
+                _ => (),
+            }
+        }
     }
 
     None
@@ -79,7 +93,7 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio
 
 fn signature_help_for_call(
     sema: &Semantics<RootDatabase>,
-    token: &SyntaxToken,
+    token: SyntaxToken,
 ) -> Option<SignatureHelp> {
     // Find the calling expression and its NameRef
     let mut node = token.parent()?;
@@ -104,7 +118,7 @@ fn signature_help_for_call(
         node = node.parent()?;
     };
 
-    let (callable, active_parameter) = callable_for_node(sema, &calling_node, token)?;
+    let (callable, active_parameter) = callable_for_node(sema, &calling_node, &token)?;
 
     let mut res =
         SignatureHelp { doc: None, signature: String::new(), parameters: vec![], active_parameter };
@@ -183,7 +197,7 @@ fn signature_help_for_call(
 
 fn signature_help_for_generics(
     sema: &Semantics<RootDatabase>,
-    token: &SyntaxToken,
+    token: SyntaxToken,
 ) -> Option<SignatureHelp> {
     let parent = token.parent()?;
     let arg_list = parent
@@ -692,6 +706,28 @@ fn bar() { foo $0 (3, ); }
     }
 
     #[test]
+    fn outside_of_arg_list() {
+        check(
+            r#"
+fn foo(a: u8) {}
+fn f() {
+    foo(123)$0
+}
+"#,
+            expect![[]],
+        );
+        check(
+            r#"
+fn foo<T>(a: u8) {}
+fn f() {
+    foo::<u32>$0()
+}
+"#,
+            expect![[]],
+        );
+    }
+
+    #[test]
     fn test_nested_method_in_lambda() {
         check(
             r#"