reddit / emacs

help with lsp + tramp + python virtual environments

azfrak · 2022-04-18 10:45
Hi all have been having trouble getting lsp-mode/eglot to work with tramp and python virtual environments. I can get lsp mode to work with tramp, but not respect python virtual environments. I have had a play around with pyvenv, but had no luck. My current solution is to open a separate terminal, activate virtual environment and start pylsp from there over tcp, and then connect to it with port forwarding to allow eglot to connect to it. Wondering if anyone has any suggestions or configuration examples on how they work with something like this. Doesn't have to be eglot either, just using it now as is easy to connect to existing lsp server with tcp. Cheers :)
DefiantAverage1 · 2022-04-18 15:34
Curious to know how you were able to make lsp-mode work with tramp. Mind posting your config?
rufusthedogwoof · 2022-04-18 19:02
It doesn’t solve your problem but another option is running eMacs on the remote via x11 forwarding and/or x2go. I opted for this as tramp is a nightmare on windows.
azfrak · 2022-04-18 21:39
I am using doom - so just enabled eglot there. There isn't much config info going on there, but what I did to get it to work is something like this. 1. ssh into server with port forwarding activated \``ssh -L XXXX:localhost:XXXX <user>@<ip>` where you pick the port number of your choice for `XXXX` 2. activate virtual environment on server 3. starter pylsp from there over tcp `pylsp --tcp --host localhost --port XXXX` 4. start eglot on local emacs, and will ask for host and port number, then just input `localhost:XXXX`
ndpian · 2022-04-18 22:51
very interesting! at least you have a working config - here I'm bashing my head against the wall to make LSP mode work over tramp.
DefiantAverage1 · 2022-04-18 23:23
Right. Any luck with using tramp + lsp-mode (as opposed to eglot)? I also use doom too and have followed the Tramp setup docs but it seems like lsp-mode (not eglot) gets confused where to look for the lsp binary (for a particular lang) at different steps of connection
azfrak · 2022-04-19 01:23
No luck with lsp unfortunately. I initially tried lsp mode, but couldnt get it to work. Really only using eglot as it allows me to connect to language server via tcp easily, which can probably do with lsp mode as well I just don't know how.
DefiantAverage1 · 2022-04-19 01:49
Oh ok I see. I might try out eglot
astoff1 · 2022-04-19 07:08
~~Two~~ Three suggestions (which I haven't tried): 1. Use an absolute file Tramp file name for the server executable, that is, something like `ssh:machine:/path/to/venv/bin/pylsp`. This can be done by setting `eglot-server-programs` (you probably want to do this dir-locally). 2. In the remote machine, activate the venv in `.profile` (not `.bashrc`!). If typing `M-! which pylsp RET` prints the right thing, then Eglot should find your language server too. 3. Customize `tramp-remote-path` to include the `bin` directory of your venv (you probably want to use connection-local variables for this).
azfrak · 2022-04-19 10:37
thanks for this, might try these out and report back :)
whompyjaw · 2022-12-06 18:27
Do you have to do this every time you want to use emacs over ssh? This seems way to tedious to be useful.
whompyjaw · 2022-12-06 18:27
Did you figure out a way to get this to work?
whompyjaw · 2022-12-06 18:28
Did any of these work?
azfrak · 2022-12-07 02:01
my end solution was to install my emacs config and lsp server on the client machine, and then just ssh into it. I tried getting lsp mode to work, to no avail. Also tried eglot and it was not as straightforward as I would of liked unfortunately.
whompyjaw · 2022-12-07 05:07
Do you mean the "remote" machine? The client would be your system. If so, you're just using the terminal GUI of Emacs then? &#x200B; Ya I have no idea why there aren't more tutorials on this. I would think this is something people would want. My work has remote servers that I work on, and I would imagine many other people have that too... I don't know.
azfrak · 2022-12-07 05:59
yeah just on my remote machines and then using terminal emacs. &#x200B; Agree that some more tutorials to address this would be fantastic.
whompyjaw · 2022-12-07 15:25
Ya… I’d prefer not to use Terminal. I asked on the doom emacs discourse so I hope I can get something figured out.
azfrak · 2022-12-08 00:06
if you find anything out, let me know as I would definitely be interested. There is still some cases where it isnt feasible for me to install emacs and the lsp servers on the remote machines.
whompyjaw · 2022-12-08 04:34
Ya, by the simple fact that there is lag, usually. At least with work connection and using VPN. But I will let you know what I find out! I commented on the lsp-mode GitHub about the terrible documentation for TRAMP and the creator said he’s working on a new addition to make it “just work” with the merging of eglot into emacs. Not sure when it will be tho.