Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.51k stars 143 forks source link

Automatic Ruby environment activation with none failed: Unexpected token 'y' "your 13107"... is not valid JSON #2370

Open jared-thoughtbot opened 1 month ago

jared-thoughtbot commented 1 month ago

Description

Error

Automatic Ruby environment activation with none failed:
Unexpected token 'y' "your 13107"... is not valid JSON

image

My environment

Reproduction steps

  1. My environment (as above)
  2. Launch VSCode (with Ruby LSP extension) via code . from WSL console
  3. Wait for extension to try and load

Error message

Automatic Ruby environment activation with none failed:
Unexpected token 'y' "your 13107"... is not valid JSON

Output tab (Ruby LSP)

2024-07-25 16:09:50.364 [info] (albaik-web) Checking if chruby is available on the path with command: /usr/bin/fish -i -c 'chruby --version'
2024-07-25 16:09:51.368 [info] (albaik-web) Checking if rbenv is available on the path with command: /usr/bin/fish -i -c 'rbenv --version'
2024-07-25 16:09:52.372 [info] (albaik-web) Checking if rvm is available on the path with command: /usr/bin/fish -i -c 'rvm --version'
2024-07-25 16:09:53.377 [info] (albaik-web) Checking if asdf is available on the path with command: /usr/bin/fish -i -c 'asdf --version'
2024-07-25 16:09:54.390 [info] (albaik-web) Discovered version manager none
2024-07-25 16:09:54.390 [info] (albaik-web) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /home/jaredt/projects/albaik-web using shell: /usr/bin/fish
2024-07-25 16:10:00.645 [error] (albaik-web) Tried parsing invalid JSON environment: your 131072x1 screen size is bogus. expect trouble
your 131072x1 screen size is bogus. expect trouble
your 131072x1 screen size is bogus. expect trouble
your 131072x1 screen size is bogus. expect trouble
{"env":{"COLORTERM":"truecolor","ANDROID_HOME":"/home/jaredt/Android/Sdk","BROWSER":"wslview","TERM":"xterm-256color","PATH":"/home/jaredt/.rvm/gems/ruby-3.3.0/bin:/home/jaredt/.rvm/gems/ruby-3.3.0@global/bin:/home/jaredt/.rvm/rubies/ruby-3.3.0/bin:/home/jaredt/.rvm/bin:/home/jaredt/.pyenv/shims:/home/jaredt/.pyenv/bin:/home/linuxbrew/.linuxbrew/opt/openssl@3/bin:/home/jaredt/.yarn/bin:/home/jaredt/bin:/home/jaredt/.vscode-server/bin/f1e16e1e6214d7c44d078b1f0607b2388f29d729/bin/remote-cli:/home/jaredt/.asdf/shims:/home/jaredt/.asdf/bin:/bin:/home/jaredt/.local/share/nvm/v16.14.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/dotnet:/mnt/c/Program Files x86/Yarn/bin:/mnt/c/Program Files x86/Tailscale IPN:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program Files/OpenSSL-Win64/bin:/mnt/c/Program Files/Mullvad VPN/resources:/mnt/c/Program Files x86/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/PowerShell/7:/mnt/c/Users/jared/AppData/Local/Programs/Python/Python37-32/Scripts:/mnt/c/Users/jared/AppData/Local/Programs/Python/Python37-32:/mnt/c/Users/jared/AppData/Local/Microsoft/WindowsApps:/mnt/c/path:/mnt/c/Users/jared/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/jared/.dotnet/tools:/mnt/c/Users/jared/AppData/Roaming/npm:/mnt/c/Users/jared/AppData/Local/Yarn/bin:/mnt/c/Users/jared/AppData/Roaming/nvm:/mnt/c/Program Files/nodejs:/snap/bin","rvm_delete_flag":"0","PYENV_ROOT":"/home/jaredt/.pyenv","LANG":"C.UTF-8","rvm_tmp_path":"/home/jaredt/.rvm/tmp","GEM_HOME":"/home/jaredt/.rvm/gems/ruby-3.3.0","rvm_action":"reload","rvm_version":"1.29.12 latest","rvm_gemsets_path":"/home/jaredt/.rvm/gemsets","rvm_stored_umask":"0022","rvm_verbose_flag":"0","NAME":"Code","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/mnt/wslg/runtime-dir/vscode-ipc-5af6e075-4536-4434-af98-ee919d7381ea.sock","WSL_DISTRO_NAME":"Ubuntu","rvm_environments_path":"/home/jaredt/.rvm/environments","rvm_patches_path":"/home/jaredt/.rvm/patches","PWD":"/home/jaredt/projects/albaik-web","rvm_src_path":"/home/jaredt/.rvm/src","rvm_docs_path":"/home/jaredt/.rvm/docs","XDG_DATA_DIRS":"/usr/local/share:/usr/share:/var/lib/snapd/desktop","VSCODE_HANDLES_SIGPIPE":"true","rvm_hooks_path":"/home/jaredt/.rvm/hooks","SHLVL":"1","rvm_user_install_flag":"1","rvm_lib_path":"/home/jaredt/.rvm/lib","VSCODE_WSL_EXT_LOCATION":"/mnt/c/Users/jared/.vscode/extensions/ms-vscode-remote.remote-wsl-0.88.2","ASDF_DIR":"/home/jaredt/.asdf","PULSE_SERVER":"unix:/mnt/wslg/PulseServer","rvm_archives_path":"/home/jaredt/.rvm/archives","WT_PROFILE_ID":"{2c4de342-38b7-51cf-b940-2309a097f518}","rvm_repos_path":"/home/jaredt/.rvm/repos","PYENV_SHELL":"fish","XDG_RUNTIME_DIR":"/mnt/wslg/runtime-dir","VSCODE_L10N_BUNDLE_LOCATION":"","rvm_path":"/home/jaredt/.rvm","rvm_bin_path":"/home/jaredt/.rvm/bin","rvm_examples_path":"/home/jaredt/.rvm/examples","WAYLAND_DISPLAY":"wayland-0","HOME":"/home/jaredt","rvm_prefix":"/home/jaredt","rvm_help_path":"/home/jaredt/.rvm/help","LOGNAME":"jaredt","rvm_scripts_path":"/home/jaredt/.rvm/scripts","rvm_pretty_print_flag":"auto","VSCODE_CWD":"/mnt/c/Users/jared/AppData/Local/Programs/Microsoft VS Code","SHELL":"/usr/bin/fish","rvm_loaded_flag":"1","rvm_token":"reload","rvm_user_path":"/home/jaredt/.rvm/user","DISPLAY":":0","WSL_INTEROP":"/run/WSL/27414_interop","rvm_parse_break":"0","rvm_man_path":"/home/jaredt/.rvm/share/man","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","rvm_debug_flag":"0","rvm_usr_path":"/home/jaredt/.rvm/usr","rvm_log_path":"/home/jaredt/.rvm/log","rvm_rubies_path":"/home/jaredt/.rvm/rubies","WT_SESSION":"f5a6c79f-7043-4744-a9d7-ee9ef745bfca","rvm_wrappers_path":"/home/jaredt/.rvm/wrappers","nvm_current_version":"v16.14.0","HOSTTYPE":"x86_64","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","USER":"jaredt","WSLENV":"ELECTRON_RUN_AS_NODE/w:WT_SESSION:WT_PROFILE_ID:","WSL2_GUI_APPS_ENABLED":"1","rvm_ruby_string":"ruby-3.3.0","GEM_PATH":"/home/jaredt/.rvm/gems/ruby-3.3.0:/home/jaredt/.rvm/gems/ruby-3.3.0@global"},"yjit":true,"version":"3.3.0"}

