Skip to content

Commit 312a7f2

Browse files
pokeypre-commit-ci[bot]AndreasArvidsson
authored
Add extension side of "subject" scope type (#1148)
- Partially addresses #1172 - Waiting to add Talon side until we're more confident in this scope type - Split from #831 ## Checklist - [x] Add Typescript - [x] Add C - [x] Add C# - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [x] I have not broken the cheatsheet Co-authored-by: Michael Doronin <warrior2031@mail.ru> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Andreas Arvidsson <andreas.arvidsson87@gmail.com>
1 parent 03931d5 commit 312a7f2

File tree

20 files changed

+381
-0
lines changed

20 files changed

+381
-0
lines changed

schemas/cursorless-snippets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"regularExpression",
8989
"statement",
9090
"string",
91+
"switchStatementSubject",
9192
"type",
9293
"value",
9394
"condition",

src/core/commandRunner/typings/targetDescriptor.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export type SimpleScopeTypeType =
108108
| "sectionLevelFive"
109109
| "sectionLevelSix"
110110
| "selector"
111+
| "switchStatementSubject"
111112
| "unit"
112113
| "xmlBothTags"
113114
| "xmlElement"

src/languages/cpp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const nodeMatchers: Partial<
8080
"function_definition[declarator][declarator][namespace]", // void ClassName::method() {}
8181
],
8282
ifStatement: "if_statement",
83+
switchStatementSubject: "switch_statement[condition][value]",
8384
string: "string_literal",
8485
comment: "comment",
8586
anonymousFunction: "lambda_expression",

src/languages/csharp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ const nodeMatchers: Partial<
148148
conditionMatcher("*[condition]"),
149149
patternMatcher("while_statement[0]"),
150150
),
151+
switchStatementSubject: [
152+
"switch_statement.tuple_expression!",
153+
"switch_statement[value]",
154+
],
151155
statement: STATEMENT_TYPES,
152156
anonymousFunction: "lambda_expression",
153157
functionCall: ["invocation_expression", "object_creation_expression"],

src/languages/java.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const nodeMatchers: Partial<
114114
),
115115
condition: conditionMatcher("*[condition]"),
116116
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
117+
switchStatementSubject: "switch_expression[condition][0]",
117118
};
118119

119120
export default createPatternMatchers(nodeMatchers);

src/languages/python.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const nodeMatchers: Partial<
137137
argumentMatcher("parameters", "argument_list"),
138138
matcher(patternFinder("call.generator_expression!"), childRangeSelector()),
139139
),
140+
switchStatementSubject: "match_statement[subject]",
140141
};
141142

142143
export default createPatternMatchers(nodeMatchers);

src/languages/rust.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ const nodeMatchers: Partial<
224224
matcher(returnValueFinder),
225225
),
226226
attribute: trailingMatcher(["mutable_specifier", "attribute_item"]),
227+
switchStatementSubject: "match_expression[value]",
227228
};
228229

229230
export default createPatternMatchers(nodeMatchers);

src/languages/scala.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const nodeMatchers: Partial<
3535
"bindings",
3636
),
3737

38+
switchStatementSubject: "match_expression[value]",
3839
name: ["*[name]", "*[pattern]"],
3940
functionName: "function_definition[name]",
4041

src/languages/typescript.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
pairSelectionExtractor,
2424
selectWithLeadingDelimiter,
2525
simpleSelectionExtractor,
26+
unwrapSelectionExtractor,
2627
xmlElementExtractor,
2728
} from "../util/nodeSelectors";
2829

