Skip to content

Commit 992965c

Browse files
committed
Return CallInfo for unclosed call expressions
1 parent 75371eb commit 992965c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

crates/ide_db/src/call_info.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use either::Either;
44
use hir::{HasAttrs, HirDisplay, Semantics, Type};
55
use stdx::format_to;
66
use syntax::{
7+
algo,
78
ast::{self, ArgListOwner, NameOwner},
8-
match_ast, AstNode, SyntaxNode, SyntaxToken, TextRange, TextSize,
9+
match_ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize,
910
};
1011

1112
use crate::RootDatabase;
@@ -43,7 +44,12 @@ pub fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo>
4344
let sema = Semantics::new(db);
4445
let file = sema.parse(position.file_id);
4546
let file = file.syntax();
46-
let token = file.token_at_offset(position.offset).next()?;
47+
let token = file
48+
.token_at_offset(position.offset)
49+
.left_biased()
50+
// if the cursor is sandwiched between two space tokens and the call is unclosed
51+
// this prevents us from leaving the CallExpression
52+
.and_then(|tok| algo::skip_trivia_token(tok, Direction::Prev))?;
4753
let token = sema.descend_into_macros(token);
4854

4955
let (callable, active_parameter) = call_info_impl(&sema, token)?;

crates/ide_db/src/call_info/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,30 @@ fn main(f: fn(i32, f64) -> char) {
522522
"#]],
523523
)
524524
}
525+
526+
#[test]
527+
fn call_info_for_unclosed_call() {
528+
check(
529+
r#"
530+
fn foo(foo: u32, bar: u32) {}
531+
fn main() {
532+
foo($0
533+
}"#,
534+
expect![[r#"
535+
fn foo(foo: u32, bar: u32)
536+
(<foo: u32>, bar: u32)
537+
"#]],
538+
);
539+
// check with surrounding space
540+
check(
541+
r#"
542+
fn foo(foo: u32, bar: u32) {}
543+
fn main() {
544+
foo( $0
545+
}"#,
546+
expect![[r#"
547+
fn foo(foo: u32, bar: u32)
548+
(<foo: u32>, bar: u32)
549+
"#]],
550+
)
551+
}

0 commit comments

Comments
 (0)