bash-lsp / bash-language-server

A language server for Bash
MIT License
2.12k stars 121 forks source link

"Go to Definition" rarely works, Bash IDE output is full of "WARNING ⛔️ Error while parsing file" #859

Open lkrms opened 1 year ago

lkrms commented 1 year ago

Code editor

Visual Studio Code

Platform

Linux and macOS

Version

v1.37.0 (last working version was Bash IDE v1.28.0)

What steps will reproduce the bug?

It's triggered by so many scripts in one of my projects, I can't be sure there aren't other causes, but here's a trivial snippet that triggers the parsing error:

! VAR=

A less trivial example that's closer to how one might actually use a negated exit status:

! VAR=$(some-command | grep .) || printf '%s\n' "$VAR"

Interestingly, statements like ! ((VAR)) are parsed without issue.

How often does it reproduce? Is there a required condition?

This issue is reproducible 100% of the time.

What is the expected behavior?

Obviously the code should parse without triggering a syntax error, but in the event that it doesn't, output more specific than "[Warn - 20:12:15] 10:12:15.379 WARNING ⛔️ Error while parsing file:///path/to/file.sh: syntax error" -- even with the BASH_IDE_LOG_LEVEL environment variable set to debug, and the VS Code settings below -- would have saved a bunch of time using bisection to identify the problematic syntax 😬

{
  "bashIde.logLevel": "debug",
  "bashIde.enableSourceErrorDiagnostics": true
}

What do you see instead?

Additional information

No response

skovhus commented 1 year ago

The parser used (tree-sitter) is by no means perfect. It keeps improving. But we specifically do no show parsing errors in the UI (as diagnostics) as there are too many false positives.

For most users the LSP works well for most script, but you might be using some bash constructs that are not supported yet in trees-sitter.

skovhus commented 1 year ago

I’m unsure how we can provide a better error here. Any suggestions are more than welcome.

LeonardoMor commented 10 months ago

Same in NeoVim. I have a main function on a script that calls other functions. Some are in a file that I am sourcing. Jump to definition works on all the functions located in the external file and only works on the main function itself in the local file. It's very strange.

LeonardoMor commented 10 months ago

Same in NeoVim. I have a main function on a script that calls other functions. Some are in a file that I am sourcing. Jump to definition works on all the functions located in the external file and only works on the main function itself in the local file. It's very strange.

I've found that if the function is called in the same file before it is defined, then jump to definition will not work.