@@ -223,6 +224,10 @@ const nodeMatchers: Partial<
223224
"do_statement[condition]",
224225
),
225226
),
227+
switchStatementSubject: matcher(
228+
patternFinder("switch_statement[value]"),
229+
unwrapSelectionExtractor,
230+
),
226231
class: [
227232
"export_statement?.class_declaration", // export class | class
228233
"export_statement?.abstract_class_declaration", // export abstract class | abstract class
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
languageId: cpp
2+
command:
3+
version: 3
4+
spokenForm: clear subject
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: switchStatementSubject}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |
14+
int main() {
15+
switch (i) {
16+
default:
17+
break;
18+
}
19+
}
20+
selections:
21+
- anchor: {line: 3, character: 4}
22+
active: {line: 3, character: 4}
23+
marks: {}
24+
finalState:
25+
documentContents: |
26+
int main() {
27+
switch () {
28+
default:
29+
break;
30+
}
31+
}
32+
selections:
33+
- anchor: {line: 1, character: 10}
34+
active: {line: 1, character: 10}
35+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
languageId: cpp
2+
command:
3+
version: 3
4+
spokenForm: clear subject
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: switchStatementSubject}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: |
14+
int main() {
15+
switch (int i = rand() % 100; i) {
16+
default:
17+
break;
18+
}
19+
}
20+
selections:
21+
- anchor: {line: 3, character: 4}
22+
active: {line: 3, character: 4}
23+
marks: {}
24+
finalState:
25+
documentContents: |
26+
int main() {
27+
switch (int i = rand() % 100; ) {
28+
default:
29+
break;
30+
}
31+
}
32+
selections:
33+
- anchor: {line: 1, character: 32}
34+
active: {line: 1, character: 32}
35+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: csharp
2+
command:
3+
version: 3
4+
spokenForm: clear subject
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: switchStatementSubject}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
switch (aaa) {
15+
default:
16+
break;
17+
}
18+
selections:
19+
- anchor: {line: 2, character: 4}
20+
active: {line: 2, character: 4}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
switch () {
25+
default:
26+
break;
27+
}
28+
selections:
29+
- anchor: {line: 0, character: 8}
30+
active: {line: 0, character: 8}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: csharp
2+
command:
3+
version: 3
4+
spokenForm: clear subject
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: switchStatementSubject}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: |-
14+
switch (aaa + 1) {
15+
default:
16+
break;
17+
}
18+
selections:
19+
- anchor: {line: 2, character: 4}
20+
active: {line: 2, character: 4}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
switch () {
25+
default:
26+
break;
27+
}
28+
selections:
29+
- anchor: {line: 0, character: 8}
30+
active: {line: 0, character: 8}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
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 subject
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: switchStatementSubject}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
class Aaa {
15+
16+
static void bbb() {
17+
switch ("0") {
18+
case ("0"):
19+
break;
20+
}
21+
}
22+
}
23+
selections:
24+
- anchor: {line: 4, character: 17}
25+
active: {line: 4, character: 17}
26+
marks: {}
27+
finalState:
28+
documentContents: |
29+
class Aaa {
30+
31+
static void bbb() {
32+
switch () {
33+
case ("0"):
34+
break;
35+
}
36+
}
37+
}
38+
selections:
39+
- anchor: {line: 3, character: 12}
40+
active: {line: 3, character: 12}
41+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
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 subject
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: switchStatementSubject}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
class Aaa {
15+
16+
static void bbb() {
17+
var s =
18+
switch ("0") {
19+
case "0" -> "zero";
20+
};
21+
}
22+
}
23+
selections:
24+
- anchor: {line: 5, character: 22}
25+
active: {line: 5, character: 22}
26+
marks: {}
27+
finalState:
28+
documentContents: |
29+
class Aaa {
30+
31+
static void bbb() {
32+
var s =
33+
switch () {
34+
case "0" -> "zero";
35+
};
36+
}
37+
}
38+
selections:
39+
- anchor: {line: 4, character: 14}
40+
active: {line: 4, character: 14}
41+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: python
2+
command:
3+
spokenForm: clear subject
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: switchStatementSubject}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
match 0:
15+
case [0]:
16+
pass
17+
selections:
18+
- anchor: {line: 2, character: 8}
19+
active: {line: 2, character: 8}
20+
marks: {}
21+
finalState:
22+
documentContents: |
23+
match :
24+
case [0]:
25+
pass
26+
selections:
27+
- anchor: {line: 0, character: 6}
28+
active: {line: 0, character: 6}
29+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: rust
2+
command:
3+
spokenForm: change subject
4+
version: 2
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: switchStatementSubject}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
match user {
15+
User { first_name: "John" } => {},
16+
User { first_name } if first_name.starts_with("P") => {}
17+
}
18+
selections:
19+
- anchor: {line: 2, character: 27}
20+
active: {line: 2, character: 54}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
match {
25+
User { first_name: "John" } => {},
26+
User { first_name } if first_name.starts_with("P") => {}
27+
}
28+
selections:
29+
- anchor: {line: 0, character: 6}
30+
active: {line: 0, character: 6}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: scala
2+
command:
3+
spokenForm: clear subject
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: switchStatementSubject}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
def matchTest(x: Int): String = x match {
15+
case 0 => "zero"
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 15}
19+
active: {line: 1, character: 15}
20+
marks: {}
21+
finalState:
22+
documentContents: |
23+
def matchTest(x: Int): String = match {
24+
case 0 => "zero"
25+
}
26+
selections:
27+
- anchor: {line: 0, character: 32}
28+
active: {line: 0, character: 32}
29+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: switchStatementSubject}}]}]

0 commit comments

Comments
 (0)