Skip to content

Commit e26a4da

Browse files
kommenbbatsov
authored andcommitted
Optimize cider-get-ns-name for clojure-ts-mode buffers
Using clojure-ts-find-ns is a bit more efficient as it leverages tree-sitter. Plus, there seem to be some egde cases where clojure-find-ns within a clojure-ts-mode buffer makes Emacs hang, as clojure-find-ns's (while t (up-list nil t t)) loop never terminates because up-list delegates to treesit-forward-sexp, which not always seem to signal an error.
1 parent 186c34f commit e26a4da

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

lisp/cider-util.el

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,14 @@ instead."
142142
(cider--text-or-limits bounds (point) end)))))
143143

144144
(defun cider-get-ns-name ()
145-
"Calls `clojure-find-ns', suppressing any errors.
146-
Therefore, possibly returns nil,
147-
so please handle that value from any callsites."
148-
(clojure-find-ns :supress-errors))
145+
"Return the current namespace in the buffer, suppressing any errors.
146+
Uses `clojure-ts-find-ns' when the buffer is in `clojure-ts-mode',
147+
otherwise falls back to `clojure-find-ns'.
148+
Therefore, possibly returns nil, so please handle that value from any callsites."
149+
(if (and (cider-clojure-ts-mode-p)
150+
(fboundp 'clojure-ts-find-ns))
151+
(clojure-ts-find-ns)
152+
(clojure-find-ns :supress-errors)))
149153

150154
(defun cider-ns-form ()
151155
"Retrieve the ns form."

0 commit comments

Comments
 (0)