Skip to content

Commit 8efb33b

Browse files
committed
Support value for case statements
1 parent 289fd08 commit 8efb33b

File tree

8 files changed

+243
-11
lines changed

8 files changed

+243
-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: 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}}]}]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: scala
2+
command:
3+
spokenForm: change value zero
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: '0'}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: value}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
def matchTest(x: Int): String = x match {
16+
case 0 => "zero"
17+
case 1 => "one"
18+
case 2 => "two"
19+
case _ => "other"
20+
}
21+
selections:
22+
- anchor: {line: 6, character: 0}
23+
active: {line: 6, character: 0}
24+
marks:
25+
default.0:
26+
start: {line: 1, character: 7}
27+
end: {line: 1, character: 8}
28+
finalState:
29+
documentContents: |
30+
def matchTest(x: Int): String = x match {
31+
case 0 =>
32+
case 1 => "one"
33+
case 2 => "two"
34+
case _ => "other"
35+
}
36+
selections:
37+
- anchor: {line: 1, character: 12}
38+
active: {line: 1, character: 12}
39+
thatMark:
40+
- anchor: {line: 1, character: 12}
41+
active: {line: 1, character: 12}
42+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '0'}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: scala
2+
command:
3+
spokenForm: change value zero
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: '0'}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: value}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
def matchTest(x: Int): String = x match {
16+
case 0 => "zero"
17+
case 1 => "one"
18+
case 2 => "two"
19+
case _ => "other"
20+
}
21+
selections:
22+
- anchor: {line: 3, character: 2}
23+
active: {line: 4, character: 2}
24+
marks:
25+
default.0:
26+
start: {line: 1, character: 7}
27+
end: {line: 1, character: 8}
28+
finalState:
29+
documentContents: |
30+
def matchTest(x: Int): String = x match {
31+
case 0 =>
32+
case 1 => "one"
33+
case 2 => "two"
34+
case _ => "other"
35+
}
36+
selections:
37+
- anchor: {line: 1, character: 12}
38+
active: {line: 1, character: 12}
39+
thatMark:
40+
- anchor: {line: 1, character: 12}
41+
active: {line: 1, character: 12}
42+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '0'}, modifiers: [{type: containingScope, scopeType: {type: value}}]}]

0 commit comments

Comments
 (0)