Skip to content

Commit 9ad9ee9

Browse files
committed
Support value for case statements
1 parent 9e7988a commit 9ad9ee9

File tree

12 files changed

+411
-11
lines changed

12 files changed

+411
-11
lines changed

src/languages/java.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,24 @@ const nodeMatchers: Partial<
110110
"method_declaration.identifier!",
111111
"constructor_declaration.identifier!",
112112
],
113-
value: leadingMatcher(
114-
[
115-
"*[declarator][value]",
116-
"assignment_expression[right]",
117-
"return_statement[0]",
118-
"*[value]",
119-
],
120-
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="],
113+
value: cascadingMatcher(
114+
leadingMatcher(
115+
[
116+
"*[declarator][value]",
117+
"assignment_expression[right]",
118+
"return_statement[0]",
119+
"*[value]",
120+
],
121+
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="],
122+
),
123+
matcher(
124+
patternFinder("switch_block_statement_group"),
125+
childRangeSelector(["switch_label"], []),
126+
),
127+
matcher(
128+
patternFinder("switch_rule"),
129+
childRangeSelector(["switch_label"], []),
130+
),
121131
),
122132
condition: cascadingMatcher(
123133
conditionMatcher("while_statement[condition]"),

src/languages/python.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const nodeMatchers: Partial<
139139
],
140140
),
141141
patternMatcher("return_statement.~return!"),
142+
patternMatcher("case_clause[consequence]"),
142143
),
143144
argumentOrParameter: cascadingMatcher(
144145
argumentMatcher("parameters", "argument_list"),

src/languages/scala.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ const nodeMatchers: Partial<
6565
],
6666
[":"],
6767
),
68-
value: leadingMatcher(
69-
["*[value]", "*[default_value]", "type_definition[type]"],
70-
["="],
68+
value: cascadingMatcher(
69+
patternMatcher("case_clause[body]"),
70+
leadingMatcher(
71+
["*[value]", "*[default_value]", "type_definition[type]"],
72+
["="],
73+
),
7174
),
7275
condition: cascadingMatcher(
7376
conditionMatcher("*[condition]"),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
languageId: java
2+
command:
3+
spokenForm: clear value
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: value}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
class Aaa {
15+
static void bbb() {
16+
switch ("0") {
17+
case ("0"):
18+
break;
19+
case ("1"):
20+
break;
21+
}
22+
}
23+
}
24+
selections:
25+
- anchor: {line: 3, character: 9}
26+
active: {line: 3, character: 9}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
class Aaa {
31+
static void bbb() {
32+
switch ("0") {
33+
case ("0"):
34+
35+
case ("1"):
36+
break;
37+
}
38+
}
39+
}
40+
selections:
41+
- anchor: {line: 4, character: 8}
42+
active: {line: 4, character: 8}
43+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
languageId: java
2+
command:
3+
spokenForm: clear value
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: value}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
class Aaa {
15+
static void bbb() {
16+
switch ("0") {
17+
case ("0"):
18+
break;
19+
case ("1"):
20+
break;
21+
}
22+
}
23+
}
24+
selections:
25+
- anchor: {line: 4, character: 11}
26+
active: {line: 4, character: 11}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
class Aaa {
31+
static void bbb() {
32+
switch ("0") {
33+
case ("0"):
34+
35+
case ("1"):
36+
break;
37+
}
38+
}
39+
}
40+
selections:
41+
- anchor: {line: 4, character: 8}
42+
active: {line: 4, character: 8}
43+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: java
2+
command:
3+
spokenForm: clear value
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: value}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
class Aaa {
15+
static void bbb() {
16+
var s =
17+
switch ("0") {
18+
case "0" -> "zero";
19+
case "1" -> "one";
20+
};
21+
}
22+
}
23+
selections:
24+
- anchor: {line: 4, character: 14}
25+
active: {line: 4, character: 14}
26+
marks: {}
27+
finalState:
28+
documentContents: |-
29+
class Aaa {
30+
static void bbb() {
31+
var s =
32+
switch ("0") {
33+
case "0" ->
34+
case "1" -> "one";
35+
};
36+
}
37+
}
38+
selections:
39+
- anchor: {line: 4, character: 20}
40+
active: {line: 4, character: 20}
41+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: java
2+
command:
3+
spokenForm: clear value
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: value}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
class Aaa {
15+
static void bbb() {
16+
var s =
17+
switch ("0") {
18+
case "0" -> "zero";
19+
case "1" -> "one";
20+
};
21+
}
22+
}
23+
selections:
24+
- anchor: {line: 4, character: 23}
25+
active: {line: 4, character: 23}
26+
marks: {}
27+
finalState:
28+
documentContents: |-
29+
class Aaa {
30+
static void bbb() {
31+
var s =
32+
switch ("0") {
33+
case "0" ->
34+
case "1" -> "one";
35+
};
36+
}
37+
}
38+
selections:
39+
- anchor: {line: 4, character: 20}
40+
active: {line: 4, character: 20}
41+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
languageId: python
2+
command:
3+
spokenForm: change value blue each
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: blue, character: e}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: value}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
match command.split():
16+
case ["quit"]:
17+
print("quit")
18+
case ["go", direction] | []:
19+
print("going", direction)
20+
case ["drop", *objects]:
21+
print("drop", objects)
22+
case _:
23+
print(f"Sorry, I couldn't understand {command!r}")
24+
selections:
25+
- anchor: {line: 9, character: 0}
26+
active: {line: 9, character: 0}
27+
marks:
28+
blue.e:
29+
start: {line: 1, character: 4}
30+
end: {line: 1, character: 8}
31+
finalState:
32+
documentContents: |
33+
match command.split():
34+
case ["quit"]:
35+
36+
case ["go", direction] | []:
37+
print("going", direction)
38+
case ["drop", *objects]:
39+
print("drop", objects)
40+
case _:
41+
print(f"Sorry, I couldn't understand {command!r}")
42+
selections:
43+
- anchor: {line: 2, character: 8}
44+
active: {line: 2, character: 8}
45+
thatMark:
46+
- anchor: {line: 2, character: 8}
47+
active: {line: 2, character: 8}
48+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: blue, character: e}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
languageId: python
2+
command:
3+
spokenForm: change value cap
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: value}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
match command.split():
16+
case ["quit"]:
17+
print("quit")
18+
case ["go", direction] | []:
19+
print("going", direction)
20+
case ["drop", *objects]:
21+
print("drop", objects)
22+
case _:
23+
print(f"Sorry, I couldn't understand {command!r}")
24+
selections:
25+
- anchor: {line: 9, character: 0}
26+
active: {line: 9, character: 0}
27+
marks:
28+
default.c:
29+
start: {line: 5, character: 4}
30+
end: {line: 5, character: 8}
31+
finalState:
32+
documentContents: |
33+
match command.split():
34+
case ["quit"]:
35+
print("quit")
36+
case ["go", direction] | []:
37+
print("going", direction)
38+
case ["drop", *objects]:
39+
40+
case _:
41+
print(f"Sorry, I couldn't understand {command!r}")
42+
selections:
43+
- anchor: {line: 6, character: 8}
44+
active: {line: 6, character: 8}
45+
thatMark:
46+
- anchor: {line: 6, character: 8}
47+
active: {line: 6, character: 8}
48+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: c}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
languageId: rust
2+
command:
3+
spokenForm: change value sun
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: s}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: value}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
match user {
16+
User { first_name: "John" } => {},
17+
User { first_name } if first_name.starts_with("P") => {}
18+
}
19+
selections:
20+
- anchor: {line: 2, character: 27}
21+
active: {line: 2, character: 54}
22+
marks:
23+
default.s:
24+
start: {line: 1, character: 4}
25+
end: {line: 1, character: 8}
26+
finalState:
27+
documentContents: |
28+
match user {
29+
User { first_name: "John" } => ,
30+
User { first_name } if first_name.starts_with("P") => {}
31+
}
32+
selections:
33+
- anchor: {line: 1, character: 35}
34+
active: {line: 1, character: 35}
35+
thatMark:
36+
- anchor: {line: 1, character: 35}
37+
active: {line: 1, character: 35}
38+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: s}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]

0 commit comments

Comments
 (0)