Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

David-Else
Copy link
Contributor

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 if shfmt is not installed then nothing happens when you save with auto-format = true.

@David-Else David-Else marked this pull request as draft May 14, 2024 10:33
@David-Else
Copy link
Contributor Author

I am not certain about turning on auto-format yet due to this issue: bash-lsp/bash-language-server#1136 (comment)

@David-Else David-Else marked this pull request as ready for review May 15, 2024 10:55
@David-Else
Copy link
Contributor Author

David-Else commented May 15, 2024

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.

the-mikedavis
the-mikedavis previously approved these changes May 15, 2024
@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. A-language-support Area: Support for programming/text languages labels May 15, 2024
@pascalkuthe
Copy link
Member

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.

@David-Else
Copy link
Contributor Author

"is using this formatter ubiquitous in this ecosystem"

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.

but I deal with plenty of existing scripts where formatting would be disruptive

[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 formatter = { command = 'shfmt', args = ["-i", "4"] }, but that is being discussed and you can use .editorconfig right now.

Perhaps @archseer can make a decision?

@the-mikedavis the-mikedavis dismissed their stale review May 16, 2024 13:12

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants