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

RuboCop v1.70 incompatibilities and new RuboCop add-on #3046

Open
2 of 3 tasks
vinistock opened this issue Jan 10, 2025 · 20 comments
Open
2 of 3 tasks

RuboCop v1.70 incompatibilities and new RuboCop add-on #3046

vinistock opened this issue Jan 10, 2025 · 20 comments
Assignees

Comments

@vinistock
Copy link
Member

vinistock commented Jan 10, 2025

RuboCop v1.70 added an add-on to provide linting and formatting via the Ruby LSP. This is a great move long term, as it allows RuboCop maintainers to improve the integrations and ensure compatibility across versions.

Unfortunately, this first iteration of the add-on is conflicting with our internal integrations with RuboCop and may cause some issues. Namely, two things may happen:

  1. Namespace conflicts like uninitialized constant RubyLsp::RuboCop::Cop (NameError) #3044
  2. Linter registration conflicts since it's using the same identifier as the one we use internally. This means that the LSP may end up using the add-on version and some features can potentially be missing or other features may break (like watching .rubocop.yml)

Transition plan

We need a transition plan since people will still rely on our internal integrations while they are upgrading RuboCop. It may take a while until the community catches up to the newest versions.

Steps

  • Decide identifier change. If we change ours from rubocop to rubocop_internal, it will avoid the conflict, but it also means that anyone who has configured to use rubocop will try to use the add-on. If the application is on an older version of RuboCop where the add-on is not available, that will fail and no formatting will be available. We can add logic to check for this scenario and try to do the right thing depending on what's available
  • Our automatic detection for linters will need to change as well. We will now need to take the add-on into account if it's available and then decide whether to use the internal or the add-on version
  • Map all feature differences between our internal integrations and the RuboCop add-on, so that we can ensure feature completeness for the community
@vinistock
Copy link
Member Author

#3045 fixed the namespace conflicts.

@Earlopain
Copy link
Contributor

Do you still think this should be reverted for now? I haven't tried it out myself yet, so no idea what the impact is.

Most of the PR is good, just removing the addon itself to give more time shouldn't be too big of a ask I think.

@vinistock
Copy link
Member Author

vinistock commented Jan 10, 2025

No longer necessary after #3045. It seems like things are working normally, although we still need to iron out the remaining details. I updated my comment on the RuboCop PR.

v0.23.5 has the fix.

@koic
Copy link
Contributor

koic commented Jan 11, 2025

@vinistock Thank you for considering the migration plan for Ruby LSP.

Ideally, in the future, it would be great if Ruby LSP could replace its dependency on RuboCop's internal APIs with RuboCop's Ruby LSP add-on. Interacting through only published interface is crucial for good design :-)

Ideally, Ruby LSP should focus solely on LSP functionality. It would be ideal if Ruby LSP no longer needed to know the internal implementation of RuboCop's Linter/Formatter, allowing each module to concentrate on its intended role. I hope my understanding aligns with what you previously conveyed.

That said, while the Ruby LSP add-on released with RuboCop 1.70 is honestly still insufficient to replace Ruby LSP's existing RuboCop dependency, I hope this serves as a starting point to gradually evolve the Ruby toolchain ecosystem toward its ideal form. Thank you.

@vinistock
Copy link
Member Author

Yes, I agree. Having RuboCop control the integrations allows for the LSP integration and internal API to evolve side by side, which opens up the possibility for more complex changes.

I created #3067, which addresses the first two points related to the formatter identifier conflict.

Now, we just need to map if there are any feature differences to make the add-on match our internal integration. And, of course, keep the internal integration for a while since people on RuboCop < 1.70 will still need it.

vinistock added a commit that referenced this issue Jan 16, 2025
### Motivation

This PR addresses point 1 and 2 from #3046

Now that the RuboCop add-on is using the `rubocop` identifier, we need to change ours to prevent conflicts, while still ensuring that users who are on older versions of RuboCop are getting the right behaviour.

### Implementation

Essentially, we are changing our identifier to `rubocop_internal`.

The only extra logic is falling back when users have explicitly configured their formatter or linter as `rubocop`. Since that is now owned by RuboCop, but only present on versions higher than v1.70, we need to check the version and ensure that it's actually available or fallback to our internal integration.

### Automated Tests

Added tests.
@mtrepanier
Copy link

Hi @vinistock thanks for the fixes. Do you know when the update will be available for VsCode?

