diff --git a/data/fixtures/scopes/c/name.argument.formal.iteration2.scope b/data/fixtures/scopes/c/name.argument.formal.iteration2.scope index 4d651af334..bc0277a46c 100644 --- a/data/fixtures/scopes/c/name.argument.formal.iteration2.scope +++ b/data/fixtures/scopes/c/name.argument.formal.iteration2.scope @@ -11,9 +11,3 @@ void aaa(int bbb, int ccc) {} [#2 Domain] = 0:9-0:25 >----------------< 0| void aaa(int bbb, int ccc) {} - - -[#3 Range] = -[#3 Domain] = 0:28-0:28 - >< -0| void aaa(int bbb, int ccc) {} diff --git a/data/fixtures/scopes/c/name.iteration.block2.scope b/data/fixtures/scopes/c/name.iteration.block2.scope index 73e54b7c16..dd07df8311 100644 --- a/data/fixtures/scopes/c/name.iteration.block2.scope +++ b/data/fixtures/scopes/c/name.iteration.block2.scope @@ -8,12 +8,6 @@ void foo() { } [#2 Range] = -[#2 Domain] = 0:9-0:9 - >< -0| void foo() { } - - -[#3 Range] = -[#3 Domain] = 0:12-0:13 +[#2 Domain] = 0:12-0:13 >-< 0| void foo() { } diff --git a/data/fixtures/scopes/cpp/name.argument.formal.constructor.iteration.scope b/data/fixtures/scopes/cpp/name.argument.formal.constructor.iteration.scope index 64ed1e42bd..9d6f2a4747 100644 --- a/data/fixtures/scopes/cpp/name.argument.formal.constructor.iteration.scope +++ b/data/fixtures/scopes/cpp/name.argument.formal.constructor.iteration.scope @@ -25,9 +25,3 @@ class MyClass { [#3 Domain] = 1:12-1:32 >--------------------< 1| MyClass(int aaa, int bbb = 2) {} - - -[#4 Range] = -[#4 Domain] = 1:35-1:35 - >< -1| MyClass(int aaa, int bbb = 2) {} diff --git a/data/fixtures/scopes/cpp/name.argument.formal.iteration.scope b/data/fixtures/scopes/cpp/name.argument.formal.iteration.scope index c94fac1f7f..c4e65a1da0 100644 --- a/data/fixtures/scopes/cpp/name.argument.formal.iteration.scope +++ b/data/fixtures/scopes/cpp/name.argument.formal.iteration.scope @@ -11,9 +11,3 @@ void aaa(int bbb = 0, int ccc = 0) {} [#2 Domain] = 0:9-0:33 >------------------------< 0| void aaa(int bbb = 0, int ccc = 0) {} - - -[#3 Range] = -[#3 Domain] = 0:36-0:36 - >< -0| void aaa(int bbb = 0, int ccc = 0) {} diff --git a/data/fixtures/scopes/cpp/name.argument.formal.method.iteration.scope b/data/fixtures/scopes/cpp/name.argument.formal.method.iteration.scope index 9b6a131190..f103bb7282 100644 --- a/data/fixtures/scopes/cpp/name.argument.formal.method.iteration.scope +++ b/data/fixtures/scopes/cpp/name.argument.formal.method.iteration.scope @@ -25,9 +25,3 @@ class MyClass { [#3 Domain] = 1:13-1:33 >--------------------< 1| void foo(int aaa, int bbb = 2) {} - - -[#4 Range] = -[#4 Domain] = 1:36-1:36 - >< -1| void foo(int aaa, int bbb = 2) {} diff --git a/data/fixtures/scopes/csharp/name.argument.formal.constructor.iteration.scope b/data/fixtures/scopes/csharp/name.argument.formal.constructor.iteration.scope index 9c96bc5807..85f5d68136 100644 --- a/data/fixtures/scopes/csharp/name.argument.formal.constructor.iteration.scope +++ b/data/fixtures/scopes/csharp/name.argument.formal.constructor.iteration.scope @@ -25,9 +25,3 @@ class MyClass { [#3 Domain] = 1:12-1:28 >----------------< 1| MyClass(int foo, int bar) {} - - -[#4 Range] = -[#4 Domain] = 1:31-1:31 - >< -1| MyClass(int foo, int bar) {} diff --git a/data/fixtures/scopes/csharp/name.argument.formal.iteration.scope b/data/fixtures/scopes/csharp/name.argument.formal.iteration.scope index cf46c08764..d259181d93 100644 --- a/data/fixtures/scopes/csharp/name.argument.formal.iteration.scope +++ b/data/fixtures/scopes/csharp/name.argument.formal.iteration.scope @@ -11,9 +11,3 @@ void myFunk(String name, int value) {} [#2 Domain] = 0:12-0:34 >----------------------< 0| void myFunk(String name, int value) {} - - -[#3 Range] = -[#3 Domain] = 0:37-0:37 - >< -0| void myFunk(String name, int value) {} diff --git a/data/fixtures/scopes/csharp/name.argument.formal.method.iteration.scope b/data/fixtures/scopes/csharp/name.argument.formal.method.iteration.scope index e621de9367..ba1fb12c7a 100644 --- a/data/fixtures/scopes/csharp/name.argument.formal.method.iteration.scope +++ b/data/fixtures/scopes/csharp/name.argument.formal.method.iteration.scope @@ -25,9 +25,3 @@ class MyClass { [#3 Domain] = 1:14-1:30 >----------------< 1| void funk(int foo, int bar) {} - - -[#4 Range] = -[#4 Domain] = 1:33-1:33 - >< -1| void funk(int foo, int bar) {} diff --git a/data/fixtures/scopes/csharp/name.iteration.block2.scope b/data/fixtures/scopes/csharp/name.iteration.block2.scope index 4ae59561fa..3736f6b85b 100644 --- a/data/fixtures/scopes/csharp/name.iteration.block2.scope +++ b/data/fixtures/scopes/csharp/name.iteration.block2.scope @@ -8,12 +8,6 @@ void MyFunk() { } [#2 Range] = -[#2 Domain] = 0:12-0:12 - >< -0| void MyFunk() { } - - -[#3 Range] = -[#3 Domain] = 0:15-0:16 +[#2 Domain] = 0:15-0:16 >-< 0| void MyFunk() { } diff --git a/data/fixtures/scopes/csharp/name.iteration.document.scope b/data/fixtures/scopes/csharp/name.iteration.document.scope index a1948c1fe5..482a9e9476 100644 --- a/data/fixtures/scopes/csharp/name.iteration.document.scope +++ b/data/fixtures/scopes/csharp/name.iteration.document.scope @@ -3,16 +3,10 @@ class MyClass {} --- -[#1 Range] = -[#1 Domain] = 0:0-2:0 +[Range] = +[Domain] = 0:0-2:0 > 0| 1| class MyClass {} 2| < - - -[#2 Range] = -[#2 Domain] = 1:15-1:15 - >< -1| class MyClass {} diff --git a/data/fixtures/scopes/csharp/statement.iteration.document.scope b/data/fixtures/scopes/csharp/statement.iteration.document.scope index a1948c1fe5..482a9e9476 100644 --- a/data/fixtures/scopes/csharp/statement.iteration.document.scope +++ b/data/fixtures/scopes/csharp/statement.iteration.document.scope @@ -3,16 +3,10 @@ class MyClass {} --- -[#1 Range] = -[#1 Domain] = 0:0-2:0 +[Range] = +[Domain] = 0:0-2:0 > 0| 1| class MyClass {} 2| < - - -[#2 Range] = -[#2 Domain] = 1:15-1:15 - >< -1| class MyClass {} diff --git a/data/fixtures/scopes/csharp/type.argument.formal.constructor.iteration.scope b/data/fixtures/scopes/csharp/type.argument.formal.constructor.iteration.scope index 5f46efab43..63f840500e 100644 --- a/data/fixtures/scopes/csharp/type.argument.formal.constructor.iteration.scope +++ b/data/fixtures/scopes/csharp/type.argument.formal.constructor.iteration.scope @@ -16,9 +16,3 @@ class MyClass { [#2 Domain] = 1:12-1:24 >------------< 1| MyClass(int a, int b) {} - - -[#3 Range] = -[#3 Domain] = 1:27-1:27 - >< -1| MyClass(int a, int b) {} diff --git a/data/fixtures/scopes/csharp/type.argument.formal.iteration.scope b/data/fixtures/scopes/csharp/type.argument.formal.iteration.scope index 772228f4b6..abc43026fe 100644 --- a/data/fixtures/scopes/csharp/type.argument.formal.iteration.scope +++ b/data/fixtures/scopes/csharp/type.argument.formal.iteration.scope @@ -1,13 +1,7 @@ void myFunk(String name, int value) {} --- -[#1 Range] = -[#1 Domain] = 0:12-0:34 +[Range] = +[Domain] = 0:12-0:34 >----------------------< 0| void myFunk(String name, int value) {} - - -[#2 Range] = -[#2 Domain] = 0:37-0:37 - >< -0| void myFunk(String name, int value) {} diff --git a/data/fixtures/scopes/csharp/type.argument.formal.method.iteration.scope b/data/fixtures/scopes/csharp/type.argument.formal.method.iteration.scope index 9fd010aa96..b8d7f6461c 100644 --- a/data/fixtures/scopes/csharp/type.argument.formal.method.iteration.scope +++ b/data/fixtures/scopes/csharp/type.argument.formal.method.iteration.scope @@ -16,9 +16,3 @@ class MyClass { [#2 Domain] = 1:14-1:26 >------------< 1| void funk(int a, int b) {} - - -[#3 Range] = -[#3 Domain] = 1:29-1:29 - >< -1| void funk(int a, int b) {} diff --git a/data/fixtures/scopes/csharp/value.argument.formal.constructor.iteration.scope b/data/fixtures/scopes/csharp/value.argument.formal.constructor.iteration.scope index e7cd07a8e1..089441dbd5 100644 --- a/data/fixtures/scopes/csharp/value.argument.formal.constructor.iteration.scope +++ b/data/fixtures/scopes/csharp/value.argument.formal.constructor.iteration.scope @@ -16,9 +16,3 @@ class MyClass { [#2 Domain] = 1:12-1:32 >--------------------< 1| MyClass(int a = 1, int b = 2) {} - - -[#3 Range] = -[#3 Domain] = 1:35-1:35 - >< -1| MyClass(int a = 1, int b = 2) {} diff --git a/data/fixtures/scopes/csharp/value.argument.formal.iteration.scope b/data/fixtures/scopes/csharp/value.argument.formal.iteration.scope index f5e17fbc98..963f3d58ac 100644 --- a/data/fixtures/scopes/csharp/value.argument.formal.iteration.scope +++ b/data/fixtures/scopes/csharp/value.argument.formal.iteration.scope @@ -1,13 +1,7 @@ void myFunk(String name, int value = 5) {} --- -[#1 Range] = -[#1 Domain] = 0:12-0:38 +[Range] = +[Domain] = 0:12-0:38 >--------------------------< 0| void myFunk(String name, int value = 5) {} - - -[#2 Range] = -[#2 Domain] = 0:41-0:41 - >< -0| void myFunk(String name, int value = 5) {} diff --git a/data/fixtures/scopes/csharp/value.argument.formal.method.iteration.scope b/data/fixtures/scopes/csharp/value.argument.formal.method.iteration.scope index c96c7e651f..ee8e38be0c 100644 --- a/data/fixtures/scopes/csharp/value.argument.formal.method.iteration.scope +++ b/data/fixtures/scopes/csharp/value.argument.formal.method.iteration.scope @@ -16,9 +16,3 @@ class MyClass { [#2 Domain] = 1:14-1:34 >--------------------< 1| void funk(int a = 1, int b = 2) {} - - -[#3 Range] = -[#3 Domain] = 1:37-1:37 - >< -1| void funk(int a = 1, int b = 2) {} diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope index 2920e986f2..c618ca69cd 100644 --- a/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope +++ b/data/fixtures/scopes/java/collectionItem.unenclosed.iteration2.scope @@ -22,17 +22,11 @@ public class MyClass { < -[#2 Range] = -[#2 Domain] = 1:23-1:23 - >< -1| public void myFunk() { - - -[#3 Range] = 2:8-2:24 +[#2 Range] = 2:8-2:24 >----------------< 2| String foo, bar; -[#3 Domain] = 1:26-3:4 +[#2 Domain] = 1:26-3:4 > 1| public void myFunk() { 2| String foo, bar; @@ -40,19 +34,19 @@ public class MyClass { ----< -[#4 Range] = 2:8-2:24 +[#3 Range] = 2:8-2:24 >----------------< 2| String foo, bar; -[#4 Domain] = 2:0-2:24 +[#3 Domain] = 2:0-2:24 >------------------------< 2| String foo, bar; -[#5 Range] = 2:15-2:23 +[#4 Range] = 2:15-2:23 >--------< 2| String foo, bar; -[#5 Domain] = 2:8-2:24 +[#4 Domain] = 2:8-2:24 >----------------< 2| String foo, bar; diff --git a/data/fixtures/scopes/java/name.iteration.block.scope b/data/fixtures/scopes/java/name.iteration.block.scope index a6a24213a1..e5ad7fb760 100644 --- a/data/fixtures/scopes/java/name.iteration.block.scope +++ b/data/fixtures/scopes/java/name.iteration.block.scope @@ -27,17 +27,8 @@ public class MyClass { < -[#3 Range] = 1:22-1:22 - >< -1| public void myFunk() { - -[#3 Domain] = 1:21-1:23 - >--< -1| public void myFunk() { - - -[#4 Range] = -[#4 Domain] = 1:25-3:3 +[#3 Range] = +[#3 Domain] = 1:25-3:3 > 1| public void myFunk() { 2| if (true) { } @@ -45,7 +36,7 @@ public class MyClass { ---< -[#5 Range] = -[#5 Domain] = 2:15-2:16 +[#4 Range] = +[#4 Domain] = 2:15-2:16 >-< 2| if (true) { } diff --git a/data/fixtures/scopes/javascript.core/name.iteration.block.scope b/data/fixtures/scopes/javascript.core/name.iteration.block.scope index e1eb393319..cb73f4ef7c 100644 --- a/data/fixtures/scopes/javascript.core/name.iteration.block.scope +++ b/data/fixtures/scopes/javascript.core/name.iteration.block.scope @@ -22,12 +22,6 @@ class MyClass { [#3 Range] = -[#3 Domain] = 1:11-1:11 - >< -1| myFunk() { } - - -[#4 Range] = -[#4 Domain] = 1:14-1:15 +[#3 Domain] = 1:14-1:15 >-< 1| myFunk() { } diff --git a/data/fixtures/scopes/javascript.core/name.iteration.block2.scope b/data/fixtures/scopes/javascript.core/name.iteration.block2.scope index 3cac5d8be0..da00f553fb 100644 --- a/data/fixtures/scopes/javascript.core/name.iteration.block2.scope +++ b/data/fixtures/scopes/javascript.core/name.iteration.block2.scope @@ -8,12 +8,6 @@ function myFunk() { } [#2 Range] = -[#2 Domain] = 0:16-0:16 - >< -0| function myFunk() { } - - -[#3 Range] = -[#3 Domain] = 0:19-0:20 +[#2 Domain] = 0:19-0:20 >-< 0| function myFunk() { } diff --git a/data/fixtures/scopes/python/collectionItem.unenclosed.iteration3.scope b/data/fixtures/scopes/python/collectionItem.unenclosed.iteration3.scope index badf04bc7e..fdee8ecd9e 100644 --- a/data/fixtures/scopes/python/collectionItem.unenclosed.iteration3.scope +++ b/data/fixtures/scopes/python/collectionItem.unenclosed.iteration3.scope @@ -2,25 +2,19 @@ def foo(): global bar, baz --- -[#1 Range] = -[#1 Domain] = 0:8-0:8 - >< -0| def foo(): - - -[#2 Range] = 1:4-1:19 +[#1 Range] = 1:4-1:19 >---------------< 1| global bar, baz -[#2 Domain] = 1:0-1:19 +[#1 Domain] = 1:0-1:19 >-------------------< 1| global bar, baz -[#3 Range] = 1:11-1:19 +[#2 Range] = 1:11-1:19 >--------< 1| global bar, baz -[#3 Domain] = 1:4-1:19 +[#2 Domain] = 1:4-1:19 >---------------< 1| global bar, baz diff --git a/data/fixtures/scopes/python/collectionItem.unenclosed.iteration4.scope b/data/fixtures/scopes/python/collectionItem.unenclosed.iteration4.scope index c5748186a1..c91ff7fbd7 100644 --- a/data/fixtures/scopes/python/collectionItem.unenclosed.iteration4.scope +++ b/data/fixtures/scopes/python/collectionItem.unenclosed.iteration4.scope @@ -3,12 +3,12 @@ for key, value in map.items(): --- [#1 Range] = -[#1 Domain] = 0:4-0:14 - >----------< +[#1 Domain] = 0:0-0:30 + >------------------------------< 0| for key, value in map.items(): [#2 Range] = -[#2 Domain] = 0:28-0:28 - >< +[#2 Domain] = 0:4-0:14 + >----------< 0| for key, value in map.items(): diff --git a/data/fixtures/scopes/scss/name.argument.formal.iteration.scope b/data/fixtures/scopes/scss/name.argument.formal.iteration.scope index 26a2864393..cb850e1273 100644 --- a/data/fixtures/scopes/scss/name.argument.formal.iteration.scope +++ b/data/fixtures/scopes/scss/name.argument.formal.iteration.scope @@ -14,9 +14,3 @@ [#2 Domain] = 0:19-0:40 >---------------------< 0| @mixin replace-text($image, $color: red) {} - - -[#3 Range] = -[#3 Domain] = 0:42-0:42 - >< -0| @mixin replace-text($image, $color: red) {} diff --git a/data/fixtures/scopes/scss/value.argument.formal.iteration.scope b/data/fixtures/scopes/scss/value.argument.formal.iteration.scope index 26a2864393..cb850e1273 100644 --- a/data/fixtures/scopes/scss/value.argument.formal.iteration.scope +++ b/data/fixtures/scopes/scss/value.argument.formal.iteration.scope @@ -14,9 +14,3 @@ [#2 Domain] = 0:19-0:40 >---------------------< 0| @mixin replace-text($image, $color: red) {} - - -[#3 Range] = -[#3 Domain] = 0:42-0:42 - >< -0| @mixin replace-text($image, $color: red) {} diff --git a/data/fixtures/scopes/textual/surroundingPair.iteration.scope b/data/fixtures/scopes/textual/surroundingPair.iteration.scope index 98176cda69..26b2ab7e16 100644 --- a/data/fixtures/scopes/textual/surroundingPair.iteration.scope +++ b/data/fixtures/scopes/textual/surroundingPair.iteration.scope @@ -3,19 +3,7 @@ --- -[#1 Range] = -[#1 Domain] = 0:0-0:0 - >< -0| - - -[#2 Range] = -[#2 Domain] = 1:0-1:3 +[Range] = +[Domain] = 1:0-1:3 >---< 1| ( ) - - -[#3 Range] = -[#3 Domain] = 2:0-2:0 - >< -2| diff --git a/data/fixtures/scopes/textual/surroundingPair.iteration2.scope b/data/fixtures/scopes/textual/surroundingPair.iteration2.scope index 5fc343d946..6fb4190a50 100644 --- a/data/fixtures/scopes/textual/surroundingPair.iteration2.scope +++ b/data/fixtures/scopes/textual/surroundingPair.iteration2.scope @@ -3,19 +3,7 @@ hello --- -[#1 Range] = -[#1 Domain] = 0:0-0:0 - >< -0| - - -[#2 Range] = -[#2 Domain] = 1:0-1:5 +[Range] = +[Domain] = 1:0-1:5 >-----< 1| hello - - -[#3 Range] = -[#3 Domain] = 2:0-2:0 - >< -2| diff --git a/packages/cursorless-engine/src/languages/TreeSitterQuery/TreeSitterQuery.ts b/packages/cursorless-engine/src/languages/TreeSitterQuery/TreeSitterQuery.ts index 60d3763a02..aee2165257 100644 --- a/packages/cursorless-engine/src/languages/TreeSitterQuery/TreeSitterQuery.ts +++ b/packages/cursorless-engine/src/languages/TreeSitterQuery/TreeSitterQuery.ts @@ -110,7 +110,7 @@ export class TreeSitterQuery { match: treeSitter.QueryMatch, ): MutableQueryMatch { return { - patternIdx: match.pattern, + patternIdx: match.patternIndex, captures: match.captures.map(({ name, node }) => ({ name, node, diff --git a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/collectionItemTextualIterationScopeHandler.ts b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/collectionItemTextualIterationScopeHandler.ts index 6c08500cb5..d570a7c7ae 100644 --- a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/collectionItemTextualIterationScopeHandler.ts +++ b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/CollectionItemScopeHandler/collectionItemTextualIterationScopeHandler.ts @@ -1,5 +1,4 @@ import { testRegex } from "@cursorless/common"; -import type { TargetScope } from "../scope.types"; import type { ComplexScopeType } from "../scopeHandler.types"; import { separatorRegex } from "./getSeparatorOccurrences"; @@ -7,15 +6,19 @@ export const collectionItemTextualIterationScopeHandler: ComplexScopeType = { type: "fallback", scopeTypes: [ { - type: "surroundingPairInterior", - delimiter: "collectionBoundary", + type: "conditional", + scopeType: { + type: "surroundingPairInterior", + delimiter: "collectionBoundary", + }, + predicate: (scope) => !scope.domain.isEmpty, }, { type: "conditional", scopeType: { type: "line", }, - predicate: (scope: TargetScope) => { + predicate: (scope) => { const text = scope.editor.document.getText(scope.domain); return testRegex(separatorRegex, text); }, diff --git a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/SurroundingPairScopeHandler.ts b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/SurroundingPairScopeHandler.ts index 615873b833..eeafbdead3 100644 --- a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/SurroundingPairScopeHandler.ts +++ b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/SurroundingPairScopeHandler.ts @@ -4,13 +4,16 @@ import type { SurroundingPairScopeType, TextEditor, } from "@cursorless/common"; -import { showError, type ScopeType } from "@cursorless/common"; +import { showError } from "@cursorless/common"; import type { LanguageDefinitions } from "../../../../languages/LanguageDefinitions"; import { ide } from "../../../../singletons/ide.singleton"; import { BaseScopeHandler } from "../BaseScopeHandler"; import { compareTargetScopes } from "../compareTargetScopes"; import type { TargetScope } from "../scope.types"; -import type { ScopeIteratorRequirements } from "../scopeHandler.types"; +import type { + ConditionalScopeType, + ScopeIteratorRequirements, +} from "../scopeHandler.types"; import { createTargetScope } from "./createTargetScope"; import { getDelimiterOccurrences } from "./getDelimiterOccurrences"; import { getIndividualDelimiters } from "./getIndividualDelimiters"; @@ -18,7 +21,11 @@ import { getSurroundingPairOccurrences } from "./getSurroundingPairOccurrences"; import type { SurroundingPairOccurrence } from "./types"; export class SurroundingPairScopeHandler extends BaseScopeHandler { - public readonly iterationScopeType: ScopeType = { type: "line" }; + public readonly iterationScopeType: ConditionalScopeType = { + type: "conditional", + scopeType: { type: "line" }, + predicate: (scope) => !scope.domain.isEmpty, + }; protected isHierarchical = true; constructor( diff --git a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/TreeSitterScopeHandler/TreeSitterIterationScopeHandler.ts b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/TreeSitterScopeHandler/TreeSitterIterationScopeHandler.ts index 55c299c4cb..e3cfca770c 100644 --- a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/TreeSitterScopeHandler/TreeSitterIterationScopeHandler.ts +++ b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/TreeSitterScopeHandler/TreeSitterIterationScopeHandler.ts @@ -47,6 +47,11 @@ export class TreeSitterIterationScopeHandler extends BaseTreeSitterScopeHandler const { range: contentRange, allowMultiple } = capture; + // Don't yield empty iteration scopes + if (contentRange.isEmpty) { + return undefined; + } + const domain = getRelatedRange(match, scopeTypeType, "iteration.domain", false) ?? contentRange; diff --git a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runBasicScopeInfoTest.ts b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runBasicScopeInfoTest.ts index f3de48e5f4..1bd4beb106 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runBasicScopeInfoTest.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runBasicScopeInfoTest.ts @@ -54,14 +54,11 @@ function helloWorld() { } `; -function getExpectedScope( - scopeSupport: ScopeSupport, - iterationScopeSupport?: ScopeSupport, -): ScopeSupportInfo { +function getExpectedScope(scopeSupport: ScopeSupport): ScopeSupportInfo { return { humanReadableName: "named function", isLanguageSpecific: true, - iterationScopeSupport: iterationScopeSupport ?? scopeSupport, + iterationScopeSupport: scopeSupport, scopeType: { type: "namedFunction", }, @@ -74,8 +71,5 @@ function getExpectedScope( } const unsupported = getExpectedScope(ScopeSupport.unsupported); -const supported = getExpectedScope( - ScopeSupport.supportedButNotPresentInEditor, - ScopeSupport.supportedAndPresentInEditor, -); +const supported = getExpectedScope(ScopeSupport.supportedButNotPresentInEditor); const present = getExpectedScope(ScopeSupport.supportedAndPresentInEditor); diff --git a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runSurroundingPairScopeInfoTest.ts b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runSurroundingPairScopeInfoTest.ts index 344aab4610..b0d054d984 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runSurroundingPairScopeInfoTest.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runSurroundingPairScopeInfoTest.ts @@ -39,10 +39,7 @@ function getExpectedScope(scopeSupport: ScopeSupport): ScopeSupportInfo { return { humanReadableName: "Matching pair of parentheses", isLanguageSpecific: false, - iterationScopeSupport: - scopeSupport === ScopeSupport.unsupported - ? ScopeSupport.unsupported - : ScopeSupport.supportedAndPresentInEditor, + iterationScopeSupport: scopeSupport, scopeType: { type: "surroundingPair", delimiter: "parentheses" }, spokenForm: { spokenForms: ["round"],