Fork me on GitHub
#nrepl
<
2022-08-08
>
danm16:08:28

👋:skin-tone-2: 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?

dpsutton16:08:56

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))

danm17:08:12

Yessss, that's got it. Ta!

🎉 1
Ivar Refsdal18:08:05

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.

cfleming09:08:27

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?

dpsutton09:08:37

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
cfleming22:08:16

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.

cfleming00:08:54

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

cfleming04:08:04

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