Fix active parameter analysis

This commit is contained in:
Lukas Wirth 2023-02-12 10:26:19 +01:00
parent 1be24e0899
commit 33cacde04b
2 changed files with 20 additions and 6 deletions

View File

@ -380,7 +380,7 @@ fn expected_type_and_name(
sema, sema,
token.clone(), token.clone(),
).map(|ap| { ).map(|ap| {
let name = ap.ident().map(NameOrNameRef::Name); let name = dbg!(ap.ident().map(NameOrNameRef::Name));
let ty = strip_refs(ap.ty); let ty = strip_refs(ap.ty);
(Some(ty), name) (Some(ty), name)

View File

@ -3,8 +3,9 @@
use either::Either; use either::Either;
use hir::{Semantics, Type}; use hir::{Semantics, Type};
use syntax::{ use syntax::{
algo::non_trivia_sibling,
ast::{self, HasArgList, HasName}, ast::{self, HasArgList, HasName},
AstNode, SyntaxToken, AstNode, Direction, SyntaxToken, TextRange,
}; };
use crate::RootDatabase; use crate::RootDatabase;
@ -66,11 +67,24 @@ pub fn callable_for_node(
ast::CallableExpr::MethodCall(call) => sema.resolve_method_call_as_callable(call), ast::CallableExpr::MethodCall(call) => sema.resolve_method_call_as_callable(call),
}?; }?;
let active_param = if let Some(arg_list) = calling_node.arg_list() { let active_param = if let Some(arg_list) = calling_node.arg_list() {
let param = arg_list let account_for_ws = |arg: &ast::Expr| {
let node = arg.syntax().clone();
let left = non_trivia_sibling(node.clone().into(), Direction::Prev)
.and_then(|it| it.into_token())?
.text_range();
let right = non_trivia_sibling(node.into(), Direction::Next)
.and_then(|it| it.into_token())?
.text_range();
Some(TextRange::new(left.end(), right.start()))
};
arg_list
.args() .args()
.take_while(|arg| arg.syntax().text_range().end() <= token.text_range().start()) .position(|arg| {
.count(); account_for_ws(&arg)
Some(param) .unwrap_or(arg.syntax().text_range())
.contains(token.text_range().start())
})
.or(Some(0))
} else { } else {
None None
}; };