Shopify / ruby-lsp

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

LSP stuck in Starting state #2286

Closed Joseph-D-Bradshaw closed 2 months ago

Joseph-D-Bradshaw commented 2 months ago

Description

Windows 11/MacOS Sonoma 14.5

Windows: ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x64-mingw-ucrt] (via RubyInstaller)

MacOS: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23] (via rbenv)

Ruby LSP stuck in Ruby LSP: Starting. Output tab in VSCode is blank.

Trying to follow an online Learn Ruby the Hard Way.

Reproduction steps

  1. Make dir my_project
  2. Put some Ruby code in ex1.rb
    
    puts "Hello World!"

class Test def initialize

end end

Test.new


3. Open VSCode via `code .` from PowerShell, into project root dir
  - For MacOS, the same only from iTerm2
4. LSP does not create any files/directories in the project, does not progress in any form

I have also tried saving as a workspace and opening the project as a workspace, same result.

Other Ruby LSP commands do not have any effect (including `Ruby LSP: Stop` which does not change the state of the extension)

Happy to provide more details, but understandably, know nothing about Ruby tooling. So instructions needed for more debugging.

Can test on both Mac and Windows.
vanner commented 2 months ago

I ran into this problem today and updating bundler (2.5.15) seems to have fixed it for me.

bundle update --bundler

Joseph-D-Bradshaw commented 2 months ago

Perhaps embarrassing, or perhaps a failure of the docs for newcomers, but either way I found out that this Ruby LSP does not work without using bundle, even if the gemfile itself is empty.

bundle init and the extension was happy to start analysing the project; perhaps add a Gemfile not found type error if it is a requirement for the LSP? :) It is sort of hinted when it is confused wondering if it is a multi-workspace project, but knowing it is ultimately because there is no Gemfile would've prevented a newbie like myself to Ruby, from having issues.

Joseph-D-Bradshaw commented 2 months ago

Closing as I resolved my particular issue

vinistock commented 2 months ago

Can you explain what wasn't working and what the original structure of the project was? If you saw the multi-root workspace warning, then it should have launched the server.

Joseph-D-Bradshaw commented 2 months ago

Sure thing, simply 1 ruby file with the mentioned code in it and 1 vscode workspace file (which I added after the LSP didn't come out of starting).

workspace file contents:

{
    "folders": [
        {
            "path": "."
        }
    ],
    "settings": {}
}

The .ruby-lsp directory wasn't made. I made some further changes and manually pointed into the ruby.exe on Windows and it made a the .ruby-lsp but did not come out of the starting state.

The thing that worked was running bundle init, which I assume just places a Gemfile in the root directory of the project. If only using out of the box functionality - I assume Gemfiles aren't needed in Ruby (for learnings sake); if I'm wrong then the LSP extension is behaving correctly. But if not, I would consider trying to make an empty Ruby project without Gemfile on a new system and seeing if you get the same issues.

I replicated it on Windows and Mac, and tried again on the Mac without bundle init to confirm.

vinistock commented 2 months ago

The .ruby-lsp directory wasn't made. I made some further changes and manually pointed into the ruby.exe on Windows and it made a the .ruby-lsp but did not come out of the starting state.

When you have workspace configurations and no lockfile, we don't try to eagerly boot the language server. If you open a Ruby file inside that workspace, then it should lazily launch. I suspect this was the reason, because it is possible to use the Ruby LSP without a bundle.

I have https://github.com/Shopify/ruby-lsp/pull/2283 up for eagerly launching the server if the editor is already focused on a Ruby document, which should likely improve this too.

Joseph-D-Bradshaw commented 2 months ago

The .ruby-lsp directory wasn't made. I made some further changes and manually pointed into the ruby.exe on Windows and it made a the .ruby-lsp but did not come out of the starting state.

When you have workspace configurations and no lockfile, we don't try to eagerly boot the language server. If you open a Ruby file inside that workspace, then it should lazily launch. I suspect this was the reason, because it is possible to use the Ruby LSP without a bundle.

I have #2283 up for eagerly launching the server if the editor is already focused on a Ruby document, which should likely improve this too.

I'm fairly confident I made new Ruby files and clicked between them whilst testing, which didn't get the LSP server to start. But I will try again when https://github.com/Shopify/ruby-lsp/pull/2283 is merged. I assume if this is on master then by extension it is in the VSCode extension marketplace?

andyw8 commented 2 months ago

I assume if this is on master then by extension it is in the VSCode extension marketplace?

No, only once we make a release of the extension.