Skip to content

Commit

Permalink
Implement more Typescript scope types using queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Jun 7, 2023
1 parent 65fab51 commit be6bdda
Show file tree
Hide file tree
Showing 20 changed files with 465 additions and 24 deletions.
24 changes: 0 additions & 24 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 @@ -227,51 +226,28 @@ const nodeMatchers: Partial<
"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(
Expand Down
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() {}
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: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: export function *aaa() {}
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: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: (function foo() {})
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
marks: {}
finalState:
documentContents: ()
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
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: (function () {})
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
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 const myFunk = () => {};
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: 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: 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 name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: functionName}
usePrePhraseSnapshot: true
initialState:
documentContents: export function *aaa() {}
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: export function *() {}
selections:
- anchor: {line: 0, character: 17}
active: {line: 0, character: 17}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: functionName}
usePrePhraseSnapshot: true
initialState:
documentContents: (function foo() {})
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
marks: {}
finalState:
documentContents: (function () {})
selections:
- anchor: {line: 0, character: 10}
active: {line: 0, character: 10}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: functionName}
usePrePhraseSnapshot: true
initialState:
documentContents: export const myFunk = () => {};
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: export const = () => {};
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: typescript
command:
version: 5
spokenForm: clear funk name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: functionName}
usePrePhraseSnapshot: true
initialState:
documentContents: const foo = function bar() {}
selections:
- anchor: {line: 0, character: 12}
active: {line: 0, character: 12}
marks: {}
finalState:
documentContents: const foo = function () {}
selections:
- anchor: {line: 0, character: 21}
active: {line: 0, character: 21}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk name
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: functionName}
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 lambda
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: anonymousFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: (function () {})
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
marks: {}
finalState:
documentContents: ()
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
Loading

0 comments on commit be6bdda

Please sign in to comment.