@vinistock
Copy link
Member Author

@mtrepanier
Copy link

Yes it just appeared in the VsCode marketplace. But even by choosing rubocop_internal instead of auto or rubocop I have same error

Error running diagnostics: uninitialized constant RubyLsp::RuboCop::Cop

@vinistock
Copy link
Member Author

Please read this section on outdated versions of the server, it's likely your server that's outdated - not the extension. Let us know if you continue to have issues.

@mtrepanier
Copy link

mtrepanier commented Jan 16, 2025

I uninstalled all ruby-lsp gem and related and did install the latest and still have same issue.

After uninstall

> gem list ruby-lsp


*** LOCAL GEMS ***

After re-install latest

> gem list ruby-lsp

*** LOCAL GEMS ***

ruby-lsp (0.23.6, 0.11.2)
ruby-lsp-rails (0.2.6)

In the output

2025-01-16 15:27:10.043 [info] (project1) Ruby LSP is ready

2025-01-16 15:27:55.636 [info] (project1) [Error - 3:27:55 PM] Request textDocument/formatting failed.
2025-01-16 15:27:55.636 [info] (project1)   Message: #<NameError: uninitialized constant RubyLsp::RuboCop::Cop>
  Code: -32603 
[object Object]

@vinistock
Copy link
Member Author

The version that runs the server is specified in the bundle composed under the .ruby-lsp directory. Did you run the Update language server gem command or BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle update ruby-lsp to trigger an update for the version currently locked as mentioned in the those outdated docs?

It using those techniques is not working, then some dependency of your app may be constraining the update, which is also explained in those docs.

@bradsb
Copy link

bradsb commented Jan 22, 2025

For me the vscode command Update language server gem and BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle update ruby-lsp failed with:

Fetching gem metadata from https://dl.fontawesome.com/basic/fontawesome-pro/ruby/...
Fetching gem metadata from https://enterprise.contribsys.com/..
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Could not find compatible versions

Because ruby-lsp-rails >= 0.3.27, < 0.3.28 depends on ruby-lsp >= 0.22.0, < 0.23.0
  and ruby-lsp-rails >= 0.3.22, < 0.3.27 depends on ruby-lsp >= 0.21.2, < 0.22.0,
  ruby-lsp-rails >= 0.3.22, < 0.3.28 requires ruby-lsp >= 0.21.2, < 0.23.0.
And because ruby-lsp-rails >= 0.3.19, < 0.3.22 depends on ruby-lsp >= 0.20.0, < 0.21.0,
  ruby-lsp-rails >= 0.3.19, < 0.3.28 requires ruby-lsp >= 0.20.0, < 0.21.0 OR >= 0.21.2, < 0.23.0.
And because ruby-lsp-rails >= 0.3.17, < 0.3.19 depends on ruby-lsp >= 0.19.0, < 0.20.0
  and ruby-lsp-rails >= 0.3.16, < 0.3.17 depends on ruby-lsp >= 0.18.0, < 0.19.0,
  ruby-lsp-rails >= 0.3.16, < 0.3.28 requires ruby-lsp >= 0.18.0, < 0.21.0 OR >= 0.21.2, < 0.23.0.
And because ruby-lsp-rails >= 0.3.12, < 0.3.16 depends on ruby-lsp >= 0.17.12, < 0.18.0
  and ruby-lsp-rails >= 0.3.8, < 0.3.12 depends on ruby-lsp >= 0.17.2, < 0.18.0,
  ruby-lsp-rails >= 0.3.8, < 0.3.28 requires ruby-lsp >= 0.17.2, < 0.21.0 OR >= 0.21.2, < 0.23.0.
And because ruby-lsp-rails >= 0.3.7, < 0.3.8 depends on ruby-lsp >= 0.17.0, < 0.18.0
  and ruby-lsp-rails < 0.3.7 depends on sorbet-runtime >= 0.5.9897,
  ruby-lsp-rails < 0.3.28 requires ruby-lsp >= 0.17.0, < 0.21.0 OR >= 0.21.2, < 0.23.0 or sorbet-runtime >= 0.5.9897.
And because sorbet-runtime >= 0.5.9897, < 0.5.10782 could not be found in rubygems repository https://dl.fontawesome.com/basic/fontawesome-pro/ruby/
  and ruby-lsp-rails >= 0.3.28 depends on ruby-lsp >= 0.23.0, < 0.24.0,
  either ruby-lsp >= 0.17.0, < 0.21.0 OR >= 0.21.2, < 0.24.0 or sorbet-runtime >= 0.5.10782.
