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

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

Open lkrms opened this issue 1 year ago • 4 comments

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?

  • "Go to Definition" and other LSP-serviced features fail for symbols in files that can't be parsed.
  • No indication is given that anything is wrong. Problematic files appear to be problem-free in VS Code.
  • In VS Code's output panel, "Bash IDE" reports "WARNING ⛔️ Error while parsing file:///path/to/file: syntax error" for many files during background scanning, and they continue whenever I'm editing a problematic file.

Additional information

No response

lkrms avatar May 29 '23 10:05 lkrms

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 avatar Jun 24 '23 04:06 skovhus

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

skovhus avatar Jun 24 '23 04:06 skovhus

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 avatar Dec 12 '23 15:12 LeonardoMor

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.

LeonardoMor avatar Dec 17 '23 17:12 LeonardoMor