[VS Code] Resolve ruby path correctly with chruby#3978
[VS Code] Resolve ruby path correctly with chruby#3978davletovalmir wants to merge 1 commit intoShopify:mainfrom
Conversation
|
I have signed the CLA! |
|
Thank you for the PR. I believe this is something specific to your setup. If you take a look at the implementation, chruby overrides You're correct that if you're using 3.2.3, the default Do you have any additional RubyGems or Bundler settings? Also, keep in mind that any configurations you make in shell scripts are not applied to the VS Code NodeJS process. So if you have any RubyGems, Bundler or even chruby configurations in something like |
|
Hey @vinistock, thanks for the response! My setup is standard The core issue is that But standard chruby sets With chruby env:Gem.path => ["~/.gem/ruby/3.2.3", "~/.rubies/ruby-3.2.3/lib/ruby/gems/3.2.0"]
Gem.user_dir => "~/.gem/ruby/3.2.0"
paths.length => 2 # condition > 2 is false, block is skippedWithout chruby env:Gem.path => ["~/.gem/ruby/3.2.0", "~/.rubies/ruby-3.2.3/lib/ruby/gems/3.2.0"]
Gem.user_dir => "~/.gem/ruby/3.2.0"
paths.length => 2 # sameThe > 2 guard would only be true if something external pre-populates I realize the UPD: for me |
Motivation
In VS Code and its forks (like
CurserCursor) Ruby LSP doesn't work as intended (if I did interpret the comment invscode/chruby_activation.rbcorrectly LOL).There is sentence in the comment:
I read this as: if we have ruby path with patch version (e.g.
"/home/user/.gem/ruby/3.2.3") we should use it instead of no-patch one (e.g."/home/user/.gem/ruby/3.2.0").But look at the snippet output below:
Maybe it's just my setup, but I have exactly 2 paths. And condition never resolves, leaving me with gems installed by Ruby LSP in the wrong directory (the default one, that we tried to avoid).
Implementation
Path size checking condition is not needed, as
Array#deleteis safe for misses, andfirst_path's existence is checked anyways. So in case of any troubles (aka the only ruby version I have is the one without patch, and thusGem.pathreturns exactly one path) - we still fall back toGem.user_dir.Automated Tests
N/A
Manual Tests
$MY_PROJECT_DIR/.ruby-lsp/home/user/.gem/ruby/3.2.0