Shopify / ruby-lsp

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

Unable to Start Ruby-LSP with VS Code and WSL2 #2580

Open jakecomp opened 1 month ago

jakecomp commented 1 month ago

Description

Hello There 👋

I'm just entering the wonderful world of ruby and currently I'm trying to get ruby-lsp installed on vscode. Below are the details of the error that I'm running into.

Ruby LSP Information

VS Code Version

1.93.1

Ruby LSP Extension Version

0.8.0

Ruby LSP Server Version

Unknown

Ruby LSP Addons

Ruby Version

Unknown

Ruby Version Manager

rbenv

Installed Extensions

Click to expand - vscode-rdbg (0.2.2) - vscode-docker (1.29.2) - ruby-extensions-pack (0.1.12) - ruby-lsp (0.8.0) - sorbet-vscode-extension (0.3.36)

Ruby LSP Settings

Click to expand ##### Workspace ```json {} ``` ##### User ```json { "enableExperimentalFeatures": false, "enabledFeatures": { "codeActions": true, "diagnostics": true, "documentHighlights": true, "documentLink": true, "documentSymbols": true, "foldingRanges": true, "formatting": true, "hover": true, "inlayHint": true, "onTypeFormatting": true, "selectionRanges": true, "semanticHighlighting": true, "completion": true, "codeLens": true, "definition": true, "workspaceSymbol": true, "signatureHelp": true, "typeHierarchy": true }, "featuresConfiguration": {}, "addonSettings": {}, "rubyVersionManager": { "identifier": "rbenv" }, "customRubyCommand": "", "formatter": "auto", "linters": null, "bundleGemfile": "", "testTimeout": 30, "branch": "", "pullDiagnosticsOn": "both", "useBundlerCompose": false, "bypassTypechecker": false, "rubyExecutablePath": "\\\\wsl.localhost\\Ubuntu\\root\\.rbenv\\versions\\3.3.4\\bin\\ruby", "indexing": {}, "erbSupport": true } ```

VS Code Specs

Version: 1.93.1 (user setup) Commit: 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40 Date: 2024-09-11T17:20:05.685Z Electron: 30.4.0 ElectronBuildId: 10073054 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.22631

OS Specs

Edition Windows 11 Home Version 23H2 Installed on ‎2023-‎03-‎06 OS build 22631.4037 Serial number PF3X5QHN Experience Windows Feature Experience Pack 1000.22700.1027.0

Ruby Version

root@Jakobslenovo:/mnt/c/Users/jake1/GameStonk# which ruby
/root/.rbenv/shims/ruby
root@Jakobslenovo:/mnt/c/Users/jake1/GameStonk# ruby --version
ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x86_64-linux]
root@Jakobslenovo:/mnt/c/Users/jake1/GameStonk#

Rbenv Version

rbenv 1.1.2

WSL2 Version

WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22631.4037

Ubuntu Version

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

Reproduction steps

  1. Start Up VS Code with WSL2 terminal
  2. Open a Ruby file
  3. ruby-lsp status mentions "Using Ruby undefined with rbenv"
  4. Select "Change manual ruby configuration", then select path to ruby binary as directed
  5. See the following error pop up in VS Code:
Command failed: \\wsl.localhost\Ubuntu\root\.rbenv\versions\3.3.4\bin\ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'

I've confirmed that the ruby-lsp gem is installed but I've had no luck starting up the lsp. It keeps prompting me to point to the path of the ruby binary I want to use but I continually get the same error above. Any help is much appreciated!

Image

jakecomp commented 1 month ago

FWIW I tried running

ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'

Directly in my WSL terminal and I see the following output which looks promising:

{"env":{"SHELL":"/bin/bash","WSL2_GUI_APPS_ENABLED":"1","WSL_DISTRO_NAME":"Ubuntu","RBENV_HOOK_PATH":"/root/.rbenv/rbenv.d:/usr/lib/rbenv/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks","NAME":"Jakobslenovo","PWD":"/mnt/c/Users/jake1/GameStonk","LOGNAME":"root","HOME":"/root","LANG":"C.UTF-8","WSL_INTEROP":"/run/WSL/2799_interop","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:.webp=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:","WAYLAND_DISPLAY":"wayland-0","LESSCLOSE":"/usr/bin/lesspipe %s %s","TERM":"xterm-256color","LESSOPEN":"| /usr/bin/lesspipe %s","USER":"root","RBENV_DIR":"/mnt/c/Users/jake1/GameStonk","DISPLAY":":0","SHLVL":"1","RBENV_VERSION":"3.3.4","XDG_RUNTIME_DIR":"/run/user/0/","WSLENV":"","XDG_DATA_DIRS":"/usr/local/share:/usr/share:/var/lib/snapd/desktop","PATH":"/root/.rbenv/versions/3.3.4/bin:/usr/lib/rbenv/libexec:/root/.rbenv/plugins/ruby-build/bin:/root/.rbenv/shims:/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/Program Files/Git/cmd:/mnt/c/Users/jake1/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/jake1/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/0/bus","HOSTTYPE":"x86_64","PULSE_SERVER":"unix:/mnt/wslg/PulseServer","RBENV_ROOT":"/root/.rbenv"},"yjit":false,"version":"3.3.4"}

But running this directly hasn't solved the current issue, as the status still states "Using Ruby undefined with rbenv" 🤔

vinistock commented 1 month ago

I'm just entering the wonderful world of ruby

Welcome! And thank you for the bug report.

We've had other reports of people having difficulties on Windows with WSL, so we are in need of better documentation on how to configure this setup.

My suspicion is that VS Code is running on the host machine (Windows) without connecting to the Linux subsystem. It's similar to how developing on containers work: you have to connect VS Code to the container, so that every part of the editor (including extensions) can run where your code exists.

VS Code has some documentation explaining exactly this. How certain extensions are UI-only and can run in the host machine and others need access to the file system where the code exists (like the terminal, the debugger and language servers such as the Ruby LSP).

Did you already follow the instructions on their documentation?

wojcraft commented 1 month ago

The same problem as @jakecomp.

It writes Ruby LSP: Starting and it doesn't seem to work at all. How to follow this documentation? There are no steps for it to be done :(

Here's screenshot: Image