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 9, 2023
1 parent 65fab51 commit adf03e9
Show file tree
Hide file tree
Showing 28 changed files with 747 additions and 54 deletions.
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,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: 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}
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: export var foo = () => {};
selections:
- anchor: {line: 0, character: 8}
active: {line: 0, character: 8}
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: const 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}
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: let 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}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
interface Aaa {
bbb(): void;
}
selections:
- anchor: {line: 1, character: 16}
active: {line: 1, character: 16}
marks: {}
finalState:
documentContents: |-
interface 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,42 @@
languageId: typescript
command:
version: 5
spokenForm: clear funk
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
class MyClass {
constructor(value: string);
constructor(value: number);
constructor(value: string | number) {}
}
selections:
- anchor: {line: 1, character: 31}
active: {line: 1, character: 31}
- anchor: {line: 2, character: 31}
active: {line: 2, character: 31}
- anchor: {line: 4, character: 42}
active: {line: 4, character: 42}
marks: {}
finalState:
documentContents: |-
class MyClass {
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
- anchor: {line: 4, character: 4}
active: {line: 4, 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: 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}
Loading

0 comments on commit adf03e9

Please sign in to comment.