Skip to content

Commit adf7c5e

Browse files
committed
Add branch scope type
1 parent ed5c04f commit adf7c5e

File tree

17 files changed

+381
-0
lines changed

17 files changed

+381
-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", "if_expression[consequence]", "else_clause.block!"],
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
languageId: rust
2+
command:
3+
spokenForm: change branch one
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: '1'}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
fn main() {
16+
let foo = if true {
17+
1
18+
} else if false {
19+
2
20+
} else {
21+
3
22+
};
23+
}
24+
selections:
25+
- anchor: {line: 3, character: 20}
26+
active: {line: 5, character: 5}
27+
marks:
28+
default.1:
29+
start: {line: 2, character: 8}
30+
end: {line: 2, character: 9}
31+
finalState:
32+
documentContents: |
33+
fn main() {
34+
let foo = if true else if false {
35+
2
36+
} else {
37+
3
38+
};
39+
}
40+
selections:
41+
- anchor: {line: 1, character: 22}
42+
active: {line: 1, character: 22}
43+
thatMark:
44+
- anchor: {line: 1, character: 22}
45+
active: {line: 1, character: 22}
46+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '1'}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
languageId: rust
2+
command:
3+
spokenForm: change branch three
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: '3'}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
fn main() {
16+
let foo = if true {
17+
1
18+
} else if false {
19+
2
20+
} else {
21+
3
22+
};
23+
}
24+
selections:
25+
- anchor: {line: 3, character: 20}
26+
active: {line: 5, character: 5}
27+
marks:
28+
default.3:
29+
start: {line: 6, character: 8}
30+
end: {line: 6, character: 9}
31+
finalState:
32+
documentContents: |
33+
fn main() {
34+
let foo = if true {
35+
1
36+
} else if false {
37+
2
38+
} else ;
39+
}
40+
selections:
41+
- anchor: {line: 5, character: 11}
42+
active: {line: 5, character: 11}
43+
thatMark:
44+
- anchor: {line: 5, character: 11}
45+
active: {line: 5, character: 11}
46+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '3'}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
languageId: rust
2+
command:
3+
spokenForm: change branch two
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: '2'}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
fn main() {
16+
let foo = if true {
17+
1
18+
} else if false {
19+
2
20+
} else {
21+
3
22+
};
23+
}
24+
selections:
25+
- anchor: {line: 3, character: 20}
26+
active: {line: 5, character: 5}
27+
marks:
28+
default.2:
29+
start: {line: 4, character: 8}
30+
end: {line: 4, character: 9}
31+
finalState:
32+
documentContents: |
33+
fn main() {
34+
let foo = if true {
35+
1
36+
} else if false else {
37+
3
38+
};
39+
}
40+
selections:
41+
- anchor: {line: 3, character: 20}
42+
active: {line: 3, character: 20}
43+
thatMark:
44+
- anchor: {line: 3, character: 20}
45+
active: {line: 3, character: 20}
46+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '2'}, 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}}]}]

0 commit comments

Comments
 (0)