Skip to content

Commit

Permalink
Enable linked locations for closure param inlay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed May 18, 2024
1 parent 4b3d7f6 commit f42e55d
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,23 @@ pub(super) fn hints(
.filter_map(|(p, arg)| {
// Only annotate hints for expressions that exist in the original file
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::Right(param) => match param.pat()? {
ast::Pat::IdentPat(it) => (it.name()?, it.name()),
_ => 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))
})
.filter(|(_, param_name, arg, _)| {
!should_hide_param_name_hint(sema, &callable, &param_name.text(), arg)
})
.map(|(param, param_name, _, FileRange { range, .. })| {
let mut linked_location = None;
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 linked_location = param.and_then(|name| sema.original_range_opt(name.syntax()));

let colon = if config.render_colons { ":" } else { "" };
let label =
Expand Down

0 comments on commit f42e55d

Please sign in to comment.