Enable linked locations for closure param inlay hints

This commit is contained in:
Lukas Wirth 2024-05-18 15:06:46 +02:00
parent ff79903cf6
commit 0de904d539

View file

@ -30,28 +30,23 @@ pub(super) fn hints(
.filter_map(|(p, arg)| { .filter_map(|(p, arg)| {
// Only annotate hints for expressions that exist in the original file // Only annotate hints for expressions that exist in the original file
let range = sema.original_range_opt(arg.syntax())?; let range = sema.original_range_opt(arg.syntax())?;
let (param_name, name_syntax) = match p.source(sema.db)?.value.as_ref() { let source = p.source(sema.db)?;
let (param_name, name_syntax) = match source.value.as_ref() {
Either::Left(pat) => (pat.name()?, pat.name()), Either::Left(pat) => (pat.name()?, pat.name()),
Either::Right(param) => match param.pat()? { Either::Right(param) => match param.pat()? {
ast::Pat::IdentPat(it) => (it.name()?, it.name()), ast::Pat::IdentPat(it) => (it.name()?, it.name()),
_ => return None, _ => return None,
}, },
}; };
// make sure the file is cached so we can map out of macros
sema.parse_or_expand(source.file_id);
Some((name_syntax, param_name, arg, range)) Some((name_syntax, param_name, arg, range))
}) })
.filter(|(_, param_name, arg, _)| { .filter(|(_, param_name, arg, _)| {
!should_hide_param_name_hint(sema, &callable, &param_name.text(), arg) !should_hide_param_name_hint(sema, &callable, &param_name.text(), arg)
}) })
.map(|(param, param_name, _, FileRange { range, .. })| { .map(|(param, param_name, _, FileRange { range, .. })| {
let mut linked_location = None; let linked_location = param.and_then(|name| sema.original_range_opt(name.syntax()));
if let Some(name) = param {
if let hir::CallableKind::Function(f) = callable.kind() {
// assert the file is cached so we can map out of macros
if sema.source(f).is_some() {
linked_location = sema.original_range_opt(name.syntax());
}
}
}
let colon = if config.render_colons { ":" } else { "" }; let colon = if config.render_colons { ":" } else { "" };
let label = let label =