fix: add location links for type, const, and lifetime parameters in inlay hints

This commit is contained in:
benodiwal 2026-01-03 01:58:48 +05:30
parent 1222bbf29c
commit 3114decb04
No known key found for this signature in database
GPG key ID: 5A94FC71DED69DBC
2 changed files with 95 additions and 1 deletions

View file

@ -692,7 +692,9 @@ impl<'db> HirDisplay<'db> for Const<'db> {
ConstKind::Param(param) => {
let generics = generics(f.db, param.id.parent());
let param_data = &generics[param.id.local_id()];
f.start_location_link_generic(param.id.into());
write!(f, "{}", param_data.name().unwrap().display(f.db, f.edition()))?;
f.end_location_link();
Ok(())
}
ConstKind::Value(const_bytes) => render_const_scalar(
@ -2041,7 +2043,9 @@ impl<'db> HirDisplay<'db> for Region<'db> {
RegionKind::ReEarlyParam(param) => {
let generics = generics(f.db, param.id.parent);
let param_data = &generics[param.id.local_id];
f.start_location_link_generic(param.id.into());
write!(f, "{}", param_data.name.display(f.db, f.edition()))?;
f.end_location_link();
Ok(())
}
RegionKind::ReBound(BoundVarIndexKind::Bound(db), idx) => {

View file

@ -1258,7 +1258,7 @@ where
}
#[test]
fn generic_param_inlay_hint_has_location_link() {
fn type_param_inlay_hint_has_location_link() {
check_expect(
InlayHintsConfig { type_hints: true, ..DISABLED_CONFIG },
r#"
@ -1292,4 +1292,94 @@ fn identity<T>(t: T) -> T {
"#]],
);
}
#[test]
fn const_param_inlay_hint_has_location_link() {
check_expect(
InlayHintsConfig { type_hints: true, ..DISABLED_CONFIG },
r#"
fn f<const N: usize>() {
let x = [0; N];
}
"#,
expect![[r#"
[
(
33..34,
[
"[i32; ",
InlayHintLabelPart {
text: "N",
linked_location: Some(
Computed(
FileRangeWrapper {
file_id: FileId(
0,
),
range: 11..12,
},
),
),
tooltip: "",
},
"]",
],
),
]
"#]],
);
}
#[test]
fn lifetime_param_inlay_hint_has_location_link() {
check_expect(
InlayHintsConfig { type_hints: true, ..DISABLED_CONFIG },
r#"
struct S<'lt>(*mut &'lt ());
fn f<'a>() {
let x = S::<'a>(loop {});
}
"#,
expect![[r#"
[
(
51..52,
[
InlayHintLabelPart {
text: "S",
linked_location: Some(
Computed(
FileRangeWrapper {
file_id: FileId(
0,
),
range: 7..8,
},
),
),
tooltip: "",
},
"<",
InlayHintLabelPart {
text: "'a",
linked_location: Some(
Computed(
FileRangeWrapper {
file_id: FileId(
0,
),
range: 35..37,
},
),
),
tooltip: "",
},
">",
],
),
]
"#]],
);
}
}