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

Internal errors occurring for various Layout/* cops #2840

Closed
davidcelis opened this issue Nov 7, 2024 · 15 comments
Closed

Internal errors occurring for various Layout/* cops #2840

davidcelis opened this issue Nov 7, 2024 · 15 comments
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes

Comments

@davidcelis
Copy link

Description

Ruby LSP Information

Ruby LSP Information

VS Code Version

1.95.1

Ruby LSP Extension Version

0.8.13

Ruby LSP Server Version

0.21.3

Ruby LSP Addons

  • Standard Ruby
  • Ruby LSP Rails

Ruby Version

3.1.4

Ruby Version Manager

asdf

Installed Extensions

Click to expand
  • atom-keybindings (3.3.0)
  • azure-repos (0.40.0)
  • cel (0.1.2)
  • circleci (2.8.4)
  • copilot (1.243.0)
  • copilot-chat (0.22.1)
  • even-better-toml (0.19.2)
  • github-vscode-theme (6.3.5)
  • gitlens (15.6.3)
  • go (0.42.1)
  • makefile-tools (0.11.13)
  • markdown-all-in-one (3.6.2)
  • remote-containers (0.388.0)
  • remote-repositories (0.42.0)
  • remotehub (0.64.0)
  • ruby-lsp (0.8.13)
  • sorbet-vscode-extension (0.3.37)
  • terraform (2.33.0)
  • vscode-buf (0.6.2)
  • vscode-docker (1.29.3)
  • vscode-graphql (0.12.1)
  • vscode-graphql-syntax (1.3.8)
  • vscode-jsonnet (0.7.2)
  • vscode-mdx (1.8.11)
  • vscode-proto3 (0.5.5)
  • vscode-pull-request-github (0.100.0)
  • vscode-tailwindcss (0.12.12)
  • vscode-yaml (1.15.0)

Ruby LSP Settings

Click to expand
Workspace
{
  "formatter": "rubocop",
  "linters": [
    "rubocop"
  ]
}
User
{
  "enableExperimentalFeatures": false,
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true,
    "references": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "rubocop",
  "linters": [
    "rubocop"
  ],
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "useLauncher": false,
  "featureFlags": {}
}

Reproduction steps

  1. Start Ruby LSP with VSCode
  2. Open a Ruby file
  3. Change a line's indentation so it does not share the same indentation level as the code surrounding it
  4. See an error dialogue:

Error running diagnostics: An internal error occurred for the Layout/IndentationConsistency cop. Updating to a newer version of RuboCop may solve this. For more details, run RuboCop on the command line.

Other Layout/* cops that come standard with StandardRB experience the same issue. Ones I've seen include:

  • Layout/IndentationConsistency
  • Layout/FirstArrayElementIndentation
  • Layout/IndentationWidth

I haven't seen any other cops cause this issue. For instance, with the below code snippet, I can change the strings at the end of the file to use single quotes and they will display inline linting issues correctly and the file will automatically format/fix on save. However, if I add extra indentation to practically any line, I get diagnostic or formatting errors with no other information.

Example code

class NotClass < BasicObject
  instance_methods.grep(/^[^_]/).each { |m| undef_method m }

  def initialize(object)
    @object = object
  end

  def method_missing(name, ...)
    !@object.send(name, ...)
  end

  def respond_to_missing?(name, include_private = false)
    @object.respond_to?(name, include_private)
  end
end

class Object
  def not = NotClass.new(self)
end

puts nil.not.nil?
puts 1.not.eql?(2)
puts [1, 3, 5, 7, 9].not.any? { |i| i % 2 == 0 }
puts "hello".not.start_with?("h")
@davidcelis davidcelis added bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes labels Nov 7, 2024
@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

👋 Are you seeing errors if you run bundle exec standardrb on the command line after changing the indentation?

@simonaslaurinavicius
Copy link

simonaslaurinavicius commented Nov 8, 2024

Same here.

Running bundle exec rubocop through the command line results in no errors, so it doesn't look like an issue related to the Rubocop but rather an integration between LSP and Rubocop.

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

@simonaslaurinavicius are you also using standardrb?

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

Also please share the versions of RuboCop/standardrb being used.

@simonaslaurinavicius
Copy link

@andyw8 nope, I'm using Rubocop. I'm using different Rubocop versions throughout multiple projects:

1.64.1
1.63.0
1.63.2

The errors persist on all the versions. Running the formatter through the command lines works fine.

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

I'm still unable to reproduce. Could one of you please share a video showing the exact change you're making? Ideally on a minimal code sample.

@Earlopain
Copy link
Contributor

Do any of you happen to have the psych gem in your lockfile, specifically at version 5.2.0? If so, this will likely be fixed by upgrading RuboCop to 1.68 which contains rubocop/rubocop#13379. I encountered similar errors for layout cops when running with ruby 3.4-dev.

@simonaslaurinavicius
Copy link

simonaslaurinavicius commented Nov 11, 2024

Thank you very much, @Earlopain, bumping Rubocop to version 1.68.0 indeed solved my issue!🙇‍♂

@Earlopain
Copy link
Contributor

Just checking, do you have psych at that version in your lockfile?

@thimo
Copy link

thimo commented Nov 12, 2024

For me that's a yes, psych was set to 5.2.0. Setting its version to 5.1.0 in the Gemfile fixes the issue for me. I'm on standard.rb 1.41.1. Can't set rubocop to 1.68 as it creates issues with standard.rb.

@Earlopain
Copy link
Contributor

Thanks for confirming. There's a PR to update RuboCop to the needed version for standard at standardrb/standard#659.

@natematykiewicz
Copy link
Contributor

natematykiewicz commented Nov 12, 2024

As of the past few days, my Ruby LSP keeps getting into a weird state where it spews these errors with every key stroke.

Image

I notice in my LSP logs, there's lots of warning: already initialized constant errors. Is Ruby LSP running something multiple times? Perhaps it's doing code reloading?

[ERROR][2024-11-12 14:50:39] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"The Gemfile's dependencies are satisfied\n"
[WARN][2024-11-12 14:50:40] .../lua/vim/lsp.lua:94	"method textDocument/documentHighlight is not supported by any of the servers registered for the current buffer"
[ERROR][2024-11-12 14:50:40] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"Ignoring prism-1.2.0 because its extensions are not built. Try: gem pristine prism --version 1.2.0\n"
[ERROR][2024-11-12 14:50:40] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"Ignoring rbs-3.6.1 because its extensions are not built. Try: gem pristine rbs --version 3.6.1\n"
[ERROR][2024-11-12 14:50:51] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.16/lib/ruby_lsp_rails/version.rb:6: warning: already initialized constant RubyLsp::Rails::VERSION\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp_rails/version.rb:6: warning: previous definition of VERSION was here\n"
[ERROR][2024-11-12 14:50:51] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.16/lib/ruby_lsp/ruby_lsp_rails/support/associations.rb:8: warning: already initialized constant RubyLsp::Rails::Support::Associations::ALL\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/support/associations.rb:8: warning: previous definition of ALL was here\n"
[ERROR][2024-11-12 14:50:51] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.16/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:8: warning: already initialized constant RubyLsp::Rails::Support::Callbacks::MODELS\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:8: warning: previous definition of MODELS was here\n"
[ERROR][2024-11-12 14:50:51] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/nate/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.16/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:37: warning: already initialized constant RubyLsp::Rails::Support::Callbacks::CONTROLLERS\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:37: warning: previous definition of CONTROLLERS was here\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.16/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:55: warning: already initialized constant RubyLsp::Rails::Support::Callbacks::JOBS\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:55: warning: previous definition of JOBS was here\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.16/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:67: warning: already initialized constant RubyLsp::Rails::Support::Callbacks::ALL\n/Users/nate/workspace/my_app/vendor/bundle/ruby/3.2.0/gems/ruby-lsp-rails-0.3.26/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb:67: warning: previous definition of ALL was here\n"

I'm not using Standard RB. rubocop 1.66.1, ruby-lsp 0.21.3, ruby-lsp-rails 0.3.26.

This file is indeed violating Layout/FirstHashElementIndentation (I'm in the middle of edits), but I'm not sure why it's printing this error instead of just showing the info virtual text at the end of the line, like it usually does.

@davidcelis
Copy link
Author

I can confirm that updating to the latest version of Rubocop (1.68.0) fixed the reported issue. Thank you all for the help!

@thimo
Copy link

thimo commented Nov 13, 2024

Some, but for standardrb: 1.42.0 has just been released and updates rubocop to 1.68.0 🎉

@joshmfrankel
Copy link

joshmfrankel commented Nov 14, 2024

I've updated rubocop to 1.68.0, ruby-lsp is 0.21.3. I am using asdf. I'm also not using standardrb Every-time I save a file with a linting issue (as @natematykiewicz mentioned above), I receive a formatting error. Running rubocop on the command line does not produce an error.

Image
Image

Set output log level to 'trace' and found the following:

Error processing textDocument/semanticTokens/range: /Users/joshfrankel/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.21.3/lib/ruby_lsp/store.rb:55:in `rescue in get' (RubyLsp::Store::NonExistingDocumentError)

Setting enabledFeatures to disable semanticHighlighting removes the error in the output logs but the issue for formatting still persists

  "rubyLsp.enabledFeatures": {
    "semanticHighlighting": false
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

No branches or pull requests

7 participants