Skip to content

Commit 1ba3331

Browse files
Added ts as and satisfies support for type scope (#1871)
Fixes #1155 ## Checklist - [x] 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 9c7ddfe commit 1ba3331

File tree

7 files changed

+148
-1
lines changed

7 files changed

+148
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,19 @@ const nodeMatchers: Partial<
231231
// Typed parameters, properties, and functions
232232
typeMatcher(),
233233
// matcher(findTypeNode, selectWithLeadingDelimiter(":")),
234-
// Type alias/interface declarations
235234
patternMatcher(
235+
// Type alias/interface declarations
236236
"export_statement?.type_alias_declaration",
237237
"export_statement?.interface_declaration",
238+
// as type declarations
239+
"as_expression.generic_type!",
240+
"as_expression.predefined_type!",
241+
// satisfies type declaration
242+
"satisfies_expression.generic_type!",
243+
"satisfies_expression.predefined_type!",
244+
// <type> declaration
245+
"type_assertion.type_arguments.generic_type!",
246+
"type_assertion.type_arguments.predefined_type!",
238247
),
239248
),
240249
argumentOrParameter: argumentMatcher("formal_parameters", "arguments"),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change type
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: type}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: const value = 2 as number;
15+
selections:
16+
- anchor: {line: 0, character: 19}
17+
active: {line: 0, character: 19}
18+
marks: {}
19+
finalState:
20+
documentContents: const value = 2 as ;
21+
selections:
22+
- anchor: {line: 0, character: 19}
23+
active: {line: 0, character: 19}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change type
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: type}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: const map = {} as Record<string, number>;
15+
selections:
16+
- anchor: {line: 0, character: 18}
17+
active: {line: 0, character: 18}
18+
marks: {}
19+
finalState:
20+
documentContents: const map = {} as ;
21+
selections:
22+
- anchor: {line: 0, character: 18}
23+
active: {line: 0, character: 18}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change type
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: type}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: const value = 2 as const satisfies number;
15+
selections:
16+
- anchor: {line: 0, character: 35}
17+
active: {line: 0, character: 35}
18+
marks: {}
19+
finalState:
20+
documentContents: const value = 2 as const satisfies ;
21+
selections:
22+
- anchor: {line: 0, character: 35}
23+
active: {line: 0, character: 35}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change type
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: type}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: const meta = {} as const satisfies Record<string, number>;
15+
selections:
16+
- anchor: {line: 0, character: 35}
17+
active: {line: 0, character: 35}
18+
marks: {}
19+
finalState:
20+
documentContents: const meta = {} as const satisfies ;
21+
selections:
22+
- anchor: {line: 0, character: 35}
23+
active: {line: 0, character: 35}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change type
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: type}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: const value = <number>2;
15+
selections:
16+
- anchor: {line: 0, character: 15}
17+
active: {line: 0, character: 15}
18+
marks: {}
19+
finalState:
20+
documentContents: const value = <>2;
21+
selections:
22+
- anchor: {line: 0, character: 15}
23+
active: {line: 0, character: 15}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: change type
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: type}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: const map = <Record<string, number>>{}
15+
selections:
16+
- anchor: {line: 0, character: 13}
17+
active: {line: 0, character: 13}
18+
marks: {}
19+
finalState:
20+
documentContents: const map = <>{}
21+
selections:
22+
- anchor: {line: 0, character: 13}
23+
active: {line: 0, character: 13}

0 commit comments

Comments
 (0)