mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Add parentheses for binding mode hints when they attach to an Or-pattern
This commit is contained in:
parent
632f804797
commit
b6c2bb21ab
@ -65,10 +65,11 @@ pub enum InlayKind {
|
|||||||
ClosureReturnTypeHint,
|
ClosureReturnTypeHint,
|
||||||
GenericParamListHint,
|
GenericParamListHint,
|
||||||
AdjustmentHint,
|
AdjustmentHint,
|
||||||
AdjustmentHintClosingParenthesis,
|
|
||||||
LifetimeHint,
|
LifetimeHint,
|
||||||
ParameterHint,
|
ParameterHint,
|
||||||
TypeHint,
|
TypeHint,
|
||||||
|
OpeningParenthesis,
|
||||||
|
ClosingParenthesis,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -671,7 +672,7 @@ fn adjustment_hints(
|
|||||||
if needs_parens {
|
if needs_parens {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::AdjustmentHint,
|
kind: InlayKind::OpeningParenthesis,
|
||||||
label: "(".into(),
|
label: "(".into(),
|
||||||
tooltip: None,
|
tooltip: None,
|
||||||
});
|
});
|
||||||
@ -716,7 +717,7 @@ fn adjustment_hints(
|
|||||||
if needs_parens {
|
if needs_parens {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::AdjustmentHintClosingParenthesis,
|
kind: InlayKind::ClosingParenthesis,
|
||||||
label: ")".into(),
|
label: ")".into(),
|
||||||
tooltip: None,
|
tooltip: None,
|
||||||
});
|
});
|
||||||
@ -880,6 +881,20 @@ fn binding_mode_hints(
|
|||||||
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
|
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,) => ()
|
(x,) => ()
|
||||||
}
|
}
|
||||||
match &(0,) {
|
match &(0,) {
|
||||||
(x,) => ()
|
(x,) | (x,) => (),
|
||||||
//^^^^ &
|
//^^^^^^^^^^^&
|
||||||
//^ ref
|
//^ ref
|
||||||
|
//^ ref
|
||||||
|
//^^^^^^^^^^^(
|
||||||
|
//^^^^^^^^^^^)
|
||||||
|
((x,) | (x,)) => (),
|
||||||
|
//^^^^^^^^^^^&
|
||||||
|
//^ ref
|
||||||
|
//^ ref
|
||||||
|
//^^^^^^^^^^^(
|
||||||
|
//^^^^^^^^^^^)
|
||||||
}
|
}
|
||||||
match &mut (0,) {
|
match &mut (0,) {
|
||||||
(x,) => ()
|
(x,) => ()
|
||||||
|
@ -440,22 +440,24 @@ pub(crate) fn inlay_hint(
|
|||||||
Ok(lsp_types::InlayHint {
|
Ok(lsp_types::InlayHint {
|
||||||
position: match inlay_hint.kind {
|
position: match inlay_hint.kind {
|
||||||
// before annotated thing
|
// before annotated thing
|
||||||
InlayKind::ParameterHint | InlayKind::AdjustmentHint | InlayKind::BindingModeHint => {
|
InlayKind::OpeningParenthesis
|
||||||
position(line_index, inlay_hint.range.start())
|
| InlayKind::ParameterHint
|
||||||
}
|
| InlayKind::AdjustmentHint
|
||||||
|
| InlayKind::BindingModeHint => position(line_index, inlay_hint.range.start()),
|
||||||
// after annotated thing
|
// after annotated thing
|
||||||
InlayKind::ClosureReturnTypeHint
|
InlayKind::ClosureReturnTypeHint
|
||||||
| InlayKind::TypeHint
|
| InlayKind::TypeHint
|
||||||
| InlayKind::ChainingHint
|
| InlayKind::ChainingHint
|
||||||
| InlayKind::GenericParamListHint
|
| InlayKind::GenericParamListHint
|
||||||
| InlayKind::AdjustmentHintClosingParenthesis
|
| InlayKind::ClosingParenthesis
|
||||||
| InlayKind::LifetimeHint
|
| InlayKind::LifetimeHint
|
||||||
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
|
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
|
||||||
},
|
},
|
||||||
padding_left: Some(match inlay_hint.kind {
|
padding_left: Some(match inlay_hint.kind {
|
||||||
InlayKind::TypeHint => !render_colons,
|
InlayKind::TypeHint => !render_colons,
|
||||||
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
|
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
|
||||||
InlayKind::AdjustmentHintClosingParenthesis
|
InlayKind::ClosingParenthesis
|
||||||
|
| InlayKind::OpeningParenthesis
|
||||||
| InlayKind::BindingModeHint
|
| InlayKind::BindingModeHint
|
||||||
| InlayKind::ClosureReturnTypeHint
|
| InlayKind::ClosureReturnTypeHint
|
||||||
| InlayKind::GenericParamListHint
|
| InlayKind::GenericParamListHint
|
||||||
@ -464,7 +466,8 @@ pub(crate) fn inlay_hint(
|
|||||||
| InlayKind::ParameterHint => false,
|
| InlayKind::ParameterHint => false,
|
||||||
}),
|
}),
|
||||||
padding_right: Some(match inlay_hint.kind {
|
padding_right: Some(match inlay_hint.kind {
|
||||||
InlayKind::AdjustmentHintClosingParenthesis
|
InlayKind::ClosingParenthesis
|
||||||
|
| InlayKind::OpeningParenthesis
|
||||||
| InlayKind::ChainingHint
|
| InlayKind::ChainingHint
|
||||||
| InlayKind::ClosureReturnTypeHint
|
| InlayKind::ClosureReturnTypeHint
|
||||||
| InlayKind::GenericParamListHint
|
| InlayKind::GenericParamListHint
|
||||||
@ -479,7 +482,8 @@ pub(crate) fn inlay_hint(
|
|||||||
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
|
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
|
||||||
Some(lsp_types::InlayHintKind::TYPE)
|
Some(lsp_types::InlayHintKind::TYPE)
|
||||||
}
|
}
|
||||||
InlayKind::AdjustmentHintClosingParenthesis
|
InlayKind::ClosingParenthesis
|
||||||
|
| InlayKind::OpeningParenthesis
|
||||||
| InlayKind::BindingModeHint
|
| InlayKind::BindingModeHint
|
||||||
| InlayKind::GenericParamListHint
|
| InlayKind::GenericParamListHint
|
||||||
| InlayKind::LifetimeHint
|
| InlayKind::LifetimeHint
|
||||||
|
Loading…
Reference in New Issue
Block a user