Skip to content

[VS Code] Resolve ruby path correctly with chruby#3978

Open
davletovalmir wants to merge 1 commit intoShopify:mainfrom
davletovalmir:patch-1
Open

[VS Code] Resolve ruby path correctly with chruby#3978
davletovalmir wants to merge 1 commit intoShopify:mainfrom
davletovalmir:patch-1

Conversation

@davletovalmir
Copy link

Motivation

In VS Code and its forks (like Curser Cursor) Ruby LSP doesn't work as intended (if I did interpret the comment in vscode/chruby_activation.rb correctly LOL).

There is sentence in the comment:

In our activation script, we check if a directory using the patch exists and then prefer that over the default one.

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:

irb(main):011> Gem.path
=> ["/home/user/.gem/ruby/3.2.3", "/home/user/.rubies/ruby-3.2.3/lib/ruby/gems/3.2.0"]
irb(main):012> Gem.user_dir
=> "/home/user/.gem/ruby/3.2.0"

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#delete is safe for misses, and first_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 thus Gem.path returns exactly one path) - we still fall back to Gem.user_dir.

Automated Tests

N/A

Manual Tests

  • Removed $MY_PROJECT_DIR/.ruby-lsp
  • Removed /home/user/.gem/ruby/3.2.0
  • Restarted VS Code
  • Checked Output of Ruby LSP
  • Paths are resolved properly 🎉

@davletovalmir davletovalmir requested a review from a team as a code owner February 25, 2026 22:23
@davletovalmir
Copy link
Author

I have signed the CLA!

@vinistock
Copy link
Member

Thank you for the PR. I believe this is something specific to your setup. If you take a look at the implementation, chruby overrides $GEM_HOME using the exact Ruby version for the project.

You're correct that if you're using 3.2.3, the default $GEM_HOME is ~/.gem/3.2.0, but it gets overridden by chruby.

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 ~/.zshrc, the extension may not know about them.

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 this pull request may close these issues.

2 participants