Skip to content

Commit

Permalink
Add repl capabilities
Browse files Browse the repository at this point in the history
This is for nbb, scittle, joyride and any other potentially
impoverished repl environment.

we want to

1. Check for cider middleware being present, before using it
(already being done)
2. Check for cider-library-present-p, before relying on anything in
the runtime
3. Make assumptions about the runtime explicit
My suggestion is =cider-connection-capabilities=.
Currently, there was an implicit assumption about the compilation
error format.

I basically have nbb and scittle working well with this setup.
You use `cider-connect` / `cider-connect-clj`.

Fix error

Connect cljs buffers with "non setup" cljs repls

scittle, nbb

Delete extra connect command
  • Loading branch information
benjamin-asdf committed Nov 29, 2022
1 parent 2f7a2f2 commit f07e661
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
29 changes: 28 additions & 1 deletion cider-connection.el
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ buffer."
(when cider-auto-mode
(cider-enable-on-existing-clojure-buffers))

(setf cider-connection-capabilities
(append
(pcase (cider-runtime)
('clojure '(clojure jvm-compilation-errors))
('babashka '(babashka jvm-compilation-errors))
(_ '()))
(when (cider-clojurescript-present-p) '(cljs))))

(run-hooks 'cider-connected-hook)))))

(defun cider--disconnected-handler ()
Expand Down Expand Up @@ -437,6 +445,22 @@ about this buffer (like variable `cider-repl-type')."
(plist-get nrepl-endpoint :host)
(plist-get nrepl-endpoint :port))))))

(defun cider-clojurescript-present-p ()
"Return non nil when ClojureScript is present."
(nrepl-dict-get (cider-sync-tooling-eval "cljs.core/inc") "value"))

(defvar-local cider-connection-capabilities '()
"A list of some of the capabilites of this connection buffer.
Aka what assumptions we make about the runtime. Aka stuff we needed to make explicit
in order for nbb to work.
This is more genaral than `cider-nrepl-op-supported-p' and `cider-library-present-p'.
But does not need to replace them.")

(defun cider-connection-has-capability-p (capability)
"Return non nil when the cider connection has CAPABILITY."
(with-current-buffer (cider-current-repl)
(member capability cider-connection-capabilities)))


;;; Connection Management Commands

Expand Down Expand Up @@ -881,10 +905,13 @@ no linked session or there is no REPL of TYPE within the current session."

(defun cider--match-repl-type (type buffer)
"Return non-nil if TYPE matches BUFFER's REPL type."
(let ((buffer-repl-type (cider-repl-type buffer)))
(let ((buffer-repl-type (cider-repl-type buffer))
(capabilities (buffer-local-value 'cider-connection-capabilities buffer)))
(cond ((null buffer-repl-type) nil)
((or (null type) (eq type 'multi) (eq type 'any)) t)
((listp type) (member buffer-repl-type type))
((or (eq 'cljs type) (and (listp type) (member 'cljs type)))
(member 'cljs capabilities))
(t (string= type buffer-repl-type)))))

(defun cider--get-host-from-session (session)
Expand Down
4 changes: 3 additions & 1 deletion cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,9 @@ when `cider-auto-inspect-after-eval' is non-nil."
(cider-emit-interactive-eval-output out))
(lambda (_buffer err)
(cider-emit-interactive-eval-err-output err)
(unless cider-show-error-buffer
(when (or (not cider-show-error-buffer)
(not (cider-connection-has-capability-p 'jvm-compilation-errors)))

;; Display errors as temporary overlays
(let ((cider-result-use-clojure-font-lock nil))
(cider--display-interactive-eval-result
Expand Down
2 changes: 1 addition & 1 deletion cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ Generally you should not disable this unless you run into some faulty check."

(defun cider-verify-clojurescript-is-present ()
"Check whether ClojureScript is present."
(unless (cider-library-present-p "cljs.core")
(unless (cider-clojurescript-present-p)
(user-error "ClojureScript is not available. See https://docs.cider.mx/cider/basics/clojurescript for details")))

(defun cider-verify-piggieback-is-present ()
Expand Down

0 comments on commit f07e661

Please sign in to comment.