From f577cee9d4839a8beeb366a64dd4267b5a186f15 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 15 Nov 2023 14:51:38 +0100 Subject: [PATCH] Expand `"type"` to include generic type arguments / parameters (#2023) - fixes https://github.com/cursorless-dev/cursorless/issues/1231 ## Checklist - [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 --- .../languages/typescript/changeType10.yml | 31 +++++++++++++++++++ .../languages/typescript/changeType11.yml | 23 ++++++++++++++ .../languages/typescript/changeType12.yml | 23 ++++++++++++++ .../languages/typescript/changeType13.yml | 23 ++++++++++++++ .../languages/typescript/changeType14.yml | 23 ++++++++++++++ .../languages/typescript/changeType15.yml | 31 +++++++++++++++++++ .../languages/typescript/changeType16.yml | 29 +++++++++++++++++ .../languages/typescript/changeType17.yml | 23 ++++++++++++++ .../languages/typescript/changeType18.yml | 23 ++++++++++++++ .../languages/typescript/changeType19.yml | 23 ++++++++++++++ .../languages/typescript/changeType20.yml | 23 ++++++++++++++ .../languages/typescript/clearType.yml | 6 ++-- .../languages/typescript/clearTypeNear.yml | 6 ++-- .../languages/typescript/clearTypeNear2.yml | 6 ++-- .../languages/typescript/clearTypeUrge.yml | 6 ++-- queries/typescript.core.scm | 17 ++++++++++ 16 files changed, 304 insertions(+), 12 deletions(-) create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType10.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType11.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType12.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType13.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType14.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType15.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType16.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType17.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType18.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType19.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType20.yml diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType10.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType10.yml new file mode 100644 index 0000000000..44b85af3f4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType10.yml @@ -0,0 +1,31 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + useState() + useState>() + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} + - anchor: {line: 1, character: 9} + active: {line: 1, character: 9} + marks: {} +finalState: + documentContents: |- + useState<>() + useState<>() + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} + - anchor: {line: 1, character: 9} + active: {line: 1, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType11.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType11.yml new file mode 100644 index 0000000000..eb89a273dd --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType11.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: foo>() + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} + marks: {} +finalState: + documentContents: foo<>() + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType12.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType12.yml new file mode 100644 index 0000000000..c398b0bb3f --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType12.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: foo() + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} + marks: {} +finalState: + documentContents: foo<, string>() + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType13.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType13.yml new file mode 100644 index 0000000000..44327c208a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType13.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: foo() + selections: + - anchor: {line: 0, character: 12} + active: {line: 0, character: 12} + marks: {} +finalState: + documentContents: foo() + selections: + - anchor: {line: 0, character: 12} + active: {line: 0, character: 12} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType14.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType14.yml new file mode 100644 index 0000000000..9bd3d60cb7 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType14.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: Foo() + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} + marks: {} +finalState: + documentContents: Foo<>() + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType15.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType15.yml new file mode 100644 index 0000000000..5f2139d919 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType15.yml @@ -0,0 +1,31 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: |+ + function foo() { + + } + + selections: + - anchor: {line: 0, character: 13} + active: {line: 0, character: 13} + marks: {} +finalState: + documentContents: |+ + function foo<>() { + + } + + selections: + - anchor: {line: 0, character: 13} + active: {line: 0, character: 13} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType16.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType16.yml new file mode 100644 index 0000000000..d0d68f88c3 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType16.yml @@ -0,0 +1,29 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: | + const bar = () => { + + } + selections: + - anchor: {line: 0, character: 13} + active: {line: 0, character: 13} + marks: {} +finalState: + documentContents: | + const bar = <>() => { + + } + selections: + - anchor: {line: 0, character: 13} + active: {line: 0, character: 13} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType17.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType17.yml new file mode 100644 index 0000000000..3debe09351 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType17.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: "const foo: Record = {}" + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} + marks: {} +finalState: + documentContents: "const foo: Record<, string> = {}" + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType18.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType18.yml new file mode 100644 index 0000000000..93ee6a3e16 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType18.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: "const foo: string = new Bar(foo);" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} + marks: {} +finalState: + documentContents: "const foo: string = new (foo);" + selections: + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType19.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType19.yml new file mode 100644 index 0000000000..2d6199ff98 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType19.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: "const foo: Bar = new Bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} + marks: {} +finalState: + documentContents: "const foo: = new Bar(foo);" + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType20.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType20.yml new file mode 100644 index 0000000000..62a707fc00 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeType20.yml @@ -0,0 +1,23 @@ +languageId: typescript +command: + version: 6 + spokenForm: change type + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: type} + usePrePhraseSnapshot: true +initialState: + documentContents: "const foo: Bar = new Bar(foo);" + selections: + - anchor: {line: 0, character: 15} + active: {line: 0, character: 15} + marks: {} +finalState: + documentContents: "const foo: Bar<> = new Bar(foo);" + selections: + - anchor: {line: 0, character: 15} + active: {line: 0, character: 15} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearType.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearType.yml index 9ccad2f42b..bf3beb3047 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearType.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearType.yml @@ -13,7 +13,7 @@ initialState: active: {line: 0, character: 18} marks: {} finalState: - documentContents: "function whatever(): {}" + documentContents: "function whatever<>(): string {}" selections: - - anchor: {line: 0, character: 24} - active: {line: 0, character: 24} + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml index d6a588d34f..da3273c682 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear.yml @@ -17,7 +17,7 @@ initialState: start: {line: 0, character: 28} end: {line: 0, character: 34} finalState: - documentContents: "const foo: string = new (foo);" + documentContents: "const foo: string = new Bar<>(foo);" selections: - - anchor: {line: 0, character: 24} - active: {line: 0, character: 24} + - anchor: {line: 0, character: 28} + active: {line: 0, character: 28} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml index 23c919f9e4..cc71200839 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeNear2.yml @@ -17,7 +17,7 @@ initialState: start: {line: 0, character: 24} end: {line: 0, character: 30} finalState: - documentContents: "const foo: = bar(foo);" + documentContents: "const foo: string = bar<>(foo);" selections: - - anchor: {line: 0, character: 11} - active: {line: 0, character: 11} + - anchor: {line: 0, character: 24} + active: {line: 0, character: 24} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml index df22813d99..95778e1f10 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/clearTypeUrge.yml @@ -17,7 +17,7 @@ initialState: start: {line: 0, character: 15} end: {line: 0, character: 21} finalState: - documentContents: "const foo: = new Bar(foo);" + documentContents: "const foo: Bar<> = new Bar(foo);" selections: - - anchor: {line: 0, character: 11} - active: {line: 0, character: 11} + - anchor: {line: 0, character: 15} + active: {line: 0, character: 15} diff --git a/queries/typescript.core.scm b/queries/typescript.core.scm index f57f699277..d1692906e2 100644 --- a/queries/typescript.core.scm +++ b/queries/typescript.core.scm @@ -173,6 +173,23 @@ type_arguments: (_)? @type.end ) +;;!! useState() +;;! ^^^^^^ +;;!! useState>() +;;! ^^^^^^^^^^^^^^^^^^^^^^ +;;! ^^^^^^ ^^^^^^ +(type_arguments + (_) @type +) + +;;!! function foo() {} +;;! ^ +;;!! const foo = () => {} +;;! ^ +(type_parameters + (_) @type +) + ;;!! interface Aaa {} ;;!! type Aaa = Bbb; (