Olical / conjure

Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile, Python and more!)
https://conjure.oli.me.uk
The Unlicense
1.73k stars 109 forks source link

Support for nrepl drawbridge #285

Open jeaye opened 2 years ago

jeaye commented 2 years ago

Heya, Olical. Happy holidays.

I'm just setting up a Heroku app and I was following a guide to configure drawbridge so I can REPL into the staging servers. The way this works with leiningen is like so:

$ lein-2.9.3 repl :connect https://my-app.herokuapp.com/repl
Connecting to nREPL at https://my-app.herokuapp.com/repl
REPL-y 0.4.4, nREPL 0.6.0
Clojure 1.10.3
OpenJDK 64-Bit Server VM 1.8.0_312-heroku-b05
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=>

However, I can't then connect Conjure to that repl connection, since lein doesn't expose it to a local port. I see that Conjure has support for host + port with :ConjureConnect, but I need to specify an actual path, since drawbridge handles the repl communications over HTTP.

It'd be great to have support for something like :ConjureConnect https://my-app.herokuapp.com/repl so this repl dream can come true. I don't know very much about what's needed to get Conjure to do the same as that leiningen command, though. What are your thoughts?

jeaye commented 2 years ago

Small note here. I changed the server to just handle drawbridge (running another jetty instance) on another port, rather than at a specific route. That way just the host + port combo would work. The only thing missing there is that Conjure would actually need to use the drawbridge client: https://github.com/nrepl/drawbridge#in-clojure-tooling

Naturally, trying to connect Conjure to the drawbridge HTTP port currently results in an immediate disconnect, due to the mismatched protocols.

Olical commented 2 years ago

Hey! It's a neat idea and I'll need to look into what it'll take to support the transport, I think I currently assume nREPL is bencode over a socket but I can probably refactor that to make it pluggable. I can't promise quick turnaround on that though, it's something I've never used before so it's going to involve a little bit of research from my end.

Keeping an open mind and will do some reading though.

jeaye commented 2 years ago

Thanks for the follow up, man. Since I wanted to get something working, I ended up dropping drawbridge for this project, since heroku has the ability to bind ports between my local machine and a remote server. So I just run an nrepl server from Clojure and then use the heroku cli tool to bind that port to localhost and create an .nrepl-port file for Conjure. Everything else just works. Here's the ./bin/heroku-repl script (it blocks on the port forward, so just Ctrl-C when you're done):

#!/usr/bin/env bash

set -euo pipefail

function cleanup
{
  rm -f .nrepl-port
}
trap cleanup EXIT

port=8123
echo "$port" > .nrepl-port
heroku ps:forward "$port"

However, if this project were using anything else for infra (AWS, Azure, GCP, etc), drawbridge would become necessary again, so I do think it'd be a really useful feature to have. Whether or not it makes sense in Conjure is up to you, good sir.