Skip to content

Commit be6bdda

Browse files
committed
Implement more Typescript scope types using queries
1 parent 65fab51 commit be6bdda

20 files changed

+465
-24
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ const nodeMatchers: Partial<
175175
patternMatcher("yield_expression.~yield!"),
176176
),
177177
ifStatement: "if_statement",
178-
anonymousFunction: ["arrow_function", "function"],
179178
comment: "comment",
180179
regularExpression: "regex",
181180
className: ["class_declaration[name]", "class[name]"],
@@ -227,51 +226,28 @@ const nodeMatchers: Partial<
227226
"export_statement.class", // export default class
228227
],
229228
functionName: [
230-
// function
231-
"function_declaration[name]",
232-
// generator function
233-
"generator_function_declaration[name]",
234-
// export default function
235-
"function[name]",
236229
// class method
237230
"method_definition[name]",
238231
// abstract class method
239232
"abstract_method_signature[name]",
240233
// class arrow method
241234
"public_field_definition[name].arrow_function",
242-
// const foo = function() { }
243-
"variable_declarator[name].function",
244-
// const foo = () => { }
245-
"variable_declarator[name].arrow_function",
246235
// foo = function() { }
247236
"assignment_expression[left].function",
248237
// foo = () => { }
249238
"assignment_expression[left].arrow_function",
250239
],
251240
namedFunction: cascadingMatcher(
252241
patternMatcher(
253-
// [export] function
254-
"export_statement?.function_declaration",
255-
// export default function
256-
// NB: We require export statement because otherwise it is an anonymous
257-
// function
258-
"export_statement.function",
259-
// export default arrow
260-
"export_statement.arrow_function",
261242
// class method
262243
"method_definition",
263244
// class arrow method
264245
"public_field_definition.arrow_function",
265246
// [export] const foo = function() { }
266-
"export_statement?.lexical_declaration.variable_declarator.function",
267-
// [export] const foo = () => { }
268-
"export_statement?.lexical_declaration.variable_declarator.arrow_function",
269247
// foo = function() { }
270248
"assignment_expression.function",
271249
// foo = () => { }
272250
"assignment_expression.arrow_function",
273-
// foo = function*() { }
274-
"generator_function_declaration",
275251
),
276252
// abstract class method
277253
matcher(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const foo = function *bar() {}
14+
selections:
15+
- anchor: {line: 0, character: 12}
16+
active: {line: 0, character: 12}
17+
marks: {}
18+
finalState:
19+
documentContents: "const foo = "
20+
selections:
21+
- anchor: {line: 0, character: 12}
22+
active: {line: 0, character: 12}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const foo = function *bar() {}
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
thrownError: {name: NoContainingScopeError}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export default function *() {}
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: ""
20+
selections:
21+
- anchor: {line: 0, character: 0}
22+
active: {line: 0, character: 0}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export function *aaa() {}
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: ""
20+
selections:
21+
- anchor: {line: 0, character: 0}
22+
active: {line: 0, character: 0}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: (function foo() {})
14+
selections:
15+
- anchor: {line: 0, character: 1}
16+
active: {line: 0, character: 1}
17+
marks: {}
18+
finalState:
19+
documentContents: ()
20+
selections:
21+
- anchor: {line: 0, character: 1}
22+
active: {line: 0, character: 1}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: (function () {})
14+
selections:
15+
- anchor: {line: 0, character: 1}
16+
active: {line: 0, character: 1}
17+
marks: {}
18+
thrownError: {name: NoContainingScopeError}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export const myFunk = () => {};
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: ""
20+
selections:
21+
- anchor: {line: 0, character: 0}
22+
active: {line: 0, character: 0}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const foo = function bar() {}
14+
selections:
15+
- anchor: {line: 0, character: 12}
16+
active: {line: 0, character: 12}
17+
marks: {}
18+
finalState:
19+
documentContents: "const foo = "
20+
selections:
21+
- anchor: {line: 0, character: 12}
22+
active: {line: 0, character: 12}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: namedFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const foo = function bar() {}
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
thrownError: {name: NoContainingScopeError}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: functionName}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export function *aaa() {}
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: export function *() {}
20+
selections:
21+
- anchor: {line: 0, character: 17}
22+
active: {line: 0, character: 17}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: functionName}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: (function foo() {})
14+
selections:
15+
- anchor: {line: 0, character: 1}
16+
active: {line: 0, character: 1}
17+
marks: {}
18+
finalState:
19+
documentContents: (function () {})
20+
selections:
21+
- anchor: {line: 0, character: 10}
22+
active: {line: 0, character: 10}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: functionName}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export const myFunk = () => {};
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: export const = () => {};
20+
selections:
21+
- anchor: {line: 0, character: 13}
22+
active: {line: 0, character: 13}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: functionName}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const foo = function bar() {}
14+
selections:
15+
- anchor: {line: 0, character: 12}
16+
active: {line: 0, character: 12}
17+
marks: {}
18+
finalState:
19+
documentContents: const foo = function () {}
20+
selections:
21+
- anchor: {line: 0, character: 21}
22+
active: {line: 0, character: 21}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear funk name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: functionName}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const foo = function bar() {}
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
thrownError: {name: NoContainingScopeError}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: typescript
2+
command:
3+
version: 5
4+
spokenForm: clear lambda
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: anonymousFunction}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: (function () {})
14+
selections:
15+
- anchor: {line: 0, character: 1}
16+
active: {line: 0, character: 1}
17+
marks: {}
18+
finalState:
19+
documentContents: ()
20+
selections:
21+
- anchor: {line: 0, character: 1}
22+
active: {line: 0, character: 1}

0 commit comments

Comments
 (0)