Skip to content

Commit adf03e9

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

28 files changed

+747
-54
lines changed

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

Lines changed: 0 additions & 54 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]"],
@@ -226,59 +225,6 @@ const nodeMatchers: Partial<
226225
"export_statement?.abstract_class_declaration", // export abstract class | abstract class
227226
"export_statement.class", // export default class
228227
],
229-
functionName: [
230-
// function
231-
"function_declaration[name]",
232-
// generator function
233-
"generator_function_declaration[name]",
234-
// export default function
235-
"function[name]",
236-
// class method
237-
"method_definition[name]",
238-
// abstract class method
239-
"abstract_method_signature[name]",
240-
// class arrow method
241-
"public_field_definition[name].arrow_function",
242-
// const foo = function() { }
243-
"variable_declarator[name].function",
244-
// const foo = () => { }
245-
"variable_declarator[name].arrow_function",
246-
// foo = function() { }
247-
"assignment_expression[left].function",
248-
// foo = () => { }
249-
"assignment_expression[left].arrow_function",
250-
],
251-
namedFunction: cascadingMatcher(
252-
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",
261-
// class method
262-
"method_definition",
263-
// class arrow method
264-
"public_field_definition.arrow_function",
265-
// [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",
269-
// foo = function() { }
270-
"assignment_expression.function",
271-
// foo = () => { }
272-
"assignment_expression.arrow_function",
273-
// foo = function*() { }
274-
"generator_function_declaration",
275-
),
276-
// abstract class method
277-
matcher(
278-
patternFinder("abstract_method_signature"),
279-
extendForwardPastOptional(";"),
280-
),
281-
),
282228
type: cascadingMatcher(
283229
// Typed parameters, properties, and functions
284230
typeMatcher(),
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: javascript
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: var foo = () => {};
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: javascript
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 var foo = () => {};
14+
selections:
15+
- anchor: {line: 0, character: 8}
16+
active: {line: 0, character: 8}
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: javascript
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 = () => {};
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: javascript
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: let foo = () => {};
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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: |-
14+
interface Aaa {
15+
bbb(): void;
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 16}
19+
active: {line: 1, character: 16}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
interface Aaa {
24+
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 4}
28+
active: {line: 1, character: 4}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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: |-
14+
class MyClass {
15+
constructor(value: string);
16+
constructor(value: number);
17+
18+
constructor(value: string | number) {}
19+
}
20+
selections:
21+
- anchor: {line: 1, character: 31}
22+
active: {line: 1, character: 31}
23+
- anchor: {line: 2, character: 31}
24+
active: {line: 2, character: 31}
25+
- anchor: {line: 4, character: 42}
26+
active: {line: 4, character: 42}
27+
marks: {}
28+
finalState:
29+
documentContents: |-
30+
class MyClass {
31+
32+
33+
34+
35+
}
36+
selections:
37+
- anchor: {line: 1, character: 4}
38+
active: {line: 1, character: 4}
39+
- anchor: {line: 2, character: 4}
40+
active: {line: 2, character: 4}
41+
- anchor: {line: 4, character: 4}
42+
active: {line: 4, character: 4}
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}

0 commit comments

Comments
 (0)