jeff-hykin / better-shell-syntax

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

Grammar makes assumptions about start of line, which causes issues when embedding it within another grammar. #70

Closed alexr00 closed 6 months ago

alexr00 commented 10 months ago

The code with a problem is:

# Example Markdown

1. Step one

    ```bash
    #!/bin/bash

    # Get the system's uptime in seconds
    uptime_seconds=$(awk '{printf "%.0f", $1}' /proc/uptime)

    # Check if uptime is less than the threshold
    if [ "$uptime_seconds" -lt "$threshold_seconds" ]; then
        echo "System uptime is less than 10 minutes. Abort."
        exit 0
    fi
  1. Step Two

The same code but not inline with an ordered list

#!/bin/bash

# Get the system's uptime in seconds
uptime_seconds=$(awk '{printf "%.0f", $1}' /proc/uptime)

# Check if uptime is less than the threshold
if [ "$uptime_seconds" -lt "$threshold_seconds" ]; then
    echo "System uptime is less than 10 minutes. Abort."
    exit 0
fi```
image

It looks like:

See the image above under "Step one".

It should look like:

In the image above under "Step Two", the bash code block is highlighted correctly.

alexr00 commented 10 months ago

Originally from https://github.com/microsoft/vscode/issues/194998.

A potential solution was posted there:

diff --git a/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json b/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json
index 9950c577c48..d988e0ce088 100644
--- a/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json
+++ b/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json
@@ -1346,7 +1346,7 @@
            "name": "storage.modifier.$0.shell"
        },
        "normal_statement": {
-           "begin": "(?!^[ \\t]*+$)(?:(?<=^until | until |\\tuntil |^while | while |\\twhile |^elif | elif |\\telif |^else | else |\\telse |^then | then |\\tthen |^do | do |\\tdo |^if | if |\\tif )|(?<=(?:^|;|\\||&|!|\\(|\\{|\\`)))[ \\t]*+(?!nocorrect\\W|nocorrect\\$|function\\W|function\\$|foreach\\W|foreach\\$|repeat\\W|repeat\\$|logout\\W|logout\\$|coproc\\W|coproc\\$|select\\W|select\\$|while\\W|while\\$|pushd\\W|pushd\\$|until\\W|until\\$|case\\W|case\\$|done\\W|done\\$|elif\\W|elif\\$|else\\W|else\\$|esac\\W|esac\\$|popd\\W|popd\\$|then\\W|then\\$|time\\W|time\\$|for\\W|for\\$|end\\W|end\\$|fi\\W|fi\\$|do\\W|do\\$|in\\W|in\\$|if\\W|if\\$)",
+           "begin": "(?!^[ \\t]*+$)(?:(?<=^until | until |\\tuntil |^while | while |\\twhile |^elif | elif |\\telif |^else | else |\\telse |^then | then |\\tthen |^do | do |\\tdo |^if | if |\\tif )|(?<=(?:^|\\G|;|\\||&|!|\\(|\\{|\\`)))[ \\t]*+(?!nocorrect\\W|nocorrect\\$|function\\W|function\\$|foreach\\W|foreach\\$|repeat\\W|repeat\\$|logout\\W|logout\\$|coproc\\W|coproc\\$|select\\W|select\\$|while\\W|while\\$|pushd\\W|pushd\\$|until\\W|until\\$|case\\W|case\\$|done\\W|done\\$|elif\\W|elif\\$|else\\W|else\\$|esac\\W|esac\\$|popd\\W|popd\\$|then\\W|then\\$|time\\W|time\\$|for\\W|for\\$|end\\W|end\\$|fi\\W|fi\\$|do\\W|do\\$|in\\W|in\\$|if\\W|if\\$)",
            "end": "(?=;|\\||&|\\n|\\)|\\`|\\{|\\}|[ \\t]*#|\\])(?<!\\\\)",
            "beginCaptures": {},
            "endCaptures": {},
@@ -2006,4 +2006,4 @@
            ]
        }
    }
-}
\ No newline at end of file
+}
jeff-hykin commented 6 months ago

Seems fixed now, but I'm not sure when that happened so let me know if this is still an issue