Configuring `shfmt`
Closed this issue · 4 comments
Code editor
NeoVim
Platform
Linux (NixOS)
Version
5.4.0
What steps will reproduce the bug?
There's no "Discussion" template, this isn't really a bug, just a question.
The documentation states:
The indentation used by shfmt is whatever has been configured for the current editor session, so there is no shfmt-specific configuration variable for this. If your editor is configured for two-space indents then that's what it will use. If you're using tabs for indentation then shfmt will use that.
I'm not sure I understand how I can configure shfmt the way I used to when I ran it standalone in my editor (-i 4 -s -ci). The README mentions EditorConfig, but that doesn't give me a global configuration, and is less convenient than relying on my default configuration for random files.
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
N/A
Additional information
No response
I found out I could use settings when configuring the LSP server to set various options for shfmt:
settings = {
bashIde = {
shfmt = {
languageDialect = "auto",
simplifyCode = true,
caseIndent = true,
},
},
},But indentation is not set correctly: I have my editor set to use 4 spaces for indentation, and my scripts get reformatted to use 8 spaces instead...
Yes, setting options via LSP server config options would be my recommendation as it is the most configurable. .editorconfig is also supported, however some options are not configurable (only simplify, IIRC). If any shfmt-specific options are set in .editorconfig then LSP config will be ignored.
The exception is indentation. Indentation always comes from the client via the language server. If you're seeing 8-space indents, then that is what the client is sending through when requesting document formatting (the default is to use tabs, so the client must have explicitly requested 8-space indents).
Perhaps some experimentation to understand behaviour might be a good place to start? For example, what if you set your editor to 3-space indents - does that result in 6-space indents, or do you get 8-space regardless? I think I'd need to see a capture of the messages between your client and the server in order to see where the problem lies, and I'm not sure I can help you with how to do that for your particular client.
It looks like the server must be sending tabs, and my editor is expending them to spaces:
- By default,
tabstop(the width of a tab) is set to 8. - Changing it to 4 or 12 changes the width used in formatting through LSP.
I think it might actually be an issue with the format-on-save plug-in that I've been using, see lukas-reineke/lsp-format.nvim/issues/94.