Not suggest type in closure parameter

This commit is contained in:
A4-Tacks 2025-10-10 12:25:24 +08:00
parent 6e85d5a47e
commit 4d08b922b7
No known key found for this signature in database
GPG key ID: DBD861323040663B

View file

@ -563,10 +563,10 @@ fn analyze<'db>(
/// Calculate the expected type and name of the cursor position.
fn expected_type_and_name<'db>(
sema: &Semantics<'db, RootDatabase>,
token: &SyntaxToken,
self_token: &SyntaxToken,
name_like: &ast::NameLike,
) -> (Option<Type<'db>>, Option<NameOrNameRef>) {
let token = prev_special_biased_token_at_trivia(token.clone());
let token = prev_special_biased_token_at_trivia(self_token.clone());
let mut node = match token.parent() {
Some(it) => it,
None => return (None, None),
@ -758,7 +758,9 @@ fn expected_type_and_name<'db>(
},
ast::ParamList(it) => {
let closure = it.syntax().parent().and_then(ast::ClosureExpr::cast);
let ty = closure.and_then(|it| sema.type_of_expr(&it.into()));
let ty = closure
.filter(|_| it.syntax().text_range().end() <= self_token.text_range().start())
.and_then(|it| sema.type_of_expr(&it.into()));
ty.and_then(|ty| ty.original.as_callable(sema.db))
.map(|c| (Some(c.return_type()), None))
.unwrap_or((None, None))