-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto-format for bash now bash language server supports formatting #10755
base: master
Are you sure you want to change the base?
Add auto-format for bash now bash language server supports formatting #10755
Conversation
I am not certain about turning on auto-format yet due to this issue: bash-lsp/bash-language-server#1136 (comment) |
The bug in bash language server has been fixed and the new versions is published to NPM! bash-lsp/bash-language-server#1163 Please go ahead and merge this PR. |
Hmm I am not sure about this. I do have shftm installed and like to use it for my own scripts/projects but I deal with plenty of existing scripts where formatting would be disruptive. I think the bar to enable formatting by default is "is using this formatter ubiquitous in this ecosystem" and for bash the answer is probably no. |
Unlike many other languages, there is no competition, shfmt is the only formatter. Do most people format their code? I don't know, but I would hope they do as there is no reason not to with built in auto-format.
[keys.normal.space.t]
f = ":toggle auto-format" I can't really say if the majority of shell scripts are formatted or not, but I can say that if people have shfmt installed on their system then they do want at least some of them formatting, so I would guess that the majority of those users would rather them all auto formatting on save than having some formatted and some not, but I might be wrong. If shfmt is not installed then nothing happens on save. I will admit that setting the default indent level for the LSP format is not as obvious as when using Perhaps @archseer can make a decision? |
Actually @pascalkuthe brings up a good point - I agree we should only be enabling auto-format by default when auto-formatting is ubiquitous in the language. You might want to format your own shell scripts but automatically formatting all scripts is likely the wrong default. shfmt
might be the only formatter but formatting bash isn't standard practice as far as I know (in the way it is for Rust for example)
Since Bash Language Server 5.3.0 shfmt formatting is built in providing the user has the
shfmt
binary installed, so now auto-format can be enabled in line with other language servers that support formatting. I checked, and ifshfmt
is not installed then nothing happens when you save withauto-format = true
.