jeff-hykin / better-shell-syntax

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

`local` highlighting is inconsistent #56

Closed jeff-hykin closed 3 months ago

jeff-hykin commented 1 year ago

The code with a problem is:


# fine
inline_weirdness_demo() {
    local -A seen
    # variable names after array initialization lose highlighting
    local -a args=("foo") unique=('%s')
    local arg_a count unique=('%s') args=("foo")
    for arg_a in "${VALUES_ARRAY[@]}"; do
        count=${seen[${arg_a}]-0}
        # some tokens lose highlighting after &&/||
        ((count > 0)) && continue
        unique+=("${arg_a}")
        args+=("bar")
        ((seen[${arg_a}] += 1))
    done
}

# inconsistent
inline_weirdness_comp() {
    local -A seen
    local -a unique=('%s')
    local -a args=("foo")
    local arg_a count
    for arg_a in "${VALUES_ARRAY[@]}"; do
        count=${seen[${arg_a}]}
        if ((count > 0)); then continue; fi
        unique+=("${arg_a}")
        args+=("bar")
        ((seen[${arg_a}] += 1))
    done
    declare -p seen unique args
}
alexr00 commented 1 year ago

These three lines also show inconsistent highlighting of vara and varb with local:

local vara varb=2

local vara=1 varb=2

local vara=1 varb
Screenshot 2023-03-19 at 7 40 51 PM Screenshot 2023-03-19 at 7 41 11 PM Screenshot 2023-03-19 at 7 54 15 PM

Original issue is here: https://github.com/microsoft/vscode/issues/177621

bland328 commented 1 year ago

I'm the OP for the migrated report above, and here to report that this is still an issue even after installing BSS v1.5.2.

balupton commented 11 months ago

Another demo of this with arrays:

#!/usr/bin/env bash

function demo () (
    local options=(
        "$@"
        --name='snap'
        --cli='snap'
        RPM='snapd'
        PAMAC='snapd'
        ZYPPER_REPO="https://download.opensuse.org/repositories/system:snappy/$(get-opensuse-release 2>/dev/null || :)/"
        ZYPPER_REPO_ALIAS='snappy'
        ZYPPER='snapd'
    )
)
image

Adding any var before the options array fixes it

#!/usr/bin/env bash

function demo () (
    local a options=(
        "$@"
        --name='snap'
        --cli='snap'
        RPM='snapd'
        PAMAC='snapd'
        ZYPPER_REPO="https://download.opensuse.org/repositories/system:snappy/$(get-opensuse-release 2>/dev/null || :)/"
        ZYPPER_REPO_ALIAS='snappy'
        ZYPPER='snapd'
    )
)
image
balupton commented 10 months ago

While it isn't much, I've posted a $20USD bounty for this: https://app.bountysource.com/issues/123759817-local-highlighting-is-inconsistent

Update: Bountysource is defunct: https://github.com/bountysource/core/issues/1586

jeff-hykin commented 3 months ago

Alright this should finally completely fixed on v1.7.1, along with a slew of other things related to variable assignment

Update: Bountysource is defunct: bountysource/core#1586

That is unfortunate, oh well. If you're feelin generous my venmo is https://account.venmo.com/u/Jeff-Hykin @balupton

balupton commented 3 months ago

Still getting the inconsistent formatting of https://github.com/jeff-hykin/better-shell-syntax/issues/56#issuecomment-1662364516 with v1.7.2:

CleanShot 2024-03-21 at 13 50 53@2x

However it seems contextual, as removing everything except those local defines removes the issue. Here is the full code snipper:

#!/usr/bin/env bash

# https://wiki.manjaro.org/index.php/Snap
# https://packages.ubuntu.com/bionic/gnome/gnome-software-plugin-snap
# https://snapcraft.io/docs/installing-snap-on-opensuse
# https://software.opensuse.org/download/package?package=snapd&project=system:snappy
# https://en.opensuse.org/Snap <-- this is the correct info
# https://software.opensuse.org/download/package?package=snapd&project=system:snappy <-- this is not correct

# https://packages.debian.org/sid/amd64/snapd/filelist
# /usr/bin/snap
# /usr/bin/snapctl
# /usr/bin/ubuntu-core-launcher

function setup_util_snap() (
    source "$DOROTHY/sources/bash.bash"

    # checks
    if ! is-linux; then
        echo-style --notice="[$0] is only intended to be run on Linux systems, skipping." >/dev/stderr
        return 0
    fi

    # setup
    local options=(
        --name='snap'
        --cli='snap'
        "$@"
        APT='snapd' # UBUNTU
        AUR='snapd' # ARCH
        RPM='snapd' # FEDORA
        ZYPPER_REPO_ALIAS='snappy'
        ZYPPER_REPO="https://download.opensuse.org/repositories/system:snappy/$(get-opensuse-release 2>/dev/null || :)/"
        ZYPPER='snapd' # SUSE
    )
    local a options=(
        --name='snap'
        --cli='snap'
        "$@"
        APT='snapd' # UBUNTU
        AUR='snapd' # ARCH
        RPM='snapd' # FEDORA
        ZYPPER_REPO_ALIAS='snappy'
        ZYPPER_REPO="https://download.opensuse.org/repositories/system:snappy/$(get-opensuse-release 2>/dev/null || :)/"
        ZYPPER='snapd' # SUSE
    )
    setup-util "${options[@]}"

    # if installed, configure
    if is-snap; then
        # log start
        echo-segment --h2='Configure snap'

        # ensure snap is discoverable to the system
        if test ! -d /snap; then
            sudo-helper -- ln -s /var/lib/snapd/snap /snap
        fi

        # ensure snap service is running
        if service-helper --supported; then
            service-helper --enable --start -- snapd.socket snapd.apparmor
        fi

        # install snap support for gnome-software (if it exists)
        if command-exists gnome-software; then
            # PAMAC='gnome-software-snap' \
            # Error: target not found: gnome-software-snap
            setup-util --optional --name='Snap via Gnome Software' "$@" \
                APT='gnome-software-plugin-snap' # UBUNTU
        fi

        # log success
        echo-segment --g2='Configure snap'
    fi
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
    setup_util_snap "$@"
fi

Other than that, really appreciating the other fixes.

balupton commented 3 months ago

That is unfortunate, oh well. If you're feelin generous my venmo is https://account.venmo.com/u/Jeff-Hykin

Venmo seems USA only, is not accepting any of my Australian payment details

jeff-hykin commented 3 months ago

Still getting the inconsistent formatting of #56 (comment) with v1.7.2:

Yeah looks like it was passing all my test cases but not much else.

Your example actually revealed some other bugs too like echo-style being wrong. Those and a handful of other things should be fixed with v1.8.0.