Class: RubyLsp::ERBDocument

Inherits:
Document show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/ruby_lsp/erb_document.rb

Defined Under Namespace

Classes: ERBScanner

Constant Summary collapse

ParseResultType =
type_member { { fixed: Prism::ParseResult } }

Instance Attribute Summary

Attributes inherited from Document

#encoding, #parse_result, #source, #uri, #version

Instance Method Summary collapse

Methods inherited from Document

#==, #cache_fetch, #cache_get, #cache_set, #create_scanner, #initialize, #push_edits

Constructor Details

This class inherits a constructor from RubyLsp::Document

Instance Method Details

#language_idObject



28
29
30
# File 'lib/ruby_lsp/erb_document.rb', line 28

def language_id
  LanguageId::ERB
end

#locate_node(position, node_types: []) ⇒ Object



38
39
40
# File 'lib/ruby_lsp/erb_document.rb', line 38

def locate_node(position, node_types: [])
  RubyDocument.locate(@parse_result.value, create_scanner.find_char_position(position), node_types: node_types)
end

#parseObject



12
13
14
15
16
17
18
19
20
# File 'lib/ruby_lsp/erb_document.rb', line 12

def parse
  return @parse_result unless @needs_parsing

  @needs_parsing = false
  scanner = ERBScanner.new(@source)
  scanner.scan
  # assigning empty scopes to turn Prism into eval mode
  @parse_result = Prism.parse(scanner.ruby, scopes: [[]])
end

#syntax_error?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_lsp/erb_document.rb', line 23

def syntax_error?
  @parse_result.failure?
end