Skip to content

Commit bd4719c

Browse files
authored
support comments in empty Go maps/lists (#1755)
I realized this was easy. Silly me. ## 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 c2e9c00 commit bd4719c

File tree

8 files changed

+162
-4
lines changed

8 files changed

+162
-4
lines changed

data/playground/go/maps_and_lists.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const one = 1
1515

1616
func mapsAndLists() {
1717
_ = A{}
18+
_ = A{ /* comment */ }
1819
_ = A{1}
1920
_ = A{1, 2}
2021
_ = A{1: 1}
@@ -27,6 +28,7 @@ func mapsAndLists() {
2728
_ = AA{{1}, {one: 1}}
2829
_ = AA{{1}, {}, {one: 1}}
2930
_ = &A{}
31+
_ = &A{ /* comment */ }
3032
_ = &A{1}
3133
_ = &A{one: 1}
3234
_ = &A{1: 1}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: "_ = T{ /* foo */ a: 0, /* foo */ }"
15+
selections:
16+
- anchor: {line: 0, character: 34}
17+
active: {line: 0, character: 34}
18+
marks: {}
19+
thrownError: {name: NoContainingScopeError}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list cap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |
16+
_ = T{ /* comment */ }
17+
selections:
18+
- anchor: {line: 0, character: 22}
19+
active: {line: 0, character: 22}
20+
marks:
21+
default.c:
22+
start: {line: 0, character: 10}
23+
end: {line: 0, character: 17}
24+
finalState:
25+
documentContents: |
26+
_ =
27+
selections:
28+
- anchor: {line: 0, character: 4}
29+
active: {line: 0, character: 4}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change list cap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: list}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |
16+
_ = &T{ /* comment */ }
17+
selections:
18+
- anchor: {line: 0, character: 23}
19+
active: {line: 0, character: 23}
20+
marks:
21+
default.c:
22+
start: {line: 0, character: 11}
23+
end: {line: 0, character: 18}
24+
finalState:
25+
documentContents: |
26+
_ =
27+
selections:
28+
- anchor: {line: 0, character: 4}
29+
active: {line: 0, character: 4}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change map
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: map}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: _ = T{ /* foo */ 0, /* foo */ }
15+
selections:
16+
- anchor: {line: 0, character: 31}
17+
active: {line: 0, character: 31}
18+
marks: {}
19+
thrownError: {name: NoContainingScopeError}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change map cap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: map}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |
16+
_ = T{ /* comment */ }
17+
selections:
18+
- anchor: {line: 0, character: 22}
19+
active: {line: 0, character: 22}
20+
marks:
21+
default.c:
22+
start: {line: 0, character: 10}
23+
end: {line: 0, character: 17}
24+
finalState:
25+
documentContents: |
26+
_ =
27+
selections:
28+
- anchor: {line: 0, character: 4}
29+
active: {line: 0, character: 4}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: go
2+
command:
3+
version: 6
4+
spokenForm: change map cap
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: map}
12+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |
16+
_ = &T{ /* comment */ }
17+
selections:
18+
- anchor: {line: 0, character: 23}
19+
active: {line: 0, character: 23}
20+
marks:
21+
default.c:
22+
start: {line: 0, character: 11}
23+
end: {line: 0, character: 18}
24+
finalState:
25+
documentContents: |
26+
_ =
27+
selections:
28+
- anchor: {line: 0, character: 4}
29+
active: {line: 0, character: 4}

queries/go.scm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@
138138
)
139139

140140
;; empty composite literals
141-
;;
142-
;; each of these will fail to match { /* some comment */ }
143-
;; because the comment node will break the anchoring.
144-
;; this is rare enough to not be worth fixing now.
145141

146142
;; &T{}
147143
(unary_expression
@@ -151,6 +147,8 @@
151147
.
152148
"{"
153149
.
150+
(comment)*
151+
.
154152
"}"
155153
.
156154
)
@@ -164,6 +162,8 @@
164162
.
165163
"{"
166164
.
165+
(comment)*
166+
.
167167
"}"
168168
.
169169
)
@@ -177,6 +177,8 @@
177177
.
178178
"{"
179179
.
180+
(comment)*
181+
.
180182
"}"
181183
.
182184
) @list @map

0 commit comments

Comments
 (0)