tpope / vim-fireplace

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

Allow connection to AF_UNIX socket nREPL servers #417

Open chancerussell opened 7 months ago

chancerussell commented 7 months ago

nREPL has had support for running servers through AF_UNIX-style domain sockets for a while: https://github.com/nrepl/nrepl/pull/270 . It'd be nice if we could connect to those servers with vim-fireplace.

I've messed around and have confirmed that vim-fireplace can talk to nREPL over a domain socket with minimal changes to the Connection class's socket method in pythonx/fireplace.py to instantiate the correct type of socket as appropriate. I’m less sure of how starting such a connection should work.

The main question I have is: how should the user indicate that they wish to connect to a domain socket server?

Options I can think of:

I’ve opened #416 as a draft proof of concept. It works, but it isn’t pretty.

Thanks for all your work on vim-fireplace!

tpope commented 7 months ago

Smarten up FireplaceConnect to recognize connection strings that represent filesystem locations.

We already support literal filesystem locations. But they're used to specify the path to a directory that contains .nrepl-port:

https://github.com/tpope/vim-fireplace/blob/f2be859ea48a761fd25a07efa037514f84abdf30/autoload/fireplace.vim#L644-L646

So all you need to do is disambiguate with a getftype() check and you're golden.

This might be problematic because of ambiguous cases where a given string could represent either a hostname or a filesystem location.

The circumstances where this could happen are extremely narrow: <port>, <host>:<port>, and URLs. And if you do hit one of those, you can use ./ to force a file path.

chancerussell commented 7 months ago

So all you need to do is disambiguate with a getftype() check and you're golden.

Very cool, I can handle that!

When we hit the "str is pointing to a socket file" case, do you think we should just pass the value as the host arg to the python script, or should we have an explicit (new) arg for socket paths?

tpope commented 7 months ago

When we hit the "str is pointing to a socket file" case, do you think we should just pass the value as the host arg to the python script, or should we have an explicit (new) arg for socket paths?

I would change the host arg to dest and drop the port arg. Those parameters are legacy: In fireplace#transport#connect() we always coerce it to a URL. (You might want to move this coercion to fireplace#ConnectCommand().)

Then you can pass the socket path through directly, and main() can look at dest and decide if it looks like a URL or a file path. This is unambiguous.