helix icon indicating copy to clipboard operation
helix copied to clipboard

Remote code editing via `distant`

Open chipsenkbeil opened this issue 1 year ago • 25 comments

Curious if there's been any thought to offering remote code editing support similar to https://code.visualstudio.com/docs/remote/remote-overview.

I've been working on a project for a couple of years called distant with a plugin (distant.nvim) geared to leverage it to introduce remote coding editing support to neovim.

Since helix is written in Rust, it could leverage directly the libraries that distant offers to enable remote editing - including remote LSPs and shells - through both ssh and the distant protocol.

chipsenkbeil avatar Sep 06 '22 01:09 chipsenkbeil

Wouldn't using something like sshfs to mount the remote fs be sufficient?

archseer avatar Sep 06 '22 03:09 archseer

@archseer, here's some of the primary differences that come to mind at the moment:

  1. Filesystem: sshfs is built using FUSE, meaning that you need support for it as a userland filesystem. Having a native integration (i.e. like distant.nvim for neovim) requires no special filesystem as the file contents are only reflected in buffers. Anything you read goes into a buffer and anything you write gets transmitted across the network to the remote file.
  2. Program locations: having a direct integration supports running programs on the remote machine, colocated with your files. Language servers would run on the remote machine, for instance. When using sshfs to mount the remote file system on your local machine, you would then run programs locally and point them to the mounted files.
    • i.e. with distant.nvim, you are leveraging the resources of a remote machine. This can be advantageous if you want to perform CPU or GPU intensive operations without heavily impacting your local machine.
    • With sshfs, you are leveraging the resources of a local machine for programs that you run. Depending on what you're doing, this can be much more expensive. If a program needs to access the filesystem frequently, this would transmit a lot of requests over the network, especially if working over a large set of files. With distant.nvim, all of the filesystem operations would happen directly on the remote machine and only the program's output would be transmitted over the network.
  3. Singular connection: instead of needing to maintain a separate connection for a shell using ssh alongside your filesystem being mounted via sshfs, having an integration like distant lets both being transmitted over the same network connection. This can be handy when you need to perform extensive authentication prior to connecting and want to avoid managing multiple connections.

There are other technical differences, but the distinctions above are - at the moment - the differences that stand out. In some cases, using sshfs might be preferred, but for my use personally and at work this is the preferred method as language servers and other utilities cannot be run locally. :)

If you want to think of what this more closely relates to, then take a look at VS Code Remote Development or the formerly-active Nuclide.

chipsenkbeil avatar Sep 06 '22 03:09 chipsenkbeil

I don't know anything about distant. But I regularly use vscode remote. As helix is more of a tui text editor wouldn't it make more sense to install it on your dev server and ssh into it? I know sshfs was mentioned but why not just plain old ssh? For reference the vscode-remote server is already bigger than the helix editor. I'm curious as to what use case you couldn't meet by doing this.

I think the case for vscode-remote is a little different as it is a web-based GUI rather than a TUI. It might be worth considering in more detail when/if helix gets a GUI?

EDIT: I'm not a dev here, just a curios user.

silvergasp avatar Sep 07 '22 21:09 silvergasp

@silvergasp good questions! The remote code functionality is agnostic to whether you use it with a terminal editor or a graphical editor.

Now, you bring up a good point about an advantage of terminal editors is that you can install and run them on remote machines more easily than a graphical editor.

The reasons that I've found a solution like this preferred - and many of my coworkers as well - are that the latency of your network doesn't affect your typing experience and similarly disruptions of your network don't fully block you from editing.

I worked on a bus to and from work for many years before 2020 and the network reliability was poor, causing tools like ssh to yield a broken pipe and mosh to freeze frequently waiting for the connection to re-establish. In contrast, VS Code's remote development feature let me continue working on a file without having my cursor and text freeze as I went in-and-out of networks.

For some of my colleagues, they live and work in locations where networks are poor, meaning that they cannot maintain a reliable ssh connection and mosh causes their editing experience to be nearly unusable as it frequently would cut out for ~10-15 seconds.

chipsenkbeil avatar Sep 08 '22 00:09 chipsenkbeil

Oh, and while this may not be as relevant to Helix, another reason is to avoid needing to copy your configuration files over to another machine. With ssh, to get the same experience with your editor, you have to copy your configuration files and plugins over to the other machine. In contrast, VS Code's remote editor and other offerings like distant let you avoid that and maintain your configurations on your local machine, only outsourcing programs and source code to the remote machine.

chipsenkbeil avatar Sep 08 '22 01:09 chipsenkbeil

Oh yeah, that seems reasonable. I'd definitely be keen on an improvement in latency/consistency!

silvergasp avatar Sep 08 '22 17:09 silvergasp

Tentatively marking as a plugin unless otherwise changed.

kirawi avatar Sep 10 '22 15:09 kirawi

Wouldn't using something like sshfs to mount the remote fs be sufficient?

I use SSHFS at work with Helix and it's almost enough to make me contemplate going back to VS Code (for work) 😆