Running commands directly in terminal (Fish shell)

$ rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

$ /usr/bin/fish -i -c 'rvm --version'
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

$ which ruby
/home/jaredt/.rvm/rubies/ruby-3.3.0/bin/ruby

$ ruby-lsp
Ruby LSP> Skipping custom bundle setup since /home/jaredt/projects/albaik-web/.ruby-lsp/Gemfile.lock already exists and is up to date
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: ((bundle check && bundle update ruby-lsp debug ruby-lsp-rails) || bundle install) 1>&2
The Gemfile's dependencies are satisfied
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Resolving dependencies...
Fetching sorbet-runtime 0.5.11495 (was 0.5.11493)
Installing sorbet-runtime 0.5.11495 (was 0.5.11493)
Bundler attempted to update ruby-lsp but its version stayed the same
Bundler attempted to update debug but its version stayed the same
Bundler attempted to update ruby-lsp-rails but its version stayed the same
Bundle updated!

Notes

motebaya commented 1 month ago

Maybe this is similar to a problem I recently experienced (#2369 ). The cause was the default terminal in VSCode not being compatible.

Screenshot 2024-07-27 150347

In fish shell, you can try changing the terminal size with the mouse or adjust the shell variables in the ~/.config/fish/config.fish file with values like

set -x COLUMNS 114
set -x LINES 48

or whatever size you prefer as long as it's more than 1. based: https://fishshell.com/docs/current/cmds/set.html

another quick solution is to change the default terminal in VSCode; that might fix the issue.

jared-thoughtbot commented 1 month ago

@motebaya amazing, thank you! Both options worked but I settled on hardcoding the columns and lines in config.fish.

Weirdly it still doesn't detect my version manager but it is working 🤷

2024-07-27 13:11:22.742 [info] (albaik-web) Checking if chruby is available on the path with command: /usr/bin/fish -i -c 'chruby --version'
2024-07-27 13:11:23.748 [info] (albaik-web) Checking if rbenv is available on the path with command: /usr/bin/fish -i -c 'rbenv --version'
2024-07-27 13:11:24.752 [info] (albaik-web) Checking if rvm is available on the path with command: /usr/bin/fish -i -c 'rvm --version'
2024-07-27 13:11:25.766 [info] (albaik-web) Checking if asdf is available on the path with command: /usr/bin/fish -i -c 'asdf --version'
2024-07-27 13:11:26.776 [info] (albaik-web) Discovered version manager none
2024-07-27 13:11:26.777 [info] (albaik-web) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /home/jaredt/projects/albaik-web using shell: /bin/fish
2024-07-27 13:11:38.653 [info] (albaik-web) Ruby LSP> Skipping custom bundle setup since /home/jaredt/projects/albaik-web/.ruby-lsp/Gemfile.lock already exists and is up to date
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
The Gemfile's dependencies are satisfied

2024-07-27 13:11:41.637 [info] (albaik-web) Initializing Ruby LSP v0.17.9...

2024-07-27 13:11:41.706 [info] (albaik-web) Finished initializing Ruby LSP!

2024-07-27 13:11:41.754 [info] (albaik-web) [Standard Ruby] Activating Standard Ruby LSP addon v1.39.1

2024-07-27 13:11:42.647 [info] (albaik-web) [Standard Ruby] Initialized Standard Ruby LSP addon 1.39.1

2024-07-27 13:11:42.647 [info] (albaik-web) Activating Ruby LSP Rails addon v0.3.11

2024-07-27 13:11:42.692 [info] (albaik-web) Ruby LSP Rails booting server

2024-07-27 13:11:49.531 [info] (albaik-web) Finished booting Ruby LSP Rails server
motebaya commented 1 month ago

@jared-thoughtbot Have you tried setting the version manager manually? i think in log, LSP checking version manager because you haven't set it up yet.

Here's what i did:

  1. in vscode, press CTRL + SHIFT + P, type version manager -> change version manager -> and select the version manager you have.
  2. create a .ruby_version file with the ruby version you're using in current directory project.
  3. adding the RUBY_VERSION variable to the ENV.

it might help.

ur5us commented 1 month ago

I have the same issue but only in 1 project:

Automatic Ruby environment activation with rvm failed: Unexpected token 'N', "No preset "... is not valid JSON

Using RVM to manage Ruby but also asdf to manage NodeJS. Bash is my shell. Annoyingly, it’s not consistent, i.e. the LSP works for gems and all other Ruby/Rails projects I work on except for one. Last week it worked without issues IIRC.

jared-thoughtbot commented 1 month ago

@ur5us can you provide the content from the Output tab with Ruby LSP selected from the dropdown? Eg.

image

ur5us commented 1 month ago

@jared-thoughtbot I think I solved it. The problem was asdf complaining about NodeJS version as per .tool-versions not installed, though IMO that should not affect the Ruby LSP in the first place as I’m using RVM to manage my Ruby versions. For reference:

2024-08-08 16:42:45.145 [info] (app) Running command: `/home/ur5us/.rvm/bin/rvm-auto-ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /home/ur5us/dev/redacted/app using shell: /usr/bin/bash
2024-08-08 16:42:47.377 [error] (app) Tried parsing invalid JSON environment: No preset version installed for command node
Please install a version by running one of the following:

asdf install nodejs 20.16.0

or add one of the following versions in your config file at /home/ur5us/dev/redacted/app/.tool-versions
nodejs 18.17.1
nodejs 20.13.0
nodejs 20.14.0
nodejs 20.15.0
nodejs 20.15.1
nodejs 22.0.0
{"env":{"SHELL":"/bin/bash","SESSION_MANAGER":"local/dragonfly:@/tmp/.ICE-unix/1538,unix/dragonfly:/tmp/.ICE-unix/1538","CSF_MDTVTexturesDirectory":"/usr/share/opencascade/resources/Textures","XDG_CONFIG_DIRS":"/run/xdg/:/etc/xdg/:/usr/share/xdg/","XDG_SESSION_PATH":"/org/freedesktop/DisplayManager/Session0","HISTCONTROL":"ignoredups","XDG_MENU_PREFIX":"gnome-","rvm_delete_flag":"0","__GL_MaxFramesAllowed":"1","rvm_prefix":"/home/ur5us","CSF_DrawPluginDefaults":"/usr/share/opencascade/resources/DrawResources","HISTSIZE":"1000","CSF_LANGUAGE":"us","SSH_AUTH_SOCK":"/run/user/1000/keyring/ssh","CSF_MIGRATION_TYPES":"/usr/share/opencascade/resources/StdResource/MigrationSheet.txt","ELECTRON_RUN_AS_NODE":"1","MY_RUBY_HOME":"/home/ur5us/.rvm/rubies/ruby-3.3.4","XMODIFIERS":"@im=ibus","DESKTOP_SESSION":"budgie-desktop","CSF_OCCTResourcePath":"/usr/share/opencascade/resources","NO_AT_BRIDGE":"1","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","CSF_STEPDefaults":"/usr/share/opencascade/resources/XSTEPResource","EMSCRIPTEN_ROOT":"/usr/share/emscripten/emsdk","EDITOR":"code-oss -w","GTK_MODULES":"gail:atk-bridge:appmenu-gtk-module:appmenu-gtk-module:appmenu-gtk-module:appmenu-gtk-module:appmenu-gtk-module","RUBY_VERSION":"ruby-3.3.4","PWD":"/home/ur5us/dev/redacted/app","LOGNAME":"ur5us","XDG_SESSION_DESKTOP":"budgie-desktop","XDG_SESSION_TYPE":"x11","DRAWHOME":"/usr/share/opencascade/resources/DrawResources","BUNDLER_EDITOR":"code-oss","rvm_version":"1.29.12-next (master)","VSCODE_CODE_CACHE_PATH":"/home/ur5us/.config/Code/CachedData/b1c0a14de1414fcdaa400695b4db1c0799bc3124","XAUTHORITY":"/home/ur5us/.Xauthority","CSF_StandardLiteDefaults":"/usr/share/opencascade/resources/StdResource","XDG_GREETER_DATA_DIR":"/var/lib/lightdm-data/ur5us","MOTD_SHOWN":"pam","GDM_LANG":"en_NZ.UTF-8","BINARYEN_ROOT":"/usr","HOME":"/home/ur5us","LANG":"en_NZ.UTF-8","XDG_CURRENT_DESKTOP":"Budgie:GNOME","BINARYEN":"/usr","VSCODE_IPC_HOOK":"/run/user/1000/vscode-0b167dcd-1.92-main.sock","PROMPT_COMMAND":"history -a;","XDG_SEAT_PATH":"/org/freedesktop/DisplayManager/Seat0","VSCODE_L10N_BUNDLE_LOCATION":"","CSF_ShadersDirectory":"/usr/share/opencascade/resources/Shaders","CHROME_DESKTOP":"code-oss.desktop","CSF_EXCEPTION_PROMPT":"1","CSF_XmlOcafResource":"/usr/share/opencascade/resources/XmlOcafResource","rvm_bin_path":"/home/ur5us/.rvm/bin","CSF_SHMessage":"/usr/share/opencascade/resources/SHMessage","GEM_PATH":"/home/ur5us/.rvm/gems/ruby-3.3.4:/home/ur5us/.rvm/gems/ruby-3.3.4@global","GEM_HOME":"/home/ur5us/.rvm/gems/ruby-3.3.4","XDG_SESSION_CLASS":"user","ASDF_DIR":"/home/ur5us/.asdf","USER":"ur5us","CSF_StandardDefaults":"/usr/share/opencascade/resources/StdResource","CSF_IGESDefaults":"/usr/share/opencascade/resources/XSTEPResource","VISUAL":"/usr/bin/nano","DISPLAY":":0","CSF_XCAFDefaults":"/usr/share/opencascade/resources/StdResource","VSCODE_PID":"631451","SHLVL":"0","INPUTRC":"/etc/inputrc","QT_IM_MODULE":"ibus","NO_GAIL":"1","VSCODE_CWD":"/home/ur5us","CSF_PluginDefaults":"/usr/share/opencascade/resources/StdResource","CSF_TObjMessage":"/usr/share/opencascade/resources/TObj","rvm_ruby_string":"ruby-3.3.4","CASROOT":"/usr","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","XDG_RUNTIME_DIR":"/run/user/1000","CSF_XSMessage":"/usr/share/opencascade/resources/XSMessage","GTK3_MODULES":"xapp-gtk3-module","MMGT_CLEAR":"1","XDG_DATA_DIRS":"/home/ur5us/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop","GDK_BACKEND":"x11","PATH":"/home/ur5us/.rvm/gems/ruby-3.3.4/bin:/home/ur5us/.rvm/gems/ruby-3.3.4@global/bin:/home/ur5us/.rvm/rubies/ruby-3.3.4/bin:/home/ur5us/.rvm/bin:/home/ur5us/.asdf/shims:/home/ur5us/.asdf/bin:/home/ur5us/.local/bin:/home/ur5us/bin:/usr/sbin:/usr/bin:/usr/local/bin:/snap/bin:/usr/local/bin:/home/ur5us/.cargo/bin:/home/ur5us/.local/bin:/home/ur5us/bin::/home/ur5us/.dotnet","CSF_TObjDefaults":"/usr/share/opencascade/resources/StdResource","HISTIGNORE":"history:ls:cd:exit","GDMSESSION":"budgie-desktop","ORIGINAL_XDG_CURRENT_DESKTOP":"Budgie:GNOME","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1000/bus","VSCODE_NLS_CONFIG":"{\"userLocale\":\"en-us\",\"osLocale\":\"en-nz\",\"resolvedLanguage\":\"en\",\"defaultMessagesFile\":\"/usr/share/vscode/resources/app/out/nls.messages.json\",\"locale\":\"en\",\"availableLanguages\":{}}","MAIL":"/var/spool/mail/ur5us","IRBRC":"/home/ur5us/.rvm/rubies/ruby-3.3.4/.irbrc","DRAWDEFAULT":"/usr/share/opencascade/resources/DrawResources/DrawDefault","GIO_LAUNCHED_DESKTOP_FILE_PID":"631451","GIO_LAUNCHED_DESKTOP_FILE":"/usr/share/applications/code-oss.desktop","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","rvm_path":"/home/ur5us/.rvm"},"yjit":true,"version":"3.3.4"}