So, because ruby-lsp >= 0.13.4 depends on sorbet-runtime >= 0.5.10782
  and sorbet-runtime >= 0.5.10782 could not be found in rubygems repository https://dl.fontawesome.com/basic/fontawesome-pro/ruby/,
  version solving has failed.

Which seems to be because .ruby-lsp/Gemfile.lock had the sorbet-runtine under a fontawesome remote. Removing the Gemfile.lock and running a bundle install and then update worked to fix it

@vinistock vinistock marked this as a duplicate of #3076 Jan 22, 2025
@andyw8
Copy link
Contributor

andyw8 commented Jan 22, 2025

@bradsb please check your Bundler version is up-to-date. IIRC some older versions had problem with resolving to incorrect sources.

@celinefb
Copy link

celinefb commented Jan 22, 2025

I am running into the same issue. RubyLSP does not index anymore in one of my projects that is using Rubocop 1.70.0 and Standard 1.44.0
My vscode extensions are up to date

@vinistock
Copy link
Member Author

@celinefb did you already make sure the server is up to date? Are there errors being printed in the editor's output tab?

@dmoore1989
Copy link

I'm also still seeing the same error in my environment (uninitialized constant RubyLsp::RuboCop::Cop). I ran BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle update ruby-lsp, which said the version stayed the same. Using ruby-lsp@0.23.6 in Neovim.

@vinistock
Copy link
Member Author

@dmoore1989 if you run cat .ruby-lsp/Gemfile.lock and search for the ruby-lsp entry, it is locked to v0.23.6?

@dmoore1989
Copy link

dmoore1989 commented Jan 24, 2025

@vinistock I'm actually seeing v0.17.16. It looks like ruby-lsp-rails was limiting it to (>= 0.17.12, < 0.18.0) and I think I just fixed it by updating that and running BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle update.

Everything appears to be working now. Thanks!

@1990eam
Copy link

1990eam commented Jan 27, 2025

Hey. I'm trying to update the server version from 0.17.2 to the latest one running the Ruby LSP: Update language server gem command to fix this issue, but I get this in the Vscode output console.

Could you confirm if it's not being updated due to the stated "Unresolved or ambiguous specs" warnings?

2025-01-27 15:21:58.122 [info] (arda) WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
      language_server-protocol (~> 3.17.0)

 Available/installed versions of this gem:
      - 3.17.0.4
      - 3.17.0.3


 logger (>= 0)

Available/installed versions of this gem:
      - 1.6.5
      - 1.6.4
      - 1.6.3
      - 1.6.1
      - 1.6.0
      - 1.5.3

2025-01-27 15:21:58.935 [info] (arda) Fetching gem metadata from https://rubygems.org/

2025-01-27 15:22:00.429 [info] (arda) Resolving dependencies...

2025-01-27 15:22:01.574 [info] (arda) WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
      stringio (>= 0)

Available/installed versions of this gem:
      - 3.1.2
      - 3.0.4

WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
Please report a bug if this causes problems.

2025-01-27 15:22:01.676 [info] (arda) Fetching rbs 2.8.4

2025-01-27 15:22:02.649 [info] (arda) Installing rbs 2.8.4 with native extensions

2025-01-27 15:22:04.647 [info] (arda) Bundle complete! 102 Gemfile dependencies, 307 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

2025-01-27 15:22:04.648 [info] (arda) 3 installed gems you directly depend on are looking for funding.
  Run `bundle fund` for details

2025-01-27 15:22:04.649 [info] (arda) Ruby LSP> Composed bundle installation complete

2025-01-27 15:22:04.849 [info] (arda) Composed Bundle set up successfully

2025-01-27 15:22:05.741 [info] (arda) Initializing Ruby LSP v0.17.2...

@vinistock
Copy link
Member Author

@1990eam those warnings are not relevant, it's just because the LSP sets up the bundle on its own and Bundler emits some of these messages.

Your problem seems to be the rbs version constraining the update for the Ruby LSP, as described in the docs.

We depend on rbs >= 3 and your bundle seems to be locked to rbs v2.8.4.

You have to ensure that you can update rbs to 3 or higher so that the LSP can auto upgrade too. If you have another dependency constraining the version of rbs to be lower than 3, than that's the thing preventing the upgrades.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants