Module: Solargraph::NodeMethods

Included in:
ApiMap, ApiMap::Source, CodeMap, Pin::BaseVariable
Defined in:
lib/solargraph/node_methods.rb

Instance Method Summary collapse

Instance Method Details

#const_from(node) ⇒ String

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/solargraph/node_methods.rb', line 28

def const_from node
  if node.kind_of?(AST::Node) and node.type == :const
    result = ''
    unless node.children[0].nil?
      result = const_from(node.children[0])
    end
    if result == ''
      result = node.children[1].to_s
    else
      result = result + '::' + node.children[1].to_s
    end
    result
  else
    nil
  end
end

#infer_literal_node_type(node) ⇒ String

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/solargraph/node_methods.rb', line 46

def infer_literal_node_type node
  return nil unless node.kind_of?(AST::Node)
  if node.type == :str or node.type == :dstr
    return 'String'
  elsif node.type == :array
    return 'Array'
  elsif node.type == :hash
    return 'Hash'
  elsif node.type == :int
    return 'Integer'
  elsif node.type == :float
    return 'Float'
  elsif node.type == :sym
    return 'Symbol'
  end
  nil
end

#pack_name(node) ⇒ Array<String>

Returns:

  • (Array<String>)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/solargraph/node_methods.rb', line 9

def pack_name(node)
  parts = []
  if node.kind_of?(AST::Node)
    node.children.each { |n|
      if n.kind_of?(AST::Node)
        if n.type == :cbase
          parts = pack_name(n)
        else
          parts += pack_name(n)
        end
      else
        parts.push n unless n.nil?
      end
    }
  end
  parts
end

#resolve_node_signature(node) ⇒ String

Get a call signature from a node. The result should be a string in the form of a method path, e.g., String.new or variable.method.

Returns:

  • (String)


69
70
71
# File 'lib/solargraph/node_methods.rb', line 69

def resolve_node_signature node
  drill_signature node, ''
end

#unpack_name(node) ⇒ String

Returns:

  • (String)


4
5
6
# File 'lib/solargraph/node_methods.rb', line 4

def unpack_name(node)
  pack_name(node).join("::")
end