From 3dd52d9e15f417b46a047ad4ae5652500dfe60a0 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 5 Oct 2023 06:22:38 +0100 Subject: [PATCH] Fix value scope nesting in Typescript (#1929) We only want nested value scopes if there is more than one declarator in a statement. Before: image After: image Unfortunately we have no good way to test this change until we have https://github.com/cursorless-dev/cursorless/issues/1524 **Edit**: I found a way to test it, but it's a bit hacky. ## Checklist - [ ] 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/changeNextValue.yml | 30 +++++++++++++++++++ queries/javascript.core.scm | 13 ++++---- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeNextValue.yml diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeNextValue.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeNextValue.yml new file mode 100644 index 00000000000..3abb6a35542 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/typescript/changeNextValue.yml @@ -0,0 +1,30 @@ +languageId: typescript +command: + version: 6 + spokenForm: change next value + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: relativeScope + scopeType: {type: value} + offset: 1 + length: 1 + direction: forward + usePrePhraseSnapshot: true +initialState: + documentContents: |- + const aaa = 0; + const bbb = 0; + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: |- + const aaa = 0; + const bbb = ; + selections: + - anchor: {line: 1, character: 12} + active: {line: 1, character: 12} diff --git a/queries/javascript.core.scm b/queries/javascript.core.scm index 371adda430d..920524256d4 100644 --- a/queries/javascript.core.scm +++ b/queries/javascript.core.scm @@ -353,11 +353,14 @@ ;; Match nodes at field `value` of their parent node, setting leading delimiter ;; to be the range until the previous named node -(_ - (_)? @value.leading.start.endOf - . - value: (_) @value @value.leading.end.startOf -) @_.domain +( + (_ + (_)? @value.leading.start.endOf + . + value: (_) @value @value.leading.end.startOf + ) @_.domain + (#not-type? @_.domain variable_declarator) +) ;;!! const aaa = {bbb}; ;;! ^^^