Skip to content

Commit 0318a74

Browse files
authored
Reuse Prism parse result for RuboCop (#3584)
1 parent ab273bd commit 0318a74

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/ruby_lsp/requests/support/rubocop_formatter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def run_formatting(uri, document)
2424
filename = uri.to_standardized_path || uri.opaque #: as !nil
2525

2626
# Invoke RuboCop with just this file in `paths`
27-
@format_runner.run(filename, document.source)
27+
@format_runner.run(filename, document.source, document.parse_result)
2828
@format_runner.formatted_source
2929
end
3030

@@ -40,7 +40,7 @@ def run_range_formatting(uri, source, base_indentation)
4040
def run_diagnostic(uri, document)
4141
filename = uri.to_standardized_path || uri.opaque #: as !nil
4242
# Invoke RuboCop with just this file in `paths`
43-
@diagnostic_runner.run(filename, document.source)
43+
@diagnostic_runner.run(filename, document.source, document.parse_result)
4444

4545
@diagnostic_runner.offenses.map do |offense|
4646
Support::RuboCopDiagnostic.new(

lib/ruby_lsp/requests/support/rubocop_runner.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def initialize(*args)
8181
@offenses = [] #: Array[::RuboCop::Cop::Offense]
8282
@errors = [] #: Array[String]
8383
@warnings = [] #: Array[String]
84+
@prism_result = nil #: Prism::ParseLexResult?
8485

8586
args += DEFAULT_ARGS
8687
rubocop_options = ::RuboCop::Options.new.parse(args).first
@@ -92,14 +93,15 @@ def initialize(*args)
9293
super(rubocop_options, config_store)
9394
end
9495

95-
#: (String path, String contents) -> void
96-
def run(path, contents)
96+
#: (String, String, Prism::ParseLexResult) -> void
97+
def run(path, contents, prism_result)
9798
# Clear Runner state between runs since we get a single instance of this class
9899
# on every use site.
99100
@errors = []
100101
@warnings = []
101102
@offenses = []
102103
@options[:stdin] = contents
104+
@prism_result = prism_result
103105

104106
super([path])
105107

0 commit comments

Comments
 (0)