mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
Adjust binding mode inlay hints to render better with @ patterns
This commit is contained in:
parent
23fc596e40
commit
5859190066
1 changed files with 27 additions and 2 deletions
|
@ -29,8 +29,17 @@ pub(super) fn hints(
|
|||
_ => None,
|
||||
})
|
||||
.last();
|
||||
let range =
|
||||
outer_paren_pat.as_ref().map_or_else(|| pat.syntax(), |it| it.syntax()).text_range();
|
||||
let range = outer_paren_pat.as_ref().map_or_else(
|
||||
|| match pat {
|
||||
// for ident patterns that @ bind a name, render the un-ref patterns in front of the inner pattern
|
||||
// instead of the name as that makes it more clear and doesn't really change the outcome
|
||||
ast::Pat::IdentPat(it) => {
|
||||
it.pat().map_or_else(|| it.syntax().text_range(), |it| it.syntax().text_range())
|
||||
}
|
||||
it => it.syntax().text_range(),
|
||||
},
|
||||
|it| it.syntax().text_range(),
|
||||
);
|
||||
let pattern_adjustments = sema.pattern_adjustments(pat);
|
||||
pattern_adjustments.iter().for_each(|ty| {
|
||||
let reference = ty.is_reference();
|
||||
|
@ -123,4 +132,20 @@ fn __(
|
|||
}"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hints_binding_modes_complex_ident_pat() {
|
||||
check_with_config(
|
||||
InlayHintsConfig { binding_mode_hints: true, ..DISABLED_CONFIG },
|
||||
r#"
|
||||
struct Struct {
|
||||
field: &'static str,
|
||||
}
|
||||
fn foo(s @ Struct { field, .. }: &Struct) {}
|
||||
//^^^^^^^^^^^^^^^^^^^^^^^^ref
|
||||
//^^^^^^^^^^^^^^^^^^^^&
|
||||
//^^^^^ref
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue