-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support toplevel defs with metadata #43
Changes from 3 commits
9112b4d
ce90a9b
7867ed5
c956302
db53936
56fbdbc
84a56ce
32dc24a
3b2e674
702af2e
026b65d
75aa34d
75edb95
774330d
cf90573
6d71712
919884b
b1e4ab0
997c591
7e44026
9152ab6
d495e11
eafed20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,7 @@ with the markdown_inline grammar." | |
|
||
:feature 'builtin | ||
:language 'clojure | ||
`(((list_lit :anchor (sym_lit (sym_name) @font-lock-keyword-face)) | ||
`(((list_lit meta: _ :? :anchor (sym_lit (sym_name) @font-lock-keyword-face)) | ||
(:match ,clojure-ts--builtin-symbol-regexp @font-lock-keyword-face)) | ||
((sym_name) @font-lock-builtin-face | ||
(:match ,clojure-ts--builtin-dynamic-var-regexp @font-lock-builtin-face))) | ||
|
@@ -810,6 +810,13 @@ forms like deftype, defrecord, reify, proxy, etc." | |
(clojure-ts--match-fn-docstring parent) | ||
(clojure-ts--match-method-docstring parent)))) | ||
|
||
(defun clojure-ts--match-toplevel-with-meta (_node parent _bol) | ||
"Match NODE when it is toplevel form and it has metadata" | ||
(let* ((grandparent (treesit-node-parent parent))) | ||
(and (string-equal "source" (treesit-node-type grandparent)) | ||
(clojure-ts--list-node-p parent) | ||
(treesit-node-child-by-field-name parent "meta")))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indent rules are some of the hardest to get right. The current indent rule that picks up the def is
Which I believe is happening because the when the cursor is between the metadata and the def form Trying to match the source string at the top should not be done though. That will not apply the rule to anything nested
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dannyfreeman thanks. I addressed this and added some test cases and checked that it matches the behavior of clojure-mode on them. |
||
|
||
(defun clojure-ts--semantic-indent-rules () | ||
"Return a list of indentation rules for `treesit-simple-indent-rules'." | ||
`((clojure | ||
|
@@ -822,6 +829,7 @@ forms like deftype, defrecord, reify, proxy, etc." | |
(clojure-ts--match-threading-macro-arg prev-sibling 0) | ||
;; https://guide.clojure.style/#vertically-align-fn-args | ||
(clojure-ts--match-function-call-arg (nth-sibling 2 nil) 0) | ||
(clojure-ts--match-toplevel-with-meta parent 0) | ||
;; Literal Sequences | ||
((parent-is "list_lit") parent 1) ;; https://guide.clojure.style/#one-space-indent | ||
((parent-is "vec_lit") parent 1) ;; https://guide.clojure.style/#bindings-alignment | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets you some of the way to syntax highlighting with these types of forms. A similar fix I believe is also needed for just about anything that follows the pattern of matching
Because any list literal can have metadata attached to the beginning. A lot of these queries want to capture the first symbol in the list to match special function calls, so they had to be
:anchor
ed to the front of the list. They all break down when metadata is present because the syntax tree lists the metadata as the first literal sub element of the list node.This also applies to the docstring queries in
clojure-ts--docstring-query
.and
The
"hello"
string in both should be highlighted withThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't get this to work for now. Shall I revert my change related to this and get the PR merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure. I need to set aside some time to get reacquainted with this problem. I'll try to do that within the next week and have a better answer for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dannyfreeman thank you! meanwhile, I had a chance to dive deeper and I think I actually figured it out (mostly?). there are a bunch of similar queries where the the optional metadata node could be added, but I didn't have time to come up with actual clojure code examples testing them so a didn't want to touch them – maybe unnecessarily.