From c6d5cc5f96bfb566a77eb7277141eaf7e27bafb0 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 25 Jan 2025 10:16:28 +0100 Subject: [PATCH] Improve item collection definition for clojure --- .../languages/clojure/chuckItemZip.yml | 6 ++- .../languages/clojure/clearItemBat.yml | 4 +- .../languages/clojure/clearItemFine.yml | 2 +- queries/clojure.scm | 50 ++++++++++++++++--- 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/data/fixtures/recorded/languages/clojure/chuckItemZip.yml b/data/fixtures/recorded/languages/clojure/chuckItemZip.yml index 6e5c8a77d5..3972d6f0ea 100644 --- a/data/fixtures/recorded/languages/clojure/chuckItemZip.yml +++ b/data/fixtures/recorded/languages/clojure/chuckItemZip.yml @@ -29,7 +29,9 @@ finalState: documentContents: |- { :foo "bar", + ;; hello + , } selections: - - anchor: {line: 2, character: 1} - active: {line: 2, character: 1} + - anchor: {line: 4, character: 1} + active: {line: 4, character: 1} diff --git a/data/fixtures/recorded/languages/clojure/clearItemBat.yml b/data/fixtures/recorded/languages/clojure/clearItemBat.yml index 3f4c9baf22..bbca55f4a6 100644 --- a/data/fixtures/recorded/languages/clojure/clearItemBat.yml +++ b/data/fixtures/recorded/languages/clojure/clearItemBat.yml @@ -28,7 +28,9 @@ initialState: finalState: documentContents: |- { - , + + ;; hello + "whatever", } selections: - anchor: {line: 1, character: 4} diff --git a/data/fixtures/recorded/languages/clojure/clearItemFine.yml b/data/fixtures/recorded/languages/clojure/clearItemFine.yml index 56bfdc6554..df2f19e0e8 100644 --- a/data/fixtures/recorded/languages/clojure/clearItemFine.yml +++ b/data/fixtures/recorded/languages/clojure/clearItemFine.yml @@ -21,7 +21,7 @@ initialState: start: {line: 0, character: 2} end: {line: 0, character: 5} finalState: - documentContents: "{}" + documentContents: "{ :baz \"whatever\"}" selections: - anchor: {line: 0, character: 1} active: {line: 0, character: 1} diff --git a/queries/clojure.scm b/queries/clojure.scm index 31f196e9c3..407e0640ac 100644 --- a/queries/clojure.scm +++ b/queries/clojure.scm @@ -8,6 +8,7 @@ ;; A list is either a vector literal or a quoted list literal (vec_lit) @list + (quoting_lit (list_lit) ) @list @@ -17,14 +18,14 @@ (list_lit (_)? @_.leading.endOf . - (_) @collectionItem.start + (_) @collectionItem . (_)? @_.trailing.startOf ) (list_lit - open: "(" @collectionItem.iteration.start.startOf - close: ")" @collectionItem.iteration.end.endOf + open: "(" @collectionItem.iteration.start.endOf + close: ")" @collectionItem.iteration.end.startOf ) @collectionItem.iteration.domain ;;!! [foo bar] @@ -32,12 +33,49 @@ (vec_lit (_)? @_.leading.endOf . - (_) @collectionItem.start + (_) @collectionItem . (_)? @_.trailing.startOf ) (vec_lit - open: "[" @collectionItem.iteration.start.startOf - close: "]" @collectionItem.iteration.end.endOf + open: "[" @collectionItem.iteration.start.endOf + close: "]" @collectionItem.iteration.end.startOf +) @collectionItem.iteration.domain + +;; Keyword follow by a value +(map_lit + (_)? @_.leading.endOf + . + (kwd_lit) @collectionItem.start + . + value: (_) @collectionItem.end + . + (_)? @_.trailing.startOf +) + +;; Keyword followed by comment or closing brace +(map_lit + (_)? @_.leading.endOf + . + (kwd_lit) @collectionItem.start + . + [ + (comment) @_.trailing.startOf + "}" + ] +) + +;; Non keyword value that is not preceded by a keyword. eg a string literal. +(map_lit + _ @_dummy + . + value: (_) @collectionItem + (#not-type? @_dummy "kwd_lit") + (#not-type? @collectionItem "kwd_lit") +) + +(map_lit + open: "{" @collectionItem.iteration.start.endOf + close: "}" @collectionItem.iteration.end.startOf ) @collectionItem.iteration.domain