Class: RuboCop::AST::PrismPreparsed

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/ast/processed_source.rb

Overview

A ‘Prism` interface’s class that provides a fixed ‘Prism::ParseLexResult` instead of parsing.

This class implements the ‘parse_lex` method to return a preparsed `Prism::ParseLexResult` rather than parsing the source code. When the parse result is already available externally, such as in Ruby LSP, the Prism parsing process can be bypassed.

Instance Method Summary collapse

Constructor Details

#initialize(prism_result) ⇒ PrismPreparsed

Returns a new instance of PrismPreparsed.



13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/ast/processed_source.rb', line 13

def initialize(prism_result)
  unless prism_result.is_a?(Prism::ParseLexResult)
    raise ArgumentError, <<~MESSAGE
      Expected a `Prism::ParseLexResult` object, but received `#{prism_result.class}`.
    MESSAGE
  end

  @prism_result = prism_result
end

Instance Method Details

#parse_lex(_source, **_prism_options) ⇒ Object



23
24
25
# File 'lib/rubocop/ast/processed_source.rb', line 23

def parse_lex(_source, **_prism_options)
  @prism_result
end