Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Bash IDE upon detecting scripts from unsupported shells #1016

Open
REALERvolker1 opened this issue Oct 27, 2023 · 0 comments
Open

Disable Bash IDE upon detecting scripts from unsupported shells #1016

REALERvolker1 opened this issue Oct 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@REALERvolker1
Copy link

What is the problem this feature will solve?

Bash Language Server is a very useful tool for Bash and POSIX shell scripts. However, it is not designed for other shells, like zsh.

In VSCod(e|ium), the activation event for Bash IDE is onLanguage:shellscript. This activates even on scripts from unsupported shells.

This feature would help to solve #935, as their error message appears much more quickly when editing these scripts.

When I have been editing a zsh script for a while and it detects a syntax error, Bash IDE repeatedly prints the following error with many distracting notifications:

[Error - 4:25:03 PM] Unhandled Rejection at promise: [object Promise], reason: RuntimeError: memory access out of bounds
    at wasm://wasm/000b627a:wasm-function[29]:0x2e90
    at wasm://wasm/000b627a:wasm-function[146]:0x1cdba
    at wasm://wasm/000b627a:wasm-function[54]:0x83af
    at wasm://wasm/000b627a:wasm-function[96]:0x131e6
    at wasm://wasm/000b627a:wasm-function[234]:0x271ea
    at Parser.parse (/home/vlk/.vscode-oss/extensions/mads-hartmann.bash-ide-vscode-1.38.0-universal/node_modules/web-tree-sitter/tree-sitter.js:1:53325)
    at Analyzer.analyze (/home/vlk/.vscode-oss/extensions/mads-hartmann.bash-ide-vscode-1.38.0-universal/node_modules/bash-language-server/out/analyser.js:47:34)
    at BashServer.<anonymous> (/home/vlk/.vscode-oss/extensions/mads-hartmann.bash-ide-vscode-1.38.0-universal/node_modules/bash-language-server/out/server.js:241:45)
    at Generator.next (<anonymous>)
    at /home/vlk/.vscode-oss/extensions/mads-hartmann.bash-ide-vscode-1.38.0-universal/node_modules/bash-language-server/out/server.js:8:71
[Error - 4:25:03 PM] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: memory access out of bounds
  Code: -32603 

This also happens if I have been cutting and pasting and making all kinds of syntax errors in bash scripts, but as issue #935 has no responses, I assume this is impossible to fix.

I would consider the script I am writing to be a relatively pedestrian zsh script:

#!/usr/bin/zsh
# script by vlk to run a clipboard persistence command
set -euo pipefail
IFS=$'\n\t'

CLIPHISTPATH="$XDG_RUNTIME_DIR/${${0##*/}%.*}-$$-$XDG_SESSION_ID.hsts"

_panic() {
    if [[ ${1:-} == '--nice' ]]; then
        shift 1
        local -i retval=0
    fi
    printf '%s\n' "$@"
    exit "${retval:-1}"
}

typeset -a checkdeps=(ps notify-send)

for i in "$@"; do
    i_val="${i:+${i#*=}}"
    case "${i:-}" in
        '--dmenucmd='*)
            DMENU_COMMAND="$i_val"
            ;;
        '--platform='*)
            PLATFORM="$i_val"
            ;;
        -*)
            # The following is a deliberate syntax error
            _panic "${0##*/} --key=val --key2=val2"
                "--platform=platform_name   (either wayland or xorg)"
                "--dmenucmd='dmenu_command --arg1 --arg2'  (full command for your dmenu-like wrapper)"
        ;;
    esac
done

checkdeps+=("${${DMENU_COMMAND:=rofi -dmenu}%% *}")

case "${PLATFORM:=${${WAYLAND_DISPLAY:+wayland}:-${DISPLAY:+xorg}}}" in
    wayland)
        checkdeps+=(wl-paste clipman)
        ;;
    xorg)
        checkdeps+=(xclip xsel)
        ;;
    *)
        _panic "Invalid platform '$PLATFORM'! Supported platforms: 'xorg' or 'wayland'"
    ;;
esac

# check dependencies
set -A faildeps
for i in "${(@)checkdeps}"; do
    command -v $i &>/dev/null || faildeps+=("$i")
done
((${#faildeps})) && _panic "Missing dependencies: ${(pj: :)faildeps}"

# print config

printf '%s\n' \
    "PLATFORM='$PLATFORM'" \
    "DMENU_COMMAND='$DMENU_COMMAND'"

# ps -ao comm,args | grep -P '([^(grep)])wl-paste.*--watch'

The bash IDE extension can tell that I am insane, but unfortunately, it cannot disable itself.

What is the feature you are proposing to solve the problem?

I propose a detection system sort of like the following awful Javascript/Perl/Rust mishmash pseudocode:

// if the language is not just detected as zsh
const file = readFile(current_file)
const language = file.lines().at(0)
if (language =~ /.*(bash|dash|ash|sh)$/) {
    return true
}
else {
    return false
}

What alternatives have you considered?

I have considered disabling the extension, but then I would have to reenable it all the time. I have also found that closing and opening vscodium temporarily "fixes" it, but this doesn't actually fix the problem.

@REALERvolker1 REALERvolker1 added the enhancement New feature or request label Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant