Skip to content

Crashes in tree-sitter in 4.10.0 #880

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

Closed
rchl opened this issue Jun 24, 2023 · 1 comment · Fixed by #881
Closed

Crashes in tree-sitter in 4.10.0 #880

rchl opened this issue Jun 24, 2023 · 1 comment · Fixed by #881

Comments

@rchl
Copy link

rchl commented Jun 24, 2023

Code editor

Sublime Text

Platform

macOS

Version

bash-language-server 4.10.0
Node 16.17.1

What steps will reproduce the bug?

Opened a .zshrc file.

The file doesn't seem to have any sensitive information so I'll provide it here but I don't know if it will reproduce without the referenced files.

.zshrc
#!/bin/zsh

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory
setopt autocd
setopt correct
setopt hist_ignore_all_dups
# setopt print_exit_value
unsetopt beep
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall

zstyle ':completion:*' completer _complete _ignored _approximate
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}'
zstyle ':completion:*' max-errors 1
zstyle ':completion:*' menu select
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename ~/.zshrc

fpath=(~/.zsh/zsh-completions/src $fpath)

autoload -Uz compinit
# -u switch to disable insecure dirs warning
compinit -u
# End of lines added by compinstall

# unsetopt BASH_AUTO_LIST
# unsetopt AUTO_MENU

autoload -U select-word-style
select-word-style bash

setopt promptsubst

# Load the prompt theme system
autoload -U promptinit
promptinit

# Use the wunjo prompt theme
# prompt wunjo
# prompt fade green

# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
  local node_version="$(nvm version)"
  local nvmrc_path="$(nvm_find_nvmrc)"

  if [ -n "$nvmrc_path" ]; then
    local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")

    if [ "$nvmrc_node_version" = "N/A" ]; then
      nvm install
    elif [ "$nvmrc_node_version" != "$node_version" ]; then
      nvm use
    fi
  elif [ "$node_version" != "$(nvm version default)" ]; then
    echo "Reverting to nvm default version"
    nvm use default
  fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

source ~/.zsh/zsh-better-npm-completion.plugin.zsh
# source ~/.zsh/git-prompt/zshrc.sh
# PROMPT='%n@%B%m${reset_color}:%B%{$fg[green]%}%~%{${reset_color}%}%b$(git_super_status)
# %# '

mov2gif() {
  out="$(echo $1 | sed 's/\.mov$/\.gif/')"
  max_width="650"
  frames_per_second="20"
  ffmpeg -i $1 -vf "scale=min(iw\,$max_width):-1" -r "$frames_per_second" -sws_flags lanczos -f image2pipe -vcodec ppm - \
    | convert -delay 5 -layers Optimize -loop 0 - "$out" &&
  echo "$(tput setaf 2)output file: $out$(tput sgr 0)" &&
  open -a Google\ Chrome $out
}

# NPM aliases
alias ni="npm i"
alias no="npm out"
alias ncuu="ncu --interactive --format group"

# General aliases.
# Single quote supresses evaluation until run time.
alias vi='vim'
alias grep='grep --text'
alias ff="find . 2>/dev/null -name"
# Send signal to node process to start debugging
alias dn='kill -SIGUSR1'
# alias rgl='rg --no-ignore --context=1 --fixed-strings --search-zip --max-columns=300 --max-columns-preview'
# Uses ripgrep-all to detect file types by content (https://github.com/phiresky/ripgrep-all)
# --rga-accurate: Use more accurate but slower matching by mime type
# --rga-adapters: Used to include or exclude (-) adapters (rga --rga-list-adapters to list)
# --fixed-strings: Don't interpet string as regex
alias rgi='rga --rga-accurate --rga-adapters=-ffmpeg,poppler,pandoc --context=1 --fixed-strings --max-columns=300 --max-columns-preview'
alias rgu='rga --rga-accurate --rga-adapters=-ffmpeg,poppler,pandoc --no-ignore --hidden --context=1 --fixed-strings --max-columns=300 --max-columns-preview'

# Extended 'du'.
function d() {
  # List directory sizes.
  # -c - shows total size
  # -s - display an entry for each specified file
  # -k - display block counts in 1024-byte (1-Kbyte) blocks
  # -h - human readable
  # -I - ignores pattern
  # -d 1 - shows directories one level deep
  # du -ch -I .git -d 1 $1 | sort -h
  du -csk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done
}

# alias d='du -ch -I .git -d 1 | sort -h'

alias pprint='pbpaste | python3 -c "import sys; import json; import ast; d = ast.literal_eval(next(sys.stdin)); print(json.dumps(d, indent=2))"'

# Git aliases.
alias t='tig'
alias ts='tig status'
alias g='git'
alias gp='git pull'
alias gs='git s'
alias gss='git stash'
alias gsp='git stash pop'
alias grh='git reset --hard'
# Fast-forwards current branch to upstream if possible.
alias gmu='`gfu` && git merge --ff-only FETCH_HEAD && _notify'

# List open listening ports.
# -n - don't resolve names
# -P - don't resolve port names
alias lsp='lsof -n -P -i TCP -s TCP:LISTEN'
alias lspp='lsof -n -i TCP -s TCP:LISTEN'

# Kills process by the port it is using.
function killport() {
  pid=`lsof -t -i :$1`
  if [[ $? -eq 0 ]]; then
    echo "Killing pid ${pid}"
    kill "${pid}"
  else
    echo "No process found for port '$1'"
  fi
}

function _notify() {
  echo -e "\a"
}

if [[ "$OSTYPE" == "cygwin" ]]; then
  # Add cygwin bin to PATH.
  PATH="/bin:$PATH"
fi

PLATFORM=$(uname)
if [[ $PLATFORM == "Darwin" ]]; then
  alias ls='ls -F'
  alias ll='ls -al -F'
elif [[ $PLATFORM == "Linux" ]]; then
  alias ls='ls -F --group-directories-first --color=auto'
  alias ll='ls -al -F --color=auto'
else
  alias subl='c:/programy/Sublime/sublime_text.exe'
  alias ls='ls -F --group-directories-first --color=auto'
  alias ll='ls -al -F --color=auto'
fi

# Color output for ls and such
export CLICOLOR=1
export EDITOR="subl -w"

ARCH="$(uname -m)"

if [[ $PLATFORM == "Darwin" ]]; then
  # MacPorts
  # MANPATH="/opt/local/share/man:$MANPATH"
  PATH="${HOME}/.composer/vendor/bin:$PATH"
  PATH="/usr/local/bin:$PATH"
  PATH="/opt/local/bin:/opt/local/sbin:$PATH"
  # M1
  PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
  export LC_ALL=en_US.UTF-8
  export LANG=en_US.UTF-8
elif [[ $PLATFORM == "Linux" ]]; then
  PATH="/usr/bin:$PATH"
else
  # Removes some annoying cygwin paths warning and some.
  export CYGWIN='codepage:oem nodosfilewarning'
  # Pretend to be Ansicon for color diagnostics in clang to work.
  export ANSICON="1"
  # Fix handling of some keys on Windows.
  # Console 2:
  # bindkey '\e[1~' beginning-of-line
  # bindkey '\e[4~' end-of-line
  # bindkey "\e[3~" delet
  # e-char
  # Mintty:
  bindkey '\e[H' beginning-of-line
  bindkey '\e[F' end-of-line
  bindkey "\e[3~" delete-char
fi

