Subject: bug#59214: [PATCH] Alternate rust-analyzer command added

From: Pankaj Jangid <[email-masked]>
Date: Thu, 17 Nov 2022 11:27:31 +0530

João Távora <[email-masked]> writes:

> Pankaj, is it really that uncommon to have a tool installed as part of
> a Rust package be in the execution path of a shell? It's not uncommon
> in other toolchains with what I think are similar package architectures,
> such as Node JS.

Perhaps I wasn't clear enough.

The rust toolchain is similar to the tools of NodeJS world. Both try to
install packages/components in a standardised location. And users are
not required to move files and create links manually using OS level
commands like `cp', `ln' etc. `npm' and `rustup' commands do that for
users.

>From the rust users mailing, as far as I have understood, the
maintainers are seeing `rust-analyzer' as a replacement for `rls'. And
`rust-analyzer' was recently moved from `nightly' to `stable'. They have
not yet placed `rust-analyzer' executable in PATH/exec-path, possibly
because they don't want to keep two executables for the same job. Or may
be they are thinking of keeping the name `rls'. Not sure though. But
`rustup run stable rust-analyzer' will work in all cases.

So my recommendation is that we keep just the `rustup' version and `rls'
as fallback. I have attached the updated patch.

>From 727e362e142ae3d292bf7abed3b592e0dff36725 Mon Sep 17 00:00:00 2001
From: Pankaj Jangid <[email-masked]>
Date: Thu, 17 Nov 2022 11:25:16 +0530
Subject: [PATCH] Invoke rust-analyzer using rustup

* lisp/progmodes/eglot.el (eglot-server-programs): There are two
ways to run rust-analyzer. After adding the rustup component,
users can add rust-analyzer executable to PATH/exec-path using OS
level `cp' or `ln' commands and then run rust-analyzer directly or
they may run ``rustup run stable rust-analyzer'' command without
making PATH changes. 2nd command is the preferred way to invoke
the language server because it doesn't require user to manually
create link inside `~/.cargo/bin'.
---
 lisp/progmodes/eglot.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 12808e80c4..fb95313aa0 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -181,7 +181,7 @@ eglot-alternatives
                       when probe return (cons probe args)
                       finally (funcall err)))))))
 
-(defvar eglot-server-programs `((rust-mode . ,(eglot-alternatives '("rust-analyzer" "rls")))
+(defvar eglot-server-programs `((rust-mode . ,(eglot-alternatives '(("rustup" "run" "stable" "rust-analyzer") "rls")))
                                 (cmake-mode . ("cmake-language-server"))
                                 (vimrc-mode . ("vim-language-server" "--stdio"))
                                 (python-mode
-- 
2.30.2