about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-05-18 15:06:46 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-05-18 15:06:46 +0200
commitf42e55dfc8378010144183f5985a7e48e9378c9a (patch)
tree2b0f02daf5f5c546ad1f6a959fcb995627f60b10
parent4b3d7f60390b73078c8614ea210196e425844368 (diff)
downloadrust-f42e55dfc8378010144183f5985a7e48e9378c9a.tar.gz
rust-f42e55dfc8378010144183f5985a7e48e9378c9a.zip
Enable linked locations for closure param inlay hints
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs
index 20e8aca8491..fb50c49a3ae 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/param_name.rs
@@ -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 =