ruby-lsp: Internal errors occurring for various Layout/* cops
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
- Start Ruby LSP with VSCode
- Open a Ruby file
- Change a line’s indentation so it does not share the same indentation level as the code surrounding it
- 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/IndentationConsistencyLayout/FirstArrayElementIndentationLayout/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")
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 15 (8 by maintainers)
For me that’s a yes,
psychwas set to 5.2.0. Setting its version to 5.1.0 in the Gemfile fixes the issue for me. I’m onstandard.rb1.41.1. Can’t setrubocopto 1.68 as it creates issues withstandard.rb.Do any of you happen to have the
psychgem in your lockfile, specifically at version 5.2.0? If so, this will likely be fixed by upgrading RuboCop to 1.68 which contains https://github.com/rubocop/rubocop/pull/13379. I encountered similar errors for layout cops when running with ruby 3.4-dev.As of the past few days, my Ruby LSP keeps getting into a weird state where it spews these errors with every key stroke.
I notice in my LSP logs, there’s lots of
warning: already initialized constanterrors. Is Ruby LSP running something multiple times? Perhaps it’s doing code reloading?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.
Thanks for confirming. There’s a PR to update RuboCop to the needed version for standard at https://github.com/standardrb/standard/pull/659.
Same here.
Running
bundle exec rubocopthrough 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.