Skip to content

Commit ed8f3a4

Browse files
Add missing javascript scope facets (#2827)
1 parent ee55475 commit ed8f3a4

File tree

10 files changed

+174
-20
lines changed

10 files changed

+174
-20
lines changed

data/fixtures/scopes/javascript.core/branch.switchCase.iteration.scope

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ switch (value) {
44
}
55
---
66

7-
[Range] =
7+
[Range] = 0:16-3:0
8+
>
9+
0| switch (value) {
10+
1| case 0: { }
11+
2| case 1: { }
12+
3| }
13+
<
14+
815
[Domain] = 0:0-3:1
916
>----------------
1017
0| switch (value) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
try {
2+
a
3+
}
4+
catch (e) {
5+
b
6+
}
7+
finally {
8+
c
9+
}
10+
---
11+
12+
[Range] =
13+
[Domain] = 0:0-8:1
14+
>-----
15+
0| try {
16+
1| a
17+
2| }
18+
3| catch (e) {
19+
4| b
20+
5| }
21+
6| finally {
22+
7| c
23+
8| }
24+
-<
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
switch (value) {
2+
case 0: { }
3+
case 1: { }
4+
}
5+
---
6+
7+
[Range] = 0:16-3:0
8+
>
9+
0| switch (value) {
10+
1| case 0: { }
11+
2| case 1: { }
12+
3| }
13+
<
14+
15+
[Domain] = 0:0-3:1
16+
>----------------
17+
0| switch (value) {
18+
1| case 0: { }
19+
2| case 1: { }
20+
3| }
21+
-<
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const aaa = 2;
2+
3+
---
4+
5+
[Range] =
6+
[Domain] = 0:0-1:0
7+
>--------------
8+
0| const aaa = 2;
9+
1|
10+
<
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Foo { }
2+
---
3+
4+
[Content] =
5+
[Removal] =
6+
[Domain] = 0:0-0:13
7+
>-------------<
8+
0| class Foo { }
9+
10+
[Insertion delimiter] = "\n"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
yield 5;
2+
---
3+
4+
[Content] = 0:6-0:7
5+
>-<
6+
0| yield 5;
7+
8+
[Removal] = 0:5-0:7
9+
>--<
10+
0| yield 5;
11+
12+
[Leading delimiter] = 0:5-0:6
13+
>-<
14+
0| yield 5;
15+
16+
[Domain] = 0:0-0:7
17+
>-------<
18+
0| yield 5;
19+
20+
[Insertion delimiter] = " "

packages/common/src/scopeSupportFacets/javascript.ts

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
77
export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
88
list: supported,
99
map: supported,
10-
ifStatement: supported,
1110
regularExpression: supported,
1211
switchStatementSubject: supported,
1312
fieldAccess: supported,
1413
disqualifyDelimiter: supported,
1514
pairDelimiter: supported,
1615

16+
"collectionItem.unenclosed": supported,
17+
1718
"textFragment.string.singleLine": supported,
1819
"textFragment.string.multiLine": supported,
1920
"textFragment.comment.line": supported,
2021
"textFragment.comment.block": supported,
2122

23+
ifStatement: supported,
24+
2225
statement: supported,
2326
"statement.iteration.document": supported,
2427
"statement.iteration.block": supported,
28+
"statement.class": supported,
2529

2630
class: supported,
2731
className: supported,
@@ -67,6 +71,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
6771
"branch.if": supported,
6872
"branch.if.iteration": supported,
6973
"branch.try": supported,
74+
"branch.try.iteration": supported,
7075
"branch.switchCase": supported,
7176
"branch.switchCase.iteration": supported,
7277
"branch.ternary": supported,
@@ -77,6 +82,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
7782
"condition.for": supported,
7883
"condition.ternary": supported,
7984
"condition.switchCase": supported,
85+
"condition.switchCase.iteration": supported,
8086

8187
"name.argument.formal": supported,
8288
"name.argument.formal.iteration": supported,
@@ -94,6 +100,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
94100
"name.constructor": supported,
95101
"name.class": supported,
96102
"name.field": supported,
103+
"name.iteration.document": supported,
97104

98105
"key.mapPair": supported,
99106
"key.mapPair.iteration": supported,
@@ -113,8 +120,52 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
113120
"value.return": supported,
114121
"value.return.lambda": supported,
115122
"value.field": supported,
116-
117-
"collectionItem.unenclosed": supported,
123+
"value.yield": supported,
124+
125+
// Unsupported
126+
127+
"collectionItem.unenclosed.iteration": unsupported,
128+
"branch.loop": unsupported,
129+
"namedFunction.iteration.block": unsupported,
130+
"functionName.iteration.block": unsupported,
131+
132+
"class.iteration.block": unsupported,
133+
"class.iteration.document": unsupported,
134+
"className.iteration.block": unsupported,
135+
"className.iteration.document": unsupported,
136+
137+
"name.iteration.block": unsupported,
138+
"name.resource": unsupported,
139+
"name.resource.iteration": unsupported,
140+
141+
"value.resource": unsupported,
142+
"value.resource.iteration": unsupported,
143+
144+
"interior.class": unsupported,
145+
"interior.function": unsupported,
146+
"interior.if": unsupported,
147+
"interior.lambda": unsupported,
148+
"interior.loop": unsupported,
149+
"interior.switchCase": unsupported,
150+
"interior.ternary": unsupported,
151+
"interior.try": unsupported,
152+
"interior.resource": unsupported,
153+
154+
// Not applicable
155+
156+
"interior.cell": notApplicable,
157+
"interior.command": notApplicable,
158+
"name.argument.actual.iteration": notApplicable,
159+
"name.argument.actual": notApplicable,
160+
"value.argument.actual": notApplicable,
161+
"value.argument.actual.iteration": notApplicable,
162+
"section.iteration.document": notApplicable,
163+
"section.iteration.parent": notApplicable,
164+
"textFragment.element": notApplicable,
165+
command: notApplicable,
166+
environment: notApplicable,
167+
notebookCell: notApplicable,
168+
section: notApplicable,
118169
};
119170

