Cannot seem to get Ruby LSP to work in a Rails 7 app at all
Ruby version
3.2.3
Code snippet
2024-02-21 18:50:06.453 [info] (LSPtest) Trying to activate Ruby environment with command: /bin/bash -i -c 'rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /workspaces/LSPtest
2024-02-21 18:57:16.932 [info] (LSPtest) Checking if asdf is available on the path with command: /bin/bash -i -c 'asdf --version'
2024-02-21 18:57:17.478 [info] (LSPtest) Checking if chruby is available on the path with command: /bin/bash -i -c 'chruby --version'
2024-02-21 18:57:18.046 [info] (LSPtest) Checking if rbenv is available on the path with command: /bin/bash -i -c 'rbenv --version'
2024-02-21 18:57:18.593 [info] (LSPtest) Discovered version manager rbenv
2024-02-21 18:57:18.593 [info] (LSPtest) Trying to activate Ruby environment with command: /bin/bash -i -c 'rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /workspaces/LSPtest
2024-02-21 18:57:22.766 [info] (LSPtest) Starting Ruby LSP v0.14.1...
2024-02-21 18:57:22.795 [info] (LSPtest) [Error - 6:57:22 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"found no changes, using resolution from the lockfile\ncontent-length":"1570"}
Shutting down server.
2024-02-21 18:57:22.795 [info] (LSPtest) [Error - 6:57:22 PM] Stopping server failed
2024-02-21 18:57:22.795 [info] (LSPtest) Error: Client is not running and can't be stopped. It's current state is: starting
at fs.shutdown (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8468)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8047)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:44:38186)
at fs.handleConnectionError (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-02-21 18:57:22.795 [info] (LSPtest) [Error - 6:57:22 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"0,\"result\":{\"capabilities\":{\"positionEncoding\":\"utf-16\",\"textDocumentSync\":{\"openClose\":true,\"change\":2},\"completionProvider\":{\"triggerCharacters\":[\"/\"],\"completionItem\":{\"labelDetailsSupport\":true}},\"hoverProvider\":{},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\" \",\",\"]},\"definitionProvider\":true,\"documentHighlightProvider\":true,\"documentSymbolProvider\":{\"symbolKind\":{\"value_set\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},\"hierarchicalDocumentSymbolSupport\":true},\"codeActionProvider\":{\"resolveProvider\":true},\"codeLensProvider\":{},\"documentLinkProvider\":{},\"documentFormattingProvider\":true,\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"{\",\"moreTriggerCharacter\":[\"\\n\",\"|\",\"d\"]},\"foldingRangeProvider\":{\"lineFoldingOnly\":true},\"selectionRangeProvider\":true,\"semanticTokensProvider\":{\"documentSelector\":{\"scheme\":\"file\",\"language\":\"ruby\"},\"legend\":{\"tokenTypes\":[\"namespace\",\"type\",\"class\",\"enum\",\"interface\",\"struct\",\"typeParameter\",\"parameter\",\"variable\",\"property\",\"enumMember\",\"event\",\"function\",\"method\",\"macro\",\"keyword\",\"modifier\",\"comment\",\"string\",\"number\",\"regexp\",\"operator\",\"decorator\"],\"tokenModifiers\":[\"declaration\",\"definition\",\"readonly\",\"static\",\"deprecated\",\"abstract\",\"async\",\"modification\",\"documentation\",\"default_library\"]},\"range\":true,\"full\":{\"delta\":false}},\"inlayHintProvider\":{},\"diagnosticProvider\":{\"interFileDependencies\":false,\"workspaceDiagnostics\":false},\"workspaceSymbolProvider\":true},\"serverInfo\":{\"name\":\"Ruby LSP\",\"version\":\"0.14.1\"},\"formatter\":\"none\"},\"jsonrpc\":\"2.0\"}Content-Length: 242"}
Shutting down server.
2024-02-21 18:57:22.796 [info] (LSPtest) [Error - 6:57:22 PM] Stopping server failed
2024-02-21 18:57:22.796 [info] (LSPtest) Error: Client is not running and can't be stopped. It's current state is: starting
at fs.shutdown (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8468)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8047)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:44:38186)
at fs.handleConnectionError (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Description
I've been getting Ruby LSP errors in my codespaces pretty consistently over the past couple months. Initially it seemed like there were maybe some wires getting crossed with rufo or htmlbeautifier or something, but as a test I just created a whole new GitHub account (not this one) to make sure my codespace was as clean a slate as possible for this extension.
Created a new repo with a Gemfile
source 'https://rubygems.org'
ruby '3.0.0'
gem 'rails', '~> 7.0'
Opened codespace
Ran bundle install
Ran Rails new .
Then installed Shopify's Ruby and Ruby LSP extensions, Ruby Sorbet, and VSCode rdbg Ruby Debugger.
Received this error (not clear why it was looking for 3.2.3 instead of 3.0.0 unless that's the current default version for Rails new .:
Failed to activate rbenv environment: Command failed: /bin/bash -i -c 'rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' bash: cannot set terminal process group (1949): Inappropriate ioctl for device bash: no job control in this shell rbenv: version `ruby-3.2.3' is not installed (set by /workspaces/LSPtest/.ruby-version)
Checked the extension readme for tips, added ruby-lsp to the Gemfile - wasn't clear if necessary or not.
Ran rbenv install 3.2.3
Tried to run rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))" again but received this error:
rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"RUBY_ENV_ACTIVATE{"env":{"SHELL":"/bin/bash","NUGET_XMLDOC_MODE":"skip","COLORTERM":"truecolor","CLOUDENV_ENVIRONMENT_ID":"33d77c35-dde6-4cef-8a9c-454f23632cb6","NVM_INC":"/usr/local/share/nvm/versions/node/v20.11.0/include/node","TERM_PROGRAM_VERSION":"1.85.2","rvm_delete_flag":"0","GITHUB_USER":"cal-bob","rvm_prefix":"/usr/local","CODESPACE_NAME":"opulent-pancake-69vv9rv9rrp6fr5r6","HOSTNAME":"codespaces-135937","JAVA_ROOT":"/home/codespace/java","JAVA_HOME":"/usr/local/sdkman/candidates/java/current","DOTNET_ROOT":"/usr/share/dotnet","CODESPACES":"true","PYTHON_ROOT":"/home/codespace/.python","GRADLE_HOME":"/usr/local/sdkman/candidates/gradle/current","RBENV_HOOK_PATH":"/home/codespace/.rbenv/rbenv.d:/usr/local/share/rbenv/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks","NVS_DIR":"/usr/local/nvs","NVS_OS":"linux","DOTNET_SKIP_FIRST_TIME_EXPERIENCE":"1","MY_RUBY_HOME":"/usr/local/rvm/rubies/ruby-3.2.3","NVS_USE_XZ":"1","SDKMAN_CANDIDATES_DIR":"/usr/local/sdkman/candidates","install_flag":"1","RUBY_VERSION":"ruby-3.2.3","PWD":"/workspaces/LSPtest","PIPX_BIN_DIR":"/usr/local/py-utils/bin","rvm_version":"1.29.12 (latest)","ORYX_DIR":"/usr/local/oryx","rvm_pretty_print_flag":"auto","ContainerVersion":"13","VSCODE_GIT_ASKPASS_NODE":"/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/node","HUGO_ROOT":"/home/codespace/.hugo","GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN":"app.github.dev","NPM_GLOBAL":"/home/codespace/.npm-global","HOME":"/home/codespace","GITHUB_API_URL":"https://api.github.com","LANG":"C.UTF-8","GITHUB_TOKEN":"ghu_lNuHS6WhwQCyQZUMEF7LYGfymw35SA1ld5cH","LS_COLORS":"rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:","DYNAMIC_INSTALL_ROOT_DIR":"/opt","NVM_SYMLINK_CURRENT":"true","PHP_PATH":"/usr/local/php/current","DEBIAN_FLAVOR":"focal-scm","GIT_ASKPASS":"/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/git/dist/askpass.sh","PHP_ROOT":"/home/codespace/.php","ORYX_ENV_TYPE":"vsonline-present","HUGO_DIR":"/usr/local/hugo/bin","DOCKER_BUILDKIT":"1","rvm_recommended_ruby":"rvm install ruby-3.0.0","GOROOT":"/usr/local/go","INTERNAL_VSCS_TARGET_URL":"https://eastus.online.visualstudio.com","SHELL_LOGGED_IN":"true","PYTHON_PATH":"/usr/local/python/current","NVM_DIR":"/usr/local/share/nvm","VSCODE_GIT_ASKPASS_EXTRA_ARGS":"","RBENV_ORIG_PATH":"/usr/local/rvm/gems/ruby-3.2.3/bin:/usr/local/rvm/gems/ruby-3.2.3@global/bin:/usr/local/rvm/rubies/ruby-3.2.3/bin:/usr/local/rvm/bin:/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/bin/remote-cli:/home/codespace/.local/bin:/home/codespace/.dotnet:/home/codespace/nvm/current/bin:/home/codespace/.php/current/bin:/home/codespace/.python/current/bin:/home/codespace/java/current/bin:/home/codespace/.ruby/current/bin:/home/codespace/.local/bin:/usr/local/python/current/bin:/usr/local/py-utils/bin:/usr/local/oryx:/usr/local/go/bin:/go/bin:/usr/local/sdkman/bin:/usr/local/sdkman/candidates/java/current/bin:/usr/local/sdkman/candidates/gradle/current/bin:/usr/local/sdkman/candidates/maven/current/bin:/usr/local/sdkman/candidates/ant/current/bin:/usr/local/share/rbenv/bin:/usr/local/php/current/bin:/opt/conda/bin:/usr/local/nvs:/usr/local/share/nvm/versions/node/v20.11.0/bin:/usr/local/hugo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/dotnet:/home/codespace/.dotnet/tools","rvm_bin_path":"/usr/local/rvm/bin","GEM_PATH":"/usr/local/rvm/gems/ruby-3.2.3:/usr/local/rvm/gems/ruby-3.2.3@global","GEM_HOME":"/usr/local/rvm/gems/ruby-3.2.3","GITHUB_CODESPACE_TOKEN":"BGKUF73YCD6VNGGOL3GMHZDF23VWPANCNFSM4AGSOXYA","LESSCLOSE":"/usr/bin/lesspipe %s %s","NVS_ROOT":"/usr/local/nvs","GITHUB_GRAPHQL_URL":"https://api.github.com/graphql","TERM":"xterm-256color","LESSOPEN":"| /usr/bin/lesspipe %s","USER":"codespace","NODE_ROOT":"/home/codespace/nvm","RBENV_DIR":"/workspaces/LSPtest","VSCODE_GIT_IPC_HANDLE":"/tmp/vscode-git-64520b8989.sock","PYTHONIOENCODING":"UTF-8","GITHUB_SERVER_URL":"https://github.com","NVS_HOME":"/usr/local/nvs","PIPX_HOME":"/usr/local/py-utils","CONDA_SCRIPT":"/opt/conda/etc/profile.d/conda.sh","MAVEN_HOME":"/usr/local/sdkman/candidates/maven/current","SDKMAN_DIR":"/usr/local/sdkman","SHLVL":"2","NVM_CD_FLAGS":"","ORYX_SDK_STORAGE_BASE_URL":"https://oryx-cdn.microsoft.io","GIT_EDITOR":"code --wait","CONDA_DIR":"/opt/conda","PROMPT_DIRTRIM":"4","SDKMAN_CANDIDATES_API":"https://api.sdkman.io/2","DOTNET_RUNNING_IN_CONTAINER":"true","DOTNET_USE_POLLING_FILE_WATCHER":"true","ENABLE_DYNAMIC_INSTALL":"true","rvm_ruby_string":"ruby-3.2.3","MAVEN_ROOT":"/home/codespace/.maven","ORYX_PREFER_USER_INSTALLED_SDKS":"true","JUPYTERLAB_PATH":"/home/codespace/.local/bin","RBENV_VERSION":"3.2.3","RVM_PATH":"/usr/local/rvm","GITHUB_REPOSITORY":"cal-bob/LSPtest","RAILS_DEVELOPMENT_HOSTS":".githubpreview.dev,.preview.app.github.dev,.app.github.dev","VSCODE_GIT_ASKPASS_MAIN":"/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/extensions/git/dist/askpass-main.js","RUBY_ROOT":"/home/codespace/.ruby","RUBY_HOME":"/usr/local/rvm/rubies/default","BROWSER":"/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/bin/helpers/browser.sh","PATH":"/home/codespace/.rbenv/versions/3.2.3/bin:/usr/local/share/rbenv/libexec:/home/codespace/.rbenv/plugins/ruby-build/bin:/usr/local/rvm/gems/ruby-3.2.3/bin:/usr/local/rvm/gems/ruby-3.2.3@global/bin:/usr/local/rvm/rubies/ruby-3.2.3/bin:/usr/local/rvm/bin:/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/bin/remote-cli:/home/codespace/.local/bin:/home/codespace/.dotnet:/home/codespace/nvm/current/bin:/home/codespace/.php/current/bin:/home/codespace/.python/current/bin:/home/codespace/java/current/bin:/home/codespace/.ruby/current/bin:/home/codespace/.local/bin:/usr/local/python/current/bin:/usr/local/py-utils/bin:/usr/local/oryx:/usr/local/go/bin:/go/bin:/usr/local/sdkman/bin:/usr/local/sdkman/candidates/java/current/bin:/usr/local/sdkman/candidates/gradle/current/bin:/usr/local/sdkman/candidates/maven/current/bin:/usr/local/sdkman/candidates/ant/current/bin:/usr/local/share/rbenv/bin:/usr/local/php/current/bin:/opt/conda/bin:/usr/local/nvs:/usr/local/share/nvm/versions/node/v20.11.0/bin:/usr/local/hugo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/dotnet:/home/codespace/.dotnet/tools","SDKMAN_PLATFORM":"linuxx64","NVM_BIN":"/usr/local/share/nvm/versions/node/v20.11.0/bin","IRBRC":"/usr/local/rvm/rubies/ruby-3.2.3/.irbrc","RUBYLIB":"/usr/local/share/rbenv/rbenv.d/exec/gem-rehash:","RBENV_ROOT":"/home/codespace/.rbenv","rvm_path":"/usr/local/rvm","OLDPWD":"/vscode/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681","GOPATH":"/go","TERM_PROGRAM":"vscode","VSCODE_IPC_HOOK_CLI":"/tmp/vscode-ipc-438158a3-1fc9-4b52-b0f9-d0798e6e6b65.sock"},"ruby_version":"3.2.3","yjit":null}RUBY_ENV_ACTIVATE
Ran rbenv global 3.2.3
Stopped codespace, restarted codespace, got this error:
2024-02-21 19:16:29.977 [info] (LSPtest) Checking if asdf is available on the path with command: /bin/bash -i -c 'asdf --version'
2024-02-21 19:16:32.160 [info] (LSPtest) Checking if chruby is available on the path with command: /bin/bash -i -c 'chruby --version'
2024-02-21 19:16:32.945 [info] (LSPtest) Checking if rbenv is available on the path with command: /bin/bash -i -c 'rbenv --version'
2024-02-21 19:16:33.945 [info] (LSPtest) Discovered version manager rbenv
2024-02-21 19:16:33.945 [info] (LSPtest) Trying to activate Ruby environment with command: /bin/bash -i -c 'rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /workspaces/LSPtest
2024-02-21 19:16:38.278 [info] (LSPtest) Starting Ruby LSP v0.14.1...
2024-02-21 19:16:38.524 [info] (LSPtest) Ruby LSP is ready
2024-02-21 19:17:46.263 [info] (LSPtest) Checking if asdf is available on the path with command: /bin/bash -i -c 'asdf --version'
2024-02-21 19:17:46.820 [info] (LSPtest) Checking if chruby is available on the path with command: /bin/bash -i -c 'chruby --version'
2024-02-21 19:17:47.375 [info] (LSPtest) Checking if rbenv is available on the path with command: /bin/bash -i -c 'rbenv --version'
2024-02-21 19:17:47.882 [info] (LSPtest) Discovered version manager rbenv
2024-02-21 19:17:47.882 [info] (LSPtest) Trying to activate Ruby environment with command: /bin/bash -i -c 'rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /workspaces/LSPtest
2024-02-21 19:17:48.881 [info] (LSPtest) Shutting down Ruby LSP...
2024-02-21 19:17:48.885 [info] (LSPtest) Shutdown complete with status 0
2024-02-21 19:17:48.927 [info] (LSPtest) [Error - 7:17:48 PM] Server process exited with code 0.
2024-02-21 19:17:49.507 [info] (LSPtest) Starting Ruby LSP v0.14.1...
2024-02-21 19:17:49.533 [info] (LSPtest) [Error - 7:17:49 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"found no changes, using resolution from the lockfile\ncontent-length":"1570"}
Shutting down server.
2024-02-21 19:17:49.535 [info] (LSPtest) [Error - 7:17:49 PM] Stopping server failed
2024-02-21 19:17:49.535 [info] (LSPtest) Error: Client is not running and can't be stopped. It's current state is: starting
at fs.shutdown (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8468)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8047)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:44:38186)
at fs.handleConnectionError (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-02-21 19:17:49.536 [info] (LSPtest) [Error - 7:17:49 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"0,\"result\":{\"capabilities\":{\"positionEncoding\":\"utf-16\",\"textDocumentSync\":{\"openClose\":true,\"change\":2},\"completionProvider\":{\"triggerCharacters\":[\"/\"],\"completionItem\":{\"labelDetailsSupport\":true}},\"hoverProvider\":{},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\" \",\",\"]},\"definitionProvider\":true,\"documentHighlightProvider\":true,\"documentSymbolProvider\":{\"symbolKind\":{\"value_set\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},\"hierarchicalDocumentSymbolSupport\":true},\"codeActionProvider\":{\"resolveProvider\":true},\"codeLensProvider\":{},\"documentLinkProvider\":{},\"documentFormattingProvider\":true,\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"{\",\"moreTriggerCharacter\":[\"\\n\",\"|\",\"d\"]},\"foldingRangeProvider\":{\"lineFoldingOnly\":true},\"selectionRangeProvider\":true,\"semanticTokensProvider\":{\"documentSelector\":{\"scheme\":\"file\",\"language\":\"ruby\"},\"legend\":{\"tokenTypes\":[\"namespace\",\"type\",\"class\",\"enum\",\"interface\",\"struct\",\"typeParameter\",\"parameter\",\"variable\",\"property\",\"enumMember\",\"event\",\"function\",\"method\",\"macro\",\"keyword\",\"modifier\",\"comment\",\"string\",\"number\",\"regexp\",\"operator\",\"decorator\"],\"tokenModifiers\":[\"declaration\",\"definition\",\"readonly\",\"static\",\"deprecated\",\"abstract\",\"async\",\"modification\",\"documentation\",\"default_library\"]},\"range\":true,\"full\":{\"delta\":false}},\"inlayHintProvider\":{},\"diagnosticProvider\":{\"interFileDependencies\":false,\"workspaceDiagnostics\":false},\"workspaceSymbolProvider\":true},\"serverInfo\":{\"name\":\"Ruby LSP\",\"version\":\"0.14.1\"},\"formatter\":\"none\"},\"jsonrpc\":\"2.0\"}Content-Length: 242"}
Shutting down server.
2024-02-21 19:17:49.536 [info] (LSPtest) [Error - 7:17:49 PM] Stopping server failed
2024-02-21 19:17:49.536 [info] (LSPtest) Error: Client is not running and can't be stopped. It's current state is: starting
at fs.shutdown (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8468)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:41:8047)
at fs.stop (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:44:38186)
at fs.handleConnectionError (/home/codespace/.vscode-remote/extensions/shopify.ruby-lsp-0.5.11/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Probably not quite germane to this as a Ruby LSP issue, but if it helps somehow: The reason I thought it was related to a formatter extension is because in previous apps on my main account, every time I attempted to format with rufo, it would format the file and then append "found no changes, using resolution from the lockfile" as plain text directly into line 1 of that file, which is text I've only been able to find in the Ruby LSP output as shown above. But maybe that's just a separate thing with Bundler.
Expected output
Not getting errors from Ruby LSP as soon as a codespace starts
Thanks for the bug report! This looks exactly like https://github.com/Shopify/ruby-lsp/issues/1675 and https://github.com/Shopify/ruby-lsp/issues/1723.
What Bundler version is your project locked to (the BUNDLED WITH entry in the lockfile)? Does upgrading bundler with bundle update --bundler make the error go away?
Also, do you have any Bundler related configurations? Either local to the project or the global one?
Basically, Bundler is printing a message to stdout which breaks the editor/server communication. We've been trying to figure how this is happening given that we set the Bundler UI level to silent to avoid this.
Whoa, sorry about the initial markdown mismatches - it didn't look like that in the preview before I published. Just fixed it.
lockfile: Bundled with 2.5.6
Ran bundle update --bundler but that did not seem to change anything.
Currently Ruby LSP seems to start fine when the codespace is first opened/refreshed:
2024-02-21 22:11:21.767 [info] (LSPtest) Checking if asdf is available on the path with command: /bin/bash -i -c 'asdf --version'
2024-02-21 22:11:21.788 [info] (LSPtest) Checking if chruby is available on the path with command: /bin/bash -i -c 'chruby --version'
2024-02-21 22:11:22.767 [info] (LSPtest) Checking if rbenv is available on the path with command: /bin/bash -i -c 'rbenv --version'
2024-02-21 22:11:23.547 [info] (LSPtest) Discovered version manager rbenv
2024-02-21 22:11:23.548 [info] (LSPtest) Trying to activate Ruby environment with command: /bin/bash -i -c 'rbenv exec ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /workspaces/LSPtest
2024-02-21 22:11:25.990 [info] (LSPtest) Starting Ruby LSP v0.14.1...
2024-02-21 22:11:26.298 [info] (LSPtest) Ruby LSP is ready
But if I go up top and run > Ruby LSP: Restart or > Ruby LSP: Stop followed by > Ruby LSP: Start, I still get the same error starting with the "Header must provide a Content-Length property" line.
My main account might have some special bundler configs inherited from class templates I've used (and I'm definitely a novice so I'm not sure I'd know for sure what's custom vs. default). But as far as I know the test app I based this issue on is about as clean slate/out-of-the-box as a codespaces or Rails setup can be, especially since I created a brand new GH account with it. There is no .bundle file after running bundle install. Closest I've got is bin/bundle:
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "rubygems"
m = Module.new do
module_function
def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end
def env_var_version
ENV["BUNDLER_VERSION"]
end
def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end
def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?
File.expand_path("../Gemfile", __dir__)
end
def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, ".locked")
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end
def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end
def bundler_requirement
@bundler_requirement ||=
env_var_version ||
cli_arg_version ||
bundler_requirement_for(lockfile_version)
end
def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version
bundler_gem_version = Gem::Version.new(version)
bundler_gem_version.approximate_recommendation
end
def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile
activate_bundler
end
def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end
def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end
m.load_bundler!
if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
If you don't have a .bundle directory in the project, do you have any configurations like DEBUG or VERBOSE in ~/.bundle/config?
Having the same problem. I'm on M1 Mac.
Bundler version is 2.5.6. I'm using RVM v1.29.12. Ruby 3.2.2 and Rails 7
I can run the server in the CLI without any problems.
I don't have a local or global .bundle/config, just the global cache directory.
Checked to make sure Ruby is compiled with YJIT support.
Nothing in my .bashrc should be interfering with this, tried turning everything off and still having the same problem.
Here's the output in case it helps:
2024-03-21 21:19:45.381 [info] (api) Trying to activate Ruby environment with command: /bin/bash -i -c 'rvm-auto-ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /Users/misham/Projects/propatienttech/api
2024-03-21 21:19:46.931 [info] (api) Ruby LSP> Skipping custom bundle setup since /Users/misham/Projects/propatienttech/api/.ruby-lsp/Gemfile.lock already exists and is up to date
2024-03-21 21:19:46.943 [info] (api) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
2024-03-21 21:19:47.204 [info] (api) Found no changes, using resolution from the lockfile
2024-03-21 21:19:47.224 [info] (api) The Gemfile's dependencies are satisfied
2024-03-21 21:19:48.294 [info] (api) Starting Ruby LSP v0.14.6...
2024-03-21 21:19:48.326 [info] (api) [Error - 9:19:48 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"found no changes, using resolution from the lockfile\ncontent-length":"1582"}
Shutting down server.
2024-03-21 21:19:48.327 [info] (api) [Error - 9:19:48 PM] Stopping server failed
2024-03-21 21:19:48.327 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at vs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8468)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8047)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:44:38355)
at vs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-03-21 21:19:48.328 [info] (api) [Error - 9:19:48 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"0,\"result\":{\"capabilities\":{\"positionEncoding\":\"utf-16\",\"textDocumentSync\":{\"openClose\":true,\"change\":2},\"completionProvider\":{\"triggerCharacters\":[\"/\",\"\\\"\",\"'\"],\"completionItem\":{\"labelDetailsSupport\":true}},\"hoverProvider\":{},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\" \",\",\"]},\"definitionProvider\":true,\"documentHighlightProvider\":true,\"documentSymbolProvider\":{\"symbolKind\":{\"value_set\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},\"hierarchicalDocumentSymbolSupport\":true},\"codeActionProvider\":{\"resolveProvider\":true},\"codeLensProvider\":{},\"documentLinkProvider\":{},\"documentFormattingProvider\":true,\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"{\",\"moreTriggerCharacter\":[\"\\n\",\"|\",\"d\"]},\"foldingRangeProvider\":{\"lineFoldingOnly\":true},\"selectionRangeProvider\":true,\"semanticTokensProvider\":{\"documentSelector\":{\"scheme\":\"file\",\"language\":\"ruby\"},\"legend\":{\"tokenTypes\":[\"namespace\",\"type\",\"class\",\"enum\",\"interface\",\"struct\",\"typeParameter\",\"parameter\",\"variable\",\"property\",\"enumMember\",\"event\",\"function\",\"method\",\"macro\",\"keyword\",\"modifier\",\"comment\",\"string\",\"number\",\"regexp\",\"operator\",\"decorator\"],\"tokenModifiers\":[\"declaration\",\"definition\",\"readonly\",\"static\",\"deprecated\",\"abstract\",\"async\",\"modification\",\"documentation\",\"default_library\"]},\"range\":true,\"full\":{\"delta\":false}},\"inlayHintProvider\":{},\"diagnosticProvider\":{\"interFileDependencies\":false,\"workspaceDiagnostics\":false},\"workspaceSymbolProvider\":true},\"serverInfo\":{\"name\":\"Ruby LSP\",\"version\":\"0.14.6\"},\"formatter\":\"rubocop\"},\"jsonrpc\":\"2.0\"}Content-Length: 242"}
Shutting down server.
2024-03-21 21:19:48.328 [info] (api) [Error - 9:19:48 PM] Stopping server failed
2024-03-21 21:19:48.328 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at vs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8468)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8047)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:44:38355)
at vs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Some more experiments. I tried out different versions of the plugin in VS Code. Between each version, I removed .ruby-lsp directory in the project folder.
The extensions worked with version 0.3.7. Everything newer than that had pretty much the same errors.
I just tried it again, with the latest version, 0.5.15, again remove the .ruby-lsp folder and got the following output:
2024-03-23 16:41:57.746 [info] (api) Trying to activate Ruby environment with command: /bin/bash -i -c 'rvm-auto-ruby -rjson -e "STDERR.printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump({ env: ENV.to_h, ruby_version: RUBY_VERSION, yjit: defined?(RubyVM::YJIT) }))"' inside directory: /Users/misham/Projects/propatienttech/api
2024-03-23 16:42:01.133 [error] (api) Failed to update global ruby-lsp gem: Error: Command failed: gem update ruby-lsp
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (Gem::RemoteFetcher::FetchError)
2024-03-23 16:42:02.487 [info] (api) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
2024-03-23 16:42:03.188 [info] (api) Found changes from the lockfile, re-resolving dependencies because the dependencies in your gemfile changed
2024-03-23 16:42:03.373 [info] (api) Resolving dependencies...
2024-03-23 16:42:03.690 [info] (api) The Gemfile's dependencies are satisfied
2024-03-23 16:42:05.575 [info] (api) Starting Ruby LSP v0.14.6...
2024-03-23 16:42:05.617 [info] (api) [Error - 4:42:05 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"found no changes, using resolution from the lockfile\ncontent-length":"1582"}
Shutting down server.
2024-03-23 16:42:05.618 [info] (api) [Error - 4:42:05 PM] Stopping server failed
2024-03-23 16:42:05.618 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at vs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8468)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8047)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:44:38355)
at vs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-03-23 16:42:05.618 [info] (api) [Error - 4:42:05 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"0,\"result\":{\"capabilities\":{\"positionEncoding\":\"utf-16\",\"textDocumentSync\":{\"openClose\":true,\"change\":2},\"completionProvider\":{\"triggerCharacters\":[\"/\",\"\\\"\",\"'\"],\"completionItem\":{\"labelDetailsSupport\":true}},\"hoverProvider\":{},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\" \",\",\"]},\"definitionProvider\":true,\"documentHighlightProvider\":true,\"documentSymbolProvider\":{\"symbolKind\":{\"value_set\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},\"hierarchicalDocumentSymbolSupport\":true},\"codeActionProvider\":{\"resolveProvider\":true},\"codeLensProvider\":{},\"documentLinkProvider\":{},\"documentFormattingProvider\":true,\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"{\",\"moreTriggerCharacter\":[\"\\n\",\"|\",\"d\"]},\"foldingRangeProvider\":{\"lineFoldingOnly\":true},\"selectionRangeProvider\":true,\"semanticTokensProvider\":{\"documentSelector\":{\"scheme\":\"file\",\"language\":\"ruby\"},\"legend\":{\"tokenTypes\":[\"namespace\",\"type\",\"class\",\"enum\",\"interface\",\"struct\",\"typeParameter\",\"parameter\",\"variable\",\"property\",\"enumMember\",\"event\",\"function\",\"method\",\"macro\",\"keyword\",\"modifier\",\"comment\",\"string\",\"number\",\"regexp\",\"operator\",\"decorator\"],\"tokenModifiers\":[\"declaration\",\"definition\",\"readonly\",\"static\",\"deprecated\",\"abstract\",\"async\",\"modification\",\"documentation\",\"default_library\"]},\"range\":true,\"full\":{\"delta\":false}},\"inlayHintProvider\":{},\"diagnosticProvider\":{\"interFileDependencies\":false,\"workspaceDiagnostics\":false},\"workspaceSymbolProvider\":true},\"serverInfo\":{\"name\":\"Ruby LSP\",\"version\":\"0.14.6\"},\"formatter\":\"rubocop\"},\"jsonrpc\":\"2.0\"}Content-Length: 242"}
Shutting down server.
2024-03-23 16:42:05.618 [info] (api) [Error - 4:42:05 PM] Stopping server failed
2024-03-23 16:42:05.618 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at vs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8468)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:41:8047)
at vs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:44:38355)
at vs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.15/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
We need to understand why only RVM gets these verbose prints from Bundler, even when we explicitly set the logging level to silent. This does not seem to happen for any other version manager.
I have a PR open to restructure the RVM activation. It should print the environment variables that are being activated when invoking RVM and hopefully that will shed some light into what is forcing Bundler into printing things to STDOUT (which is what ends up messing the server communication with the editor).
If an RVM user is up for testing the PR, here are the instructions:
- Clone this repo
- Switch to the branch on the PR
git checkout vs/migrate_rvm - Ensure node dependencies are installed
cd vscode && yarn install - Go into the
Run and debugpanel in VS Code - Select the
Run extensiontask - Click run. This will open a second window, which is running the development version of the extension
- On the second window, open a Ruby project using RVM to manage its Ruby version
- Did the LSP boot properly with the new implementation?
- If not, in the second window, go into
Outputand select theRuby LSPchannel. It should have printed the activated environment. Are there any environment variables that could be making Bundler print to STDOUT? Things likeVERBOSE,DEBUGor anything includingBUNDLE
I've just released https://github.com/Shopify/ruby-lsp/releases/tag/vscode-ruby-lsp-v0.5.16 with the updated RVM activation. Can someone please give it a try and report back if you find any issues?
@vinistock Thanks for continuing to work on this, really appreciate it.
Just tried it out. (deleted my earlier comment, messed something up). Running v0.5.16. The output is pretty long and looks like the extension retries a few times. See the output below, but tl;dr; is it's not finding libpq cause it was installed via Homebrew.
I don't have any include paths or LD paths setup in my environment. I'm guessing RVM is doing some magic to load the Homebrew versions when running bundle install but I have no idea. Somehow that's not getting picked up when the extension is installing the needed gems.
The output is way too long to paste here, instead here's the gist of it: https://gist.github.com/misham/9a4c5e7ec34144015681479c9555db35
@misham thank you for the output, that's really helpful. From the output, bundler is clearly being executed with verbose mode (you don't get that many prints with verbose mode off), which explains why stuff is being printed to STDOUT, messing up the communication with the editor. It's still unclear why. Does RVM always run Bundler with verbose mode? Is there a configuration in RVM setting verbose mode on?
Concerning installing PG, you'll probably need to configure ~/.bundle/config so that it looks for the libraries in the Homebrew installation. That should probably fix it.
@vinistock I don't see where RVM uses verbose mode for bundle. Running the command from the CLI doesn't output anything extra.
I dug through RVM docs and code and I'm not seeing it defaulting to debug output. Based on the below error, I'm wondering if the issue is with how the shell is created within VS Code to execute rvm.
FWIW, I tried running it in bash (my default) and zsh and getting the same results.
Here's another error that I'm getting within VS Code but it works just fine in terminal:
Failed to activate rvm environment: Command failed: /bin/bash -ic 'rvm-auto-ruby --disable-gems -rjson -e "printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump(ENV.to_h))"' bash: no job control in this shell bash: brew: command not found bash: bat: command not found bash: bat: command not found bash: brew: command not found bash: /etc/bash_completion: No such file or directory bash: brew: command not found bash: /nvm.sh: No such file or directory bash: starship: command not found bash: rvm-auto-ruby: command not found
We just released https://github.com/Shopify/ruby-lsp/releases/tag/vscode-ruby-lsp-v0.5.17, with some RVM fixes. Can you please give it a try and let us know if the issue has been fixed?
@vinistock Same problem :(
Would it help if you generated a debug build that I can run locally to test out?
Here's output from bash (my default)
2024-04-03 15:18:36.322 [info] (api) Activated Ruby environment: GEM_HOME=/Users/misham/.local/share/gem/ruby/3.2.0 GEM_PATH=/Users/misham/.local/share/gem/ruby/3.2.0:/Users/misham/.rvm/rubies/ruby-3.2.2/lib/ruby/gems/3.2.0 PATH=/Users/misham/.local/share/gem/ruby/3.2.0/bin:/Users/misham/.rvm/rubies/ruby-3.2.2/lib/ruby/gems/3.2.0/bin:/Users/misham/.rvm/rubies/ruby-3.2.2/bin:/usr/bin:/bin:/usr/sbin:/sbin
2024-04-03 15:18:38.453 [error] (api) Failed to update global ruby-lsp gem: Error: Command failed: gem update ruby-lsp
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (Gem::RemoteFetcher::FetchError)
2024-04-03 15:18:38.895 [info] (api) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
2024-04-03 15:18:39.082 [info] (api) Found changes from the lockfile, re-resolving dependencies because the dependencies in your gemfile changed
2024-04-03 15:18:39.169 [info] (api) Resolving dependencies...
2024-04-03 15:18:39.354 [info] (api) The Gemfile's dependencies are satisfied
2024-04-03 15:18:40.541 [info] (api) Starting Ruby LSP v0.14.6...
2024-04-03 15:18:40.573 [info] (api) [Error - 3:18:40 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"found no changes, using resolution from the lockfile\ncontent-length":"1582"}
Shutting down server.
2024-04-03 15:18:40.574 [info] (api) [Error - 3:18:40 PM] Stopping server failed
2024-04-03 15:18:40.574 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at Cs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:41:8468)
at Cs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:41:8047)
at Cs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:44:38355)
at Cs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-04-03 15:18:40.574 [info] (api) [Error - 3:18:40 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"{\"id\"":"0,\"result\":{\"capabilities\":{\"positionEncoding\":\"utf-16\",\"textDocumentSync\":{\"openClose\":true,\"change\":2},\"completionProvider\":{\"triggerCharacters\":[\"/\",\"\\\"\",\"'\"],\"completionItem\":{\"labelDetailsSupport\":true}},\"hoverProvider\":{},\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\",\" \",\",\"]},\"definitionProvider\":true,\"documentHighlightProvider\":true,\"documentSymbolProvider\":{\"symbolKind\":{\"value_set\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},\"hierarchicalDocumentSymbolSupport\":true},\"codeActionProvider\":{\"resolveProvider\":true},\"codeLensProvider\":{},\"documentLinkProvider\":{},\"documentFormattingProvider\":true,\"documentOnTypeFormattingProvider\":{\"firstTriggerCharacter\":\"{\",\"moreTriggerCharacter\":[\"\\n\",\"|\",\"d\"]},\"foldingRangeProvider\":{\"lineFoldingOnly\":true},\"selectionRangeProvider\":true,\"semanticTokensProvider\":{\"documentSelector\":{\"scheme\":\"file\",\"language\":\"ruby\"},\"legend\":{\"tokenTypes\":[\"namespace\",\"type\",\"class\",\"enum\",\"interface\",\"struct\",\"typeParameter\",\"parameter\",\"variable\",\"property\",\"enumMember\",\"event\",\"function\",\"method\",\"macro\",\"keyword\",\"modifier\",\"comment\",\"string\",\"number\",\"regexp\",\"operator\",\"decorator\"],\"tokenModifiers\":[\"declaration\",\"definition\",\"readonly\",\"static\",\"deprecated\",\"abstract\",\"async\",\"modification\",\"documentation\",\"default_library\"]},\"range\":true,\"full\":{\"delta\":false}},\"inlayHintProvider\":{},\"diagnosticProvider\":{\"interFileDependencies\":false,\"workspaceDiagnostics\":false},\"workspaceSymbolProvider\":true},\"serverInfo\":{\"name\":\"Ruby LSP\",\"version\":\"0.14.6\"},\"formatter\":\"rubocop\"},\"jsonrpc\":\"2.0\"}Content-Length: 242"}
Shutting down server.
2024-04-03 15:18:40.575 [info] (api) [Error - 3:18:40 PM] Stopping server failed
2024-04-03 15:18:40.575 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at Cs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:41:8468)
at Cs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:41:8047)
at Cs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:44:38355)
at Cs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.16/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Here's output from switching to Zsh (just default config on Mac)
2024-04-03 15:35:18.959 [info] (api) Activated Ruby environment: SHELL=/bin/bash XPC_FLAGS=0x0 NVM_INC=/Users/misham/.nvm/versions/node/v20.11.0/include/node HISTCONTROL=ignoredboth rvm_delete_flag=0 CONDA_EXE=/opt/homebrew/Caskroom/miniforge/base/bin/conda rvm_prefix=/Users/misham HISTSIZE=10000 LESS_TERMCAP_se=[0m LESS_TERMCAP_so=[01;44;33m __CFBundleIdentifier=com.microsoft.VSCode SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.36vqgolQS1/Listeners MallocNanoZone=0 ELECTRON_RUN_AS_NODE=1 MY_RUBY_HOME=/Users/misham/.rvm/rubies/ruby-3.2.2 VSCODE_AMD_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess GPG_TTY=not a tty EDITOR=vim RUBY_VERSION=ruby-3.2.2 PROJECT_DIR=Projects PWD=/Users/misham/Projects/propatienttech/api LOGNAME=misham CONDA_PREFIX=/opt/homebrew/Caskroom/miniforge/base rvm_trust_rvmrcs_flag=1 rvm_version=1.29.12 (latest) rvm_pretty_print_flag=1 VSCODE_CODE_CACHE_PATH=/Users/misham/Library/Application Support/Code/CachedData/863d2581ecda6849923a2118d93a088b0745d9d6 COMMAND_MODE=unix2003 HOME=/Users/misham rvmmake_flags=-j 4 VSCODE_IPC_HOOK=/Users/misham/Library/Application Support/Code/1.87-main.sock STARSHIP_SHELL=bash CONDA_PROMPT_MODIFIER=(base) TMPDIR=/var/folders/0j/b6l2sbsj3298hkd16_f77fb40000gn/T/ BASH_SILENCE_DEPRECATION_WARNING=1 STARSHIP_SESSION_KEY=2671316606313373 rvm_gem_options=--no-rdoc --no-ri NVM_DIR=/Users/misham/.nvm rvm_bin_path=/Users/misham/.rvm/bin GEM_PATH=/Users/misham/.rvm/gems/ruby-3.2.2@propatienttech-api:/Users/misham/.rvm/gems/ruby-3.2.2@global GEM_HOME=/Users/misham/.rvm/gems/ruby-3.2.2@propatienttech-api LESS_TERMCAP_mb=[01;31m LESS_TERMCAP_me=[0m LESS_TERMCAP_md=[01;31m USER=misham CONDA_SHLVL=1 VSCODE_PID=78029 SHLVL=2 LESS_TERMCAP_ue=[0m LESS_TERMCAP_us=[01;32m VSCODE_CWD=/ rvm_ruby_string=ruby-3.2.2 XPC_SERVICE_NAME=application.com.microsoft.VSCode.93022823.93022829 CONDA_PYTHON_EXE=/opt/homebrew/Caskroom/miniforge/base/bin/python rvm_autoupdate_flag=2 VSCODE_CRASH_REPORTER_PROCESS_TYPE=extensionHost CONDA_DEFAULT_ENV=base GCC_COLORS=error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01 PATH=/Users/misham/.rvm/gems/ruby-3.2.2@propatienttech-api/bin:/Users/misham/.rvm/gems/ruby-3.2.2@global/bin:/Users/misham/.rvm/rubies/ruby-3.2.2/bin:/Users/misham/.rvm/bin:/opt/homebrew/Caskroom/miniforge/base/bin:/opt/homebrew/Caskroom/miniforge/base/condabin:/Users/misham/.nvm/versions/node/v20.11.0/bin:/usr/local/bin:/sbin:/usr/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/misham/bin:/Users/misham/.local/bin:/Users/misham/go/bin:/Users/misham/.poetry/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin HISTFILESIZE=10000 ORIGINAL_XDG_CURRENT_DESKTOP=undefined VSCODE_NLS_CONFIG={"locale":"en-us","osLocale":"en-us","availableLanguages":{},"_languagePackSupport":true} NVM_BIN=/Users/misham/.nvm/versions/node/v20.11.0/bin tmp_path=/usr/local/bin:/sbin:/usr/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/misham/bin:/Users/misham/.local/bin:/Users/misham/go/bin:/Users/misham/.poetry/bin:/Users/misham/.rvm/bin IRBRC=/Users/misham/.rvm/rubies/ruby-3.2.2/.irbrc VSCODE_HANDLES_UNCAUGHT_ERRORS=true rvm_path=/Users/misham/.rvm GOPATH=/Users/misham/go __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
2024-04-03 15:35:24.184 [error] (api) Failed to update global ruby-lsp gem: Error: Command failed: gem update ruby-lsp
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
bad response Not Found 404 (Gem::RemoteFetcher::FetchError)
2024-04-03 15:35:24.944 [info] (api) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
2024-04-03 15:35:25.325 [info] (api) Found changes from the lockfile, re-resolving dependencies because the dependencies in your gemfile changed
2024-04-03 15:35:25.597 [info] (api) Resolving dependencies...
2024-04-03 15:35:26.846 [info] (api) The Gemfile's dependencies are satisfied
2024-04-03 15:35:30.063 [info] (api) Starting Ruby LSP v0.14.6...
2024-04-03 15:35:30.064 [info] (api) [Error - 3:35:30 PM] Client Ruby LSP: connection to server is erroring.
Header must provide a Content-Length property.
{"found no changes, using resolution from the lockfile\ncontent-length":"1582"}
Shutting down server.
2024-04-03 15:35:30.065 [info] (api) [Error - 3:35:30 PM] Stopping server failed
2024-04-03 15:35:30.066 [info] (api) Error: Client is not running and can't be stopped. It's current state is: starting
at Cs.shutdown (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.17/out/extension.js:41:8468)
at Cs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.17/out/extension.js:41:8047)
at Cs.stop (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.17/out/extension.js:44:38355)
at Cs.handleConnectionError (/Users/misham/.vscode/extensions/shopify.ruby-lsp-0.5.17/out/extension.js:43:63)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Thanks for sharing the outputs, this is super helpful. The first one is quite strange as no environment variable was exported from the script, but the second seems a lot more promising. You can see that RVM properly set GEM_HOME, GEM_PATH, etc.
Concerning the verbose printing, I suspect rvm_pretty_print_flag=1 might be the culprit here. Looking at https://github.com/rvm/rvm/blob/a9c478dea7d097b3403461cb8e7c2515575a3bc7/scripts/functions/logging#L84, it seems like the flag decides whether to print stuff to STDOUT or not.
Do you have that configured anywhere in your rvmrc files or shell configurations? If we can determine that this is indeed what causes the prints, then we can automatically remove that when activating RVM.
Same problem setting rvm_pretty_print_flag=0.
I really want to fix this, but I honestly have no clue how Bundler gets into this verbose mode only for RVM users. Let's see if printing the environment and the Bundler settings before booting the server shines a light on what is happening.
If you do the following:
- Open the Ruby LSP code for editing
BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle open ruby-lsp - Then above this line https://github.com/Shopify/ruby-lsp/blob/044568eb7de2f6bc10ee9e012c213804e7663412/exe/ruby-lsp#L89, put these prints (must be stderr or it'll mess up the communication with the editor)
# Print env
$stderr.puts(ENV.to_h)
# Print Bundler settings
$stderr.puts(Bundler.settings.all)
# Print the Bundler UI level (which should be silent since we force that)
$stderr.puts(Bundler.ui.level)
Do you see anything that might be putting Bundler into verbose mode? Any setting or env variable named verbose, debug or similar?
@vinistock thanks so much for continuing to troubleshoot this problem.
I solved it :) The offending issue is the official MongoDB extension 👎
You can see there's an environment variable set in what I posted above: DEBUG=WARN.
I tried unsettling it in the ruby-lsp gem, just before the $stderr.puts, but that did nothing. Well, it did unset the var, but the bundler output was still in verbose mode.
After going through each extension one by one, removing Mongo's made everything work again.
From my end, I consider the issue solved cause I couldn't care less about Mongo; it's screwing me over yet again.
Again, HUGE thanks for the patience, perseverance, awesome support, and the work you're doing on this extension.
@misham thank you so much for the kind words, you've made my day.
Also, thank you for reporting back the solution. I think we can apply this generally in the extension, as we would never want DEBUG or VERBOSE to be a part of the environment variables passed to the server Ruby process.
The associated PR sanitizes the environment to always remove those automatically, which should hopefully fix this for everybody.