Skip to content

Commit db2ead4

Browse files
authored
Support watching several shadow-cljs builds (#2940)
Add a cider-shadow-watched-builds customization variable which is the list of builds to watch. If not defined fallback on watching the default build set in cider-shadow-default-options or prompt the user.
1 parent b197dbc commit db2ead4

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New features
66

77
* [#2909](https://github.com/clojure-emacs/cider/issues/2909): Add new customization variable `cider-inspector-auto-select-buffer` to control the auto selection of the inspector buffer.
8+
* [#2940](https://github.com/clojure-emacs/cider/pull/2940): Add a new customization variable cider-shadow-watched-builds to allow watching several shadow-cljs builds at the same time.
89

910
### Bugs fixed
1011

cider.el

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,11 @@ Generally you should not disable this unless you run into some faulty check."
719719
options
720720
(concat ":" options)))
721721

722+
(defcustom cider-shadow-watched-builds nil
723+
"Defines the list of builds `shadow-cljs' should watch."
724+
:type '(repeat string)
725+
:package-version '(cider . "1.0"))
726+
722727
(defcustom cider-shadow-default-options nil
723728
"Defines default `shadow-cljs' options."
724729
:type 'string
@@ -758,17 +763,26 @@ not just a string."
758763
We have to prompt the user to select a build, that's why
759764
this is a command, not just a string."
760765
(let* ((shadow-require "(require '[shadow.cljs.devtools.api :as shadow])")
766+
767+
(default-build (cider-normalize-cljs-init-options
768+
(or cider-shadow-default-options
769+
(car cider-shadow-watched-builds)
770+
(completing-read "Select shadow-cljs build: "
771+
(cider--shadow-get-builds)))))
772+
773+
(watched-builds (or (mapcar #'cider-normalize-cljs-init-options cider-shadow-watched-builds)
774+
(list default-build)))
775+
776+
(watched-builds-form (mapconcat (lambda (build) (format "(shadow/watch %s)" build))
777+
watched-builds
778+
" "))
761779
;; form used for user-defined builds
762-
(user-build-form "(do %s (shadow/watch %s) (shadow/nrepl-select %s))")
780+
(user-build-form "(do %s %s (shadow/nrepl-select %s))")
763781
;; form used for built-in builds like :browser-repl and :node-repl
764-
(default-build-form "(do %s (shadow/%s))")
765-
(options (or cider-shadow-default-options
766-
(completing-read "Select shadow-cljs build: "
767-
(cider--shadow-get-builds))))
768-
(build (cider-normalize-cljs-init-options options)))
769-
(if (member build '(":browser-repl" ":node-repl"))
770-
(format default-build-form shadow-require (string-remove-prefix ":" build))
771-
(format user-build-form shadow-require build build))))
782+
(default-build-form "(do %s (shadow/%s))"))
783+
(if (member default-build '(":browser-repl" ":node-repl"))
784+
(format default-build-form shadow-require (string-remove-prefix ":" default-build))
785+
(format user-build-form shadow-require watched-builds-form default-build))))
772786

773787
(defcustom cider-figwheel-main-default-options nil
774788
"Defines the `figwheel.main/start' options.

doc/modules/ROOT/pages/cljs/shadow-cljs.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ root of your project.
4444
[source,clojure]
4545
----
4646
((nil . ((cider-default-cljs-repl . shadow)
47-
(cider-shadow-default-options . "<your-build-name-here>"))))
47+
(cider-shadow-default-options . "<your-build-name-here>")
48+
(cider-shadow-watched-builds . ("<first-build>" "<other-build>")))))
4849
----
4950

5051
=== Using cider-connect-cljs

test/cider-tests.el

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@
338338
(spy-on 'completing-read :and-return-value ":browser-repl")
339339
(expect (cider-shadow-cljs-init-form)
340340
:to-equal
341-
"(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/browser-repl))"))))
341+
"(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/browser-repl))")))
342+
(describe "can watch multiple builds"
343+
(it "watches 2 builds and selects user-defined builds"
344+
(setq-local cider-shadow-default-options "client-build")
345+
(setq-local cider-shadow-watched-builds '("client-build" "other-build"))
346+
(expect (cider-shadow-cljs-init-form)
347+
:to-equal
348+
"(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :client-build) (shadow/watch :other-build) (shadow/nrepl-select :client-build))"))))
342349

343350
(provide 'cider-tests)
344351

0 commit comments

Comments
 (0)