Skip to content

Commit 88e708b

Browse files
Support text based an syntax tree item
1 parent a672947 commit 88e708b

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

data/fixtures/recorded/languages/typescript/takeItem.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ finalState:
2323
2424
const value = { a: 1, b: 2, c: 3 };
2525
selections:
26-
- anchor: {line: 1, character: 0}
27-
active: {line: 1, character: 35}
26+
- anchor: {line: 1, character: 6}
27+
active: {line: 1, character: 34}

data/fixtures/scopes/javascript.core/collectionItem.unenclosed.iteration.scope

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/common/src/scopeSupportFacets/javascript.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
114114
"value.field": supported,
115115

116116
"collectionItem.unenclosed": supported,
117-
"collectionItem.unenclosed.iteration": supported,
118117
};
119118

120119
export const javascriptJsxScopeSupport: LanguageScopeSupportFacetMap = {

packages/cursorless-engine/src/processTargets/modifiers/ContainingScopeStage.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,39 @@ export class ContainingScopeStage implements ModifierStage {
4545
.run(target);
4646
}
4747

48-
const containingScope = getContainingScopeTarget(
48+
const containingScopes = getContainingScopeTarget(
4949
target,
5050
scopeHandler,
5151
ancestorIndex,
5252
);
53-
54-
if (containingScope == null) {
55-
if (scopeType.type === "collectionItem") {
56-
// For `collectionItem`, fall back to generic implementation
57-
return this.modifierStageFactory
53+
if (scopeType.type === "collectionItem") {
54+
// For `collectionItem`, combine with generic implementation
55+
try {
56+
const legacyScopes = this.modifierStageFactory
5857
.getLegacyScopeStage(this.modifier)
5958
.run(target);
59+
if (containingScopes == null) {
60+
return legacyScopes;
61+
}
62+
if (containingScopes.length === 1 && legacyScopes.length === 1) {
63+
const containingRange = containingScopes[0].contentRange;
64+
const legacyRange = legacyScopes[0].contentRange;
65+
if (
66+
containingRange.contains(legacyRange) &&
67+
!containingRange.isRangeEqual(legacyRange)
68+
) {
69+
return legacyScopes;
70+
}
71+
}
72+
} catch (_ex) {
73+
// Do nothing
6074
}
75+
}
6176

77+
if (containingScopes == null) {
6278
throw new NoContainingScopeError(this.modifier.scopeType.type);
6379
}
6480

65-
return containingScope;
81+
return containingScopes;
6682
}
6783
}

queries/javascript.core.scm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,6 @@
285285
(#insertion-delimiter! @collectionItem ", ")
286286
)
287287

288-
;;!! let foo, bar;
289-
;;! ^^^^^^^^
290-
;;! -------------
291-
(lexical_declaration
292-
.
293-
(_) @collectionItem.iteration.start.startOf
294-
";"? @collectionItem.iteration.end.startOf
295-
) @collectionItem.iteration.domain
296-
297288
(expression_statement
298289
[
299290
;; name:

0 commit comments

Comments
 (0)