Skip to content

Commit df8a74d

Browse files
Switch statement subject (#2046)
`subject, switchStatementSubject` ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] 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) - [-] I have not broken the cheatsheet
1 parent 932cde0 commit df8a74d

File tree

25 files changed

+54
-52
lines changed

25 files changed

+54
-52
lines changed

cursorless-talon/src/spoken_forms.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
126126
handle_csv(
127127
"modifier_scope_types.csv",
128128
pluralize_lists=["scope_type"],
129-
extra_allowed_values=["private.fieldAccess"],
129+
extra_allowed_values=[
130+
"private.fieldAccess",
131+
"private.switchStatementSubject",
132+
],
130133
default_list_name="scope_type",
131134
),
132135
handle_csv(

packages/common/src/types/command/PartialTargetDescriptor.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const simpleScopeTypeTypes = [
139139
"sectionLevelFive",
140140
"sectionLevelSix",
141141
"selector",
142-
"switchStatementSubject",
142+
"private.switchStatementSubject",
143143
"unit",
144144
"xmlBothTags",
145145
"xmlElement",

packages/cursorless-engine/src/languages/cpp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +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]",
83+
["private.switchStatementSubject"]: "switch_statement[condition][value]",
8484
string: "string_literal",
8585
comment: "comment",
8686
anonymousFunction: "lambda_expression",

packages/cursorless-engine/src/languages/csharp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const nodeMatchers: Partial<
148148
conditionMatcher("*[condition]"),
149149
patternMatcher("while_statement[0]"),
150150
),
151-
switchStatementSubject: [
151+
["private.switchStatementSubject"]: [
152152
"switch_statement.tuple_expression!",
153153
"switch_statement[value]",
154154
],

packages/cursorless-engine/src/languages/java.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const nodeMatchers: Partial<
116116
condition: conditionMatcher("*[condition]"),
117117
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
118118
branch: ["switch_block_statement_group", "switch_rule"],
119-
switchStatementSubject: "switch_expression[condition][0]",
119+
["private.switchStatementSubject"]: "switch_expression[condition][0]",
120120
};
121121

122122
export default createPatternMatchers(nodeMatchers);

packages/cursorless-engine/src/languages/python.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const nodeMatchers: Partial<
8686
]),
8787
ternaryBranchMatcher("conditional_expression", [0, 2]),
8888
),
89-
switchStatementSubject: "match_statement[subject]",
89+
["private.switchStatementSubject"]: "match_statement[subject]",
9090
};
9191

9292
export default createPatternMatchers(nodeMatchers);

packages/cursorless-engine/src/languages/rust.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const nodeMatchers: Partial<
241241
matcher(patternFinder("else_clause"), elseExtractor("if_expression")),
242242
matcher(patternFinder("if_expression"), elseIfExtractor()),
243243
),
244-
switchStatementSubject: "match_expression[value]",
244+
["private.switchStatementSubject"]: "match_expression[value]",
245245
};
246246

247247
export default createPatternMatchers(nodeMatchers);

packages/cursorless-engine/src/languages/scala.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const nodeMatchers: Partial<
4444
}),
4545
),
4646

47-
switchStatementSubject: "match_expression[value]",
47+
["private.switchStatementSubject"]: "match_expression[value]",
4848
name: ["*[name]", "*[pattern]"],
4949
functionName: "function_definition[name]",
5050

