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

LSP server crash can leave the extension in a stuck state #1766

Closed
1 task done
Earlopain opened this issue Jan 26, 2024 · 8 comments
Closed
1 task done

LSP server crash can leave the extension in a stuck state #1766

Earlopain opened this issue Jan 26, 2024 · 8 comments
Labels
bug Something isn't working pinned This issue or pull request is pinned and won't be marked as stale transferred This issue was transferred from vscode-ruby-lsp

Comments

@Earlopain
Copy link
Contributor

Operating System

Windows 11

Ruby version

3.2.2

Project has a bundle

  • Has bundle

Ruby version manager being used

rbenv

Description

There are a few issues here I believe:

When using a custom gemfile and that gemfile gets updated the server crashes. The required gems are not installed => it can't start up anymore. This is documented in the readme:

Note: when using this, gems will not be installed automatically and neither will ruby-lsp upgrades.

That error message isn't nicely surfaced however, you need to look in the extension output instead. Related to/Same as #1769 I would say.

However, through that crash the LSP client gets the internal state startFailed, which results in the Restart/Stop/Start commands not working even after the issues has been fixed. You have to perform a Window reload instead:

Restart (logged to output only):

Error restarting the server: Client is not running and can't be stopped. It's current state is: startFailed

Start/Stop:
grafik

This happens because through some codepath they all end up calling dispose. This fails because there is no active connection:
https://github.com/microsoft/vscode-languageserver-node/blob/c0982bf544bab9600df223146dd75c93c9004dc3/client/src/common/client.ts#L1374-L1376

I looked through the public API but didn't immediatly find something that would hint to that being the case. The exposed client states are also more limited to than what vscode works with internally (state vs $state which is private)

@Earlopain Earlopain added the bug Something isn't working label Jan 26, 2024
@vinistock
Copy link
Member

Thank you for the bug report!

For surfacing nicer Bundler errors, we have this issue #1769. I think we can add a custom error handler and do a much better job of showing what went wrong.

Regarding restarting the server, it's interesting that the state is not a part of the state exposed in the client. We try to handle all states here, but clearly that one is kind of a "sub-state" not listed in that enumerable type.

We need to figure out how we can determine that the client is in the startFailed state, so that we can avoid invoking stop on it and instead just dispose and create a fresh client.

@vinistock vinistock added the pinned This issue or pull request is pinned and won't be marked as stale label Feb 5, 2024
@st0012 st0012 transferred this issue from Shopify/vscode-ruby-lsp Mar 18, 2024
@st0012 st0012 added the transferred This issue was transferred from vscode-ruby-lsp label Mar 18, 2024
@lpender
Copy link

lpender commented Mar 20, 2024

I have this issue too in Os X. Uninstall / reinstall / restart computer didn't fix it.

EDIT: This is a better solution.

I had to do this:

gem install ruby-lsp
ruby-lsp

Or to keep it running in the background:

nohup ruby-lsp &

in a terminal window.

@vinistock
Copy link
Member

Unless I'm missing something, if you run the server in the background with nohup, you're basically using it to run bundle install.

The extension has no knowledge that the process is running from the terminal nor does it have ownership over the STDIN, STDERR and STDOUT pipes to communicate with it.

That's just running bundle install for the custom bundle with the background process and then the extension spawns a second process (owned by the extension) and boots the server.

If you inspect the processes for ruby-lsp, you'll likely have two running, no?

ps aux | grep ruby-lsp

@lpender
Copy link

lpender commented Mar 20, 2024

No, I just see processes for ruby_lsp_rails/server.rb and ruby-lsp

I'm not sure how that's equivalent to it running bundle install, but the fact is that the extension did not work in VSCode before I did this.

Whether I call Ruby LSP: Stop, Start, Restart, the output says Error restarting the server: Client is not running and can't be stopped. It's current state is: startFailed).

That said, I finally got it to work properly:

gem uninstall `ruby-lsp` 
gem uninstall `ruby-lsp-rails`
  1. Uninstall and re-install VSCode extension
  2. Reload VSCode.

@vinistock
Copy link
Member

I'm not sure how that's equivalent to it running bundle install, but the fact is that the extension did not work in VSCode before I did this.

As part of launching the server, we set up a custom bundle under the .ruby-lsp directory so that you don't have to include the gem in your application's dependencies and then we run bundle install.

If you run ruby-lsp in the terminal, the only thing that happens is you setup the custom bundle, run bundle install and then the server keeps waiting for input forever until its terminated (because the editor is not connected to it, so it never receives any requests).

Anyway, I'm glad it's fixed.

@yndajas
Copy link

yndajas commented May 8, 2024

gem uninstall `ruby-lsp` 
gem uninstall `ruby-lsp-rails`
  1. Uninstall and re-install VSCode extension
  2. Reload VSCode.

This worked for me just now. After upgrading from Ruby 3.2.2 to 3.2.4, I accidentally switched the Ruby formatter to rubocop.vscode-rubocop by mistake, which runs a lot slower than Shopify.ruby-lsp in my setup. When trying to revert to using the Ruby LSP as the formatter (using RuboCop under the hood), I was encountering issues like Shopify/vscode-shopify-ruby#443 and #1866. The steps above as described by @lpender seem to have fixed things

@vinistock
Copy link
Member

I believe this has been fixed in recent versions of the extension. Please let us know if that's not the case.

@Earlopain
Copy link
Contributor Author

Earlopain commented Jun 11, 2024

Yes, I think you are right. I can't actually remember the last time I ran into this. I guess there was some critical part where it really shouldn't have crashed and now it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned This issue or pull request is pinned and won't be marked as stale transferred This issue was transferred from vscode-ruby-lsp
Projects
None yet
Development

No branches or pull requests

5 participants