120171
export const javascriptJsxScopeSupport: LanguageScopeSupportFacetMap = {
@@ -132,16 +183,25 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
132183
...javascriptCoreScopeSupport,
133184
...javascriptJsxScopeSupport,
134185

135-
"type.variable": notApplicable,
136-
"type.argument.formal": notApplicable,
186+
// Types are defined here because we don't want typescript to import them and
187+
// accidentally forget to add support for them.
188+
"value.typeAlias": notApplicable,
189+
"type.alias": notApplicable,
190+
"type.argument.formal.constructor.iteration": notApplicable,
191+
"type.argument.formal.constructor": notApplicable,
137192
"type.argument.formal.iteration": notApplicable,
138-
"type.argument.formal.method": notApplicable,
139193
"type.argument.formal.method.iteration": notApplicable,
140-
"type.argument.formal.constructor": notApplicable,
141-
"type.argument.formal.constructor.iteration": notApplicable,
142-
"type.return": notApplicable,
194+
"type.argument.formal.method": notApplicable,
195+
"type.argument.formal": notApplicable,
196+
"type.cast": notApplicable,
197+
"type.class": notApplicable,
198+
"type.enum": notApplicable,
199+
"type.field.iteration": notApplicable,
143200
"type.field": notApplicable,
144201
"type.foreach": notApplicable,
145202
"type.interface": notApplicable,
146-
command: notApplicable,
203+
"type.return": notApplicable,
204+
"type.typeArgument.iteration": notApplicable,
205+
"type.typeArgument": notApplicable,
206+
"type.variable": notApplicable,
147207
};

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const scopeSupportFacetInfos: Record<
173173
scopeType: "functionName",
174174
},
175175
"functionName.method.iteration.class": {
176-
description: "Iteration scope for function names: class bodies",
176+
description: "Iteration scope for method names: class bodies",
177177
scopeType: "functionName",
178178
isIteration: true,
179179
},

packages/common/src/scopeSupportFacets/typescript.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const { supported } = ScopeSupportFacetLevel;
77
export const typescriptScopeSupport: LanguageScopeSupportFacetMap = {
88
...javascriptCoreScopeSupport,
99

10-
"name.field": supported,
11-
1210
"type.argument.formal": supported,
1311
"type.argument.formal.iteration": supported,
1412
"type.argument.formal.method": supported,
@@ -23,8 +21,5 @@ export const typescriptScopeSupport: LanguageScopeSupportFacetMap = {
2321
"type.return": supported,
2422
"type.variable": supported,
2523

26-
"value.field": supported,
2724
"value.typeAlias": supported,
28-
29-
disqualifyDelimiter: supported,
3025
};

queries/javascript.core.scm

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,16 @@
607607

608608
(switch_default) @branch
609609

610-
;;!! switch () {}
611-
;;! ^^^^^^^^^^^^
612-
(switch_statement) @branch.iteration @condition.iteration
610+
;;!! switch () { }
611+
;;! ^
612+
(switch_statement
613+
body: (_
614+
.
615+
"{" @branch.iteration.start.endOf @condition.iteration.start.endOf
616+
"}" @branch.iteration.end.startOf @condition.iteration.end.startOf
617+
.
618+
)
619+
) @branch.iteration.domain @condition.iteration.domain
613620

614621
;;!! if () {}
615622
;;! ^^^^^^^^

0 commit comments

Comments
 (0)