@@ -637,17 +637,33 @@ See `clojure-ts--definition-node-p' when an exact match is possible."
637
637
(and
638
638
(clojure-ts--list-node-p node)
639
639
(let* ((child (clojure-ts--node-child-skip-metadata node 0 ))
640
- (child-txt (clojure-ts--named-node-text child)))
640
+ (child-txt (clojure-ts--named-node-text child))
641
+ (name-sym (clojure-ts--node-child-skip-metadata node 1 )))
641
642
(and (clojure-ts--symbol-node-p child)
643
+ (clojure-ts--symbol-node-p name-sym)
642
644
(string-match-p definition-type-regexp child-txt)))))
643
645
646
+ (defun clojure-ts--kwd-definition-node-match-p (node )
647
+ " Return non-nil if the NODE is a keyword definition."
648
+ (and (clojure-ts--list-node-p node)
649
+ (let* ((child (clojure-ts--node-child-skip-metadata node 0 ))
650
+ (child-txt (clojure-ts--named-node-text child))
651
+ (child-ns (clojure-ts--node-namespace-text child))
652
+ (name-kwd (clojure-ts--node-child-skip-metadata node 1 )))
653
+ (and child-ns
654
+ (clojure-ts--symbol-node-p child)
655
+ (clojure-ts--keyword-node-p name-kwd)
656
+ (string-equal child-txt " def" )))))
657
+
644
658
(defun clojure-ts--standard-definition-node-name (node )
645
659
" Return the definition name for the given NODE.
646
- Returns nil if NODE is not a list with symbols as the first two children.
647
- For example the node representing the expression (def foo 1) would return foo.
648
- The node representing (ns user) would return user.
649
- Does not does any matching on the first symbol (def, defn, etc), so identifying
650
- that a node is a definition is intended to be done elsewhere.
660
+
661
+ Returns nil if NODE is not a list with symbols as the first two
662
+ children. For example the node representing the expression (def foo 1)
663
+ would return foo. The node representing (ns user) would return user.
664
+ Does not do any matching on the first symbol (def, defn, etc), so
665
+ identifying that a node is a definition is intended to be done
666
+ elsewhere.
651
667
652
668
Can be called directly, but intended for use as `treesit-defun-name-function' ."
653
669
(when (and (clojure-ts--list-node-p node)
@@ -663,6 +679,21 @@ Can be called directly, but intended for use as `treesit-defun-name-function'."
663
679
(concat (treesit-node-text ns) " /" (treesit-node-text name))
664
680
(treesit-node-text name)))))))
665
681
682
+ (defun clojure-ts--kwd-definition-node-name (node )
683
+ " Return the keyword name for the given NODE.
684
+
685
+ Returns nil if NODE is not a list where the first element is a symbol
686
+ and the second is a keyword. For example, a node representing the
687
+ expression (s/def ::foo int?) would return foo.
688
+
689
+ Can be called directly, but intended for use as
690
+ `treesit-defun-name-function' ."
691
+ (when (and (clojure-ts--list-node-p node)
692
+ (clojure-ts--symbol-node-p (clojure-ts--node-child-skip-metadata node 0 )))
693
+ (let ((kwd (clojure-ts--node-child-skip-metadata node 1 )))
694
+ (when (clojure-ts--keyword-node-p kwd)
695
+ (treesit-node-text (treesit-node-child-by-field-name kwd " name" ))))))
696
+
666
697
(defvar clojure-ts--function-type-regexp
667
698
(rx string-start (or (seq " defn" (opt " -" )) " defmethod" " deftest" ) string-end)
668
699
" Regular expression for matching definition nodes that resemble functions." )
@@ -713,7 +744,6 @@ Includes a dispatch value when applicable (defmethods)."
713
744
" Return non-nil if NODE represents a protocol or interface definition."
714
745
(clojure-ts--definition-node-match-p clojure-ts--interface-type-regexp node))
715
746
716
-
717
747
(defvar clojure-ts--imenu-settings
718
748
`((" Namespace" " list_lit" clojure-ts--ns-node-p)
719
749
(" Function" " list_lit" clojure-ts--function-node-p
@@ -722,7 +752,11 @@ Includes a dispatch value when applicable (defmethods)."
722
752
(" Macro" " list_lit" clojure-ts--defmacro-node-p)
723
753
(" Variable" " list_lit" clojure-ts--variable-definition-node-p)
724
754
(" Interface" " list_lit" clojure-ts--interface-node-p)
725
- (" Class" " list_lit" clojure-ts--class-node-p))
755
+ (" Class" " list_lit" clojure-ts--class-node-p)
756
+ (" Keyword"
757
+ " list_lit"
758
+ clojure-ts--kwd-definition-node-match-p
759
+ clojure-ts--kwd-definition-node-name))
726
760
" The value for `treesit-simple-imenu-settings' .
727
761
By default `treesit-defun-name-function' is used to extract definition names.
728
762
See `clojure-ts--standard-definition-node-name' for the implementation used." )
0 commit comments