nrepl

danm 2022-08-08T16:41:28.613829Z

👋🏻 New to looking at the internals of nREPL, and I'm trying to understand what's going on here. We launch a REPL within our application using the standard CIDER set of middleware. This works fine for my colleagues who use CIDER, they connect to it on a host and port and get all the output back that they expect. However it doesn't seem to work for those of us using Cursive. stderr messages are printed to the tty the REPL server is running in (a docker container, remote process on a K8s node, etc), but don't appear on my Cursive REPL session. Likewise, stdout from external applications that have been triggered from within our app (e.g. by using conch to shell out to something) appear in the remote tty but not my session. If I launch the REPL directly from Cursive using it's lein integration, I get the expected output, but of course that only works for a local REPL. Everything contained within Clojure/Java seems OK, but not anything going directly to the default *out*. The nREPL docs says that ls-middleware is a core operation (https://nrepl.org/nrepl/ops.html#ls-middleware), but I'm failing to find it in the API docs to know what namespace to load to run it from, to at least verify that the expected middleware (`cider.nrepl/wrap-out` in this case, I believe) is even loaded. Can anyone point me in a good starting direction?

dpsutton 2022-08-08T16:47:56.803309Z

you might want to send a message of “out-subscribe” https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/out.clj#L180 When CIDER starts up it will run

;; Redirect the nREPL's terminal output to a REPL buffer.
         ;; If we don't do this the server's output will end up
         ;; in the *nrepl-server* buffer.
         (when (and cider-redirect-server-output-to-repl
                    (cider-nrepl-op-supported-p "out-subscribe"))
           (cider--subscribe-repl-to-server-out))

danm 2022-08-08T17:50:12.671439Z

Yessss, that's got it. Ta!

🎉 1
Ivar Refsdal 2022-08-08T18:13:05.246039Z

Hi, for cursive etc. you might want to look at this issue: https://github.com/nrepl/nrepl/issues/119 which links a gist that solves this issue.

cfleming 2022-08-09T09:36:27.439529Z

Is the cider-redirect-server-output-to-repl part in that CIDER code snippet a config flag? Is this something the user has to opt-in to or is this on by default in CIDER?

dpsutton 2022-08-09T09:56:37.196979Z

That's part of the code that runs when the repl connects. It's actually opt out. Unless they've set some preference, if the repl supports it it subscribes out

👍🏻 1
cfleming 2022-08-08T22:26:16.514919Z

Is it possible to dynamically load middleware from the client these days? Thinking about this issue: https://clojurians.slack.com/archives/C17JYSA3H/p1659976888613829, it would be nice to be able to load the middleware from the client.

cfleming 2022-08-11T04:16:04.534259Z

Thanks, very interesting! I hadn’t seen that one before.

cfleming 2022-08-09T00:26:54.300069Z

Actually, never mind me, I’ve just seen the add-middleware op.