Skip to content

Commit cc12d9d

Browse files
committed
Auto merge of rust-lang#12120 - iDawer:ide.sig_help, r=Veykril
fix: Don't show signature help after closing bracket Stop showing signature help after closing angle/round brackets. Fixes rust-lang#11624
2 parents b0d092b + dffbab4 commit cc12d9d

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

crates/ide/src/signature_help.rs

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use stdx::format_to;
88
use syntax::{
99
algo,
1010
ast::{self, HasArgList},
11-
AstNode, Direction, SyntaxToken, TextRange, TextSize,
11+
match_ast, AstNode, Direction, SyntaxToken, TextRange, TextSize,
1212
};
1313

1414
use crate::RootDatabase;
@@ -66,20 +66,34 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio
6666
.and_then(|tok| algo::skip_trivia_token(tok, Direction::Prev))?;
6767
let token = sema.descend_into_macros_single(token);
6868

69-
if let Some(help) = signature_help_for_call(&sema, &token) {
70-
return Some(help);
71-
}
72-
73-
if let Some(help) = signature_help_for_generics(&sema, &token) {
74-
return Some(help);
69+
for node in token.ancestors() {
70+
match_ast! {
71+
match node {
72+
ast::ArgList(arg_list) => {
73+
let cursor_outside = arg_list.r_paren_token().as_ref() == Some(&token);
74+
if cursor_outside {
75+
return None;
76+
}
77+
return signature_help_for_call(&sema, token);
78+
},
79+
ast::GenericArgList(garg_list) => {
80+
let cursor_outside = garg_list.r_angle_token().as_ref() == Some(&token);
81+
if cursor_outside {
82+
return None;
83+
}
84+
return signature_help_for_generics(&sema, token);
85+
},
86+
_ => (),
87+
}
88+
}
7589
}
7690

7791
None
7892
}
7993

8094
fn signature_help_for_call(
8195
sema: &Semantics<RootDatabase>,
82-
token: &SyntaxToken,
96+
token: SyntaxToken,
8397
) -> Option<SignatureHelp> {
8498
// Find the calling expression and its NameRef
8599
let mut node = token.parent()?;
@@ -104,7 +118,7 @@ fn signature_help_for_call(
104118
node = node.parent()?;
105119
};
106120

107-
let (callable, active_parameter) = callable_for_node(sema, &calling_node, token)?;
121+
let (callable, active_parameter) = callable_for_node(sema, &calling_node, &token)?;
108122

109123
let mut res =
110124
SignatureHelp { doc: None, signature: String::new(), parameters: vec![], active_parameter };
@@ -183,7 +197,7 @@ fn signature_help_for_call(
183197

184198
fn signature_help_for_generics(
185199
sema: &Semantics<RootDatabase>,
186-
token: &SyntaxToken,
200+
token: SyntaxToken,
187201
) -> Option<SignatureHelp> {
188202
let parent = token.parent()?;
189203
let arg_list = parent
@@ -691,6 +705,28 @@ fn bar() { foo $0 (3, ); }
691705
);
692706
}
693707

708+
#[test]
709+
fn outside_of_arg_list() {
710+
check(
711+
r#"
712+
fn foo(a: u8) {}
713+
fn f() {
714+
foo(123)$0
715+
}
716+
"#,
717+
expect![[]],
718+
);
719+
check(
720+
r#"
721+
fn foo<T>(a: u8) {}
722+
fn f() {
723+
foo::<u32>$0()
724+
}
725+
"#,
726+
expect![[]],
727+
);
728+
}
729+
694730
#[test]
695731
fn test_nested_method_in_lambda() {
696732
check(

0 commit comments

Comments
 (0)