Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve chruby handling for missing .ruby-version and missing Ruby installations #2793

Open
vinistock opened this issue Oct 28, 2024 · 2 comments
Labels
enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes

Comments

@vinistock
Copy link
Member

There are some corner cases for our chruby integration that aren't very user friendly at the moment.

Missing .ruby-version file

There are two ways to define a "global" Ruby version with chruby. The first one is to set the version via a shellscript, which doesn't do anything in the editor since the NodeJS process running the extension is not sourcing those files. It only impacts the terminal.

The second one is to define a .ruby-version in a parent directory. Chruby goes up directories trying to find a .ruby-version file. I had assumed that this was quite common and the standard way of using chruby, but based on our telemetry this is clearly not the case.

The question then becomes what to do if we can't find a .ruby-version in any of the parent directories. We can try to launch with whatever is the latest Ruby installed, but that may conflict with the Ruby constraints defined in the Gemfile, which will fail to launch the language server. We could first check if the Gemfile has that constraint, but that may also mean having to parse the constraints ourselves (e.g.: ruby "~> 3.1").

We can also try to better explain that adding a .ruby-version in parent directories serves as the fallback, but that will still require manual intervention from the user, even if it's just clicking a button to create the new file.

Whatever we end up deciding here, it's really important to show in the UI what happened, so that it's clear why the LSP is running with a specific Ruby version.

Missing rubies

The second part of the problem is when there is a .ruby-version file, but the version specified is not installed. This is in part related to #2173.

We could also try to launch with an alternative Ruby, but we face similar limitations as the ones described previously with Gemfile constraints.

We also don't know how to install rubies for chruby since the tool doesn't come with Ruby installation. People can use whatever they want to install Ruby (Homebrew, ruby-install, ruby-build) and then use chruby only for switching versions, which limits what we can offer as part of the experience here.

It might be possible, although a higher maintenance cost, to introduce integration with Ruby installers in addition to version "switchers". That way, for tools like chruby that only support switching versions, we can try to discover what the user has available to install rubies and offer to use that.

@vinistock vinistock added enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes labels Oct 28, 2024
@leewaa
Copy link

leewaa commented Nov 8, 2024

Don't mean to hijack here, but I wanted to raise awareness as to push for this issue.

I'm using sublime text 4 and chruby. I simply cannot get ruby-lsp to work without adding a hardcoded path to the ruby version in the LSP config. I also have no idea where the version miss-match is coming from and cannot debug it. Generally I always define .ruby-version file for all of my rails/ruby projects.

According to the docs, the setup should simply work out of the box. As I said, I cannot see where ruby-lsp is getting it's ruby version from.

@vinistock
Copy link
Member Author

This issue is related to our chruby integration for the VS Code extension, which you can't use in Sublime. Since you already created a separate issue for Sublime, let's centralize the discussions there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

No branches or pull requests

2 participants