[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

# Powerlevel10k
# POWERLEVEL9K_MODE='nerdfont-complete'
# POWERLEVEL9K_PROMPT_ON_NEWLINE=true
# POWERLEVEL9K_RPROMPT_ON_NEWLINE=true
# POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir newline vcs)
# POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
if [[ $ARCH == 'arm64' ]]; then
  source /opt/homebrew/opt/powerlevel10k/powerlevel10k.zsh-theme
else
  source /usr/local/opt/powerlevel10k/powerlevel10k.zsh-theme
fi
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

# FZF
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Uses rga to list files but doesn't search them
export FZF_CTRL_T_COMMAND="$SHELL -c 'rga --files --color never'"
export FZF_ALT_C_COMMAND="fd -t d"
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
export FZF_CTRL_T_OPTS="--preview '[[ \$(file --mime {}) =~ binary ]] &&
                                     /Users/rchlodnicki/.iterm2/imgcat {} ||
                                     (bat --color=always {} || cat {} || tree -C {}) 2> /dev/null | head -200'"
if [[ $ARCH == 'arm64' ]]; then
  source /opt/homebrew/opt/powerlevel10k/powerlevel10k.zsh-theme
else
  source /usr/local/opt/powerlevel10k/powerlevel10k.zsh-theme
fi

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
source /opt/homebrew/opt/powerlevel10k/powerlevel10k.zsh-theme

# pnpm
export PNPM_HOME="/Users/rafal/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"
# pnpm end

How often does it reproduce? Is there a required condition?

Open the specific .zshrc file

What is the expected behavior?

No crash

What do you see instead?

Server crashes with error:

LSP-bash: TypeError: Cannot read properties of undefined (reading 'apply')
LSP-bash:     at e.<computed> (/Users/rafal/Library/Caches/Sublime Text/Package Storage/LSP-bash/16.17.1/language-server/node_modules/web-tree-sitter/tree-sitter.js:1:16465)
LSP-bash:     at wasm://wasm/001ec906:wasm-function[21]:0x1ccf
LSP-bash:     at e.<computed> (/Users/rafal/Library/Caches/Sublime Text/Package Storage/LSP-bash/16.17.1/language-server/node_modules/web-tree-sitter/tree-sitter.js:1:16465)
LSP-bash:     at wasm://wasm/001ec906:wasm-function[19]:0x17aa
LSP-bash:     at wasm://wasm/000b627a:wasm-function[234]:0x25842
LSP-bash:     at Module._ts_parser_parse_wasm (/Users/rafal/Library/Caches/Sublime Text/Package Storage/LSP-bash/16.17.1/language-server/node_modules/web-tree-sitter/tree-sitter.js:1:33493)
LSP-bash:     at Parser.parse (/Users/rafal/Library/Caches/Sublime Text/Package Storage/LSP-bash/16.17.1/language-server/node_modules/web-tree-sitter/tree-sitter.js:1:53325)
LSP-bash:     at Analyzer.analyze (/Users/rafal/Library/Caches/Sublime Text/Package Storage/LSP-bash/16.17.1/language-server/node_modules/bash-language-server/out/analyser.js:47:34)
LSP-bash:     at BashServer.<anonymous> (/Users/rafal/Library/Caches/Sublime Text/Package Storage/LSP-bash/16.17.1/language-server/node_modules/bash-language-server/out/server.js:241:45)
LSP-bash:     at Generator.next (<anonymous>)

Additional information

To save you some potential debugging, the code around the place where it crashes looks like this:

 var proxyHandler = {
   get: function(e, t) {
     switch (t) {
       case '__memory_base':
         return memoryBase;
       case '__table_base':
         return tableBase
     }
     if (t in asmLibraryArg)
       return asmLibraryArg[t];
     var r;
     t in e || (e[t] = function() {
       return r || (r = resolveSymbol(t)),
              r.apply(null, arguments)  // <=== CRASHES HERE
     });
     return e[t]
   }
 },
     proxy = new Proxy({}, proxyHandler), info = {
       'GOT.mem': new Proxy({}, GOTHandler),
       'GOT.func': new Proxy({}, GOTHandler),
       env: proxy,
       wasi_snapshot_preview1: proxy
     };

Check also related issue in the LSP-bash Sublime Text plugin - sublimelsp/LSP-bash#63

@skovhus
Copy link
Collaborator

skovhus commented Jun 26, 2023

Thanks for reporting this.

The following script reproduces the issue:

#!/bin/zsh

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

It seems like this is a regression in the parser – it shouldn't throw an error while parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants