I’m having a problem implementing support for nrepl.edn
in Cursive, although I’m not sure if this is an nREPL problem or a piggieback one.
I thought I had implemented the support, but when I try to test piggieback, I get:
Connecting to local nREPL server...
nREPL server started on port 52466 on host 127.0.0.1
Clojure 1.10.1
(require 'cljs.repl.nashorn 'cider.piggieback)
=> nil
(cider.piggieback/cljs-repl (cljs.repl.nashorn/repl-env))
Execution error (IllegalStateException) at cider.piggieback/cljs-repl (piggieback_impl.clj:168).
Can't change/establish root binding of: *cljs-repl-env* with set
I found a couple of issues about this, but they were either about using very old versions of various things, or about using trampoline with leiningen.
I’m establishing my server like this:
`(do
(-> (File. ~(.getCanonicalPath init-file))
(.deleteOnExit))
(try (require 'nrepl.server 'nrepl.config 'nrepl.cmdline)
(catch Throwable t#
(println "Error loading nrepl.server:"
(or (.getMessage t#) (type t#)))))
(try
(let [config# (merge {:host "127.0.0.1"
:port 0}
nrepl.config/config)
{:keys [port# bind# handler# transport# greeting#]} (nrepl.cmdline/server-opts config#)
server# (nrepl.server/start-server
:port port#
:bind bind#
:ack-port ~ack-port
:handler handler#
:transport-fn transport#
:greeting-fn greeting#)
port# (:port server#)]
(println "nREPL server started on port" port# "on host 127.0.0.1"))
(catch Throwable t#
(println "Error starting server:"
(or (.getMessage t#) (type t#))))))
deps.edn:
{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}
:aliases {:repl {:extra-deps {nrepl/nrepl {:mvn/version "0.6.0"}
cider/piggieback {:mvn/version "0.4.2"}}}}}
nrepl.edn:
{:middleware [cider.piggieback/wrap-cljs-repl]}
I’m not directly invoking nrepl.cmdline
for everything, but I am reusing most of its logic, in particular for creating the handler from the configured middleware.
Am I missing something obvious?
Ok, one problem was that nrepl.edn
should have been .nrepl.edn
, so the middleware wasn’t being found. However even after fixing that I’m still having the same problem.
I’ve debugged this, and the piggieback middleware does seem to be being applied to the handler correctly, which means I’m pretty much out of ideas.
Hmm, if the handler is correct I can’t imagine how this wouldn’t work.
I’m going to try just calling nrepl.cmdline directly and passing the args as if I were calling -main, and see if I’m missing something subtle.
Did you try it with some other middleware as well?
No, is there an easy one to test with?
Is there an echo middleware or something like that?
There’s not, but I guess it’s not a bad idea. 🙂 There a few pretty basic ops in cider-nrepl
, though - e.g. classpath
.
The problem is I don’t have anything in the client for sending custom messages.
I’m going to try calling nrepl.cmdline first, which is an easy test.
Oh, got it. I always assumed you had some generic support for custom messages.
:thumbsup:
I don’t really use custom messages at all, so I’ve never had the need.
Ok, so if I just call nrepl.cmdline directly, that works.
So I’m obviously missing something either subtle or obvious.
I think I’ll just keep doing that so that Cursive will interop better with all the related nREPL tooling, and things like .nrepl.port
should just work.
It would be nice to be able to hide the port ack message.
I agree. I’d also welcome some feedback on the current state of the nrepl.cmdline
API, which I consider experimental at this point. Obviously without having clients of it around it was hard to assess if we got it right or not. 🙂
Can you file a ticket about this?
This is currently the extent of my use of it:
(try (require 'nrepl.cmdline)
(catch Throwable t#
(println "Error loading nREPL:"
(or (.getMessage t#) (type t#)))
(System/exit 1)))
(nrepl.cmdline/-main "--ack" ~(str ack-port))
🙂
That definitely surprised me, as your code looked legit to me, but I’m glad to hear we didn’t break something. 😄
Ah, got it. I thought you went more granular than that. 😄
One bit of feedback I see is that maybe we should suppress exceptions coming from -main
.
Yeah, it’s weird. I think I’ll continue just calling that directly, but it’s definitely odd.