Skip to content

Commit eefee91

Browse files
authored
Add name.variable and value.variable (#2219)
I think it's worth distinguishing between an assignment (`foo = bar`) and a variable declarateion (`const foo = bar`) to make it clear we want to support both. I think the name `name.variable` and `value.variable` are clear enough and consistent with `name.function` ## 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
1 parent bae9ce0 commit eefee91

File tree

12 files changed

+132
-53
lines changed

12 files changed

+132
-53
lines changed

packages/common/src/scopeSupportFacets/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const htmlScopeSupport: LanguageScopeSupportFacetMap = {
4343
"namedFunction.method": notApplicable,
4444
"string.multiLine": notApplicable,
4545
"string.singleLine": notApplicable,
46-
"type.assignment": notApplicable,
46+
"type.variable": notApplicable,
4747
"type.field": notApplicable,
4848
"type.foreach": notApplicable,
4949
"type.formalParameter": notApplicable,

packages/common/src/scopeSupportFacets/javascript.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
6060
"name.foreach": supported,
6161
"name.assignment": supported,
6262
"name.assignment.pattern": supported,
63+
"name.variable": supported,
64+
"name.variable.pattern": supported,
6365
"name.function": supported,
6466
"name.class": supported,
6567
"name.field": supported,
@@ -70,6 +72,7 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
7072
"value.mapPair": supported,
7173
"value.mapPair.iteration": supported,
7274
"value.assignment": supported,
75+
"value.variable": supported,
7376
"value.foreach": supported,
7477
"value.return": supported,
7578
"value.return.lambda": supported,
@@ -83,7 +86,7 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
8386
"key.attribute": supported,
8487
"value.attribute": supported,
8588

86-
"type.assignment": notApplicable,
89+
"type.variable": notApplicable,
8790
"type.formalParameter": notApplicable,
8891
"type.return": notApplicable,
8992
"type.field": notApplicable,

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ export const scopeSupportFacetInfos: Record<
223223
description: "LHS of an assignment with pattern destructuring",
224224
scopeType: "name",
225225
},
226+
"name.variable": {
227+
description: "Name (LHS) of a variable declaration",
228+
scopeType: "name",
229+
},
230+
"name.variable.pattern": {
231+
description:
232+
"Name (LHS) of a variable declaration with pattern destructuring",
233+
scopeType: "name",
234+
},
226235
"name.foreach": {
227236
description: "Iteration variable name in a for each loop",
228237
scopeType: "name",
@@ -269,6 +278,10 @@ export const scopeSupportFacetInfos: Record<
269278
description: "Value (RHS) of an assignment",
270279
scopeType: "value",
271280
},
281+
"value.variable": {
282+
description: "Value (RHS) of a variable declaration",
283+
scopeType: "value",
284+
},
272285
"value.mapPair": {
273286
description: "Value (RHS) of a key-value pair in a map",
274287
scopeType: "value",
@@ -314,8 +327,8 @@ export const scopeSupportFacetInfos: Record<
314327
isIteration: true,
315328
},
316329

317-
"type.assignment": {
318-
description: "Type of variable in an assignment",
330+
"type.variable": {
331+
description: "Type of variable in a variable declaration",
319332
scopeType: "type",
320333
},
321334
"type.formalParameter": {

packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const scopeSupportFacets = [
5959

6060
"name.assignment",
6161
"name.assignment.pattern",
62+
"name.variable",
63+
"name.variable.pattern",
6264
"name.foreach",
6365
"name.function",
6466
"name.class",
@@ -71,6 +73,7 @@ const scopeSupportFacets = [
7173
"key.mapPair.iteration",
7274

7375
"value.assignment",
76+
"value.variable",
7477
"value.mapPair",
7578
"value.mapPair.iteration",
7679
"value.attribute",
@@ -82,7 +85,7 @@ const scopeSupportFacets = [
8285
"value.resource",
8386
"value.resource.iteration",
8487

85-
"type.assignment",
88+
"type.variable",
8689
"type.formalParameter",
8790
"type.return",
8891
"type.field",

packages/common/src/scopeSupportFacets/typescript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
const { supported } = ScopeSupportFacetLevel;
99

1010
export const typescriptScopeSupport: LanguageScopeSupportFacetMap = {
11-
"type.assignment": supported,
11+
"type.variable": supported,
1212
"type.formalParameter": supported,
1313
"type.return": supported,
1414
"type.field": supported,
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
const { aaa: bbb } = ccc;
1+
{ aaa: bbb } = ccc;
22
---
33

4-
[Content] = 0:6-0:18
5-
0| const { aaa: bbb } = ccc;
6-
>------------<
4+
[Content] = 0:0-0:12
5+
0| { aaa: bbb } = ccc;
6+
>------------<
77

8-
[Removal] = 0:0-0:21
9-
0| const { aaa: bbb } = ccc;
10-
>---------------------<
8+
[Removal] = 0:0-0:15
9+
0| { aaa: bbb } = ccc;
10+
>---------------<
1111

12-
[Leading delimiter] = 0:5-0:6
13-
0| const { aaa: bbb } = ccc;
14-
>-<
12+
[Trailing delimiter] = 0:12-0:15
13+
0| { aaa: bbb } = ccc;
14+
>---<
1515

16-
[Trailing delimiter] = 0:18-0:19
17-
0| const { aaa: bbb } = ccc;
18-
>-<
19-
20-
[Domain] = 0:0-0:25
21-
0| const { aaa: bbb } = ccc;
22-
>-------------------------<
16+
[Domain] = 0:0-0:19
17+
0| { aaa: bbb } = ccc;
18+
>-------------------<
2319

2420
[Insertion delimiter] = " "
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
const name = "Hello world";
1+
aaa = bbb;
22
---
33

4-
[Content] = 0:6-0:10
5-
0| const name = "Hello world";
6-
>----<
4+
[Content] = 0:0-0:3
5+
0| aaa = bbb;
6+
>---<
77

8-
[Removal] = 0:0-0:13
9-
0| const name = "Hello world";
10-
>-------------<
8+
[Removal] = 0:0-0:6
9+
0| aaa = bbb;
10+
>------<
1111

12-
[Leading delimiter] = 0:5-0:6
13-
0| const name = "Hello world";
14-
>-<
12+
[Trailing delimiter] = 0:3-0:6
13+
0| aaa = bbb;
14+
>---<
1515

16-
[Trailing delimiter] = 0:10-0:11
17-
0| const name = "Hello world";
18-
>-<
19-
20-
[Domain] = 0:0-0:27
21-
0| const name = "Hello world";
22-
>---------------------------<
16+
[Domain] = 0:0-0:10
17+
0| aaa = bbb;
18+
>----------<
2319

2420
[Insertion delimiter] = " "
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const {aaa: bbb} = ccc;
2+
---
3+
4+
[Content] = 0:6-0:16
5+
0| const {aaa: bbb} = ccc;
6+
>----------<
7+
8+
[Removal] = 0:0-0:19
9+
0| const {aaa: bbb} = ccc;
10+
>-------------------<
11+
12+
[Leading delimiter] = 0:5-0:6
13+
0| const {aaa: bbb} = ccc;
14+
>-<
15+
16+
[Trailing delimiter] = 0:16-0:17
17+
0| const {aaa: bbb} = ccc;
18+
>-<
19+
20+
[Domain] = 0:0-0:23
21+
0| const {aaa: bbb} = ccc;
22+
>-----------------------<
23+
24+
[Insertion delimiter] = " "
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const name = "Hello world";
2+
---
3+
4+
[Content] = 0:6-0:10
5+
0| const name = "Hello world";
6+
>----<
7+
8+
[Removal] = 0:0-0:13
9+
0| const name = "Hello world";
10+
>-------------<
11+
12+
[Leading delimiter] = 0:5-0:6
13+
0| const name = "Hello world";
14+
>-<
15+
16+
[Trailing delimiter] = 0:10-0:11
17+
0| const name = "Hello world";
18+
>-<
19+
20+
[Domain] = 0:0-0:27
21+
0| const name = "Hello world";
22+
>---------------------------<
23+
24+
[Insertion delimiter] = " "
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const name = "Hello world";
1+
aaa = bbb;
22
---
33

4-
[Content] = 0:13-0:26
5-
0| const name = "Hello world";
6-
>-------------<
4+
[Content] = 0:6-0:9
5+
0| aaa = bbb;
6+
>---<
77

8-
[Removal] = 0:10-0:26
9-
0| const name = "Hello world";
10-
>----------------<
8+
[Removal] = 0:3-0:9
9+
0| aaa = bbb;
10+
>------<
1111

12-
[Leading delimiter] = 0:10-0:13
13-
0| const name = "Hello world";
14-
>---<
12+
[Leading delimiter] = 0:3-0:6
13+
0| aaa = bbb;
14+
>---<
1515

16-
[Domain] = 0:0-0:27
17-
0| const name = "Hello world";
18-
>---------------------------<
16+
[Domain] = 0:0-0:10
17+
0| aaa = bbb;
18+
>----------<
1919

2020
[Insertion delimiter] = " "
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const name = "Hello world";
2+
---
3+
4+
[Content] = 0:13-0:26
5+
0| const name = "Hello world";
6+
>-------------<
7+
8+
[Removal] = 0:10-0:26
9+
0| const name = "Hello world";
10+
>----------------<
11+
12+
[Leading delimiter] = 0:10-0:13
13+
0| const name = "Hello world";
14+
>---<
15+
16+
[Domain] = 0:0-0:27
17+
0| const name = "Hello world";
18+
>---------------------------<
19+
20+
[Insertion delimiter] = " "

0 commit comments

Comments
 (0)