mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Fix signature help not showing up when cursor is between ))
or >>
This commit is contained in:
parent
3827e3ddf1
commit
b65b02fd97
1 changed files with 43 additions and 15 deletions
|
@ -74,20 +74,28 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio
|
||||||
ast::ArgList(arg_list) => {
|
ast::ArgList(arg_list) => {
|
||||||
let cursor_outside = arg_list.r_paren_token().as_ref() == Some(&token);
|
let cursor_outside = arg_list.r_paren_token().as_ref() == Some(&token);
|
||||||
if cursor_outside {
|
if cursor_outside {
|
||||||
return None;
|
continue;
|
||||||
}
|
}
|
||||||
return signature_help_for_call(&sema, token);
|
return signature_help_for_call(&sema, arg_list, token);
|
||||||
},
|
},
|
||||||
ast::GenericArgList(garg_list) => {
|
ast::GenericArgList(garg_list) => {
|
||||||
let cursor_outside = garg_list.r_angle_token().as_ref() == Some(&token);
|
let cursor_outside = garg_list.r_angle_token().as_ref() == Some(&token);
|
||||||
if cursor_outside {
|
if cursor_outside {
|
||||||
return None;
|
continue;
|
||||||
}
|
}
|
||||||
return signature_help_for_generics(&sema, token);
|
return signature_help_for_generics(&sema, garg_list, token);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop at multi-line expressions, since the signature of the outer call is not very
|
||||||
|
// helpful inside them.
|
||||||
|
if let Some(expr) = ast::Expr::cast(node.clone()) {
|
||||||
|
if expr.syntax().text().contains_char('\n') {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -95,10 +103,11 @@ pub(crate) fn signature_help(db: &RootDatabase, position: FilePosition) -> Optio
|
||||||
|
|
||||||
fn signature_help_for_call(
|
fn signature_help_for_call(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
|
arg_list: ast::ArgList,
|
||||||
token: SyntaxToken,
|
token: SyntaxToken,
|
||||||
) -> Option<SignatureHelp> {
|
) -> Option<SignatureHelp> {
|
||||||
// Find the calling expression and its NameRef
|
// Find the calling expression and its NameRef
|
||||||
let mut node = token.parent()?;
|
let mut node = arg_list.syntax().parent()?;
|
||||||
let calling_node = loop {
|
let calling_node = loop {
|
||||||
if let Some(callable) = ast::CallableExpr::cast(node.clone()) {
|
if let Some(callable) = ast::CallableExpr::cast(node.clone()) {
|
||||||
if callable
|
if callable
|
||||||
|
@ -109,14 +118,6 @@ fn signature_help_for_call(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop at multi-line expressions, since the signature of the outer call is not very
|
|
||||||
// helpful inside them.
|
|
||||||
if let Some(expr) = ast::Expr::cast(node.clone()) {
|
|
||||||
if expr.syntax().text().contains_char('\n') {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node = node.parent()?;
|
node = node.parent()?;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -200,10 +201,11 @@ fn signature_help_for_call(
|
||||||
|
|
||||||
fn signature_help_for_generics(
|
fn signature_help_for_generics(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
|
garg_list: ast::GenericArgList,
|
||||||
token: SyntaxToken,
|
token: SyntaxToken,
|
||||||
) -> Option<SignatureHelp> {
|
) -> Option<SignatureHelp> {
|
||||||
let parent = token.parent()?;
|
let arg_list = garg_list
|
||||||
let arg_list = parent
|
.syntax()
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.filter_map(ast::GenericArgList::cast)
|
.filter_map(ast::GenericArgList::cast)
|
||||||
.find(|list| list.syntax().text_range().contains(token.text_range().start()))?;
|
.find(|list| list.syntax().text_range().contains(token.text_range().start()))?;
|
||||||
|
@ -770,6 +772,32 @@ fn f() {
|
||||||
"#,
|
"#,
|
||||||
expect![[]],
|
expect![[]],
|
||||||
);
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo(a: u8) -> u8 {a}
|
||||||
|
fn bar(a: u8) -> u8 {a}
|
||||||
|
fn f() {
|
||||||
|
foo(bar(123)$0)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
fn foo(a: u8) -> u8
|
||||||
|
^^^^^
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Vec<T>(T);
|
||||||
|
struct Vec2<T>(T);
|
||||||
|
fn f() {
|
||||||
|
let _: Vec2<Vec<u8>$0>
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
struct Vec2<T>
|
||||||
|
^
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue