@@ -657,17 +657,33 @@ See `clojure-ts--definition-node-p' when an exact match is possible."
657
657
(and
658
658
(clojure-ts--list-node-p node)
659
659
(let* ((child (clojure-ts--node-child-skip-metadata node 0 ))
660
- (child-txt (clojure-ts--named-node-text child)))
660
+ (child-txt (clojure-ts--named-node-text child))
661
+ (name-sym (clojure-ts--node-child-skip-metadata node 1 )))
661
662
(and (clojure-ts--symbol-node-p child)
663
+ (clojure-ts--symbol-node-p name-sym)
662
664
(string-match-p definition-type-regexp child-txt)))))
663
665
666
+ (defun clojure-ts--kwd-definition-node-match-p (node )
667
+ " Return non-nil if the NODE is a keyword definition."
668
+ (and (clojure-ts--list-node-p node)
669
+ (let* ((child (clojure-ts--node-child-skip-metadata node 0 ))
670
+ (child-txt (clojure-ts--named-node-text child))
671
+ (child-ns (clojure-ts--node-namespace-text child))
672
+ (name-kwd (clojure-ts--node-child-skip-metadata node 1 )))
673
+ (and child-ns
674
+ (clojure-ts--symbol-node-p child)
675
+ (clojure-ts--keyword-node-p name-kwd)
676
+ (string-equal child-txt " def" )))))
677
+
664
678
(defun clojure-ts--standard-definition-node-name (node )
665
679
" Return the definition name for the given NODE.
666
- Returns nil if NODE is not a list with symbols as the first two children.
667
- For example the node representing the expression (def foo 1) would return foo.
668
- The node representing (ns user) would return user.
669
- Does not does any matching on the first symbol (def, defn, etc), so identifying
670
- that a node is a definition is intended to be done elsewhere.
680
+
681
+ Returns nil if NODE is not a list with symbols as the first two
682
+ children. For example the node representing the expression (def foo 1)
683
+ would return foo. The node representing (ns user) would return user.
684
+ Does not do any matching on the first symbol (def, defn, etc), so
685
+ identifying that a node is a definition is intended to be done
686
+ elsewhere.
671
687
672
688
Can be called directly, but intended for use as `treesit-defun-name-function' ."
673
689
(when (and (clojure-ts--list-node-p node)
@@ -683,6 +699,21 @@ Can be called directly, but intended for use as `treesit-defun-name-function'."
683
699
(concat (treesit-node-text ns) " /" (treesit-node-text name))
684
700
(treesit-node-text name)))))))
685
701
702
+ (defun clojure-ts--kwd-definition-node-name (node )
703
+ " Return the keyword name for the given NODE.
704
+
705
+ Returns nil if NODE is not a list where the first element is a symbol
706
+ and the second is a keyword. For example, a node representing the
707
+ expression (s/def ::foo int?) would return foo.
708
+
709
+ Can be called directly, but intended for use as
710
+ `treesit-defun-name-function' ."
711
+ (when (and (clojure-ts--list-node-p node)
712
+ (clojure-ts--symbol-node-p (clojure-ts--node-child-skip-metadata node 0 )))
713
+ (let ((kwd (clojure-ts--node-child-skip-metadata node 1 )))
714
+ (when (clojure-ts--keyword-node-p kwd)
715
+ (treesit-node-text (treesit-node-child-by-field-name kwd " name" ))))))
716
+
686
717
(defvar clojure-ts--function-type-regexp
687
718
(rx string-start (or (seq " defn" (opt " -" )) " defmethod" " deftest" ) string-end)
688
719
" Regular expression for matching definition nodes that resemble functions." )
@@ -733,7 +764,6 @@ Includes a dispatch value when applicable (defmethods)."
733
764
" Return non-nil if NODE represents a protocol or interface definition."
734
765
(clojure-ts--definition-node-match-p clojure-ts--interface-type-regexp node))
735
766
736
-
737
767
(defvar clojure-ts--imenu-settings
738
768
`((" Namespace" " list_lit" clojure-ts--ns-node-p)
739
769
(" Function" " list_lit" clojure-ts--function-node-p
@@ -742,7 +772,11 @@ Includes a dispatch value when applicable (defmethods)."
742
772
(" Macro" " list_lit" clojure-ts--defmacro-node-p)
743
773
(" Variable" " list_lit" clojure-ts--variable-definition-node-p)
744
774
(" Interface" " list_lit" clojure-ts--interface-node-p)
745
- (" Class" " list_lit" clojure-ts--class-node-p))
775
+ (" Class" " list_lit" clojure-ts--class-node-p)
776
+ (" Keyword"
777
+ " list_lit"
778
+ clojure-ts--kwd-definition-node-match-p
779
+ clojure-ts--kwd-definition-node-name))
746
780
" The value for `treesit-simple-imenu-settings' .
747
781
By default `treesit-defun-name-function' is used to extract definition names.
748
782
See `clojure-ts--standard-definition-node-name' for the implementation used." )
0 commit comments