Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 33cacde

Browse files
committed
Fix active parameter analysis
1 parent 1be24e0 commit 33cacde

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

crates/ide-completion/src/context/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn expected_type_and_name(
380380
sema,
381381
token.clone(),
382382
).map(|ap| {
383-
let name = ap.ident().map(NameOrNameRef::Name);
383+
let name = dbg!(ap.ident().map(NameOrNameRef::Name));
384384

385385
let ty = strip_refs(ap.ty);
386386
(Some(ty), name)

crates/ide-db/src/active_parameter.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
use either::Either;
44
use hir::{Semantics, Type};
55
use syntax::{
6+
algo::non_trivia_sibling,
67
ast::{self, HasArgList, HasName},
7-
AstNode, SyntaxToken,
8+
AstNode, Direction, SyntaxToken, TextRange,
89
};
910

1011
use crate::RootDatabase;
@@ -66,11 +67,24 @@ pub fn callable_for_node(
6667
ast::CallableExpr::MethodCall(call) => sema.resolve_method_call_as_callable(call),
6768
}?;
6869
let active_param = if let Some(arg_list) = calling_node.arg_list() {
69-
let param = arg_list
70+
let account_for_ws = |arg: &ast::Expr| {
71+
let node = arg.syntax().clone();
72+
let left = non_trivia_sibling(node.clone().into(), Direction::Prev)
73+
.and_then(|it| it.into_token())?
74+
.text_range();
75+
let right = non_trivia_sibling(node.into(), Direction::Next)
76+
.and_then(|it| it.into_token())?
77+
.text_range();
78+
Some(TextRange::new(left.end(), right.start()))
79+
};
80+
arg_list
7081
.args()
71-
.take_while(|arg| arg.syntax().text_range().end() <= token.text_range().start())
72-
.count();
73-
Some(param)
82+
.position(|arg| {
83+
account_for_ws(&arg)
84+
.unwrap_or(arg.syntax().text_range())
85+
.contains(token.text_range().start())
86+
})
87+
.or(Some(0))
7488
} else {
7589
None
7690
};

0 commit comments

Comments
 (0)