Skip to content

Commit b6c2bb2

Browse files
committed
Add parentheses for binding mode hints when they attach to an Or-pattern
1 parent 632f804 commit b6c2bb2

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

crates/ide/src/inlay_hints.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ pub enum InlayKind {
6565
ClosureReturnTypeHint,
6666
GenericParamListHint,
6767
AdjustmentHint,
68-
AdjustmentHintClosingParenthesis,
6968
LifetimeHint,
7069
ParameterHint,
7170
TypeHint,
71+
OpeningParenthesis,
72+
ClosingParenthesis,
7273
}
7374

7475
#[derive(Debug)]
@@ -671,7 +672,7 @@ fn adjustment_hints(
671672
if needs_parens {
672673
acc.push(InlayHint {
673674
range: expr.syntax().text_range(),
674-
kind: InlayKind::AdjustmentHint,
675+
kind: InlayKind::OpeningParenthesis,
675676
label: "(".into(),
676677
tooltip: None,
677678
});
@@ -716,7 +717,7 @@ fn adjustment_hints(
716717
if needs_parens {
717718
acc.push(InlayHint {
718719
range: expr.syntax().text_range(),
719-
kind: InlayKind::AdjustmentHintClosingParenthesis,
720+
kind: InlayKind::ClosingParenthesis,
720721
label: ")".into(),
721722
tooltip: None,
722723
});
@@ -880,6 +881,20 @@ fn binding_mode_hints(
880881
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
881882
});
882883
}
884+
ast::Pat::OrPat(pat) => {
885+
acc.push(InlayHint {
886+
range: pat.syntax().text_range(),
887+
kind: InlayKind::OpeningParenthesis,
888+
label: "(".into(),
889+
tooltip: None,
890+
});
891+
acc.push(InlayHint {
892+
range: pat.syntax().text_range(),
893+
kind: InlayKind::ClosingParenthesis,
894+
label: ")".into(),
895+
tooltip: None,
896+
});
897+
}
883898
_ => (),
884899
}
885900

@@ -2951,9 +2966,18 @@ fn __(
29512966
(x,) => ()
29522967
}
29532968
match &(0,) {
2954-
(x,) => ()
2955-
//^^^^ &
2969+
(x,) | (x,) => (),
2970+
//^^^^^^^^^^^&
29562971
//^ ref
2972+
//^ ref
2973+
//^^^^^^^^^^^(
2974+
//^^^^^^^^^^^)
2975+
((x,) | (x,)) => (),
2976+
//^^^^^^^^^^^&
2977+
//^ ref
2978+
//^ ref
2979+
//^^^^^^^^^^^(
2980+
//^^^^^^^^^^^)
29572981
}
29582982
match &mut (0,) {
29592983
(x,) => ()

crates/rust-analyzer/src/to_proto.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -440,22 +440,24 @@ pub(crate) fn inlay_hint(
440440
Ok(lsp_types::InlayHint {
441441
position: match inlay_hint.kind {
442442
// before annotated thing
443-
InlayKind::ParameterHint | InlayKind::AdjustmentHint | InlayKind::BindingModeHint => {
444-
position(line_index, inlay_hint.range.start())
445-
}
443+
InlayKind::OpeningParenthesis
444+
| InlayKind::ParameterHint
445+
| InlayKind::AdjustmentHint
446+
| InlayKind::BindingModeHint => position(line_index, inlay_hint.range.start()),
446447
// after annotated thing
447448
InlayKind::ClosureReturnTypeHint
448449
| InlayKind::TypeHint
449450
| InlayKind::ChainingHint
450451
| InlayKind::GenericParamListHint
451-
| InlayKind::AdjustmentHintClosingParenthesis
452+
| InlayKind::ClosingParenthesis
452453
| InlayKind::LifetimeHint
453454
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
454455
},
455456
padding_left: Some(match inlay_hint.kind {
456457
InlayKind::TypeHint => !render_colons,
457458
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
458-
InlayKind::AdjustmentHintClosingParenthesis
459+
InlayKind::ClosingParenthesis
460+
| InlayKind::OpeningParenthesis
459461
| InlayKind::BindingModeHint
460462
| InlayKind::ClosureReturnTypeHint
461463
| InlayKind::GenericParamListHint
@@ -464,7 +466,8 @@ pub(crate) fn inlay_hint(
464466
| InlayKind::ParameterHint => false,
465467
}),
466468
padding_right: Some(match inlay_hint.kind {
467-
InlayKind::AdjustmentHintClosingParenthesis
469+
InlayKind::ClosingParenthesis
470+
| InlayKind::OpeningParenthesis
468471
| InlayKind::ChainingHint
469472
| InlayKind::ClosureReturnTypeHint
470473
| InlayKind::GenericParamListHint
@@ -479,7 +482,8 @@ pub(crate) fn inlay_hint(
479482
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
480483
Some(lsp_types::InlayHintKind::TYPE)
481484
}
482-
InlayKind::AdjustmentHintClosingParenthesis
485+
InlayKind::ClosingParenthesis
486+
| InlayKind::OpeningParenthesis
483487
| InlayKind::BindingModeHint
484488
| InlayKind::GenericParamListHint
485489
| InlayKind::LifetimeHint

0 commit comments

Comments
 (0)