Only start server in bundler projects if lockfile is present #826
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, if we are using
ruby-lsp
in an editor other than VS Code, if we happen to open a bundler project that has a Gemfile but that we haven't runbundle install
yet, the language server crashes due to the lack of the locked dependencies of the app. The main issue is that the user just gets the exception in the output and no explanation of what needs to be done.Fixes #824
Implementation
As per @vinistock's suggestion, I simply added a check that prints a warning message if the project has a Gemfile but doesn't have a Gemfile.lock and exits the server program.
My only point of uncertainty is concerning the message itself, but, otherwise, manually testing on Sublime, this worked fine. Which is to say, sublime just complains the server crashes, but attempting to start the process manually show the error message as expected. For the editor, I believe that, like the VS Code extension, the problem needs to be dealt with the Sublime package running the server.
Automated Tests
I haven't added automated tests because I couldn't find the file where the executable is tested, or at least the files that I expected to have the executable tests seemed to test other things. But if there is a place to add an automated test for this, I'd be happy to know and add that to the PR.
Manual Tests
This issue doesn't affect VS Code. It seems that the editor's extension runs bundle install in case there is no lockfile.
In other editors or simply running the server in the terminal all you need to do is:
bundle install
or
The error message, however, is only visible if you try to start it manually or if you open up your editor's LSP plugin's logs. For example, in Sublime, you can do Cmd + Shift + P (or Ctrl + Shift + P on Windows and Linux, I believe) and run
LSP: Toggle Log Panel
. You should see output similar to this: