Class: RubyLsp::RubyLspSlim::SlimDocument

Inherits:
ERBDocument
  • Object
show all
Defined in:
lib/ruby_lsp/ruby_lsp_slim/slim_document.rb

Instance Method Summary collapse

Instance Method Details

#language_id ⇒ Object



26
27
28
29
30
31
# File 'lib/ruby_lsp/ruby_lsp_slim/slim_document.rb', line 26

def language_id
  # Return :erb so that ruby-lsp's Definition listener applies the same
  # "Object" receiver-type fallback it uses for ERB templates, allowing
  # bare method calls like `current_user` to resolve via the index.
  :erb
end

#parse! ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_lsp/ruby_lsp_slim/slim_document.rb', line 8

def parse!
  return false unless @needs_parsing

  @needs_parsing = false
  scanner = SlimScanner.new(@source)
  scanner.scan
  @host_language_source = scanner.host_language
  @parse_result = Prism.parse_lex(scanner.ruby, partial_script: true)
  @code_units_cache = @parse_result.code_units_cache(@encoding)
  true
rescue StandardError => e
  @host_language_source = +""
  @parse_result = Prism.parse_lex("", partial_script: true)
  @code_units_cache = @parse_result.code_units_cache(@encoding)
  $stderr.puts("[Ruby LSP Slim] Parse error: #{e.message}")
  true
end