packages/cursorless-engine/src/languages/typescript.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const nodeMatchers: Partial<
116116
"do_statement[condition]",
117117
),
118118
),
119-
switchStatementSubject: matcher(
119+
["private.switchStatementSubject"]: matcher(
120120
patternFinder("switch_statement[value]"),
121121
unwrapSelectionExtractor,
122122
),

packages/cursorless-engine/src/scopeProviders/ScopeInfoProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function isLanguageSpecific(scopeType: ScopeType): boolean {
144144
case "sectionLevelFive":
145145
case "sectionLevelSix":
146146
case "selector":
147-
case "switchStatementSubject":
147+
case "private.switchStatementSubject":
148148
case "unit":
149149
case "xmlBothTags":
150150
case "xmlElement":

packages/cursorless-engine/src/scopeProviders/scopeTypeToString.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66

77
export function scopeTypeToString(scopeType: ScopeType): string {
88
if (isSimpleScopeType(scopeType)) {
9-
return camelCaseToAllDown(scopeType.type);
9+
return camelCaseToAllDown(scopeType.type).replace(".", " ");
1010
}
1111

1212
if (scopeType.type === "surroundingPair") {

packages/cursorless-engine/src/spokenForms/defaultSpokenFormMapCore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
9898

9999
["private.fieldAccess"]: isPrivate("access"),
100100
string: isPrivate("parse tree string"),
101-
switchStatementSubject: isPrivate("subject"),
101+
["private.switchStatementSubject"]: isPrivate("subject"),
102102
},
103103

104104
surroundingPairForceDirection: {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/cpp/clearSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ command:
77
- type: primitive
88
modifiers:
99
- type: containingScope
10-
scopeType: {type: switchStatementSubject}
10+
scopeType: {type: private.switchStatementSubject}
1111
usePrePhraseSnapshot: true
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
int main() {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/cpp/clearSubject2.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ command:
77
- type: primitive
88
modifiers:
99
- type: containingScope
10-
scopeType: {type: switchStatementSubject}
10+
scopeType: {type: private.switchStatementSubject}
1111
usePrePhraseSnapshot: false
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
int main() {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/csharp/clearSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ command:
77
- type: primitive
88
modifiers:
99
- type: containingScope
10-
scopeType: {type: switchStatementSubject}
10+
scopeType: {type: private.switchStatementSubject}
1111
usePrePhraseSnapshot: true
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |-
1717
switch (aaa) {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/csharp/clearSubject2.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ command:
77
- type: primitive
88
modifiers:
99
- type: containingScope
10-
scopeType: {type: switchStatementSubject}
10+
scopeType: {type: private.switchStatementSubject}
1111
usePrePhraseSnapshot: false
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |-
1717
switch (aaa + 1) {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/java/clearSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ command:
66
- type: primitive
77
modifiers:
88
- type: containingScope
9-
scopeType: {type: switchStatementSubject}
9+
scopeType: {type: private.switchStatementSubject}
1010
usePrePhraseSnapshot: true
1111
action: {name: clearAndSetSelection}
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
class Aaa {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/java/clearSubject2.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ command:
66
- type: primitive
77
modifiers:
88
- type: containingScope
9-
scopeType: {type: switchStatementSubject}
9+
scopeType: {type: private.switchStatementSubject}
1010
usePrePhraseSnapshot: true
1111
action: {name: clearAndSetSelection}
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
class Aaa {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ command:
66
- type: primitive
77
modifiers:
88
- type: containingScope
9-
scopeType: {type: switchStatementSubject}
9+
scopeType: {type: private.switchStatementSubject}
1010
usePrePhraseSnapshot: true
1111
action: {name: clearAndSetSelection}
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
match 0:

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/rust/changeSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ command:
66
- type: primitive
77
modifiers:
88
- type: containingScope
9-
scopeType: {type: switchStatementSubject}
9+
scopeType: {type: private.switchStatementSubject}
1010
usePrePhraseSnapshot: true
1111
action: {name: clearAndSetSelection}
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
match user {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/scala/clearSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ command:
66
- type: primitive
77
modifiers:
88
- type: containingScope
9-
scopeType: {type: switchStatementSubject}
9+
scopeType: {type: private.switchStatementSubject}
1010
usePrePhraseSnapshot: true
1111
action: {name: clearAndSetSelection}
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |
1717
def matchTest(x: Int): String = x match {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearSubject.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ command:
77
- type: primitive
88
modifiers:
99
- type: containingScope
10-
scopeType: {type: switchStatementSubject}
10+
scopeType: {type: private.switchStatementSubject}
1111
usePrePhraseSnapshot: true
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |-
1717
switch(aaa) {

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearSubject2.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ command:
77
- type: primitive
88
modifiers:
99
- type: containingScope
10-
scopeType: {type: switchStatementSubject}
10+
scopeType: {type: private.switchStatementSubject}
1111
usePrePhraseSnapshot: true
1212
spokenFormError: >-
13-
simple scope type type with id switchStatementSubject; this is a private
14-
spoken form currently only for internal experimentation
13+
simple scope type type with id private.switchStatementSubject; this is a
14+
private spoken form currently only for internal experimentation
1515
initialState:
1616
documentContents: |-
1717
switch(aaa + 1) {

packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomSpokenFormScopeInfoTest.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const spokenFormJsonContents = {
7979
},
8080
{
8181
type: "simpleScopeTypeType",
82-
id: "switchStatementSubject",
82+
id: "private.switchStatementSubject",
8383
spokenForms: ["custom subject"],
8484
},
8585
{
@@ -96,22 +96,22 @@ const spokenFormJsonContents = {
9696
};
9797

9898
const subjectStandard: ScopeTypeInfo = {
99-
humanReadableName: "switch statement subject",
99+
humanReadableName: "private switch statement subject",
100100
isLanguageSpecific: true,
101-
scopeType: { type: "switchStatementSubject" },
101+
scopeType: { type: "private.switchStatementSubject" },
102102
spokenForm: {
103103
isPrivate: true,
104104
reason:
105-
"simple scope type type with id switchStatementSubject; this is a private spoken form currently only for internal experimentation",
105+
"simple scope type type with id private.switchStatementSubject; this is a private spoken form currently only for internal experimentation",
106106
requiresTalonUpdate: false,
107107
type: "error",
108108
},
109109
};
110110

111111
const subjectCustom: ScopeTypeInfo = {
112-
humanReadableName: "switch statement subject",
112+
humanReadableName: "private switch statement subject",
113113
isLanguageSpecific: true,
114-
scopeType: { type: "switchStatementSubject" },
114+
scopeType: { type: "private.switchStatementSubject" },
115115
spokenForm: {
116116
spokenForms: ["custom subject"],
117117
type: "success",

schemas/cursorless-snippets.json

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"regularExpression",
9797
"statement",
9898
"string",
99-
"switchStatementSubject",
10099
"type",
101100
"value",
102101
"condition",

0 commit comments

Comments
 (0)