Skip to content

Commit e2f9ffd

Browse files
committed
Ugly patch for misbehaving ClojureScript REPLs
Lots of people are reporting that their CLJS REPL suddenly starts thinking it's a CLJ REPL (due to a wrong cider-repl-type). Until we fix that, I decided to apply this workaround so that people can get work done.
1 parent 77085ed commit e2f9ffd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cider-client.el

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,31 @@ CONNECTION defaults to `cider-current-connection'."
271271
(`"clj" "cljs")
272272
(_ "clj")))))
273273

274+
(defvar cider--has-warned-about-bad-repl-type nil)
275+
276+
(defun cider--guess-cljs-connection ()
277+
"Hacky way to find a ClojureScript REPL.
278+
DO NOT USE THIS FUNCTION.
279+
It was written only to be used in `cider-map-connections', as a workaround
280+
to a still-undetermined bug in the state-stracker backend."
281+
(when-let ((project-connections (cider-find-connection-buffer-for-project-directory
282+
nil :all-connections))
283+
(cljs-conn
284+
;; So we have multiple connections. Look for the connection type we
285+
;; want, prioritizing the current project.
286+
(or (seq-find (lambda (c) (string-match "\\bCLJS\\b" (buffer-name c)))
287+
project-connections)
288+
(seq-find (lambda (c) (string-match "\\bCLJS\\b" (buffer-name c)))
289+
(cider-connections)))))
290+
(unless cider--has-warned-about-bad-repl-type
291+
(setq cider--has-warned-about-bad-repl-type t)
292+
(read-char
293+
(concat "The ClojureScript REPL seems to be is misbehaving."
294+
(substitute-command-keys
295+
"\nWe have applied a workaround, but please also file a bug report with `\\[cider-report-bug]'.")
296+
"\nPress any key to continue.")))
297+
cljs-conn))
298+
274299
(defun cider-map-connections (function which &optional any-mode)
275300
"Call FUNCTION once for each appropriate connection.
276301
The function is called with one argument, the connection buffer.
@@ -303,6 +328,8 @@ connection but can be invoked from any buffer (like `cider-refresh')."
303328
(pcase which
304329
(`:any (let ((type (cider-connection-type-for-buffer)))
305330
(or (cider-current-connection type)
331+
(when (equal type "cljs")
332+
(cider--guess-cljs-connection))
306333
(err (substitute-command-keys
307334
(format "needs a Clojure%s REPL.\nIf you don't know what that means, you probably need to jack-in (%s)."
308335
(if (equal type "cljs") "Script" "")

0 commit comments

Comments
 (0)