Unnamed repository; edit this file 'description' to name the repository.
Add parentheses for binding mode hints when they attach to an Or-pattern
Lukas Wirth 2022-12-17
parent 632f804 · commit b6c2bb2
-rw-r--r--crates/ide/src/inlay_hints.rs34
-rw-r--r--crates/rust-analyzer/src/to_proto.rs18
2 files changed, 40 insertions, 12 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 08ce7be181..b5b4d6ca64 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -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,) => ()
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 3ce24bdd14..a7106acc78 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -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