Skip to content

Commit e69fb5e

Browse files
committed
Auto merge of #13696 - jonas-schievink:signature-help-between-closing-delims, r=jonas-schievink
fix: Fix signature help not showing up when cursor is between `))` or `>>` Fixes #13672
2 parents 3827e3d + b65b02f commit e69fb5e

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

crates/ide/src/signature_help.rs

+43-15
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,40 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio
7474
ast::ArgList(arg_list) => {
7575
let cursor_outside = arg_list.r_paren_token().as_ref() == Some(&token);
7676
if cursor_outside {
77-
return None;
77+
continue;
7878
}
79-
return signature_help_for_call(&sema, token);
79+
return signature_help_for_call(&sema, arg_list, token);
8080
},
8181
ast::GenericArgList(garg_list) => {
8282
let cursor_outside = garg_list.r_angle_token().as_ref() == Some(&token);
8383
if cursor_outside {
84-
return None;
84+
continue;
8585
}
86-
return signature_help_for_generics(&sema, token);
86+
return signature_help_for_generics(&sema, garg_list, token);
8787
},
8888
_ => (),
8989
}
9090
}
91+
92+
// Stop at multi-line expressions, since the signature of the outer call is not very
93+
// helpful inside them.
94+
if let Some(expr) = ast::Expr::cast(node.clone()) {
95+
if expr.syntax().text().contains_char('\n') {
96+
return None;
97+
}
98+
}
9199
}
92100

93101
None
94102
}
95103

96104
fn signature_help_for_call(
97105
sema: &Semantics<'_, RootDatabase>,
106+
arg_list: ast::ArgList,
98107
token: SyntaxToken,
99108
) -> Option<SignatureHelp> {
100109
// Find the calling expression and its NameRef
101-
let mut node = token.parent()?;
110+
let mut node = arg_list.syntax().parent()?;
102111
let calling_node = loop {
103112
if let Some(callable) = ast::CallableExpr::cast(node.clone()) {
104113
if callable
@@ -109,14 +118,6 @@ fn signature_help_for_call(
109118
}
110119
}
111120

112-
// Stop at multi-line expressions, since the signature of the outer call is not very
113-
// helpful inside them.
114-
if let Some(expr) = ast::Expr::cast(node.clone()) {
115-
if expr.syntax().text().contains_char('\n') {
116-
return None;
117-
}
118-
}
119-
120121
node = node.parent()?;
121122
};
122123

@@ -200,10 +201,11 @@ fn signature_help_for_call(
200201

201202
fn signature_help_for_generics(
202203
sema: &Semantics<'_, RootDatabase>,
204+
garg_list: ast::GenericArgList,
203205
token: SyntaxToken,
204206
) -> Option<SignatureHelp> {
205-
let parent = token.parent()?;
206-
let arg_list = parent
207+
let arg_list = garg_list
208+
.syntax()
207209
.ancestors()
208210
.filter_map(ast::GenericArgList::cast)
209211
.find(|list| list.syntax().text_range().contains(token.text_range().start()))?;
@@ -770,6 +772,32 @@ fn f() {
770772
"#,
771773
expect![[]],
772774
);
775+
check(
776+
r#"
777+
fn foo(a: u8) -> u8 {a}
778+
fn bar(a: u8) -> u8 {a}
779+
fn f() {
780+
foo(bar(123)$0)
781+
}
782+
"#,
783+
expect![[r#"
784+
fn foo(a: u8) -> u8
785+
^^^^^
786+
"#]],
787+
);
788+
check(
789+
r#"
790+
struct Vec<T>(T);
791+
struct Vec2<T>(T);
792+
fn f() {
793+
let _: Vec2<Vec<u8>$0>
794+
}
795+
"#,
796+
expect![[r#"
797+
struct Vec2<T>
798+
^
799+
"#]],
800+
);
773801
}
774802

775803
#[test]

0 commit comments

Comments
 (0)