A) I'm having a problem where Cider can't cider-connect-clj
(or cider-connect-cljs
) to an nREPL server I launch in my application code. Cursive also doesn't work. It must be a simple configuration or middleware that needs to be included. But I've been looking at this code too long. What I missing?
I have a Clojure file that looks something like this.
(ns some.namespace
(:require nrepl.server
cider.nrepl))
(nrepl.server/start-server
:port 1234
:handler
(fn [_]
(nrepl.server/default-handler cider.nrepl/cider-middleware)))
nrepl.server/start-server
starts ok.
From Emacs I can connect by calling cider-connect-clj
(or cider-connect-cljs
). But then the REPL fails to initialize on a "sync" request.
i. Emacs console
[nREPL] Direct connection to localhost:6776 established
nrepl-send-sync-request: Sync nREPL request timed out (op clone id 1 time-stamp 2021-02-04 23:13:46.789763000)
ii. nREPL console
[WARNING] No nREPL middleware descriptor in metadata of null, see nrepl.middleware/set-descriptor!
B) I'm actually running Figwheel-Main and connecting an nREPL, for a Clojurescript connection. All within my Clojure app.
;; λ clj -A:dev -m some.namespace
:dev
{:extra-paths ["dev" "test"]
:extra-deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.520"}
com.bhauman/figwheel-main {:mvn/version "0.2.0"}
nrepl/nrepl {:mvn/version "0.8.3"}
cider/cider-nrepl {:mvn/version "0.25.8"}
cider/piggieback {:mvn/version "0.4.2"}}}
I don't think the Figwheel portion is affecting cider's attempts to connect. But I'm including it just for context.
(defn -main [& args]
;; Start Figwheel Server
(figwheel.main.api/start
{:mode :serve} "dev")
;; Start nREPL
(def server (nrepl.server/start-server
:port 1234
:handler
(fn [_]
(nrepl.server/default-handler cider.nrepl/cider-middleware))))
;; Start Figwheel REPL
(fig/cljs-repl "dev"))
It seems that you're starting the nREPL on port 1234, but then Emacs is trying to connect to port 6776. Could that be the reason?
When you run
cider-connect-clj
you can select the port you want connect to. Try changing the default port to 1234 and see if that helps.