Skip to content

Commit b9e5013

Browse files
Add jack-in support for ClojureCLR
1 parent 91b320b commit b9e5013

5 files changed

Lines changed: 75 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
### New features
2424

2525
- `cider-eval-commands-map` (`C-c C-v` prefix) now binds five long-existing eval commands that previously had no presence under the prefix: `cider-eval-last-sexp-to-repl` (`j`/`C-j`), `cider-eval-print-last-sexp` (`p`/`C-p`), `cider-read-and-eval` (`:`), `cider-eval-defun-to-comment` (`;`), and `cider-pprint-eval-last-sexp-to-repl` (`f j e`). Existing chords (`C-c M-e`, `C-c M-:`, `C-c M-;`) are unchanged.
26+
- [#3839](https://github.com/clojure-emacs/cider/pull/3839): Add jack-in support for ClojureCLR.
2627

2728
### Bugs fixed
2829

doc/modules/ROOT/pages/basics/up_and_running.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ The following Clojure build tools are supported so far
182182
- kbd:[M-3 C-c C-x j u] jack-in using babashka.
183183
- kbd:[M-4 C-c C-x j u] jack-in using nbb.
184184
- kbd:[M-5 C-c C-x j u] jack-in using basilisp.
185+
- kbd:[M-6 C-c C-x j u] jack-in using ClojureCLR.
185186

186187
Here is an example of how to bind kbd:[F12] for quickly bringing up a
187188
babashka REPL:

doc/modules/ROOT/pages/caveats.adoc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ from your Emacs config.
6060

6161
== ClojureCLR Support
6262

63-
CIDER currently has very basic support for ClojureCLR (via Arcadia's nREPL server). The reasons for this are the following:
63+
CIDER currently has very basic support for ClojureCLR (via either a port of Babashka's nREPL server or Arcadia's nREPL server). The reasons for this are the following:
6464

65-
* nREPL itself runs only on the JVM (because it leverages Java APIs
66-
internally). There's an
67-
https://github.com/clojure/clr.tools.nrepl[nREPL port for ClojureCLR], but
68-
it's not actively maintained and it doesn't behave like the Clojure nREPL.
69-
* `cider-nrepl` uses a lot of Java code internally itself.
65+
* The https://github.com/clojure/clr.tools.nrepl/tree/master/partial-nrepl-nrepl-port[nrepl/nrepl port to ClojureCLR] is not yet working
66+
* `cider-nrepl` uses a lot of Java code internally itself and would need to be adapted/ported like any
67+
other clojure library adapted/ported to ClojureCLR.
7068

7169
Those issues are not insurmountable, but are beyond the scope of our current roadmap.
7270
If someone would like to tackle them, we'd be happy to provide assistance.

doc/modules/ROOT/pages/platforms/clojureclr.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
== Current Status
44

5-
ClojureCLR on CIDER is not great due to the lack of a fully-functional nREPL
6-
server for ClojureCLR. There are currently two options:
5+
You will get basic CIDER functionality with ClojureCLR. Three nREPL server options:
76

8-
- https://github.com/clojure/clr.tools.nrepl[clr.tools.nrepl]: A direct (but incomplete) port of the reference Clojure nREPL server.
7+
- https://github.com/clojure/clr.tools.nrepl[clr.tools.nrepl]: At present port of babashka's nREPL server (https://github.com/babashka/babashka.nrepl[babashka.nrepl]).
8+
- https://github.com/clojure/clr.tools.nrepl/tree/master/partial-nrepl-nrepl-port[port of nrepl/nrepl]: A non-working, work-in-progress port of nrepl/nrepl, which may
9+
ultimately better integrate with CIDER once CIDER's middleware (cider-nrepl) is also adapted/ported.
910
- https://github.com/arcadia-unity/Arcadia/blob/master/Editor/NRepl.cs[Arcadia's nREPL]: A basic, but working nREPL implementation in C#.
1011

11-
If you need to use CIDER with ClojureCLR today Arcadia's nREPL is your only usable option. That being said - `clr.tools.nrepl` is a much
12-
more sophisticated project and ideally we should get it over to the finish line.
12+
An alternative to CIDER & a nREPL server is inf-clojure with ClojureCLR's stock socket REPL server.
1313

1414
== Usage
1515

1616
NOTE: Contributions welcome!
1717

18-
As `cider-jack-in` doesn't support ClojureCLR projects out-of-the-box currently, you'll need to start an nREPL server externally and
19-
connect to it with `cider-connect`.
18+
`cider-jack-in-universal` will jack into a clr.tools.nrepl server as long as a `deps-clr.edn` file
19+
exists in the project directory, otherwise you may call `cider-jack-in-universal` with prefix
20+
argument 6, by either `M-6` or `C-u 6` followed by `M-x cider-jack-in-universal`.
2021

2122
== Plans
2223

2324
In an ideal world we'll achieve the following objectives:
2425

25-
- out-of-the-box ClojureCLR support with `cider-jack-in`
2626
- feature parity between Clojure's nREPL implementation and `clr.tools.nrepl` (the project can use some help)
2727
- adapting `cider-nrepl` for ClojureCLR (some of its codebase is JVM-specific)
2828

lisp/cider-jack-in.el

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,30 @@ By default we favor the project-specific shadow-cljs over the system-wide."
207207
:safe #'stringp
208208
:package-version '(cider . "1.14.0"))
209209

210+
(defcustom cider-clojure-clr-cli-command
211+
"cljr"
212+
"The command used to execute ClojureCLR."
213+
:type 'string
214+
:group 'cider
215+
:safe #'stringp
216+
:package-version '(cider . "1.21.0"))
217+
218+
(defcustom cider-clojure-clr-cli-parameters
219+
"-X clojure.tools.nrepl/start-server!"
220+
"Params passed to ClojureCLR to start an nREPL server via `cider-jack-in'."
221+
:type 'string
222+
:group 'cider
223+
:safe #'stringp
224+
:package-version '(cider . "1.21.0"))
225+
226+
;; Clojure git deps require :git/sha even when :git/tag is set, just do full SHA
227+
(defcustom cider-clojure-clr-cli-nrepl-sha "a6bf822a5f72ec613f703eaf95420758591f2437"
228+
"The version of clr.tools.nrepl injected on jack-in with ClojureCLR."
229+
:type 'string
230+
:group 'cider
231+
:safe #'stringp
232+
:package-version '(cider . "1.21.0"))
233+
210234

211235
;;; Jack-in defaults and toggles
212236

@@ -623,6 +647,30 @@ Does so by concatenating PARAMS and DEPENDENCIES."
623647
" "
624648
params)))
625649

650+
(defun cider-clojure-clr-cli-jack-in-dependencies (params dependencies &optional command)
651+
"Create ClojureCLR clr.core.cli jack-in dependencies.
652+
Does so by concatenating DEPENDENCIES, and PARAMS into a
653+
suitable `cljr` invocation and quoting, also accounting for COMMAND if
654+
provided."
655+
(let* ((all-deps (thread-last dependencies
656+
(cider--dedupe-deps)
657+
(seq-map (lambda (dep)
658+
(if (listp (cadr dep))
659+
(format "%s {%s}"
660+
(car dep)
661+
(seq-reduce
662+
(lambda (acc v)
663+
(concat acc (format " :%s \"%s\" " (car v) (cdr v))))
664+
(cadr dep)
665+
""))
666+
(format "%s {:git/sha \"%s\"}" (car dep) (cadr dep)))))))
667+
(deps (format "{:deps {%s}}"
668+
(string-join all-deps " ")))
669+
(deps-quoted (cider--shell-quote-argument deps command)))
670+
(format "-Sdeps %s %s"
671+
deps-quoted
672+
(if params (format " %s" params) ""))))
673+
626674
(defun cider-add-clojure-dependencies-maybe (dependencies)
627675
"Return DEPENDENCIES with an added Clojure dependency if requested.
628676
See also `cider-jack-in-auto-inject-clojure'."
@@ -682,6 +730,12 @@ COMMAND is the resolved jack-in command, used to handle PowerShell quoting."
682730
(cider-add-clojure-dependencies-maybe cider-jack-in-dependencies)
683731
(cider-jack-in-normalized-nrepl-middlewares)))
684732

733+
(defun cider--clojure-clr-cli-inject-deps (params _project-type _command)
734+
"Inject CIDER deps into PARAMS for a ClojureCLR CLI project."
735+
(cider-clojure-clr-cli-jack-in-dependencies
736+
params
737+
`(("io.github.clojure/clr.tools.nrepl" ,cider-clojure-clr-cli-nrepl-sha))))
738+
685739
(defun cider-inject-jack-in-dependencies (params project-type &optional command)
686740
"Return PARAMS with injected REPL dependencies for PROJECT-TYPE.
687741
Looks up the tool's :inject-fn in `cider-jack-in-tools' and calls it with
@@ -849,6 +903,13 @@ Throws an error if PROJECT-TYPE is unknown."
849903
:project-files '("basilisp.edn")
850904
:universal-prefix-arg 5)
851905

906+
(cider-register-jack-in-tool 'clojure-clr-cli
907+
:command-var 'cider-clojure-clr-cli-command
908+
:params-var 'cider-clojure-clr-cli-parameters
909+
:project-files '("deps-clr.edn")
910+
:inject-fn #'cider--clojure-clr-cli-inject-deps
911+
:universal-prefix-arg 6)
912+
852913

853914
;;; ClojureScript jack-in helpers
854915

0 commit comments

Comments
 (0)