class LanguageServer::Project::Parser
Attributes
path[R]
result[R]
Public Class Methods
new(src, path)
click to toggle source
Calls superclass method
# File lib/language_server/project/parser.rb, line 26 def initialize(src, path) super(src, path && path.remote_path) @path = path @result = Result.new end
parse(src, path = nil)
click to toggle source
# File lib/language_server/project/parser.rb, line 19 def parse(src, path = nil) new(src, path).tap(&:parse).result end
Private Instance Methods
build_node(klass, **args)
click to toggle source
# File lib/language_server/project/parser.rb, line 105 def build_node(klass, **args) klass.new({ lineno: lineno, character: character, path: path }.merge(args)) end
lineno()
click to toggle source
Calls superclass method
# File lib/language_server/project/parser.rb, line 39 def lineno # Language Server Protocol's lineno is zero origin super - 1 end
on_assign(left, right)
click to toggle source
# File lib/language_server/project/parser.rb, line 80 def on_assign(left, right) result.constants << left if left.instance_of?(Constant) left.value = right if left.respond_to?(:value) # TODO: remove this condition left end
on_class(constant, superclass, children)
click to toggle source
# File lib/language_server/project/parser.rb, line 96 def on_class(constant, superclass, children) cn = children.select { |child| child.respond_to?(:unshift_namespace) } build_node(Class, constant: constant, superclass: superclass, children: cn).tap do |c| result.classes << c cn.each { |child| child.unshift_namespace(c) } end end
on_const(name)
click to toggle source
# File lib/language_server/project/parser.rb, line 64 def on_const(name) build_node(Constant, namespaces: [], name: name, value: nil) end
on_const_path_ref(*nodes)
click to toggle source
# File lib/language_server/project/parser.rb, line 54 def on_const_path_ref(*nodes) if nodes.all? { |n| [Constant, ConstPathRef, VarRef].include?(n.class) } build_node(ConstPathRef, nodes: nodes).tap do |n| result.refs << n end else nodes end end
on_def(*args)
click to toggle source
# File lib/language_server/project/parser.rb, line 68 def on_def(*args) args.flatten.compact end
on_int(value)
click to toggle source
# File lib/language_server/project/parser.rb, line 72 def on_int(value) build_node(LiteralValue, value: value.to_i) end
on_module(constant, children)
click to toggle source
# File lib/language_server/project/parser.rb, line 87 def on_module(constant, children) cn = children.select { |child| child.respond_to?(:unshift_namespace) } build_node(Module, constant: constant, children: cn).tap do |m| result.modules << m cn.each { |child| child.unshift_namespace(m) } end end
on_stmts_add(*args)
click to toggle source
# File lib/language_server/project/parser.rb, line 76 def on_stmts_add(*args) args.flatten.compact end
on_var_ref(node)
click to toggle source
# File lib/language_server/project/parser.rb, line 44 def on_var_ref(node) if node.instance_of?(Constant) build_node(VarRef, node: node).tap do |n| result.refs << n end else node end end