Skip to content

Commit f7c7f89

Browse files
committed
Annotate type hints for pattern name ranges instead of the pattern itself
1 parent b363755 commit f7c7f89

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

crates/ide/src/inlay_hints.rs

+32-6
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,12 @@ fn get_bind_pat_hints(
194194
if should_not_display_type_hint(sema, &pat, &ty) {
195195
return None;
196196
}
197+
197198
acc.push(InlayHint {
198-
range: pat.syntax().text_range(),
199+
range: match pat.name() {
200+
Some(name) => name.syntax().text_range(),
201+
None => pat.syntax().text_range(),
202+
},
199203
kind: InlayKind::TypeHint,
200204
label: hint_iterator(sema, &famous_defs, config, &ty)
201205
.unwrap_or_else(|| ty.display_truncated(sema.db, config.max_length).to_string().into()),
@@ -799,6 +803,28 @@ fn main() {
799803
);
800804
}
801805

806+
#[test]
807+
fn type_hints_bindings_after_at() {
808+
check_types(
809+
r#"
810+
//- minicore: option
811+
fn main() {
812+
let ref foo @ bar @ ref mut baz = 0;
813+
//^^^ &i32
814+
//^^^ i32
815+
//^^^ &mut i32
816+
let [x @ ..] = [0];
817+
//^ [i32; 1]
818+
if let x @ Some(_) = Some(0) {}
819+
//^ Option<i32>
820+
let foo @ (bar, baz) = (3, 3);
821+
//^^^ (i32, i32)
822+
//^^^ i32
823+
//^^^ i32
824+
}"#,
825+
);
826+
}
827+
802828
#[test]
803829
fn default_generic_types_should_not_be_displayed() {
804830
check(
@@ -839,7 +865,7 @@ impl<T> Iterator for SomeIter<T> {
839865
840866
fn main() {
841867
let mut some_iter = SomeIter::new();
842-
//^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
868+
//^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
843869
some_iter.push(iter::repeat(2).take(2));
844870
let iter_of_iters = some_iter.take(2);
845871
//^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
@@ -938,7 +964,7 @@ fn main() {
938964
//^^^^ i32
939965
let test: i32 = 33;
940966
let mut test = 33;
941-
//^^^^^^^^ i32
967+
//^^^^ i32
942968
let _ = 22;
943969
let test = "test";
944970
//^^^^ &str
@@ -1048,7 +1074,7 @@ impl<T> IntoIterator for Vec<T> {
10481074
10491075
fn main() {
10501076
let mut data = Vec::new();
1051-
//^^^^^^^^ Vec<&str>
1077+
//^^^^ Vec<&str>
10521078
data.push("foo");
10531079
for i in
10541080
@@ -1076,7 +1102,7 @@ impl<T> IntoIterator for Vec<T> {
10761102
10771103
fn main() {
10781104
let mut data = Vec::new();
1079-
//^^^^^^^^ Vec<&str>
1105+
//^^^^ Vec<&str>
10801106
data.push("foo");
10811107
for i in data {
10821108
//^ &str
@@ -1153,7 +1179,7 @@ fn main() {
11531179
r#"
11541180
fn main() {
11551181
let mut start = 0;
1156-
//^^^^^^^^^ i32
1182+
//^^^^^ i32
11571183
(0..2).for_each(|increment| { start += increment; });
11581184
//^^^^^^^^^ i32
11591185

0 commit comments

Comments
 (0)