branch: elpa/clojure-ts-mode commit 08b1c3b961f4284d9718dfcdaa9cb7e8b5b42b27 Author: Roman Rudakov <rruda...@fastmail.com> Commit: Bozhidar Batsov <bozhi...@batsov.dev>
[#120] Fix a bug when vars with metadata were not listed in imenu --- CHANGELOG.md | 1 + clojure-ts-mode.el | 11 ++++------- test/clojure-ts-mode-imenu-test.el | 6 ++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15087a6591d..3bf23ec015d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Add documentation and bug reporting commands from `clojure-mode`. - [#118](https://github.com/clojure-emacs/clojure-ts-mode/pull/118): Add some ns manipulation functions from `clojure-mode`. - Fix a bug in `clojure-ts-add-arity` when body has more than one expression. +- [#120](https://github.com/clojure-emacs/clojure-ts-mode/issues/120): Fix a bug when symbols with metadata were not listed in imenu. ## 0.5.1 (2025-06-17) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 3152e397549..c35b357e303 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -1003,13 +1003,10 @@ If there is no namespace, returns nil." (defun clojure-ts--node-child-skip-metadata (node n) "Return the Nth child of NODE like `treesit-node-child', sans metadata. Skip the optional metadata node at pos 0 if present." - (let ((first-child (treesit-node-child node 0 t))) - (treesit-node-child - node - (if (clojure-ts--metadata-node-p first-child) - (1+ n) - n) - t))) + (let ((value-nodes (thread-last (treesit-node-children node t) + (seq-filter (lambda (child) + (string= (treesit-node-field-name child) "value")))))) + (seq-elt value-nodes n))) (defun clojure-ts--first-value-child (node) "Return the first value child of the given NODE. diff --git a/test/clojure-ts-mode-imenu-test.el b/test/clojure-ts-mode-imenu-test.el index 1822231496e..3a493fce871 100644 --- a/test/clojure-ts-mode-imenu-test.el +++ b/test/clojure-ts-mode-imenu-test.el @@ -33,6 +33,12 @@ (expect (imenu-find-default "a" flatten-index) :to-equal "Variable:a")))) + (it "should index def with meta data before symbol" + (with-clojure-ts-buffer "(def ^:private a 1)" + (let ((flatten-index (imenu--flatten-index-alist (imenu--make-index-alist) t))) + (expect (imenu-find-default "a" flatten-index) + :to-equal "Variable:a")))) + (it "should index defn with meta data" (with-clojure-ts-buffer "^{:foo 1}(defn a [])" (let ((flatten-index (imenu--flatten-index-alist (imenu--make-index-alist) t)))