Skip to content

Commit fede4a2

Browse files
Improve item collection definition for clojure (#2758)
Fix some of the clojure collection item regression from #2683 Related #2723 ## 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 01966b1 commit fede4a2

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

data/fixtures/recorded/languages/clojure/chuckItemZip.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ finalState:
2929
documentContents: |-
3030
{
3131
:foo "bar",
32+
;; hello
33+
,
3234
}
3335
selections:
34-
- anchor: {line: 2, character: 1}
35-
active: {line: 2, character: 1}
36+
- anchor: {line: 4, character: 1}
37+
active: {line: 4, character: 1}

data/fixtures/recorded/languages/clojure/clearItemBat.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ initialState:
2828
finalState:
2929
documentContents: |-
3030
{
31-
,
31+
32+
;; hello
33+
"whatever",
3234
}
3335
selections:
3436
- anchor: {line: 1, character: 4}

data/fixtures/recorded/languages/clojure/clearItemFine.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ initialState:
2121
start: {line: 0, character: 2}
2222
end: {line: 0, character: 5}
2323
finalState:
24-
documentContents: "{}"
24+
documentContents: "{ :baz \"whatever\"}"
2525
selections:
2626
- anchor: {line: 0, character: 1}
2727
active: {line: 0, character: 1}

queries/clojure.scm

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
;; A list is either a vector literal or a quoted list literal
1010
(vec_lit) @list
11+
1112
(quoting_lit
1213
(list_lit)
1314
) @list
@@ -17,27 +18,64 @@
1718
(list_lit
1819
(_)? @_.leading.endOf
1920
.
20-
(_) @collectionItem.start
21+
(_) @collectionItem
2122
.
2223
(_)? @_.trailing.startOf
2324
)
2425

2526
(list_lit
26-
open: "(" @collectionItem.iteration.start.startOf
27-
close: ")" @collectionItem.iteration.end.endOf
27+
open: "(" @collectionItem.iteration.start.endOf
28+
close: ")" @collectionItem.iteration.end.startOf
2829
) @collectionItem.iteration.domain
2930

3031
;;!! [foo bar]
3132
;;! ^^^ ^^^
3233
(vec_lit
3334
(_)? @_.leading.endOf
3435
.
35-
(_) @collectionItem.start
36+
(_) @collectionItem
3637
.
3738
(_)? @_.trailing.startOf
3839
)
3940

4041
(vec_lit
41-
open: "[" @collectionItem.iteration.start.startOf
42-
close: "]" @collectionItem.iteration.end.endOf
42+
open: "[" @collectionItem.iteration.start.endOf
43+
close: "]" @collectionItem.iteration.end.startOf
44+
) @collectionItem.iteration.domain
45+
46+
;; Keyword follow by a value
47+
(map_lit
48+
(_)? @_.leading.endOf
49+
.
50+
(kwd_lit) @collectionItem.start
51+
.
52+
value: (_) @collectionItem.end
53+
.
54+
(_)? @_.trailing.startOf
55+
)
56+
57+
;; Keyword followed by comment or closing brace
58+
(map_lit
59+
(_)? @_.leading.endOf
60+
.
61+
(kwd_lit) @collectionItem.start
62+
.
63+
[
64+
(comment) @_.trailing.startOf
65+
"}"
66+
]
67+
)
68+
69+
;; Non keyword value that is not preceded by a keyword. eg a string literal.
70+
(map_lit
71+
_ @_dummy
72+
.
73+
value: (_) @collectionItem
74+
(#not-type? @_dummy "kwd_lit")
75+
(#not-type? @collectionItem "kwd_lit")
76+
)
77+
78+
(map_lit
79+
open: "{" @collectionItem.iteration.start.endOf
80+
close: "}" @collectionItem.iteration.end.startOf
4381
) @collectionItem.iteration.domain

0 commit comments

Comments
 (0)