From aed028e2763673bdbe8858ae3ed402f7124d9a23 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 12:44:15 +0000 Subject: [PATCH] Add support for `yield` statements for `"value"` in Python (#2215) Fixes #2214 ## 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 --- .../common/src/scopeSupportFacets/python.ts | 1 + .../scopeSupportFacetInfos.ts | 4 ++++ .../scopeSupportFacets.types.ts | 1 + .../fixtures/scopes/python/value.yield.scope | 21 +++++++++++++++++++ queries/python.scm | 12 +++++++++++ 5 files changed, 39 insertions(+) create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/python/value.yield.scope diff --git a/packages/common/src/scopeSupportFacets/python.ts b/packages/common/src/scopeSupportFacets/python.ts index 1e1b4fd791..b9c666ffa6 100644 --- a/packages/common/src/scopeSupportFacets/python.ts +++ b/packages/common/src/scopeSupportFacets/python.ts @@ -12,6 +12,7 @@ export const pythonScopeSupport: LanguageScopeSupportFacetMap = { "name.resource": supported, "name.resource.iteration": supported, "value.foreach": supported, + "value.yield": supported, "value.resource": supported, "value.resource.iteration": supported, diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index d47086df2c..e5781be5a6 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -299,6 +299,10 @@ export const scopeSupportFacetInfos: Record< description: "Value (RHS) of a field in a class / interface", scopeType: "value", }, + "value.yield": { + description: "Value of a yield statement", + scopeType: "value", + }, "value.resource": { description: "Value of a 'with' / 'use' / 'using' statement", scopeType: "value", diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 3adfe5c1ca..cde875d921 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -78,6 +78,7 @@ const scopeSupportFacets = [ "value.return", "value.return.lambda", "value.field", + "value.yield", "value.resource", "value.resource.iteration", diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/python/value.yield.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/python/value.yield.scope new file mode 100644 index 0000000000..1935369c84 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/python/value.yield.scope @@ -0,0 +1,21 @@ +def aaa(): + yield bbb +--- + +[Content] = 1:10-1:13 +1| yield bbb + >---< + +[Removal] = 1:9-1:13 +1| yield bbb + >----< + +[Leading delimiter] = 1:9-1:10 +1| yield bbb + >-< + +[Domain] = 1:4-1:13 +1| yield bbb + >---------< + +[Insertion delimiter] = " " diff --git a/queries/python.scm b/queries/python.scm index 1f465abea9..074d497295 100644 --- a/queries/python.scm +++ b/queries/python.scm @@ -142,6 +142,18 @@ (_) @value ) @_.domain +;;!! yield 1 +;;! ^ +;;! xx +;;! ------- +;; +;; NOTE: in tree-sitter, both "yield" and the "1" are children of `yield` but +;; "yield" is anonymous whereas "1" is named node, so no need to exclude +;; explicitly +(yield + (_) @value +) @_.domain + ;;!! with aaa: ;;! ^^^ ;;! --------