Skip to content

Commit 87482ed

Browse files
committed
Support value for case statements
1 parent 1a06165 commit 87482ed

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
@@ -103,14 +103,24 @@ const nodeMatchers: Partial<
103103
"method_declaration.identifier!",
104104
"constructor_declaration.identifier!",
105105
],
106-
value: leadingMatcher(
107-
[
108-
"*[declarator][value]",
109-
"assignment_expression[right]",
110-
"return_statement[0]",
111-
"*[value]",
112-
],
113-
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="],
106+
value: cascadingMatcher(
107+
leadingMatcher(
108+
[
109+
"*[declarator][value]",
110+
"assignment_expression[right]",
111+
"return_statement[0]",
112+
"*[value]",
113+
],
114+
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="],
115+
),
116+
matcher(
117+
patternFinder("switch_block_statement_group"),
118+
childRangeSelector(["switch_label"], []),
119+
),
120+
matcher(
121+
patternFinder("switch_rule"),
122+
childRangeSelector(["switch_label"], []),
123+
),
114124
),
115125
condition: conditionMatcher("*[condition]"),
116126
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),

src/languages/python.ts

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

src/languages/scala.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ const nodeMatchers: Partial<
6262
],
6363
[":"],
6464
),
65-
value: leadingMatcher(
66-
["*[value]", "*[default_value]", "type_definition[type]"],
67-
["="],
65+
value: cascadingMatcher(
66+
patternMatcher("case_clause[body]"),
67+
leadingMatcher(
68+
["*[value]", "*[default_value]", "type_definition[type]"],
69+
["="],
70+
),
6871
),
6972
condition: conditionMatcher("*[condition]"),
7073

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)