Auto merge of #13783 - Veykril:bm-hints, r=Veykril

Add parentheses for binding mode hints when they attach to an Or-pattern
This commit is contained in:
bors 2022-12-16 19:53:06 +00:00
commit 8f6d0cd1b0
2 changed files with 40 additions and 12 deletions

View File

@ -65,10 +65,11 @@ pub enum InlayKind {
ClosureReturnTypeHint,
GenericParamListHint,
AdjustmentHint,
AdjustmentHintClosingParenthesis,
LifetimeHint,
ParameterHint,
TypeHint,
OpeningParenthesis,
ClosingParenthesis,
}
#[derive(Debug)]
@ -671,7 +672,7 @@ fn adjustment_hints(
if needs_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::AdjustmentHint,
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
@ -716,7 +717,7 @@ fn adjustment_hints(
if needs_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::AdjustmentHintClosingParenthesis,
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
@ -880,6 +881,20 @@ fn binding_mode_hints(
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
});
}
ast::Pat::OrPat(pat) => {
acc.push(InlayHint {
range: pat.syntax().text_range(),
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
acc.push(InlayHint {
range: pat.syntax().text_range(),
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
}
_ => (),
}
@ -2951,9 +2966,18 @@ fn __(
(x,) => ()
}
match &(0,) {
(x,) => ()
//^^^^ &
(x,) | (x,) => (),
//^^^^^^^^^^^&
//^ ref
//^ ref
//^^^^^^^^^^^(
//^^^^^^^^^^^)
((x,) | (x,)) => (),
//^^^^^^^^^^^&
//^ ref
//^ ref
//^^^^^^^^^^^(
//^^^^^^^^^^^)
}
match &mut (0,) {
(x,) => ()

View File

@ -440,22 +440,24 @@ pub(crate) fn inlay_hint(
Ok(lsp_types::InlayHint {
position: match inlay_hint.kind {
// before annotated thing
InlayKind::ParameterHint | InlayKind::AdjustmentHint | InlayKind::BindingModeHint => {
position(line_index, inlay_hint.range.start())
}
InlayKind::OpeningParenthesis
| InlayKind::ParameterHint
| InlayKind::AdjustmentHint
| InlayKind::BindingModeHint => position(line_index, inlay_hint.range.start()),
// after annotated thing
InlayKind::ClosureReturnTypeHint
| InlayKind::TypeHint
| InlayKind::ChainingHint
| InlayKind::GenericParamListHint
| InlayKind::AdjustmentHintClosingParenthesis
| InlayKind::ClosingParenthesis
| InlayKind::LifetimeHint
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
},
padding_left: Some(match inlay_hint.kind {
InlayKind::TypeHint => !render_colons,
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
InlayKind::AdjustmentHintClosingParenthesis
InlayKind::ClosingParenthesis
| InlayKind::OpeningParenthesis
| InlayKind::BindingModeHint
| InlayKind::ClosureReturnTypeHint
| InlayKind::GenericParamListHint
@ -464,7 +466,8 @@ pub(crate) fn inlay_hint(
| InlayKind::ParameterHint => false,
}),
padding_right: Some(match inlay_hint.kind {
InlayKind::AdjustmentHintClosingParenthesis
InlayKind::ClosingParenthesis
| InlayKind::OpeningParenthesis
| InlayKind::ChainingHint
| InlayKind::ClosureReturnTypeHint
| InlayKind::GenericParamListHint
@ -479,7 +482,8 @@ pub(crate) fn inlay_hint(
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
Some(lsp_types::InlayHintKind::TYPE)
}
InlayKind::AdjustmentHintClosingParenthesis
InlayKind::ClosingParenthesis
| InlayKind::OpeningParenthesis
| InlayKind::BindingModeHint
| InlayKind::GenericParamListHint
| InlayKind::LifetimeHint