Skip to content

Commit 8cbd8f8

Browse files
authored
Reuse the prism result again (#3729)
RuboCop 1.80.1 contains a fix for why this was broken, so it should be safe to enable this again. Revert: #3672 Fix: rubocop/rubocop#14478
1 parent e64731f commit 8cbd8f8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/ruby_lsp/requests/support/rubocop_runner.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class ConfigurationError < StandardError; end
6161
"RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
6262
] #: Array[String]
6363

64+
# Functionality was introduced in 1.75.0 but had issues with autocorrect
65+
REUSE_PRISM_RESULT = begin
66+
gem("rubocop", ">= 1.80.1")
67+
true
68+
rescue LoadError
69+
false
70+
end #: bool
71+
6472
#: Array[::RuboCop::Cop::Offense]
6573
attr_reader :offenses
6674

@@ -81,7 +89,7 @@ def initialize(*args)
8189
@offenses = [] #: Array[::RuboCop::Cop::Offense]
8290
@errors = [] #: Array[String]
8391
@warnings = [] #: Array[String]
84-
# @prism_result = nil #: Prism::ParseLexResult?
92+
@prism_result = nil #: Prism::ParseLexResult?
8593

8694
args += DEFAULT_ARGS
8795
rubocop_options = ::RuboCop::Options.new.parse(args).first
@@ -101,11 +109,7 @@ def run(path, contents, prism_result)
101109
@warnings = []
102110
@offenses = []
103111
@options[:stdin] = contents
104-
105-
# Setting the Prism result before running the RuboCop runner makes it reuse the existing AST and avoids
106-
# double-parsing. Unfortunately, this leads to a bunch of cops failing to execute properly under LSP mode.
107-
# Uncomment this once reusing the Prism result is more stable
108-
# @prism_result = prism_result
112+
@prism_result = prism_result if REUSE_PRISM_RESULT
109113

110114
super([path])
111115

0 commit comments

Comments
 (0)