lassik/emacs-format-all-the-code

Minimal LSP support

rassie opened this issue · 4 comments

It seems that unification efforts (e.g. #4) stalled a bit. I'd like to propose (and kindly ask to be implemented, since my elisp is basically non-existent) a minimal solution for LSP integration inside format-all-the-code which would make my developer life a bit more consistent.

I'd imagine it'd work this way:

  1. If lsp-mode is not enabled for the current buffer, fallback to the current behaviour.
  2. Otherwise, check for textDocument/formatting capability of the current language server (or maybe servers, since that's apparently a supported workflow). If it's not available, fallback to current behaviour.
  3. Otherwise, use textDocument/formatting (probably via lsp-format-buffer) instead of the predefined tool.

Does this sound sensible and would you consider this for format-all-the-code?

Thanks for bringing LSP to our attention. Sounds sensible to support it in format-all, but I know almost nothing about it so I don't know what the best approach is. lsp-format-buffer could be the right thing. I'm a bit swamped with other projects right now...

That's only fair, more reason for me to dive into elisp :)

However, I've looked into code and noticed that doom-emacs, which I'm a user of, does quite a bit of wrapping around format-all. Might be a better idea to check for LSP in the doom-emacs auto-formatter and leave format-all as it is.

@hlissner: what do you think?

Either approach is fine with me. However, format-all is designed to work with bare Emacs for all users.

How does LSP work from a user's standpoint? Is there a separate server (command line program) for each language (or group of languages), and Emacs commands to start them in the background and connect them to Emacs?

Yes, exactly, there is protocol (https://microsoft.github.io/language-server-protocol/), so that a single editing mode can communicate with a range of so-called "language servers". One of the commands is textDocument/formatting which asks the language server to format code (whole buffer, snippet, etc., depending on language server's capabilities).