Skip to content

Commit 7ba66c5

Browse files
committed
Add branch scope type
1 parent ed5c04f commit 7ba66c5

File tree

16 files changed

+305
-0
lines changed

16 files changed

+305
-0
lines changed

cursorless-talon/src/modifiers/scopes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"selector": "selector",
4747
"state": "statement",
4848
"string": "string",
49+
"branch": "branch",
4950
"type": "type",
5051
"value": "value",
5152
"condition": "condition",

schemas/cursorless-snippets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"argumentOrParameter",
7474
"anonymousFunction",
7575
"attribute",
76+
"branch",
7677
"class",
7778
"className",
7879
"collectionItem",

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+
branch: ["switch_block_statement_group", "switch_rule"],
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+
branch: "case_clause",
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
@@ -218,6 +218,7 @@ const nodeMatchers: Partial<
218218
matcher(returnValueFinder),
219219
),
220220
attribute: trailingMatcher(["mutable_specifier", "attribute_item"]),
221+
branch: "match_arm",
221222
};
222223

223224
export default createPatternMatchers(nodeMatchers);

src/languages/scala.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const nodeMatchers: Partial<
3434
"class_parameters",
3535
"bindings",
3636
),
37+
branch: "case_clause",
3738

3839
name: ["*[name]", "*[pattern]"],
3940
functionName: "function_definition[name]",

src/processTargets/targets/ScopeTypeTarget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ function getDelimiter(scopeType: SimpleScopeTypeType): string {
169169
case "comment":
170170
case "xmlElement":
171171
case "collectionItem":
172+
case "branch":
172173
return "\n";
173174

174175
default:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: java
2+
command:
3+
spokenForm: clear branch
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
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: 12}
26+
active: {line: 4, character: 12}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
class Aaa {
31+
static void bbb() {
32+
switch ("0") {
33+
34+
case ("1"):
35+
break;
36+
}
37+
}
38+
}
39+
selections:
40+
- anchor: {line: 3, character: 6}
41+
active: {line: 3, character: 6}
42+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
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 branch
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
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+
34+
case "1" -> "one";
35+
};
36+
}
37+
}
38+
selections:
39+
- anchor: {line: 4, character: 8}
40+
active: {line: 4, character: 8}
41+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: java
2+
command:
3+
spokenForm: pour branch
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
10+
usePrePhraseSnapshot: true
11+
action: {name: editNewLineAfter}
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: 21}
25+
active: {line: 4, character: 21}
26+
marks: {}
27+
finalState:
28+
documentContents: |-
29+
class Aaa {
30+
static void bbb() {
31+
var s =
32+
switch ("0") {
33+
case "0" -> "zero";
34+
35+
case "1" -> "one";
36+
};
37+
}
38+
}
39+
selections:
40+
- anchor: {line: 5, character: 8}
41+
active: {line: 5, character: 8}
42+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
languageId: python
2+
command:
3+
spokenForm: clear branch
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
match 0:
15+
case [0]:
16+
pass
17+
case [1]:
18+
pass
19+
selections:
20+
- anchor: {line: 2, character: 10}
21+
active: {line: 2, character: 10}
22+
marks: {}
23+
finalState:
24+
documentContents: |
25+
match 0:
26+
27+
case [1]:
28+
pass
29+
selections:
30+
- anchor: {line: 1, character: 4}
31+
active: {line: 1, character: 4}
32+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
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: clear branch
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
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: 1, character: 26}
20+
active: {line: 1, character: 26}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
match user {
25+
26+
User { first_name } if first_name.starts_with("P") => {}
27+
}
28+
selections:
29+
- anchor: {line: 1, character: 4}
30+
active: {line: 1, character: 4}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
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: clear branch
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
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: 30}
20+
active: {line: 2, character: 30}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
match user {
25+
User { first_name: "John" } => {},
26+
27+
}
28+
selections:
29+
- anchor: {line: 2, character: 4}
30+
active: {line: 2, character: 4}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
languageId: scala
2+
command:
3+
spokenForm: change branch
4+
version: 2
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: branch}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |
14+
def matchTest(x: Int): String = x match {
15+
case 0 => "zero"
16+
case 1 => "one"
17+
case 2 => "two"
18+
case _ => "other"
19+
}
20+
selections:
21+
- anchor: {line: 1, character: 13}
22+
active: {line: 1, character: 17}
23+
marks: {}
24+
finalState:
25+
documentContents: |
26+
def matchTest(x: Int): String = x match {
27+
case 1 => "one"
28+
case 2 => "two"
29+
case _ => "other"
30+
}
31+
selections:
32+
- anchor: {line: 1, character: 2}
33+
active: {line: 1, character: 2}
34+
thatMark:
35+
- anchor: {line: 1, character: 2}
36+
active: {line: 1, character: 2}
37+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: scala
2+
command:
3+
spokenForm: chuck branch 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: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: remove}
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.s:
26+
start: {line: 2, character: 2}
27+
end: {line: 2, character: 6}
28+
finalState:
29+
documentContents: |
30+
def matchTest(x: Int): String = x match {
31+
case 0 => "zero"
32+
case 2 => "two"
33+
case _ => "other"
34+
}
35+
selections:
36+
- anchor: {line: 2, character: 2}
37+
active: {line: 3, character: 2}
38+
thatMark:
39+
- anchor: {line: 2, character: 2}
40+
active: {line: 2, character: 2}
41+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: s}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]

src/typings/targetDescriptor.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export type SimpleScopeTypeType =
8181
| "argumentOrParameter"
8282
| "anonymousFunction"
8383
| "attribute"
84+
| "branch"
8485
| "class"
8586
| "className"
8687
| "collectionItem"

0 commit comments

Comments
 (0)