jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
50 stars 4 forks source link

IF statement with basic math operations breaks syntax highlighting. #82

Closed prplwtf closed 3 months ago

prplwtf commented 3 months ago

The code with a problem is:

if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="y"
  if [[ $(( $# - 2 )) != 1 ]]; then PRINT FATAL "Expected 1 argument but got $(( $# - 2 )).";exit 2;fi
  # [..]
fi

https://github.com/BlueprintFramework/main/blob/da8b8001c4414c56fca9fcee46cb78dd2c36b41f/blueprint.sh#L323

It looks like:

image All commands below this IF statement have incorrect syntax highlighting.

It should look like:

image Screenshot without the "Better Shell Syntax" VSCode extension enabled.

jeff-hykin commented 3 months ago

Alright should be sorta fixed now. Some of the math operators won't be highlighted, but I'm afraid there's not much that can be done about it.

check="$((xcode-\select --install) 2>&1)"

This ^ is valid but isn't arithmetic. And the parsing engine isn't smart enough to be able to "look ahead" and see if something ends with "))" or ends with ") 2>&1 )". We have to guess at the begining whether its arithmetic or not. And because there's an insane number of hacks going on just to match the name of a command (vs arguments), there isn't a great way to just add math operators to $() when inside of an if statement.

I might be able to add a hack in the future to improve the situation a bit, but for now v1.8.0 fixes the cascading breakage by assuming non-arithmetic.

prplwtf commented 3 months ago

Aright, thanks for fixing it.