Skip to content

Commit e3d9482

Browse files
committed
Fix active parameter analysis once more
1 parent d2cf8c2 commit e3d9482

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

crates/ide-db/src/active_parameter.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
use either::Either;
44
use hir::{Semantics, Type};
5+
use parser::T;
56
use syntax::{
6-
algo::non_trivia_sibling,
77
ast::{self, HasArgList, HasName},
8-
AstNode, Direction, SyntaxToken, TextRange,
8+
AstNode, NodeOrToken, SyntaxToken,
99
};
1010

1111
use crate::RootDatabase;
@@ -59,32 +59,24 @@ pub fn callable_for_node(
5959
calling_node: &ast::CallableExpr,
6060
token: &SyntaxToken,
6161
) -> Option<(hir::Callable, Option<usize>)> {
62-
let callable = match &calling_node {
62+
let callable = match calling_node {
6363
ast::CallableExpr::Call(call) => {
6464
let expr = call.expr()?;
6565
sema.type_of_expr(&expr)?.adjusted().as_callable(sema.db)
6666
}
6767
ast::CallableExpr::MethodCall(call) => sema.resolve_method_call_as_callable(call),
6868
}?;
6969
let active_param = if let Some(arg_list) = calling_node.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
81-
.args()
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))
70+
dbg!(token);
71+
Some(
72+
arg_list
73+
.syntax()
74+
.children_with_tokens()
75+
.filter_map(NodeOrToken::into_token)
76+
.filter(|t| t.kind() == T![,])
77+
.take_while(|t| dbg!(t).text_range().start() <= token.text_range().start())
78+
.count(),
79+
)
8880
} else {
8981
None
9082
};

crates/ide/src/signature_help.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,4 +1594,27 @@ impl S {
15941594
"#]],
15951595
);
15961596
}
1597+
1598+
#[test]
1599+
fn test_enum_in_nested_method_in_lambda() {
1600+
check(
1601+
r#"
1602+
enum A {
1603+
A,
1604+
B
1605+
}
1606+
1607+
fn bar(_: A) { }
1608+
1609+
fn main() {
1610+
let foo = Foo;
1611+
std::thread::spawn(move || { bar(A:$0) } );
1612+
}
1613+
"#,
1614+
expect![[r#"
1615+
fn bar(_: A)
1616+
^^^^
1617+
"#]],
1618+
);
1619+
}
15971620
}

0 commit comments

Comments
 (0)