Subject: Re: bug#67442: [PATCH] eglot: Add ruff-lsp as an alternative python server

From: Niall Dooley <[email-masked]>
Date: Mon, 27 Nov 2023 11:22:02 +0100

On Sun, 26 Nov 2023 at 10:53, João Távora <[email-masked]> wrote:
> But just because we can doesn't mean we should. It's possible that the
  ruff server wasn't meant to be a full alternative to those other
  servers. Reading from its website hints ruff is mainly a linter, so it
  has a fraction of what other servers have

It is also a formatter but yes it does not provide all the features one
might expect from an LSP server.  Do the others?  I don't know if it
will provide other features in the future.  I presume if more features
are added to ruff then they would also be added to ruff-lsp.

> The proponents of this patch should argue in terms of ruff-only LSP
  support in python buffers. Maybe enough value that it's reasonable to
  install as-is, maybe not and we should wait for 'eglot-alongside'.

My argument for its inclusion is that it is a server adhering to the LSP
protocol and thus can be listed as an alternative.  Its inclusion offers
users the choice to use it or not.  It would mean users would not have
to write, install or configure built-in or third party packages to use
ruff to lint, format or organize imports in their python projects.  They
would simply need to open a python file and M-x eglot to have ruff
perform these functions.  I think users aware of it will be aware of its
capabilities and limitations.  Ruff is a young project but quickly
replacing the other linters/formatters in the python ecosystem within a
single tool.

Counter argument a ruff plugin exists for pylsp which is already listed
as an alternative and offers other LSP features not provided by
ruff-lsp.

> Or just wait for someone to code a flymake-ruff backend in
  python-mode.el. That seems much more promising way to get the intended
  ruff experience into Emacs.

That already exists [1] but I've been able to have ruff lint my code by
simply setting `python-flymake-command' as follows:

("ruff" "check" "--quiet" "--stdin-filename=stdin" "-")

This doesn't include a "ruff" prefix identifying the source of the
flymake report like we get when using it via eglot but I believe that is
because servers provides a :source parameter to distinguish multiple
sources.  Could such a prefix be added to flymake reports when not used
via eglot?  I think it would be an improvement even if they could only
be one source of the report.

Neither of these solutions allow the user to make use of the formatting
capabilities or other code actions of ruff-lsp.  Another package would
have to be used to make use of these capabilities.

> There is also the common misconception (not sure if the case here)
  that if a server isn't mentioned in 'eglot-server-programs' directly
  then Eglot doesn't support it. And this is far from the truth: if
  'ruff' is installed in a user's machine M-x eglot can easily be made
  to prompt for it. I've tried dozens of servers like that.

Not here but I can see why that might be the case - users may assume
those listed in Eglot's README are only those that are supported.  Small
correction it is 'ruff-lsp' that would need to be installed which
naturally includes 'ruff' as a dependency.

[1] https://github.com/erickgnavar/flymake-ruff