Add Shell extension
Resubmission of #1064 on a dedicated feature branch.
shell.zed
Repository: https://github.com/rburmorrison/shell.zed
Support for Bash, POSIX Shell, and ZSH.
- Tree Sitter: tree-sitter-bash
- Language Server: bash-language-server
Features
- Smart LSP Detection
- Auto-detects installed language server
- Falls back to installed language server if offline
- Syntax Highlighting
- Adapted from nvim-treesitter
- Highlights command flags
- Comprehensive Bracket Jumping
- Smart Indentation
- Linting and Formatting (when dependencies are installed)
Thanks for putting this together, @rburmorrison!
One thing to note is that Zed already has support for shell, bash, and zsh built-in using the bash grammar:
https://github.com/zed-industries/zed/blob/272be98ec854b0cd240fe392101cf02a207c29df/crates/languages/src/bash/config.toml
There's also the basher extension (https://github.com/d1y/bash.zed) which provides a Bash language server.
Does this extension add anything that isn't covered by either of those?
@maxdeviant
Hey there! Yeah, I've made several improvements that I think separate this from the base support and Basher.
For one, I work offline quite a lot, and the Basher plugin doesn't take into account if the bash-language-server is already installed or not. My plugin detects if it does and uses that without reaching out to the internet and auto-installs/updates like normal otherwise. It also falls back to a previous automatically-installed version if it detects that it can't grab the update. Basher just fails to work in those situations and always tries to connect to the internet even if I have something already present, so I can't use it at all. So that's one big improvement.
As for the grammar for Shell that's both built-into Zed and in Basher (which I believe use the same queries), I've used different base queries and enhanced it quite a bit. The syntax highlighting is more detailed and highlights several nuances that aren't covered in the existing solutions. I've adapted it from the grammar which is a bit more comprehensive with the highlighting.
Some more features that my queries have that the base one doesn't include are:
- Functions are included in the "outline" view (both POSIX-compliant and
functionkeyword-prefixed) - Indentation automatically increments and decrements with certain keywords (the base one doesn't indent at all)
- Array Contruction
- Function Bodies
- Increments after:
then,do,else, etc - Decrements after:
else,elif,fi, etc
- Comprehensive bracket jumping for more brackets for use with
%in Vim mode$(())[[]]<()- And more Bash braces (the base one accounts only for
(,[, and{)
There's more improvements such as balanced braces being generated (the base version will do [[ ] when typing in [[ rather than [[ ]], for example) as well.
I think it's awesome that Basher exists and that Zed has built-in support, but I believe this plugin significantly improves the user experience for Shell scripts in Zed from the existing solutions.
@maxdeviant
Hey again, wanted to check in on this since it's been a few weeks.
Is there anything I can clarify or do to get this merged in? It's be great to have this enhanced Shell support in Zed!
I'd also like to offer to push the queries that I've made to Zed's core to enhance the out-of-the-box shell experience as well. Let me know if that would be something that the project would like :)
@maxdeviant
Hey again, wanted to check in on this since it's been a few weeks.
Is there anything I can clarify or do to get this merged in? It's be great to have this enhanced Shell support in Zed!
I'd also like to offer to push the queries that I've made to Zed's core to enhance the out-of-the-box shell experience as well. Let me know if that would be something that the project would like :)
Right now it's not clear to me what this extension offers that is not available in the built-in shell support in Zed and the basher extension (which provides a Bash language server).
You mention some improvements that you've made both to how the bash-language-server installation works as well as to the queries, but I think these would be better off as contributions to Zed/basher rather than creating another competing extension.
@maxdeviant
Understood.
This plugin is a fundamentally different approach to what the author of Basher has taken. I'd have to completely re-write their code and queries in order to implement what I need, which is why I opted to make a new one entirely. Additionally, the author has not responded to any issues posted for months, including one which requests support for using an already-installed (d1y/bash.zed#2), so I didn't want to spend time on it if it wasn't going to get a response anyway.
With all that said, I get not wanting to have too many options in the store. I think this is significantly different, but if I have time I'll try again in the overall Zed repository since I've already done the work for it or just use it locally for myself.
If none of this changes your mind, feel free to close this issue, and I appreciate your time anyway 🙂
@rburmorrison Please don't give up. You might have something cool we just need to understand better.
I personally like it that you added more tree-sitter queries. It might be a good idea to contribute to the https://github.com/tree-sitter/tree-sitter-bash. Then not only Zed users can benefit. Personally I think it is the only sane place to add queries, unless you are building a very specialised theme that uses very specialised custom captures.
I'm going to close this for now, but I would like to see if we can get some of the improvements contributed to the existing extensions, where applicable.
I’d like to share a fresh perspective @maxdeviant
Consider allowing overhauls of existing extensions to give developers and users more freedom:
- Restricting submissions from new and talented maintainers solely because similar extension already exist risks driving the developers away due to discouragement.
- Extension repository have higher chance to thrive and flourish in popularity with fresh and active maintainers who can take ownership of the code.
- New users get poor first impression when prevalent features require third-party extensions, and also remain stale for months with alternatives being rejected.
This exact scenario is bound to happen again sooner or later :slightly_frowning_face:
Furthermore, problems with Basher
- 8 months of inactivity in Basher's codebase:
- Commonplace issues (like LSP PATH detection) haven't been acknowledged
- TODO from initial implementation never got addressed
- Maintainer's Github Profile shows little activity in recent months
- Extension is stuck on tree-sitter-bash release from March
- @rburmorrison's code is a comprehensive rewrite rather than an enhancement:
- Basher currently provides only basic bare-bones support for Bash
- This PR includes new valuable QOL features with enhanced performance
- Trivial shortcomings of Basher are perfectly summed up by the improvements described above
Given that an overwhelming majority of Linux distributions rely on Shell Scripting, it's very disheartening to see it treated as a second-class citizen
Considering there are at the time of writing four different markdown extensions, I don't see the reason why this PR was closed. I would very much love to use this extension over basher, considering that its lack of the "Auto-detects installed language server" is a total blocker on NixOS.
Please re-open this issue, basher is dead and/or ignores a very valid concern (i.e., be able to run your own bash-language-server instead of downloading).