Skip to content

Commit 3baed3e

Browse files
committed
Fix formatting of nested unit switch statements
1 parent 82e7b6f commit 3baed3e

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

corpus/unit.spicy

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ switch {
3131
};
3232
};
3333

34+
type X = unit {
35+
switch (True) {
36+
* -> {
37+
switch (True) {
38+
* -> x: uint8;
39+
};
40+
}
41+
};
42+
};
43+
3444
type X = unit{
3545
on %init {}
3646
b: uint8 {print $$;}

corpus/unit.spicy.expected

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ type X = unit {
4040
};
4141
};
4242

43+
type X = unit {
44+
switch (True) {
45+
* -> {
46+
switch (True) {
47+
* -> x: uint8;
48+
};
49+
}
50+
};
51+
};
52+
4353
type X = unit {
4454
on %init {}
4555
b: uint8 {

src/query.scm

+7-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"=" @append_antispace
6060
)
6161

62+
(struct_decl "struct" @append_space)
63+
6264
("struct"
6365
(field_decl) @append_empty_softline
6466
.
@@ -75,6 +77,10 @@
7577
"}" @prepend_indent_end @prepend_hardline
7678
)
7779

80+
(unit_switch
81+
"switch" @append_space
82+
)
83+
7884
(unit_switch_case
7985
"{" @append_indent_start @append_hardline
8086
"}" @prepend_indent_end @prepend_hardline
@@ -86,16 +92,7 @@
8692
(comment)? @do_nothing
8793
)
8894

89-
(struct_decl "struct" @append_space)
90-
91-
(unit_switch
92-
"switch" @append_space
93-
)
94-
(unit_switch
95-
(unit_switch_case) @append_hardline
96-
.
97-
(comment)? @do_nothing
98-
)
95+
(unit_switch_case) @prepend_hardline
9996
(unit_switch_case
10097
"->" @prepend_space @append_space
10198
)

0 commit comments

Comments
 (0)