bash-lsp / bash-language-server

A language server for Bash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable Bash IDE upon detecting scripts from unsupported shells

REALERvolker1 opened this issue · comments

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.