I am a new Kakoune user starting to use the kak-lsp plugin for working with Rust. The lsp-formatting command has an indent width of 8 spaces, but I’m more used to 4 (I’m coming from emacs, where the indentation engine happens to use that many spaces).
How do I adjust the width down to 4 spaces and, out of curiosity, what is doing the actual reformatting? I thought it might be rustfmt, according to cargo, that isn’t installed. So it must be some other component in the system.
While I’m at it, is there a way to have a single key (such as Tab) do indentation. Emacs does that, but it doesn’t have to be that specific key. Maybe a best practice is to have a dedicated key combination to run the formatting (or automatically do it on save or compile).
The Rush Language Server is built from various pre-existing components. Code completions are provided by the racer project, warnings and errors are generated by the compiler itself and by clippy, and formatting comes from rustfmt. Those extra programs aren’t lying aren’t lying around to be run directly (unless you install them separately) but they’re built into the rls binary.
I think Kakoune’s indentwidth and/or tabstop options might be being passed through kak-lsp to the formatter; either way, the Right Thing is probably to make a rustfmt.toml so everyone who works on that project can have the same settings.
Automatically formatting the buffer on save is absolutely a best practice. kak-lsp provides a special lsp-formatting-sync command (synchronous to guarantee the formatting completes before the buffer is written). The kak-lsp readme describes how to set it up.
OK, great. I had indentwidth set in my kakrc already, but that did not seem to have an effect. I took your advice created a rustfmt.toml for the project and the set up Kakoune to invoke lsp-formatting-sync on save. Thanks!
I’m not sure if your code is working. You should use defer keyword for all your set-options, and config for hooks. This is because all variables are located in the module, and module gets loaded when the command itself is called. This is valid example configuration:
plug "andreyorst/smarttab.kak" defer smarttab %{
set-option global softtabstop 4
} config %{
hook global BufCreate .* expandtab
hook global WinSetOption filetype=(makefile|gas) noexpandtab
}