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, shallow = false) ⇒ ScopeParser

Returns a new instance of ScopeParser.



304
305
306
307
308
309
310
311
312
313
# File 'lib/ruby_language_server/scope_parser.rb', line 304

def initialize(text, shallow = false)
  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, shallow)
  @root_scope = processor.root_scope
end

Instance Attribute Details

#root_scopeObject (readonly)

Returns the value of attribute root_scope.



302
303
304
# File 'lib/ruby_language_server/scope_parser.rb', line 302

def root_scope
  @root_scope
end