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

Unable to activate vscode ruby lsp extension due to failing to globally gem install ruby lsp and other gems #1882

Open
robertfromsms opened this issue Apr 4, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@robertfromsms
Copy link

Description

Reproduction steps

System Combination:
platform: Mac OS
IDE: VScode
Ruby version: 3.3.0
ruby version control: none in the docker container
docker user permission: does not have global write permission
Other vscode extensions: dev containers
BUNDLE_PATH: project's vendor/bundle

Steps:

  • docker compose up to spin up all services/containers
  • use dev containers extension to go into rails project container
  • Ruby LSP restart server
  • fails on i guess globally installing ruby-lsp, ruby-lsp-rails and debug, (no write permission)

Current work around:

  • include in Dockerfile, RUN gem install ruby-lsp ruby-lsp-rails debug
  • those will get installed globally
  • vscode ruby lsp extension sees they are installed globally, um... sets up .ruby-lsp folder in rails project
  • then at some point vscode ruby lsp extension sees that my BUNDLE_PATH is pointing at rails project's vendor/bundle
  • it then install all of the things (ruby-lsp, ruby-lsp-rails, debug, and i guess all of the dependencies?) under vendor/bundle
  • extension then works as intended.

Desired Behavior:

  • can the extension just sees that the current user can't install stuff globally then falls back to idk maybe installing ruby-lsp, ruby-lsp-rails and debug at another place that I tell it to?
  • Or maybe can it just fall back to installing everything under what i set BUNDLE_PATH to be?
  • I mean as long as you guys don't include more gems than ruby-lsp, ruby-lsp-rails and debug as the "starting point"? then this work around will still work, but it's definitely not ideal, maybe update in instructions/readme for folks developing in a container/other situations where the user can't install gems globally to have those gems already installed? Or update the error output to be like, "you need to install these gems ahead of time."
@robertfromsms robertfromsms added the bug Something isn't working label Apr 4, 2024
@vinistock
Copy link
Member

Thank you for the bug report!

Rubygems already provides an option to choose where gems installed via gem install end up. It does need to be configured apart from Bundler. The bundle path configuration is not re-used by rubygems.

If you specify the install directory in your ~/.gemrc file, does that work?

# ~/.gemrc
install-dir: wherever/you/want/to/install/gems

If that works, then I don't believe we should add any extra settings for the VS Code extension. Better to reuse rubygems own configuration and have consistency between the extension and what happens on the terminal.

Although, it would be great to document this since the question has come up more than once.

@robertfromsms
Copy link
Author

So I'm guessing that the vscode extension will either use gem install or somehow listen to configurations set for rubygems, such as setting the install-dir. I'm also guessing that the gems don't have to installed in specific ways related to where ruby is installed.

I have to rework my dockerfile, it's a good opportunity.

I think in terms of documentation, you can definitely mention that if you don't have write permission in some way (like using docker), you would either have to globally install those 3 gems before (with elevated permissions or when you would have elevated permissions, like in dockerfile)...
or you can configure rubygems to install to somewhere you/vscode will have write permission... I haven't tried that configurating install-dir in .gemrc, I'm sure it will work, but I sorta have to rework my dockerfile to have stuff setup correctly.
I feel like no additional development is necessary, but would probably be fantastic; I think having documentations for work around/configuring .gemrc would be sufficient.

@vinistock
Copy link
Member

So I'm guessing that the vscode extension will either use gem install or somehow listen to configurations set for rubygems, such as setting the install-dir. I'm also guessing that the gems don't have to installed in specific ways related to where ruby is installed.

We run gem install ruby-lsp, so that we can launch the ruby-lsp executable. Launching that will run bundle install to ensure your gems are installed so that we can boot the language server with bundle exec afterwards.

If you have BUNDLE_PATH configured, then the bundle install part should already be doing the right thing. The gem install part is likely the issue. I'm hoping that by setting install-dir, rubygems will return to us the correct GEM_HOME so that we can find the executable properly.

you would either have to globally install those 3 gems before

This doesn't quite solve the full story. We also auto-update the global installation, so that we can always use the latest executable, which would fail if you just installed them manually.

I believe that, at the core of the issue, is the fact that most people configure their BUNDLE_PATH, so that running bundle install will put gems in the place they want, but that doesn't affect gem install in any way - it's a separate configuration.

If the idea is to have all gems installed in a given directory that isn't the default, then I do believe the right solution is to configure both Bundler and rubygems to install everything in that directory.

If you give this a try, please let us know if it worked properly. We may discover that we still need a couple of tweaks to the VS Code extension to make it work, but we do want to support this use case.

@robertfromsms
Copy link
Author

robertfromsms commented Apr 13, 2024

Okay, so I ended up not going that route with gemrc... I believe the syntax is something like
gem: --user-install
or
gem: --install-dir DIR

I was trying to get it to work, but I gave up after a little bit. Yall can try it. I believe a documented working approach involving gemrc would be very great!

Something sorta unrelated fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants