Skip to content

Commit 0fe1b84

Browse files
authored
Implement Typescript "funk" using queries (#1516)
- Fixes #711 - Fixes #1365 - Fixes #1238 ## Checklist - [x] Make sure that `"name"` behaves as well as `"funk name"` now does - [x] Create PR with migration `"funk name"` => `"name funk"`, and then remove all the `"funk name"` stuff (#1518). Might want to bail on that - [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 85a50bb commit 0fe1b84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1094
-57
lines changed

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

-54
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(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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: |-
14+
class Aaa {
15+
bbb = () => {};
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 19}
19+
active: {line: 1, character: 19}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
class Aaa {
24+
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 4}
28+
active: {line: 1, character: 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const aaa = "bbb";
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: const = "bbb";
20+
selections:
21+
- anchor: {line: 0, character: 6}
22+
active: {line: 0, character: 6}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export const aaa = "bbb";
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: export const = "bbb";
20+
selections:
21+
- anchor: {line: 0, character: 13}
22+
active: {line: 0, character: 13}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: var aaa = "bbb";
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: var = "bbb";
20+
selections:
21+
- anchor: {line: 0, character: 4}
22+
active: {line: 0, character: 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export var aaa = "bbb";
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: export var = "bbb";
20+
selections:
21+
- anchor: {line: 0, character: 11}
22+
active: {line: 0, character: 11}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: const aaa = "bbb", ccc = "ddd";
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: const = "bbb", = "ddd";
20+
selections:
21+
- anchor: {line: 0, character: 6}
22+
active: {line: 0, character: 6}
23+
- anchor: {line: 0, character: 16}
24+
active: {line: 0, character: 16}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: export const aaa = "bbb", ccc = "ddd";
14+
selections:
15+
- anchor: {line: 0, character: 0}
16+
active: {line: 0, character: 0}
17+
marks: {}
18+
finalState:
19+
documentContents: export const = "bbb", = "ddd";
20+
selections:
21+
- anchor: {line: 0, character: 13}
22+
active: {line: 0, character: 13}
23+
- anchor: {line: 0, character: 23}
24+
active: {line: 0, character: 23}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
class Aaa {
15+
bbb = "ccc";
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 16}
19+
active: {line: 1, character: 16}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
class Aaa {
24+
= "ccc";
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 4}
28+
active: {line: 1, character: 4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
languageId: javascript
2+
command:
3+
version: 5
4+
spokenForm: clear name
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: name}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
class Aaa {
15+
bbb = "ccc"
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 15}
19+
active: {line: 1, character: 15}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
class Aaa {
24+
= "ccc"
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 4}
28+
active: {line: 1, character: 4}
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}
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}
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}
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}

0 commit comments

Comments
 (0)