Skip to content

Commit 091b73c

Browse files
committed
Add subject scope type
1 parent ed5c04f commit 091b73c

File tree

13 files changed

+317
-6
lines changed

13 files changed

+317
-6
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+
"subject": "subject",
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
@@ -88,6 +88,7 @@
8888
"regularExpression",
8989
"statement",
9090
"string",
91+
"subject",
9192
"type",
9293
"value",
9394
"condition",

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

223224
export default createPatternMatchers(nodeMatchers);

src/languages/scala.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ const nodeMatchers: Partial<
6161
],
6262
[":"],
6363
),
64-
value: leadingMatcher(
65-
["*[value]", "*[default_value]", "type_definition[type]"],
66-
["="],
67-
),
68-
condition: conditionMatcher("*[condition]"),
69-
64+
subject: "match_expression[value]",
7065
// Scala features unsupported in Cursorless terminology
7166
// - Pattern matching
7267

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 subject blue whale
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: blue, character: w}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: subject}
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.w:
42+
start: {line: 2, character: 8}
43+
end: {line: 2, character: 14}
44+
finalState:
45+
documentContents: |
46+
class C {
47+
static void main(String args[]) {
48+
switch () {
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" -> "zero";
62+
case "1" -> "one";
63+
default -> "other";
64+
};
65+
System.out.println(s);
66+
}
67+
}
68+
selections:
69+
- anchor: {line: 2, character: 16}
70+
active: {line: 2, character: 16}
71+
thatMark:
72+
- anchor: {line: 2, character: 16}
73+
active: {line: 2, character: 16}
74+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: blue, character: w}, modifiers: [{type: containingScope, scopeType: {type: subject}}]}]
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 subject whale
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: w}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: subject}
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.w:
42+
start: {line: 14, character: 16}
43+
end: {line: 14, character: 22}
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 () {
61+
case "0" -> "zero";
62+
case "1" -> "one";
63+
default -> "other";
64+
};
65+
System.out.println(s);
66+
}
67+
}
68+
selections:
69+
- anchor: {line: 14, character: 24}
70+
active: {line: 14, character: 24}
71+
thatMark:
72+
- anchor: {line: 14, character: 24}
73+
active: {line: 14, character: 24}
74+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: w}, modifiers: [{type: containingScope, scopeType: {type: subject}}]}]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
languageId: python
2+
command:
3+
spokenForm: change subject harp
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: h}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: subject}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
13+
initialState:
14+
documentContents: |
15+
match command.split():
16+
case ["quit"]:
17+
print("quit")
18+
case ["go", direction] | []:
19+
print("going", direction)
20+
case ["drop", *objects]:
21+
print("drop", objects)
22+
case _:
23+
print(f"Sorry, I couldn't understand {command!r}")
24+
selections:
25+
- anchor: {line: 9, character: 0}
26+
active: {line: 9, character: 0}
27+
marks:
28+
default.h:
29+
start: {line: 0, character: 0}
30+
end: {line: 0, character: 5}
31+
finalState:
32+
documentContents: |
33+
match :
34+
case ["quit"]:
35+
print("quit")
36+
case ["go", direction] | []:
37+
print("going", direction)
38+
case ["drop", *objects]:
39+
print("drop", objects)
40+
case _:
41+
print(f"Sorry, I couldn't understand {command!r}")
42+
selections:
43+
- anchor: {line: 0, character: 6}
44+
active: {line: 0, character: 6}
45+
thatMark:
46+
- anchor: {line: 0, character: 6}
47+
active: {line: 0, character: 6}
48+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: h}, modifiers: [{type: containingScope, scopeType: {type: subject}}]}]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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: subject}
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+
thatMark:
32+
- anchor: {line: 0, character: 6}
33+
active: {line: 0, character: 6}
34+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: subject}}]}]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
languageId: scala
2+
command:
3+
spokenForm: change subject
4+
version: 2
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: subject}
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: 3, character: 2}
22+
active: {line: 4, character: 2}
23+
marks: {}
24+
finalState:
25+
documentContents: |
26+
def matchTest(x: Int): String = match {
27+
case 0 => "zero"
28+
case 1 => "one"
29+
case 2 => "two"
30+
case _ => "other"
31+
}
32+
selections:
33+
- anchor: {line: 0, character: 32}
34+
active: {line: 0, character: 32}
35+
thatMark:
36+
- anchor: {line: 0, character: 32}
37+
active: {line: 0, character: 32}
38+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: subject}}]}]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: scala
2+
command:
3+
spokenForm: change subject trap
4+
version: 2
5+
targets:
6+
- type: primitive
7+
mark: {type: decoratedSymbol, symbolColor: default, character: t}
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: subject}
11+
usePrePhraseSnapshot: true
12+
action: {name: clearAndSetSelection}
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: 6, character: 0}
23+
active: {line: 6, character: 0}
24+
marks:
25+
default.t:
26+
start: {line: 0, character: 34}
27+
end: {line: 0, character: 39}
28+
finalState:
29+
documentContents: |
30+
def matchTest(x: Int): String = match {
31+
case 0 => "zero"
32+
case 1 => "one"
33+
case 2 => "two"
34+
case _ => "other"
35+
}
36+
selections:
37+
- anchor: {line: 0, character: 32}
38+
active: {line: 0, character: 32}
39+
thatMark:
40+
- anchor: {line: 0, character: 32}
41+
active: {line: 0, character: 32}
42+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: t}, modifiers: [{type: containingScope, scopeType: {type: subject}}]}]

src/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+
| "subject"
111112
| "unit"
112113
| "xmlBothTags"
113114
| "xmlElement"

0 commit comments

Comments
 (0)