nrepl / piggieback

nREPL support for ClojureScript REPLs
480 stars 48 forks source link

out and err have the wrong message ID, vanish entirely on reconnection #111

Open Olical opened 4 years ago

Olical commented 4 years ago

I've been doing a little digging into a simple piggieback nREPL server. I've found that messages to out and err have the message ID of the call that started piggieback in the first place, not the message that triggered the output. For example.

I had a dig into the source trying to fix it myself and realised output-bindings doesn't seem to do anything.

https://github.com/nrepl/piggieback/blob/417efae16ebb515c02ca8f3941bf8e30fd8f30a6/src/cider/piggieback_impl.clj#L214-L235

You can take it out completely and get the exact same result, so I think these bindings aren't being used and they're falling through to the outer environment which still has the original message ID from when piggieback started.

I also discovered that if I reconnect to the nREPL server and assume the same session I won't see any out or err whatsoever. I think this is to do with the same issue, I'm pretty sure they'd both be fixed by the same change.

My theory is the bindings just need to go elsewhere, where CLJS can hook into the pre-defined out and err handlers, I just can't work out where. If anyone knows where those bindings should be (or what their vars should be called?) I'll happily make the change.