Class: RubyLanguageServer::ScopeParser

Inherits:
Ripper
  • Object
show all
Defined in:
lib/ruby_language_server/scope_parser.rb

Overview

This class builds on Ripper’s sexp processor to add ruby and rails magic. Specifically it knows about things like alias, attr_*, has_one/many, etc. It adds the appropriate definitions for those magic words.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ ScopeParser

Returns a new instance of ScopeParser.



336
337
338
339
340
341
342
343
344
345
# File 'lib/ruby_language_server/scope_parser.rb', line 336

def initialize(text)
  text ||= '' # empty is the same as nil - but it doesn't crash
  begin
    sexp = self.class.sexp(text)
  rescue TypeError => e
    RubyLanguageServer.logger.error("Exception in sexp: #{e} for text: #{text}")
  end
  processor = SEXPProcessor.new(sexp, text.split("\n").length)
  @root_scope = processor.root_scope
end

Instance Attribute Details

#root_scopeObject (readonly)

Returns the value of attribute root_scope.



334
335
336
# File 'lib/ruby_language_server/scope_parser.rb', line 334

def root_scope
  @root_scope
end