about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-12-16 20:52:31 +0100
committerLukas Wirth <lukastw97@gmail.com>2022-12-16 20:52:31 +0100
commitb6c2bb21ab54a84a05163fcb0fce87b540c4ed1e (patch)
tree2462292e60f21dde576a045181f5c207ab5e094a
parent632f80479763b325b396ac6633cad5235379a47d (diff)
downloadrust-b6c2bb21ab54a84a05163fcb0fce87b540c4ed1e.tar.gz
rust-b6c2bb21ab54a84a05163fcb0fce87b540c4ed1e.zip
Add parentheses for binding mode hints when they attach to an Or-pattern
-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 08ce7be1811..b5b4d6ca64f 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 3ce24bdd14f..a7106acc78b 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