bash-language-server icon indicating copy to clipboard operation
bash-language-server copied to clipboard

Handle zsh syntax

Open gibfahn opened this issue 5 years ago • 17 comments

I have a bunch of scripts (not least my dotfiles) where I have to deal with both bash and zsh. However whenever I add some zsh syntax, for example [[ -n "${foo[(r)b]}" ]] && echo 'b was found.' || echo 'b was not found.', the entire file becomes highlighted as an error.

I guess possible solutions are:

  1. Support zsh syntax
  2. Limit the error highlighting to just the affected line
  3. Recognise a magic comment to ignore issues for a particular line.

The first option sounds like a big rewrite, to the point where it's probably a different project (although supporting both would be really useful as scripts often mingle the two formats).

Unsure if the second and third options are feasible.

gibfahn avatar Jul 05 '20 12:07 gibfahn

+1

zfogg avatar Aug 21 '21 02:08 zfogg

Would love to see this too.

pboushy avatar Nov 19 '21 23:11 pboushy

Just wanted to point out a similar thread at koalaman/shellcheck#809. Personally these two issues are the only thing keeping me from switching to zsh (I use vim with ale and vim-lsp).

lukelbd avatar Feb 21 '22 00:02 lukelbd

Just a little update here. Unfortunately we are still blocked by having a better parser for zsh. And official shellcheck support would also be great.

But the experience for zsh files should have been improved compared to when this issue originally was created. The language server doesn’t highlight any parsing issues anymore.

skovhus avatar Mar 08 '23 19:03 skovhus

I saw https://github.com/koalaman/shellcheck/issues/809#issuecomment-1411855521 , which points to https://github.com/psprint/zsh-sweep . I haven't tried it, but if it works well for zsh files, integrating that instead of shellcheck for zsh might be the easiest path forward.

gibfahn avatar Mar 10 '23 09:03 gibfahn

We need to port ZSH parser & lexer to a new LSP server.

If anyone is interested in porting zsh parser & lexer to the new LSP please let me know. Let's unite to create it.

I would expected it to be written by using C++/Clang/Cmake/ and other building tools. Currently ZSH uses GNU Autoconfig and some other old and outdated stuff.

hinell avatar May 16 '23 04:05 hinell

After https://github.com/tree-sitter/tree-sitter-bash/pull/115/files, tree-sitter-bash start to try to support zsh. Is it helpful for bash-language-server to handle zsh syntax?

Freed-Wu avatar Aug 29 '23 17:08 Freed-Wu

@Freed-Wu This is a huge mistake. These flags shouldn't be a part of bash syntax, cause it's likely to fail in real world dev tools.

FYI @amaanq is currently busy with writing zsh parser from scratch. Get in touch with him if anyone interested.

I think the best approach would be adopting already-existing zsh parser and provide tree-sitter api instead. It would be much better.

hinell avatar Aug 29 '23 19:08 hinell