trptcolin / reply

REPL-y: A fitter, happier, more productive REPL for Clojure.
Eclipse Public License 1.0
338 stars 44 forks source link

Port arg is missing :parse-fn #201

Closed stefan-toubia closed 4 years ago

stefan-toubia commented 4 years ago

Trying to start reply with a --port arg throws the following exception

ClassCastException java.lang.String cannot be cast to java.lang.Number
    nrepl.server/start-server/addr--1156 (server.clj:120)
    nrepl.server/start-server (server.clj:128)
    nrepl.server/start-server (server.clj:96)
    reply.eval-modes.nrepl/get-connection (nrepl.clj:158)
    reply.eval-modes.nrepl/get-connection (nrepl.clj:156)
    reply.eval-modes.nrepl/main (nrepl.clj:202)
    reply.eval-modes.nrepl/main (nrepl.clj:200)
    reply.main/launch-nrepl/fn--2391 (main.clj:79)
    clojure.core/with-redefs-fn (core.clj:7514)
    clojure.core/with-redefs-fn (core.clj:7498)
    reply.main/launch-nrepl (main.clj:78)
    reply.main/launch-nrepl (main.clj:72)

Looks like there needs to be a :parse-fn added to parse strings to int.

https://github.com/trptcolin/reply/blob/445622358072bc6397ee13cad2f1c7833f577157/src/clj/reply/main.clj#L45

trptcolin commented 4 years ago

Which version of reply are you using? This was a bug fixed in 0.4.4 - details in https://github.com/trptcolin/reply/issues/199

stefan-toubia commented 4 years ago

Oh! I'm on 0.4.3, thanks!

While I have you here, I've been trying to work reply into my workflow with calva. Right now if I start a standalone nrepl, nrepl automatically chooses a port and exposes a port you can connect to, as well as making an .nrepl-port file.

nREPL server started on port 60959 on host localhost - nrepl://localhost:60959

I may have missed this but I did not see how to mimic this when using reply, is this supported?

trptcolin commented 4 years ago

Hmm, lein trampoline run does use nREPL by default, and picks a random port. And then lein trampoline run --attach PORT_NUMBER will let you attach to the same runtime.

I'm not sure there's currently a way to get that generated port number other than (a) doing the thing I did, where you lsof -nPi | grep java and find the exposed port, or (b) if you're in the runtime, looking at (:port @reply.eval-modes.nrepl/nrepl-server). Details: https://github.com/trptcolin/reply/blob/445622358072bc6397ee13cad2f1c7833f577157/src/clj/reply/eval_modes/nrepl.clj#L156-L169

I don't think I'd want us to write an .nrepl-port file explicitly, since that naming responsibility seems like it belongs all together wherever it lives (sounds like in the nREPL codebase), but I'm open to having some config where you could tell REPLy something like --write-port-file "path/to/file"? I'd defer to @bbatsov though.

trptcolin commented 4 years ago

I'm going to go ahead & close this issue - feel free to open another (or a PR!) if the above answer doesn't get you what you need for connecting to a port!

stefan-toubia commented 4 years ago

Thanks again for the help!