Skip to content

Commit

Permalink
Add name.variable and value.variable (#2219)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pokey authored Feb 3, 2024
1 parent bae9ce0 commit eefee91
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/scopeSupportFacets/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const htmlScopeSupport: LanguageScopeSupportFacetMap = {
"namedFunction.method": notApplicable,
"string.multiLine": notApplicable,
"string.singleLine": notApplicable,
"type.assignment": notApplicable,
"type.variable": notApplicable,
"type.field": notApplicable,
"type.foreach": notApplicable,
"type.formalParameter": notApplicable,
Expand Down
5 changes: 4 additions & 1 deletion packages/common/src/scopeSupportFacets/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
"name.foreach": supported,
"name.assignment": supported,
"name.assignment.pattern": supported,
"name.variable": supported,
"name.variable.pattern": supported,
"name.function": supported,
"name.class": supported,
"name.field": supported,
Expand All @@ -70,6 +72,7 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
"value.mapPair": supported,
"value.mapPair.iteration": supported,
"value.assignment": supported,
"value.variable": supported,
"value.foreach": supported,
"value.return": supported,
"value.return.lambda": supported,
Expand All @@ -83,7 +86,7 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
"key.attribute": supported,
"value.attribute": supported,

"type.assignment": notApplicable,
"type.variable": notApplicable,
"type.formalParameter": notApplicable,
"type.return": notApplicable,
"type.field": notApplicable,
Expand Down
17 changes: 15 additions & 2 deletions packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ export const scopeSupportFacetInfos: Record<
description: "LHS of an assignment with pattern destructuring",
scopeType: "name",
},
"name.variable": {
description: "Name (LHS) of a variable declaration",
scopeType: "name",
},
"name.variable.pattern": {
description:
"Name (LHS) of a variable declaration with pattern destructuring",
scopeType: "name",
},
"name.foreach": {
description: "Iteration variable name in a for each loop",
scopeType: "name",
Expand Down Expand Up @@ -269,6 +278,10 @@ export const scopeSupportFacetInfos: Record<
description: "Value (RHS) of an assignment",
scopeType: "value",
},
"value.variable": {
description: "Value (RHS) of a variable declaration",
scopeType: "value",
},
"value.mapPair": {
description: "Value (RHS) of a key-value pair in a map",
scopeType: "value",
Expand Down Expand Up @@ -314,8 +327,8 @@ export const scopeSupportFacetInfos: Record<
isIteration: true,
},

"type.assignment": {
description: "Type of variable in an assignment",
"type.variable": {
description: "Type of variable in a variable declaration",
scopeType: "type",
},
"type.formalParameter": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const scopeSupportFacets = [

"name.assignment",
"name.assignment.pattern",
"name.variable",
"name.variable.pattern",
"name.foreach",
"name.function",
"name.class",
Expand All @@ -71,6 +73,7 @@ const scopeSupportFacets = [
"key.mapPair.iteration",

"value.assignment",
"value.variable",
"value.mapPair",
"value.mapPair.iteration",
"value.attribute",
Expand All @@ -82,7 +85,7 @@ const scopeSupportFacets = [
"value.resource",
"value.resource.iteration",

"type.assignment",
"type.variable",
"type.formalParameter",
"type.return",
"type.field",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/scopeSupportFacets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
const { supported } = ScopeSupportFacetLevel;

export const typescriptScopeSupport: LanguageScopeSupportFacetMap = {
"type.assignment": supported,
"type.variable": supported,
"type.formalParameter": supported,
"type.return": supported,
"type.field": supported,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const { aaa: bbb } = ccc;
{ aaa: bbb } = ccc;
---

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

[Removal] = 0:0-0:21
0| const { aaa: bbb } = ccc;
>---------------------<
[Removal] = 0:0-0:15
0| { aaa: bbb } = ccc;
>---------------<

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

[Trailing delimiter] = 0:18-0:19
0| const { aaa: bbb } = ccc;
>-<

[Domain] = 0:0-0:25
0| const { aaa: bbb } = ccc;
>-------------------------<
[Domain] = 0:0-0:19
0| { aaa: bbb } = ccc;
>-------------------<

[Insertion delimiter] = " "
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const name = "Hello world";
aaa = bbb;
---

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

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

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

[Trailing delimiter] = 0:10-0:11
0| const name = "Hello world";
>-<

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

[Insertion delimiter] = " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const {aaa: bbb} = ccc;
---

[Content] = 0:6-0:16
0| const {aaa: bbb} = ccc;
>----------<

[Removal] = 0:0-0:19
0| const {aaa: bbb} = ccc;
>-------------------<

[Leading delimiter] = 0:5-0:6
0| const {aaa: bbb} = ccc;
>-<

[Trailing delimiter] = 0:16-0:17
0| const {aaa: bbb} = ccc;
>-<

[Domain] = 0:0-0:23
0| const {aaa: bbb} = ccc;
>-----------------------<

[Insertion delimiter] = " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const name = "Hello world";
---

[Content] = 0:6-0:10
0| const name = "Hello world";
>----<

[Removal] = 0:0-0:13
0| const name = "Hello world";
>-------------<

[Leading delimiter] = 0:5-0:6
0| const name = "Hello world";
>-<

[Trailing delimiter] = 0:10-0:11
0| const name = "Hello world";
>-<

[Domain] = 0:0-0:27
0| const name = "Hello world";
>---------------------------<

[Insertion delimiter] = " "
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const name = "Hello world";
aaa = bbb;
---

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

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

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

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

[Insertion delimiter] = " "
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const name = "Hello world";
---

[Content] = 0:13-0:26
0| const name = "Hello world";
>-------------<

[Removal] = 0:10-0:26
0| const name = "Hello world";
>----------------<

[Leading delimiter] = 0:10-0:13
0| const name = "Hello world";
>---<

[Domain] = 0:0-0:27
0| const name = "Hello world";
>---------------------------<

[Insertion delimiter] = " "

0 comments on commit eefee91

Please sign in to comment.