The connection is stable, the main issue is I can't use the file picker or global search because there are so many files on the remote server it hangs Helix for minutes at a time, sometimes even crashing it. Even just typing :o <space> out of muscle memory makes me need to restart the editor. It's a big repo (not as big as you'd think) but even small ones are plagued by this problem. I'd definitely appreciate a solution for this!

jfaz1 avatar Sep 20 '22 22:09 jfaz1

Even just typing :o out of muscle memory makes me need to restart the editor. It's a big repo (not as big as you'd think) but even small ones are plagued by this problem.

Not to hand wave the issue, because there is room for improvement there, but this sounds unusual. Are you sure there isn't a problem with IO on your server?

dead10ck avatar Sep 20 '22 22:09 dead10ck

Not to hand wave the issue, because there is room for improvement there, but this sounds unusual. Are you sure there isn't a problem with IO on your server?

Yeah, we route our network through a VPN which isn't the fastest, which will definitely slow things down. But even then I added an exception out of curiosity and while it was noticeably faster, was still unusable in the grand scheme of things. For context, opening the file picker in the fully cloned local repository takes around a second. So it's definitely a large repo. But I tried some more manageably-sized repos and it was still pretty sluggish.

jfaz1 avatar Sep 21 '22 02:09 jfaz1

Hi all, just curious if there have been any updates on this issue. I love Helix and am very interested in using this feature.

taylorpool avatar Jan 12 '23 20:01 taylorpool

Hi all, just curious if there have been any updates on this issue. I love Helix and am very interested in using this feature.

I haven't revisited yet. Distant is maturing more and more over time. One of the last major features was persistent connections, meaning that if you lose your connection with the remote machine, it will be able to reconnect later without any extra work or reauthentication from the user's side.

I'd be happy to work with someone on the helix side to integrate this. Either by just supporting the client-component of the library, or even making it where having helix on both machines would let you set up helix as a server for other helix instances to connect to.

Either way, going to let the folks from the helix side reach out if there's interest and availability. :)

chipsenkbeil avatar Jan 13 '23 17:01 chipsenkbeil

I have another use case for this. I have to access servers that are on the other side of the planet. The latency between my machine and the server is often higher than 300 ms. This can be very annoying while trying to type on a terminal-based IDE, like Helix. The remote feature proposed by this issue has the potential to ameliorate these latency issues.

luigifcruz avatar Mar 22 '23 07:03 luigifcruz

I also see a benefit to this. I have a remote environment running on Amazon Linux 2 that comes packaged with glibc 2.26

As a result, helix can't be run natively there so support for running it remotely from my actual device would be a super handy workaround.

beegan avatar May 23 '23 16:05 beegan

Another benefit would be for development on older systems that cannot support helix. I am using debian 9 (I know, don't tell me it sucks), and literally cannot install it. Would be nice if I could ssh into the system with helix.

shane-tran-whitmire avatar Jun 29 '23 16:06 shane-tran-whitmire

helix runs just fine on older systems you just have to compile it yourself.

pascalkuthe avatar Jun 30 '23 00:06 pascalkuthe

helix runs just fine on older systems you just have to compile it yourself.

I might be a bit of an idiot, but I blew up (boot loader went bye bye) a system trying to get a new enough version of c++ to compile helix onto that system. My resolution was just to give up trying to get helix to run on debian 9.

shane-tran-whitmire avatar Jun 30 '23 16:06 shane-tran-whitmire

That shuldn't happen. iiirc all C++ compilers released since 2015 rhold support everything we need so I am surprised it doesn't work out to the box. It can be a bit of a pain to get newer compiler sunning but I bootstrapped clang-15 on centos 7 so it's definitely possible. There are probably existing docker images for this. I would not recommend messing with a live system.

I use this docker image to build my other rust projects for ancient glibc versions. I am not sure if it has everything helix has but you could try that if you don't find anything else

pascalkuthe avatar Jun 30 '23 22:06 pascalkuthe

Since potentially many of us are subscribed to the issue to see updates on the remote functionality, I kindly ask you to move unrelated discussions somewhere else to avoid unnecessary notifications for everybody.

gyzerok avatar Jul 01 '23 06:07 gyzerok

Zed is now open source. Maybe we can look and see what Zed did?

nyabinary avatar Jan 25 '24 12:01 nyabinary

Zed doesn't have remote code editing either: https://github.com/zed-industries/zed/issues/5347

TJTorola avatar Jan 25 '24 18:01 TJTorola

Zed doesn't have remote code editing either: zed-industries/zed#5347

Zed does have good collab editing, tho.

nyabinary avatar Jan 25 '24 18:01 nyabinary

Zed is GPL and based on the Matrix conversation we can't reference it at all without polluting Helix's licensing.

kirawi avatar Jan 25 '24 19:01 kirawi

Lapce has a remote code editing support although Lapce itself is not stable yet.

lianghu avatar Mar 28 '24 05:03 lianghu

If you guys want an alternative to sshfs that doesnt freeze up whenever you use the file picker, check this out, seems particularly good for this case! It is just a workaround for now, but still might help out https://github.com/kahing/catfs/

tulilirockz avatar Mar 29 '24 17:03 tulilirockz