Subject: Re: bug#61748: 27.2; Eglot should use shell-file-name when launching the language server for a remote file

From: [email-masked]
Date: Tue, 28 Feb 2023 15:49:18 +0100 (CET)

João Távora <joaotavora <at> gmail.com> writes:
> On Tue, Feb 28, 2023 at 1:59 PM <[email-masked]> wrote:
> 
> > > This works, and this would explain the instability I saw earlier.
> > > Thanks.  I wonder if it fixes Jerôme's problem, too.
> > No I've already got it setup as part of my config before I ever
> > access
> > Tramp, which seems only logical: first configure the environment,
> > then
> > try to use it.
> 
> It may seem logical to you but since you didn't state this in your
> original recipe, it's only logical that I wondered.
> 
> For me, a change to a variable should take effect immediately,
> no reboots or restarts.  If you're satisfied with less, suit yourself
> (maybe you're on M$ windows?).
> 
My main platform is Linux, I only use W$ at work because I have to. But
on either platform, I don't expect changes to the environment to be 
picked by child processes or connections that were started before the
change.

> > 1. When told that the language server is `rust-analyzer`, Eglot
> > fails
> Patches welcome.  Patches that remove code and don't break anything
> even more welcome.  The patch you sent is insufficient, by your own
> admission.  And Eli didn't like it either.
> 
Here you go:

==============================8<------------------------------
--- a/eglot.el  2023-02-28 15:38:01.161316788 +0100
+++ b/eglot.el  2023-02-28 15:38:57.445653435 +0100
@@ -1156,10 +1156,11 @@
       ;;
       ;; Not only does this seem like there should be a better way,
       ;; but it almost certainly doesn’t work on non-unix systems.
-      (list "sh" "-c"
-            (string-join (cons "stty raw > /dev/null;"
-                               (mapcar #'shell-quote-argument contact))
-             " "))
+      (with-connection-local-variables
+       (list shell-file-name shell-command-switch
+             (string-join (cons "stty raw > /dev/null;"
+                                (mapcar #'shell-quote-argument contact))
+                          " ")))
     contact))

 (defvar-local eglot--cached-server nil
------------------------------>8==============================

Note that:
- I said it was insufficient because it only fixed point 1 not point 2,
  but that doesn't mean it's not worthwhile (see below for point 2).
- Eli didn't like it due to a doubt about the behaviour of
  `shell-file-name` for remote connections, but Michael has confirmed
  that this use is correct.

> > 2. Eglot doesn't detect `rust-analyzer` automatically. 
> 
> Eglot uses (executable-find "rust-analyzer" t).  The second argument
> asks to consider the remote path, but sometimes that path, which is
> configured by tramp-remote-path isn't considered immediately. Michael
> clarified this and I expressed the opinion that it is shortcoming
> of Tramp.
> 
Effectively, `(executable-find "rust-analyzer" t)` doesn't find it. I'll
try to find out why, but this point should indeed be fixed in
`executable-find` rather than Eglot.

Jérôme