Skip to content

Commit 8e5e910

Browse files
committed
[clojure-emacs#120] Fix a bug when vars with metadata were not listed in imenu
1 parent 32490c8 commit 8e5e910

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Add documentation and bug reporting commands from `clojure-mode`.
1212
- [#118](https://github.com/clojure-emacs/clojure-ts-mode/pull/118): Add some ns manipulation functions from `clojure-mode`.
1313
- Fix a bug in `clojure-ts-add-arity` when body has more than one expression.
14+
- [#120](https://github.com/clojure-emacs/clojure-ts-mode/issues/120): Fix a bug when symbols with metadata were not listed in imenu.
1415

1516
## 0.5.1 (2025-06-17)
1617

clojure-ts-mode.el

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,10 @@ If there is no namespace, returns nil."
10031003
(defun clojure-ts--node-child-skip-metadata (node n)
10041004
"Return the Nth child of NODE like `treesit-node-child', sans metadata.
10051005
Skip the optional metadata node at pos 0 if present."
1006-
(let ((first-child (treesit-node-child node 0 t)))
1007-
(treesit-node-child
1008-
node
1009-
(if (clojure-ts--metadata-node-p first-child)
1010-
(1+ n)
1011-
n)
1012-
t)))
1006+
(let ((value-nodes (thread-last (treesit-node-children node t)
1007+
(seq-filter (lambda (child)
1008+
(string= (treesit-node-field-name child) "value"))))))
1009+
(seq-elt value-nodes n)))
10131010

10141011
(defun clojure-ts--first-value-child (node)
10151012
"Return the first value child of the given NODE.

test/clojure-ts-mode-imenu-test.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
(expect (imenu-find-default "a" flatten-index)
3434
:to-equal "Variable:a"))))
3535

36+
(it "should index def with meta data before symbol"
37+
(with-clojure-ts-buffer "(def ^:private a 1)"
38+
(let ((flatten-index (imenu--flatten-index-alist (imenu--make-index-alist) t)))
39+
(expect (imenu-find-default "a" flatten-index)
40+
:to-equal "Variable:a"))))
41+
3642
(it "should index defn with meta data"
3743
(with-clojure-ts-buffer "^{:foo 1}(defn a [])"
3844
(let ((flatten-index (imenu--flatten-index-alist (imenu--make-index-alist) t)))

0 commit comments

Comments
 (0)