Shopify / ruby-lsp

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

Run `bundle install` if Gemfile but no `Gemfile.lock` #1944

Open Earlopain opened 4 months ago

Earlopain commented 4 months ago

Description

Reproduction steps

Check out a fresh copy of a repo with Gemfile.lock in .gitignore (rubocop/rubocop for example).

The LSP starting will first show a notice about mulitroot workspaces and after discarding that refuse to start with the following:

Project contains a Gemfile, but no Gemfile.lock. Run bundle install to lock gems and restart the server

Would it make sense to automatically run bundle install for the user in these cases? This would probably require explicit user confirmation, similarly to how VSCode asks about trusted folders. Gems may execute arbitrary commands during installation (I think, especially C extensions during compilation). Perhaps the confirmation of VSCode is already enough, if the extension isn't opting in to trusted mode, https://code.visualstudio.com/docs/editor/workspace-trust. I believe that is the case currently, however looks to be vscode specific and not part of the LSP protocol.

andyw8 commented 4 months ago

Similarly, this also happens if you use bundle gem when creating a new gem, since there's initially no Gemfile.lock.

vinistock commented 4 months ago

After discussing this with the team, our general sentiment is that the LSP should not run bundle install automatically on a non-locked project. Having the bundle locked is fundamental for anything to work really. Without that, you're unable to run tests, run linters or really do much.

That said, we also believe that the experience is currently quite odd for that scenario. We are only checking if the lockfile exists and then we display a warning including information about multi-root workspaces.

We should definitely include a check to see if a Gemfile or gems.rb file exists and then we can definitely offer from the VS Code extension to first run bundle install on the project's bundle before trying to launch the language server. How does that sound?

Earlopain commented 4 months ago

LSP should not run bundle install automatically on a non-locked project

We should definitely include a check to see if a Gemfile or gems.rb file exists and then we can definitely offer from the VS Code extension to first run bundle install

These two seem to be in conflict unless the important part here is "automatically", as in without user interaction. Offering to run bundle install for the user sounds perfectly fine and is one possible solution I was writing about.

Right now you can open a project, ruby-lsp will show some signs of life, and then just not work. That is my main gripe I think.

vinistock commented 4 months ago

Yes, indeed the point of discussing was the automatic aspect. Because we actually run bundle install only for the custom bundle under .ruby-lsp, which would create .ruby-lsp/Gemfile.lock, but no top level lockfile - which can be a bit weird.

We should definitely show a message and give the chance for the user to run bundle install if desired.

github-actions[bot] commented 2 months ago

This issue is being marked as stale because there was no activity in the last 2 months