Skip to content

Commit 973e104

Browse files
committed
Add support for shadow-cljs to cider-jack-in
1 parent 57d235b commit 973e104

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Make it possible to start a Nashorn ClojureScript REPL.
1818
* [#2235](https://github.com/clojure-emacs/cider/pull/2235): Make the REPL ignore blank input rather than evaluating.
1919
* [#2241](https://github.com/clojure-emacs/cider/pull/2241): Make `cider-test-ediff` diff eval'ed values
20+
* Add support for shadow-cljs to `cider-jack-in`.
2021

2122
### Bugs Fixed
2223

cider.el

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ version from the CIDER package or library.")
164164
:safe #'stringp
165165
:package-version '(cider . "0.17.0"))
166166

167+
(defcustom cider-shadow-cljs-command
168+
"shadow-cljs"
169+
"The command used to execute shadow-cljs."
170+
:type 'string
171+
:group 'cider
172+
:package-version '(cider . "0.17.0"))
173+
174+
(defcustom cider-shadow-cljs-global-options
175+
""
176+
"Command line options used to execute shadow-cljs (e.g.: -v for verbose mode)."
177+
:type 'string
178+
:group 'cider
179+
:safe #'stringp
180+
:package-version '(cider . "0.17.0"))
181+
182+
(defcustom cider-shadow-cljs-parameters
183+
"server"
184+
"Params passed to shadow-cljs to start an nREPL server via `cider-jack-in'."
185+
:type 'string
186+
:group 'cider
187+
:safe #'stringp
188+
:package-version '(cider . "0.17.0"))
189+
167190
(defcustom cider-gradle-command
168191
"gradle"
169192
"The command used to execute Gradle."
@@ -211,6 +234,7 @@ command when there is no ambiguity."
211234
:type '(choice (const "lein")
212235
(const "boot")
213236
(const "clojure")
237+
(const "shadow-cljs")
214238
(const "gradle")
215239
(const :tag "Always ask" nil))
216240
:group 'cider
@@ -292,6 +316,7 @@ Sub-match 1 must be the project path.")
292316
("lein" cider-lein-command)
293317
("boot" cider-boot-command)
294318
("clojure" cider-clojure-cli-command)
319+
("shadow-cljs" cider-shadow-cljs-command)
295320
("gradle" cider-gradle-command)
296321
(_ (user-error "Unsupported project type `%s'" project-type))))
297322

@@ -303,6 +328,7 @@ Throws an error if PROJECT-TYPE is unknown. Known types are
303328
("lein" (cider--lein-resolve-command))
304329
("boot" (cider--boot-resolve-command))
305330
("clojure" (cider--clojure-cli-resolve-command))
331+
("shadow-cljs" (cider--shadow-cljs-resolve-command))
306332
("gradle" (cider--gradle-resolve-command))
307333
(_ (user-error "Unsupported project type `%s'" project-type))))
308334

@@ -312,6 +338,7 @@ Throws an error if PROJECT-TYPE is unknown. Known types are
312338
("lein" cider-lein-global-options)
313339
("boot" cider-boot-global-options)
314340
("clojure" cider-clojure-cli-global-options)
341+
("shadow-cljs" cider-shadow-cljs-global-options)
315342
("gradle" cider-gradle-global-options)
316343
(_ (user-error "Unsupported project type `%s'" project-type))))
317344

@@ -321,6 +348,7 @@ Throws an error if PROJECT-TYPE is unknown. Known types are
321348
("lein" cider-lein-parameters)
322349
("boot" cider-boot-parameters)
323350
("clojure" cider-clojure-cli-parameters)
351+
("shadow-cljs" cider-shadow-cljs-parameters)
324352
("gradle" cider-gradle-parameters)
325353
(_ (user-error "Unsupported project type `%s'" project-type))))
326354

@@ -450,6 +478,20 @@ Does so by concatenating GLOBAL-OPTS, DEPENDENCIES finally PARAMS."
450478
"}}' "
451479
params)))
452480

481+
(defun cider-shadow-cljs-jack-in-dependencies (global-opts params dependencies)
482+
"Create shadow-cljs jack-in deps.
483+
Does so by concatenating GLOBAL-OPTS, DEPENDENCIES finally PARAMS."
484+
(let ((dependencies (append dependencies
485+
`(("cider/cider-nrepl" ,(upcase cider-version))))))
486+
(concat
487+
global-opts
488+
(unless (seq-empty-p global-opts) " ")
489+
(mapconcat #'identity
490+
(seq-map (lambda (dep) (format "-d %s:%s" (car dep) (cadr dep))) dependencies)
491+
" ")
492+
" "
493+
params)))
494+
453495
(defun cider-add-clojure-dependencies-maybe (dependencies)
454496
"Return DEPENDENCIES with an added Clojure dependency if requested.
455497
@@ -495,6 +537,11 @@ dependencies."
495537
params
496538
(cider-add-clojure-dependencies-maybe
497539
cider-jack-in-dependencies)))
540+
("shadow-cljs" (cider-shadow-cljs-jack-in-dependencies
541+
global-opts
542+
params
543+
(cider-add-clojure-dependencies-maybe
544+
cider-jack-in-dependencies)))
498545
("gradle" (concat
499546
global-opts
500547
(unless (seq-empty-p global-opts) " ")
@@ -902,6 +949,7 @@ Use `cider-ps-running-nrepls-command' and `cider-ps-running-nrepl-path-regexp-li
902949
(build-files '(("lein" . "project.clj")
903950
("boot" . "build.boot")
904951
("clojure" . "deps.edn")
952+
("shadow-cljs" . "shadow-cljs.edn")
905953
("gradle" . "build.gradle"))))
906954
(delq nil
907955
(mapcar (lambda (candidate)
@@ -968,6 +1016,16 @@ In case `default-directory' is non-local we assume the command is available."
9681016
(executable-find (concat cider-clojure-cli-command ".exe")))))
9691017
(shell-quote-argument command)))
9701018

1019+
;; TODO: Implement a check for `cider-shadow-cljs-command' over tramp
1020+
(defun cider--shadow-cljs-resolve-command ()
1021+
"Find `cider-shadow-cljs-command' on `exec-path' if possible, or return nil.
1022+
1023+
In case `default-directory' is non-local we assume the command is available."
1024+
(when-let* ((command (or (and (file-remote-p default-directory) cider-shadow-cljs-command)
1025+
(executable-find cider-shadow-cljs-command)
1026+
(executable-find (concat cider-shadow-cljs-command ".exe")))))
1027+
(shell-quote-argument command)))
1028+
9711029

9721030
;;; Check that the connection is working well
9731031
;; TODO: This is nrepl specific. It should eventually go into some cider-nrepl-client

0 commit comments

Comments
 (0)