mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Return CallInfo for unclosed call expressions
This commit is contained in:
parent
75371eb0fa
commit
992965cd82
2 changed files with 35 additions and 2 deletions
|
@ -4,8 +4,9 @@ use either::Either;
|
|||
use hir::{HasAttrs, HirDisplay, Semantics, Type};
|
||||
use stdx::format_to;
|
||||
use syntax::{
|
||||
algo,
|
||||
ast::{self, ArgListOwner, NameOwner},
|
||||
match_ast, AstNode, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
||||
match_ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
||||
};
|
||||
|
||||
use crate::RootDatabase;
|
||||
|
@ -43,7 +44,12 @@ pub fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo>
|
|||
let sema = Semantics::new(db);
|
||||
let file = sema.parse(position.file_id);
|
||||
let file = file.syntax();
|
||||
let token = file.token_at_offset(position.offset).next()?;
|
||||
let token = file
|
||||
.token_at_offset(position.offset)
|
||||
.left_biased()
|
||||
// if the cursor is sandwiched between two space tokens and the call is unclosed
|
||||
// this prevents us from leaving the CallExpression
|
||||
.and_then(|tok| algo::skip_trivia_token(tok, Direction::Prev))?;
|
||||
let token = sema.descend_into_macros(token);
|
||||
|
||||
let (callable, active_parameter) = call_info_impl(&sema, token)?;
|
||||
|
|
|
@ -522,3 +522,30 @@ fn main(f: fn(i32, f64) -> char) {
|
|||
"#]],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_info_for_unclosed_call() {
|
||||
check(
|
||||
r#"
|
||||
fn foo(foo: u32, bar: u32) {}
|
||||
fn main() {
|
||||
foo($0
|
||||
}"#,
|
||||
expect![[r#"
|
||||
fn foo(foo: u32, bar: u32)
|
||||
(<foo: u32>, bar: u32)
|
||||
"#]],
|
||||
);
|
||||
// check with surrounding space
|
||||
check(
|
||||
r#"
|
||||
fn foo(foo: u32, bar: u32) {}
|
||||
fn main() {
|
||||
foo( $0
|
||||
}"#,
|
||||
expect![[r#"
|
||||
fn foo(foo: u32, bar: u32)
|
||||
(<foo: u32>, bar: u32)
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue