bash-language-server
bash-language-server copied to clipboard
falsely reported syntax error for negated conditional assignment statements
I'm getting the message Syntax error: expected "word" somewhere in the file when I have statements like if ! myvar="$( some_func )"; then
A minimal, complete example:
#! /usr/bin/env bash
bar() {
echo "bar"
return 1
}
foo=''
if ! foo="$(bar)"; then # <-- Syntax error: expected "word" somewhere in the file
echo "ok."
fi
If I change it to just
if foo="$( bar )"; then, then it doesn't bark. It's the!that makes it angry.
this is valid bash and executes without issue. This also didn't happen in an older version of bash-language-server. I upgraded the other day, but I'm not sure what the old version I had running was. I use this structure in my code all the time so it's kinda annoying to constantly see this syntax error.
Sorry to hear. The grammar we are using were recently upgraded, so I'm pretty sure this is an issue with https://github.com/tree-sitter/tree-sitter-bash
Can you create an issue over there?
Will do! I’ll try to relay the info as best I can since the error message comes from you so it may be hard to properly describe the issue. But I’ll do my best. Thanks!
This seems to still be an issue. Is there a workaround?
This is still a problem:
#!/usr/bin/env bash
# Problem message on next line: Syntax error: expected "word" somewhere in the file"
if ! current_directory=$(pwd); then
printf "FAILLD with code %s: message is %s\n" "$?" "${current_directory}"
else
printf "Directory is %s\n" "${current_directory}"
fi
# no messages
if current_directory=$(pwd); then
printf "Directory is %s\n" "${current_directory}"
else
printf "FAILLD with code %s: message is %s\n" "$?" "${current_directory}"
fi
This is with the Bash IDE Visual Studio Code Plugin v1.14.0 - I've got no idea how that corresponds to the tree-sitter-bash version so I don't know if the problem is still open with them under #51 or if the fix just hasn't been pulled across yet.
This seems to have been fixed in the newer version of the grammar