Module: Solargraph::Source::NodeMethods
- Included in:
- Pin::BaseVariable, Solargraph::Source, NodeChainer, SourceChainer, Solargraph::SourceMap::Mapper
- Defined in:
- lib/solargraph/source/node_methods.rb
Class Method Summary collapse
- .const_from(node) ⇒ String
- .drill_signature(node, signature) ⇒ Object
- .get_node_end_position(node) ⇒ Object
- .get_node_start_position(node) ⇒ Object
- .infer_literal_node_type(node) ⇒ String
- .pack_name(node) ⇒ Array<String>
-
.resolve_node_signature(node) ⇒ String
Get a call signature from a node.
- .unpack_name(node) ⇒ String
Class Method Details
.const_from(node) ⇒ String
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/solargraph/source/node_methods.rb', line 31 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 |
.drill_signature(node, signature) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/solargraph/source/node_methods.rb', line 89 def drill_signature node, signature return signature unless node.kind_of?(AST::Node) if node.type == :const or node.type == :cbase unless node.children[0].nil? signature += drill_signature(node.children[0], signature) end signature += '::' unless signature.empty? signature += node.children[1].to_s elsif node.type == :lvar or node.type == :ivar or node.type == :cvar signature += '.' unless signature.empty? signature += node.children[0].to_s elsif node.type == :send unless node.children[0].nil? signature += drill_signature(node.children[0], signature) end signature += '.' unless signature.empty? signature += node.children[1].to_s end signature end |
.get_node_end_position(node) ⇒ Object
85 86 87 |
# File 'lib/solargraph/source/node_methods.rb', line 85 def get_node_end_position(node) Position.new(node.loc.last_line, node.loc.last_column) end |
.get_node_start_position(node) ⇒ Object
81 82 83 |
# File 'lib/solargraph/source/node_methods.rb', line 81 def get_node_start_position(node) Position.new(node.loc.line, node.loc.column) end |
.infer_literal_node_type(node) ⇒ String
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/solargraph/source/node_methods.rb', line 49 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' # @todo Maybe ignore nils # elsif node.type == :nil # return 'NilClass' end nil end |
.pack_name(node) ⇒ Array<String>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/solargraph/source/node_methods.rb', line 12 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.
75 76 77 78 79 |
# File 'lib/solargraph/source/node_methods.rb', line 75 def resolve_node_signature node result = drill_signature node, '' return nil if result.empty? result end |
.unpack_name(node) ⇒ String
7 8 9 |
# File 'lib/solargraph/source/node_methods.rb', line 7 def unpack_name(node) pack_name(node).join("::") end |