Skip to content

Commit

Permalink
Make new jack-in-dependencies COMMAND arg &optional
Browse files Browse the repository at this point in the history
so that it does not break API compatibility
  • Loading branch information
ikappaki authored and bbatsov committed May 18, 2023
1 parent d21f4b2 commit 99c90fc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
14 changes: 7 additions & 7 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,12 @@ rules to quote it."
(utf-16le-command (encode-coding-string command 'utf-16le)))
(format "-encodedCommand %s" (base64-encode-string utf-16le-command t))))

(defun cider-clojure-cli-jack-in-dependencies (global-options params dependencies command)
(defun cider-clojure-cli-jack-in-dependencies (global-options params dependencies &optional command)
"Create Clojure tools.deps jack-in dependencies.
Does so by concatenating DEPENDENCIES, PARAMS and GLOBAL-OPTIONS into a
suitable `clojure` invocation and quoting suitable for COMMAND invocation.
The main is placed in an inline alias :cider/nrepl so that if your aliases
contain any mains, the cider/nrepl one will be the one used."
suitable `clojure` invocation and quoting, also accounting for COMMAND if
provided. The main is placed in an inline alias :cider/nrepl so that if
your aliases contain any mains, the cider/nrepl one will be the one used."
(let* ((all-deps (thread-last
dependencies
(append (cider--jack-in-required-dependencies))
Expand Down Expand Up @@ -838,12 +838,12 @@ See also `cider-jack-in-auto-inject-clojure'."
dependencies))
dependencies))

(defun cider-inject-jack-in-dependencies (global-opts params project-type command)
(defun cider-inject-jack-in-dependencies (global-opts params project-type &optional command)
"Return GLOBAL-OPTS and PARAMS with injected REPL dependencies.
These are set in `cider-jack-in-dependencies', `cider-jack-in-lein-plugins'
and `cider-jack-in-nrepl-middlewares' are injected from the CLI according
to the used PROJECT-TYPE and COMMAND. Eliminates the need for hacking
profiles.clj or the boot script for supporting CIDER with its nREPL
to the used PROJECT-TYPE, and COMMAND if provided. Eliminates the need for
hacking profiles.clj or the boot script for supporting CIDER with its nREPL
middleware and dependencies."
(pcase project-type
('lein (cider-lein-jack-in-dependencies
Expand Down
44 changes: 26 additions & 18 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
(setq-local cider-enrich-classpath t))

(it "can inject dependencies in a lein project"
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein "lein")
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein)
:to-equal (concat "update-in :dependencies conj "
(shell-quote-argument "[nrepl/nrepl \"0.9.0\"]")
" -- update-in :plugins conj "
Expand All @@ -160,7 +160,7 @@

(it "can inject dependencies in a lein project with an exclusion"
(setq-local cider-jack-in-dependencies-exclusions '(("nrepl/nrepl" ("org.clojure/clojure"))))
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein "lein")
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein)
:to-equal (concat
"update-in :dependencies conj "
(shell-quote-argument "[nrepl/nrepl \"0.9.0\" :exclusions [org.clojure/clojure]]")
Expand All @@ -173,7 +173,7 @@

(it "can inject dependencies in a lein project with multiple exclusions"
(setq-local cider-jack-in-dependencies-exclusions '(("nrepl/nrepl" ("org.clojure/clojure" "foo.bar/baz"))))
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein "lein")
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein)
:to-equal (concat "update-in :dependencies conj "
(shell-quote-argument "[nrepl/nrepl \"0.9.0\" :exclusions [org.clojure/clojure foo.bar/baz]]")
" -- update-in :plugins conj "
Expand All @@ -184,7 +184,7 @@
" -- repl :headless")))

(it "can inject dependencies in a boot project"
(expect (cider-inject-jack-in-dependencies "" "repl -s wait" 'boot "boot")
(expect (cider-inject-jack-in-dependencies "" "repl -s wait" 'boot)
:to-equal (concat
"-i \"(require 'cider.tasks)\""
" -d "
Expand All @@ -197,7 +197,7 @@
" repl -s wait")))

(it "can inject dependencies in a gradle project"
(expect (cider-inject-jack-in-dependencies "--no-daemon" ":clojureRepl" 'gradle "grandle")
(expect (cider-inject-jack-in-dependencies "--no-daemon" ":clojureRepl" 'gradle)
:to-equal (concat "--no-daemon "
(shell-quote-argument "-Pdev.clojurephant.jack-in.nrepl=nrepl:nrepl:0.9.0,cider:cider-nrepl:0.28.5")
" :clojureRepl "
Expand All @@ -210,7 +210,7 @@
(setq-local cider-jack-in-nrepl-middlewares '("refactor-nrepl.middleware/wrap-refactor" "cider.nrepl/cider-middleware"))
(setq-local cider-jack-in-dependencies-exclusions '()))
(it "can inject dependencies in a lein project"
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein "lein")
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein)
:to-equal (concat "update-in :dependencies conj "
(shell-quote-argument "[nrepl/nrepl \"0.9.0\"]")
" -- update-in :plugins conj "
Expand All @@ -224,7 +224,7 @@

(it "can inject dependencies in a boot project"
(setq-local cider-jack-in-dependencies '(("refactor-nrepl" "2.0.0")))
(expect (cider-inject-jack-in-dependencies "" "repl -s wait" 'boot "boot")
(expect (cider-inject-jack-in-dependencies "" "repl -s wait" 'boot)
:to-equal (concat "-i \"(require 'cider.tasks)\""
" -d "
(shell-quote-argument "nrepl/nrepl:0.9.0")
Expand All @@ -247,7 +247,7 @@
(setq-local cider-jack-in-nrepl-middlewares '("cider.nrepl/cider-middleware"))
(setq-local cider-jack-in-dependencies-exclusions '()))
(it "can concat in a lein project"
(expect (cider-inject-jack-in-dependencies "-o -U" "repl :headless" 'lein "lein")
(expect (cider-inject-jack-in-dependencies "-o -U" "repl :headless" 'lein)
:to-equal (concat "-o -U update-in :dependencies conj "
(shell-quote-argument "[nrepl/nrepl \"0.9.0\"]")
" -- update-in :plugins conj "
Expand All @@ -257,7 +257,7 @@
" -- update-in :middleware conj cider.enrich-classpath/middleware"
" -- repl :headless")))
(it "can concat in a boot project"
(expect (cider-inject-jack-in-dependencies "-C -o" "repl -s wait" 'boot "boot")
(expect (cider-inject-jack-in-dependencies "-C -o" "repl -s wait" 'boot)
:to-equal (concat "-C -o -i \"(require 'cider.tasks)\""
" -d "
(shell-quote-argument "nrepl/nrepl:0.9.0")
Expand All @@ -268,7 +268,7 @@
(shell-quote-argument "cider.nrepl/cider-middleware")
" repl -s wait")))
(it "can concat in a gradle project"
(expect (cider-inject-jack-in-dependencies "--no-daemon" ":clojureRepl" 'gradle "grandle")
(expect (cider-inject-jack-in-dependencies "--no-daemon" ":clojureRepl" 'gradle)
:to-equal (concat "--no-daemon "
(shell-quote-argument "-Pdev.clojurephant.jack-in.nrepl=nrepl:nrepl:0.9.0,cider:cider-nrepl:0.28.5")
" :clojureRepl "
Expand Down Expand Up @@ -326,7 +326,7 @@
(setq-local cider-jack-in-dependencies-exclusions '())
(setq-local cider-enrich-classpath t))
(it "uses them in a lein project"
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein "lein")
(expect (cider-inject-jack-in-dependencies "" "repl :headless" 'lein)
:to-equal (concat "update-in :dependencies conj "
(shell-quote-argument "[nrepl/nrepl \"0.9.0\"]")
" -- update-in :plugins conj "
Expand All @@ -345,7 +345,7 @@
(setq-local cider-jack-in-dependencies '(("refactor-nrepl" "2.0.0")))
(setq-local cider-jack-in-dependencies-exclusions '()))
(it "uses them in a boot project"
(expect (cider-inject-jack-in-dependencies "" "repl -s wait" 'boot "boot")
(expect (cider-inject-jack-in-dependencies "" "repl -s wait" 'boot)
:to-equal (concat "-i \"(require 'cider.tasks)\""
" -d "
(shell-quote-argument "nrepl/nrepl:0.9.0")
Expand Down Expand Up @@ -405,6 +405,14 @@
(expect (cider--shadow-parse-builds (parseedn-read-str "[oops]"))
:to-equal '(browser-repl node-repl))))

(describe "cider--shell-quote-argument"
(it "can quote powershell argument"
(expect (cider--shell-quote-argument "one \"two\" three" "powershell")
:to-equal "'one \"\"two\"\" three'"))
(it "can quote any other argument"
(expect (cider--shell-quote-argument "one \"two\" three")
:to-equal (shell-quote-argument "one \"two\" three"))))

(describe "cider--powershell-encode-command"
(it "base64 encodes command and parameters"
(expect (cider--powershell-encode-command "cmd-params")
Expand Down Expand Up @@ -483,20 +491,20 @@
""))
(deps '(("nrepl/nrepl" "0.9.0"))))
(let ((cider-clojure-cli-aliases ":test"))
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps "clojure")
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps)
:to-equal expected))
(describe "should strip out leading exec opts -A -M -T -X"
(let ((cider-clojure-cli-aliases "-A:test"))
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps "clojure")
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps)
:to-equal expected))
(let ((cider-clojure-cli-aliases "-M:test"))
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps "clojure")
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps)
:to-equal expected))
(let ((cider-clojure-cli-aliases "-T:test"))
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps "clojure")
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps)
:to-equal expected))
(let ((cider-clojure-cli-aliases "-T:test"))
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps "clojure")
(expect (cider-clojure-cli-jack-in-dependencies nil nil deps)
:to-equal expected)))))
(it "allows for global options"
(let ((expected (string-join `("-J-Djdk.attach.allowAttachSelf -Sdeps "
Expand All @@ -505,7 +513,7 @@
""))
(deps '(("nrepl/nrepl" "0.9.0"))))
(let ((cider-clojure-cli-aliases ":test"))
(expect (cider-clojure-cli-jack-in-dependencies "-J-Djdk.attach.allowAttachSelf" nil deps "clojure")
(expect (cider-clojure-cli-jack-in-dependencies "-J-Djdk.attach.allowAttachSelf" nil deps)
:to-equal expected))))
(it "allows to specify git coordinate as cider-jack-in-dependency"
(setq-local cider-jack-in-dependencies '(("org.clojure/tools.deps" (("git/sha" . "6ae2b6f71773de7549d7f22759e8b09fec27f0d9")
Expand Down

0 comments on commit 99c90fc

Please sign in to comment.