Open benjamin-asdf opened 1 month ago
I looked into having a command as nice as 'jack in clj&cljs'.
Video of current state: https://github.com/user-attachments/assets/1f3298cc-89fb-4788-8037-c592a5f87d53
Current v1 is a bespoke command:
;; -*- lexical-binding: t; -*-
(defun clerk-render-repl-cider-jack-in-clj&cljs (&optional params)
"A bespoke cider jack in for clerk-render-repl.
This waits for both nrepl servers to run and then jacks in a clj and a cljs nrepl."
(interactive "P")
(let* ((params (thread-first
params
(plist-put
:project-type 'clojure-cli)
(plist-put
:cljs-repl-type 'sci-browser-nrepl)))
(cljs-endpoint '(:host "localhost" :port 1339))
(params (cider--update-params params))
(orig-buffer (current-buffer)))
(nrepl-start-server-process
(plist-get params :project-dir)
(plist-get params :jack-in-cmd)
(let ((clj-endpoint nil)
(clj-endpoint-ready nil)
(cljs-endpoint-ready nil))
(lambda (server-buffer)
(cond ((equal cljs-endpoint
nrepl-endpoint)
(setf cljs-endpoint-ready t))
(t
(progn
(setf
clj-endpoint
nrepl-endpoint)
(setf clj-endpoint-ready t))))
;; ----------------------
;; signal that we are not done waiting,
(setf nrepl-endpoint nil)
;; -----------------------
(when (and cljs-endpoint-ready
clj-endpoint-ready)
;; ... until we are done waiting
(setf nrepl-endpoint clj-endpoint)
(with-current-buffer
orig-buffer
(let ((clj-repl (cider-connect-sibling-clj
params
server-buffer)))
(cider-register-cljs-repl-type 'sci-browser-nrepl)
;; I think it first needed to open the browser or something,
;; it's possible you need to increase this
;; (symptom was that cider timed out with sync request 'describe op')
(sit-for 1)
(cider-connect-sibling-cljs
(thread-first
params
(plist-put
:port (plist-get cljs-endpoint :port))
(plist-put
:host (plist-get cljs-endpoint :host)))
clj-repl)))))))))
(let ((cider-clojure-cli-aliases ":dev"))
(clerk-render-repl-cider-jack-in-clj&cljs))
This get's rid of the delay: https://github.com/benjamin-asdf/clerk-render-repl/blob/9f25b822411ffdb066e9bfa58ba94b25c1064590/dev/user.clj#L11
instead of waiting for the nrepl server to output a port, we can wait for 'nrepl-port' files
but, we want multiple nrepl port files per project, so for this we need to update nrepl
in a nutshell:
./nrepl/repl-name.edn
, contains connection infoconnection info can support unix sockets
I have a tiny example working for clerk-render-repl, hacked a sci-nrepl-port file into sci-n
repl
Does editor specify the connections (file names?) up front?
doess editor wait for files to appear in 'nrepl/' and try to connect?
Should the file then contain additional info of how to connect?
The problem:
Cider connections (~= 'repl buffer') are either 'clj or cljs' connections. Cider needs to decide between them for each connection.
General approach 1: Specify up front whether it is cljs. General approach 2: Let cider discover whether clojurescript is present itself.
Suggested fix 1: Specify 'cljs' up front (approach 1)
Config:
(cider-register-cljs-repl-type 'sci-browser-nrepl)
Run
cider-jack-in-clj
Run
cider-connect-cljs
, select host: localhost and port:1339
, and cljs repl typesci-browser-nrepl
.Or evaluate:
sesman-link-with-buffer
, I checked withCIDER 1.16.0 (Kherson)
.sesman-link-with-buffer
is neccessary.cider-merge-sessions
).cider-repls
, it can be traced withtrace-function
to debug.)Suggested fix 2: Discover cljs capability (approach 2)
cider-jack-in-clj
(with dev alias)cider-connect-clj
, enter1339
when prompted for the port.Note you use cider-connect-clj, not
cider-connect-cljs
, this is because we skip cljs setup flow and still mark the resulting connection as having clojurescript.As a future step, this could be part of cider proper.
More background
Approach 2 is implemented in cider to some degree, but tied to 'nrepl version' (comes from the output of :describe ob). A few known repls are listed, but not sci nrepl.
Questions
If you could split the processes in two:
1 clerk server:
viewer.connect_render_nrepl
2 sci nrepl process: listening on nrepl port (1339) and websocket port (1340)
Then, one could make the same flow as shodow connect with
cider-connect-clj&cljs
.pros:
cons:
(but cider doesn't handle it automatically so well atm - visible by the 'listening on port' issue).
Potential future work:
sesman-link-with-buffer
is needed (when using suggested fix 1)