tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.74k stars 139 forks source link

Connecting to embedded nrepl running in docker #387

Closed metasoarous closed 3 years ago

metasoarous commented 3 years ago

I seem to be unable to connect to an embedded repl using vim-fireplace when the embedded repl is running from within docker.

I've got an alias set up so that I can run clojure -X:the-alias, which calls out to a function which (does some stuff) and in turn calls (nrepl-server/start-server :port 8889 :hander cider.nrepl/cider-nrepl-handler), as per guidance on the cider/nrepl docs.

When I simply run clojure -X:the-alias directly from my machine, I'm able to :Connect 8889 from vim without issue. However, I'd like to set this command up to automatically run from docker/docker-compose (we've got a system with several components, and as a dev convenience, I'd like to be able to have folks run the entire system with docker-compose up for smooth dev onboarding without having to set up an entire development environment on their local machine). However, when I try to connect to the same process running from docker/docker-compose, I get the following error:

Vim(call):E630: ch_sendexpr(): write while not connected

Interestingly, if I try to connect again, even after shutting down the docker container and running from outside docker, I then get:

Error detected while processing function fireplace#ConnectCommand[29]..<SNR>122_transport_clone[1]..fireplace#se
ssion#for[7]..<SNR>122_transport_message[36]..<SNR>122_json_send:
line    4:
E906: not an open channel
Error detected while processing function fireplace#ConnectCommand[29]..<SNR>103_register:
line    1:
E121: Undefined variable: transport
E116: Invalid arguments for function extend({'session': a:session, 'transport': a:session.transport, 'cljs_sessi
ons': []}, deepcopy(s:repl)))
E116: Invalid arguments for function insert

What's weird is that I've successfully connected to an nREPL process running from within docker before, but in this case, it wasn't an embedded call; It was calling clojure -R:nREPL -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]" --port 3850 from within a run script called by the Dockerfile. (You can see this setup here: https://github.com/compdemocracy/analysis).

Any idea what might be going on here, or how I can get around this issue? Please let me know if there's any additional information which would be helpful.

Thanks so much.

metasoarous commented 3 years ago

Looks like I sorted this out. The problem was that I needed to set :bind "0.0.0.0" in the call to (nrepl-server/start-server ...). I eventually realized that in the project where I had this working, this was set in the .nrepl.edn file, which the -m nrepl.cmdline invocation was picking up. Not sure why this is specifically necessary in this case, or how I figured out how to set this previously, but in any case I'm past the hurdle.

Thanks