Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Typescript "funk" using queries #1516

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions packages/cursorless-engine/src/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ const nodeMatchers: Partial<
patternMatcher("yield_expression.~yield!"),
),
ifStatement: "if_statement",
anonymousFunction: ["arrow_function", "function"],
comment: "comment",
regularExpression: "regex",
className: ["class_declaration[name]", "class[name]"],
Expand Down Expand Up @@ -226,59 +225,6 @@ const nodeMatchers: Partial<
"export_statement?.abstract_class_declaration", // export abstract class | abstract class
"export_statement.class", // export default class
],
functionName: [
// function
"function_declaration[name]",
// generator function
"generator_function_declaration[name]",
// export default function
"function[name]",
// class method
"method_definition[name]",
// abstract class method
"abstract_method_signature[name]",
// class arrow method
"public_field_definition[name].arrow_function",
// const foo = function() { }
"variable_declarator[name].function",
// const foo = () => { }
"variable_declarator[name].arrow_function",
// foo = function() { }
"assignment_expression[left].function",
// foo = () => { }
"assignment_expression[left].arrow_function",
],
namedFunction: cascadingMatcher(
patternMatcher(
// [export] function
"export_statement?.function_declaration",
// export default function
// NB: We require export statement because otherwise it is an anonymous
// function
"export_statement.function",
// export default arrow
"export_statement.arrow_function",
// class method
"method_definition",
// class arrow method
"public_field_definition.arrow_function",
// [export] const foo = function() { }
"export_statement?.lexical_declaration.variable_declarator.function",
// [export] const foo = () => { }
"export_statement?.lexical_declaration.variable_declarator.arrow_function",
// foo = function() { }
"assignment_expression.function",
// foo = () => { }
"assignment_expression.arrow_function",
// foo = function*() { }
"generator_function_declaration",
),
// abstract class method
matcher(
patternFinder("abstract_method_signature"),
extendForwardPastOptional(";"),
),
),
type: cascadingMatcher(
// Typed parameters, properties, and functions
typeMatcher(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: javascript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
class Aaa {
bbb = () => {};
}
selections:
- anchor: {line: 1, character: 19}
active: {line: 1, character: 19}
marks: {}
finalState:
documentContents: |-
class Aaa {

}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: const aaa = "bbb";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: const = "bbb";
selections:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: export const aaa = "bbb";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: export const = "bbb";
selections:
- anchor: {line: 0, character: 13}
active: {line: 0, character: 13}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: var aaa = "bbb";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: var = "bbb";
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: export var aaa = "bbb";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: export var = "bbb";
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: const aaa = "bbb", ccc = "ddd";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: const = "bbb", = "ddd";
selections:
- anchor: {line: 0, character: 6}
active: {line: 0, character: 6}
- anchor: {line: 0, character: 16}
active: {line: 0, character: 16}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: export const aaa = "bbb", ccc = "ddd";
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: export const = "bbb", = "ddd";
selections:
- anchor: {line: 0, character: 13}
active: {line: 0, character: 13}
- anchor: {line: 0, character: 23}
active: {line: 0, character: 23}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
class Aaa {
bbb = "ccc";
}
selections:
- anchor: {line: 1, character: 16}
active: {line: 1, character: 16}
marks: {}
finalState:
documentContents: |-
class Aaa {
= "ccc";
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: javascript
command:
version: 5
spokenForm: clear name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
class Aaa {
bbb = "ccc"
}
selections:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 15}
marks: {}
finalState:
documentContents: |-
class Aaa {
= "ccc"
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: const foo = function *bar() {}
pokey marked this conversation as resolved.
Show resolved Hide resolved
selections:
- anchor: {line: 0, character: 12}
active: {line: 0, character: 12}
marks: {}
finalState:
documentContents: "const foo = "
selections:
- anchor: {line: 0, character: 12}
active: {line: 0, character: 12}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: const foo = function *bar() {}
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
thrownError: {name: NoContainingScopeError}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: export default function *() {}
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: javascript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: var foo = () => {};
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Loading