Skip to content

Commit 90619bc

Browse files
committed
Add branch scope type
1 parent ed5c04f commit 90619bc

File tree

15 files changed

+409
-0
lines changed

15 files changed

+409
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ const nodeMatchers: Partial<
114114
),
115115
condition: conditionMatcher("*[condition]"),
116116
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
117+
branch: cascadingMatcher(
118+
matcher(
119+
patternFinder("switch_block_statement_group"),
120+
childRangeSelector(["switch_label"], []),
121+
),
122+
matcher(
123+
patternFinder("switch_rule"),
124+
childRangeSelector(["switch_label"], []),
125+
),
126+
),
117127
};
118128

119129
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]",
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
languageId: java
2+
command:
3+
spokenForm: change branch air
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: a}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
class C {
16+
static void main(String args[]) {
17+
switch (arg[0]) {
18+
case("0"):
19+
System.out.println("zero");
20+
break;
21+
case("1"):
22+
System.out.println("one");
23+
break;
24+
default:
25+
System.out.println("other");
26+
break;
27+
};
28+
29+
var s = switch (arg[0]) {
30+
case "0" -> "zero";
31+
case "1" -> "one";
32+
default -> "other";
33+
};
34+
System.out.println(s);
35+
}
36+
}
37+
selections:
38+
- anchor: {line: 22, character: 0}
39+
active: {line: 22, character: 0}
40+
marks:
41+
default.a:
42+
start: {line: 15, character: 12}
43+
end: {line: 15, character: 16}
44+
finalState:
45+
documentContents: |
46+
class C {
47+
static void main(String args[]) {
48+
switch (arg[0]) {
49+
case("0"):
50+
System.out.println("zero");
51+
break;
52+
case("1"):
53+
System.out.println("one");
54+
break;
55+
default:
56+
System.out.println("other");
57+
break;
58+
};
59+
60+
var s = switch (arg[0]) {
61+
case "0" ->
62+
case "1" -> "one";
63+
default -> "other";
64+
};
65+
System.out.println(s);
66+
}
67+
}
68+
selections:
69+
- anchor: {line: 15, character: 24}
70+
active: {line: 15, character: 24}
71+
thatMark:
72+
- anchor: {line: 15, character: 24}
73+
active: {line: 15, character: 24}
74+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
languageId: java
2+
command:
3+
spokenForm: change branch 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: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
class C {
16+
static void main(String args[]) {
17+
switch (arg[0]) {
18+
case("0"):
19+
System.out.println("zero");
20+
break;
21+
case("1"):
22+
System.out.println("one");
23+
break;
24+
default:
25+
System.out.println("other");
26+
break;
27+
};
28+
29+
var s = switch (arg[0]) {
30+
case "0" -> "zero";
31+
case "1" -> "one";
32+
default -> "other";
33+
};
34+
System.out.println(s);
35+
}
36+
}
37+
selections:
38+
- anchor: {line: 22, character: 0}
39+
active: {line: 22, character: 0}
40+
marks:
41+
blue.e:
42+
start: {line: 3, character: 12}
43+
end: {line: 3, character: 16}
44+
finalState:
45+
documentContents: |
46+
class C {
47+
static void main(String args[]) {
48+
switch (arg[0]) {
49+
case("0"):
50+
51+
case("1"):
52+
System.out.println("one");
53+
break;
54+
default:
55+
System.out.println("other");
56+
break;
57+
};
58+
59+
var s = switch (arg[0]) {
60+
case "0" -> "zero";
61+
case "1" -> "one";
62+
default -> "other";
63+
};
64+
System.out.println(s);
65+
}
66+
}
67+
selections:
68+
- anchor: {line: 4, character: 16}
69+
active: {line: 4, character: 16}
70+
thatMark:
71+
- anchor: {line: 4, character: 16}
72+
active: {line: 4, character: 16}
73+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: blue, character: e}, modifiers: [{type: containingScope, scopeType: {type: branch}}]}]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
languageId: Log
2+
command:
3+
spokenForm: chuck branch 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: branch}
11+
usePrePhraseSnapshot: true
12+
action: {name: remove}
13+
initialState:
14+
documentContents: ""
15+
selections:
16+
- anchor: {line: 0, character: 0}
17+
active: {line: 0, character: 0}
18+
marks:
19+
default.c:
20+
start: {line: 5, character: 4}
21+
end: {line: 5, character: 8}
22+
finalState:
23+
documentContents: ""
24+
selections:
25+
- anchor: {line: 0, character: 0}
26+
active: {line: 0, character: 0}
27+
thatMark:
28+
- anchor: {line: 5, character: 0}
29+
active: {line: 5, character: 0}
30+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: c}, 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}}]}]

0 commit comments

Comments
 (0)