solargraph 0.28.4 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/solargraph/api_map.rb +43 -10
- data/lib/solargraph/api_map/store.rb +13 -0
- data/lib/solargraph/bundle.rb +3 -0
- data/lib/solargraph/complex_type.rb +5 -4
- data/lib/solargraph/core_fills.rb +3 -2
- data/lib/solargraph/language_server/host.rb +0 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +4 -3
- data/lib/solargraph/language_server/message/extended/document_gems.rb +7 -0
- data/lib/solargraph/language_server/transport/socket.rb +7 -1
- data/lib/solargraph/library.rb +1 -1
- data/lib/solargraph/page.rb +1 -2
- data/lib/solargraph/pin.rb +1 -0
- data/lib/solargraph/pin/base.rb +8 -1
- data/lib/solargraph/pin/base_variable.rb +1 -1
- data/lib/solargraph/pin/block_parameter.rb +5 -0
- data/lib/solargraph/pin/conversions.rb +1 -1
- data/lib/solargraph/pin/method.rb +59 -1
- data/lib/solargraph/pin/method_alias.rb +19 -0
- data/lib/solargraph/pin/yard_pin/method.rb +2 -2
- data/lib/solargraph/source.rb +63 -1
- data/lib/solargraph/source/chain/call.rb +39 -20
- data/lib/solargraph/source/node_chainer.rb +1 -1
- data/lib/solargraph/source/node_methods.rb +81 -0
- data/lib/solargraph/source_map.rb +15 -0
- data/lib/solargraph/source_map/clip.rb +1 -1
- data/lib/solargraph/source_map/mapper.rb +9 -421
- data/lib/solargraph/source_map/node_processor.rb +75 -0
- data/lib/solargraph/source_map/node_processor/alias_node.rb +21 -0
- data/lib/solargraph/source_map/node_processor/args_node.rb +28 -0
- data/lib/solargraph/source_map/node_processor/base.rb +68 -0
- data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -0
- data/lib/solargraph/source_map/node_processor/block_node.rb +14 -0
- data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -0
- data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -0
- data/lib/solargraph/source_map/node_processor/def_node.rb +54 -0
- data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -0
- data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -0
- data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -0
- data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -0
- data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -0
- data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -0
- data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -0
- data/lib/solargraph/source_map/node_processor/send_node.rb +150 -0
- data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -0
- data/lib/solargraph/source_map/region.rb +58 -0
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +17 -10
- data/lib/yard-solargraph.rb +0 -2
- metadata +24 -18
@@ -0,0 +1,75 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
# The processor classes used by SourceMap::Mapper to generate pins from
|
4
|
+
# parser nodes.
|
5
|
+
#
|
6
|
+
module NodeProcessor
|
7
|
+
autoload :Base, 'solargraph/source_map/node_processor/base'
|
8
|
+
autoload :BeginNode, 'solargraph/source_map/node_processor/begin_node'
|
9
|
+
autoload :DefNode, 'solargraph/source_map/node_processor/def_node'
|
10
|
+
autoload :DefsNode, 'solargraph/source_map/node_processor/defs_node'
|
11
|
+
autoload :SendNode, 'solargraph/source_map/node_processor/send_node'
|
12
|
+
autoload :NamespaceNode, 'solargraph/source_map/node_processor/namespace_node'
|
13
|
+
autoload :SclassNode, 'solargraph/source_map/node_processor/sclass_node'
|
14
|
+
autoload :ModuleNode, 'solargraph/source_map/node_processor/module_node'
|
15
|
+
autoload :IvasgnNode, 'solargraph/source_map/node_processor/ivasgn_node'
|
16
|
+
autoload :CvasgnNode, 'solargraph/source_map/node_processor/cvasgn_node'
|
17
|
+
autoload :LvasgnNode, 'solargraph/source_map/node_processor/lvasgn_node'
|
18
|
+
autoload :GvasgnNode, 'solargraph/source_map/node_processor/gvasgn_node'
|
19
|
+
autoload :CasgnNode, 'solargraph/source_map/node_processor/casgn_node'
|
20
|
+
autoload :AliasNode, 'solargraph/source_map/node_processor/alias_node'
|
21
|
+
autoload :ArgsNode, 'solargraph/source_map/node_processor/args_node'
|
22
|
+
autoload :BlockNode, 'solargraph/source_map/node_processor/block_node'
|
23
|
+
autoload :OrasgnNode, 'solargraph/source_map/node_processor/orasgn_node'
|
24
|
+
autoload :SymNode, 'solargraph/source_map/node_processor/sym_node'
|
25
|
+
|
26
|
+
class << self
|
27
|
+
@@processors ||= {}
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def register node, cls
|
32
|
+
@@processors[node] = cls
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
register :source, BeginNode
|
37
|
+
register :begin, BeginNode
|
38
|
+
register :kwbegin, BeginNode
|
39
|
+
# # @todo Is this the best way to handle rescue nodes?
|
40
|
+
register :rescue, BeginNode
|
41
|
+
register :resbody, BeginNode
|
42
|
+
register :def, DefNode
|
43
|
+
register :defs, DefsNode
|
44
|
+
register :send, SendNode
|
45
|
+
register :class, NamespaceNode
|
46
|
+
register :module, NamespaceNode
|
47
|
+
register :sclass, SclassNode
|
48
|
+
register :ivasgn, IvasgnNode
|
49
|
+
register :cvasgn, CvasgnNode
|
50
|
+
register :lvasgn, LvasgnNode
|
51
|
+
register :gvasgn, GvasgnNode
|
52
|
+
register :casgn, CasgnNode
|
53
|
+
register :alias, AliasNode
|
54
|
+
register :args, ArgsNode
|
55
|
+
register :block, BlockNode
|
56
|
+
register :or_asgn, OrasgnNode
|
57
|
+
register :sym, SymNode
|
58
|
+
|
59
|
+
module_function
|
60
|
+
|
61
|
+
# @param node [Parser::AST::Node]
|
62
|
+
# @param region [Region]
|
63
|
+
# @param pins [Array<Pin::Base>]
|
64
|
+
# @return [Array<Pin::Base>]
|
65
|
+
def process node, region = Region.new(nil, '', :instance, :public, []), pins = []
|
66
|
+
pins.push Pin::Namespace.new(region.source.location, '', '', nil, :class, :public) if pins.empty?
|
67
|
+
return pins unless node.is_a?(Parser::AST::Node) #&& @@processors.key?(node.type)
|
68
|
+
klass = @@processors[node.type] || BeginNode
|
69
|
+
processor = klass.new(node, region, pins)
|
70
|
+
processor.process
|
71
|
+
processor.pins
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class AliasNode < Base
|
5
|
+
def process
|
6
|
+
pin = pins.select{|p| p.name == node.children[1].children[0].to_s && p.namespace == region.namespace && p.scope == region.scope}.first
|
7
|
+
if pin.nil?
|
8
|
+
pins.push Solargraph::Pin::MethodAlias.new(get_node_location(node), region.namespace, node.children[0].children[0].to_s, region.scope, node.children[1].children[0].to_s)
|
9
|
+
else
|
10
|
+
if pin.is_a?(Solargraph::Pin::Method)
|
11
|
+
pins.push Solargraph::Pin::Method.new(get_node_location(node), pin.namespace, node.children[0].children[0].to_s, comments_for(node) || pin.comments, pin.scope, pin.visibility, pin.parameters, pin.node)
|
12
|
+
elsif pin.is_a?(Solargraph::Pin::Attribute)
|
13
|
+
pins.push Solargraph::Pin::Attribute.new(get_node_location(node), pin.namespace, node.children[0].children[0].to_s, comments_for(node) || pin.comments, pin.access, pin.scope, pin.visibility)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
process_children
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class ArgsNode < Base
|
5
|
+
def process
|
6
|
+
return if node.children.empty?
|
7
|
+
here = get_node_start_position(node)
|
8
|
+
context = named_path_pin(here)
|
9
|
+
block = block_pin(here)
|
10
|
+
if block.kind == Solargraph::Pin::BLOCK
|
11
|
+
pi = 0
|
12
|
+
node.children.each do |u|
|
13
|
+
pins.push Solargraph::Pin::BlockParameter.new(get_node_location(u), region.namespace, "#{u.children[0]}", comments_for(node), block)
|
14
|
+
block.parameters.push pins.last
|
15
|
+
pi += 1
|
16
|
+
end
|
17
|
+
else
|
18
|
+
node.children.each do |u|
|
19
|
+
presence = Range.new(here, block.location.range.ending)
|
20
|
+
pins.push Solargraph::Pin::MethodParameter.new(get_node_location(u), region.namespace, u.children[0].to_s, comments_for(node), u.children[1], infer_literal_node_type(u.children[1]), context, block, presence)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
process_children
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class Base
|
5
|
+
include Solargraph::Source::NodeMethods
|
6
|
+
|
7
|
+
# @return [Parser::AST::Node]
|
8
|
+
attr_reader :node
|
9
|
+
|
10
|
+
# @return [Region]
|
11
|
+
attr_reader :region
|
12
|
+
|
13
|
+
# @return [Array<Pin::Base>]
|
14
|
+
attr_reader :pins
|
15
|
+
|
16
|
+
# @param node [Parser::AST::Node]
|
17
|
+
# @param region [Region]
|
18
|
+
# @param pins [Array<Pin::Base>]
|
19
|
+
def initialize node, region, pins
|
20
|
+
@node = node
|
21
|
+
@region = region
|
22
|
+
@pins = pins
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Subclasses should override this method to generate new pins.
|
28
|
+
#
|
29
|
+
# @return [void]
|
30
|
+
def process
|
31
|
+
raise NoMethodError, "#{self.class} does not implement the `process` method"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# @param subregion [Region]
|
37
|
+
# @return [void]
|
38
|
+
def process_children subregion = region
|
39
|
+
node.children.each do |child|
|
40
|
+
next unless child.is_a?(Parser::AST::Node)
|
41
|
+
NodeProcessor.process(child, subregion, pins)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param node [Parser::AST::Node]
|
46
|
+
# @return [Solargraph::Location]
|
47
|
+
def get_node_location(node)
|
48
|
+
st = Position.new(node.loc.line, node.loc.column)
|
49
|
+
en = Position.new(node.loc.last_line, node.loc.last_column)
|
50
|
+
range = Range.new(st, en)
|
51
|
+
Location.new(region.filename, range)
|
52
|
+
end
|
53
|
+
|
54
|
+
def comments_for(node)
|
55
|
+
region.source.comments_for(node)
|
56
|
+
end
|
57
|
+
|
58
|
+
def named_path_pin position
|
59
|
+
pins.select{|pin| [Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) and pin.location.range.contain?(position)}.last
|
60
|
+
end
|
61
|
+
|
62
|
+
def block_pin position
|
63
|
+
pins.select{|pin| [Pin::BLOCK, Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) and pin.location.range.contain?(position)}.last
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class BlockNode < Base
|
5
|
+
def process
|
6
|
+
here = get_node_start_position(node)
|
7
|
+
named_path = named_path_pin(here)
|
8
|
+
pins.push Solargraph::Pin::Block.new(get_node_location(node), region.namespace, '', comments_for(node), node.children[0], named_path.context)
|
9
|
+
process_children
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class CasgnNode < Base
|
5
|
+
def process
|
6
|
+
here = get_node_start_position(node)
|
7
|
+
block = block_pin(here)
|
8
|
+
pins.push Solargraph::Pin::Constant.new(get_node_location(node), region.namespace, node.children[1].to_s, comments_for(node), node.children[2], infer_literal_node_type(node.children[2]), block.context, :public)
|
9
|
+
process_children
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class CvasgnNode < Base
|
5
|
+
def process
|
6
|
+
here = get_node_start_position(node)
|
7
|
+
context = named_path_pin(here)
|
8
|
+
pins.push Solargraph::Pin::ClassVariable.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), context.context)
|
9
|
+
process_children
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class DefNode < Base
|
5
|
+
def process
|
6
|
+
methpin = Solargraph::Pin::Method.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), region.scope, region.visibility, method_args, node)
|
7
|
+
if methpin.name == 'initialize' and methpin.scope == :instance
|
8
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, 'new', methpin.comments, :class, :public, methpin.parameters, nil)
|
9
|
+
# @todo Smelly instance variable access.
|
10
|
+
pins.last.instance_variable_set(:@return_complex_type, ComplexType.parse(methpin.namespace))
|
11
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, methpin.scope, :private, methpin.parameters, methpin.node)
|
12
|
+
elsif region.visibility == :module_function
|
13
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, :class, :public, methpin.parameters, methpin.node)
|
14
|
+
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.comments, :instance, :private, methpin.parameters, methpin.node)
|
15
|
+
else
|
16
|
+
pins.push methpin
|
17
|
+
end
|
18
|
+
process_children
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def method_args
|
24
|
+
return [] if node.nil?
|
25
|
+
list = nil
|
26
|
+
args = []
|
27
|
+
node.children.each { |c|
|
28
|
+
if c.kind_of?(AST::Node) and c.type == :args
|
29
|
+
list = c
|
30
|
+
break
|
31
|
+
end
|
32
|
+
}
|
33
|
+
return args if list.nil?
|
34
|
+
list.children.each { |c|
|
35
|
+
if c.type == :arg
|
36
|
+
args.push c.children[0].to_s
|
37
|
+
elsif c.type == :restarg
|
38
|
+
args.push "*#{c.children[0]}"
|
39
|
+
elsif c.type == :optarg
|
40
|
+
args.push "#{c.children[0]} = #{region.code_for(c.children[1])}"
|
41
|
+
elsif c.type == :kwarg
|
42
|
+
args.push "#{c.children[0]}:"
|
43
|
+
elsif c.type == :kwoptarg
|
44
|
+
args.push "#{c.children[0]}: #{region.code_for(c.children[1])}"
|
45
|
+
elsif c.type == :blockarg
|
46
|
+
args.push "&#{c.children[0]}"
|
47
|
+
end
|
48
|
+
}
|
49
|
+
args
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class DefsNode < DefNode
|
5
|
+
def process
|
6
|
+
s_visi = region.visibility
|
7
|
+
s_visi = :public if s_visi == :module_function || region.scope != :class
|
8
|
+
if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
|
9
|
+
dfqn = region.namespace
|
10
|
+
else
|
11
|
+
dfqn = unpack_name(node.children[0])
|
12
|
+
end
|
13
|
+
unless dfqn.nil?
|
14
|
+
pins.push Solargraph::Pin::Method.new(get_node_location(node), dfqn, "#{node.children[1]}", comments_for(node), :class, s_visi, method_args, node)
|
15
|
+
process_children region.update(namespace: dfqn)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class GvasgnNode < Base
|
5
|
+
def process
|
6
|
+
pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), pins.first.context)
|
7
|
+
process_children
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class IvasgnNode < Base
|
5
|
+
def process
|
6
|
+
here = get_node_start_position(node)
|
7
|
+
named_path = named_path_pin(here)
|
8
|
+
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(node), region.namespace,node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), named_path.context)
|
9
|
+
if region.visibility == :module_function and named_path.kind == Pin::METHOD
|
10
|
+
other = ComplexType.parse("Module<#{named_path.context.namespace}>")
|
11
|
+
pins.push Solargraph::Pin::InstanceVariable.new(get_node_location(node), region.namespace,node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), other)
|
12
|
+
end
|
13
|
+
process_children
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class LvasgnNode < Base
|
5
|
+
def process
|
6
|
+
here = get_node_start_position(node)
|
7
|
+
context = named_path_pin(here)
|
8
|
+
block = block_pin(here)
|
9
|
+
presence = Range.new(here, block.location.range.ending)
|
10
|
+
pins.push Solargraph::Pin::LocalVariable.new(get_node_location(node), region.namespace, node.children[0].to_s, comments_for(node), node.children[1], infer_literal_node_type(node.children[1]), context.context, block, presence)
|
11
|
+
process_children
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class NamespaceNode < Base
|
5
|
+
def process
|
6
|
+
visibility = :public
|
7
|
+
if node.children[0].kind_of?(AST::Node) and node.children[0].children[0].kind_of?(AST::Node) and node.children[0].children[0].type == :cbase
|
8
|
+
tree = pack_name(node.children[0])
|
9
|
+
tree.shift if tree.first.empty?
|
10
|
+
else
|
11
|
+
tree = region.namespace.empty? ? [] : [region.namespace]
|
12
|
+
tree.concat pack_name(node.children[0])
|
13
|
+
end
|
14
|
+
fqn = tree.join('::')
|
15
|
+
sc = nil
|
16
|
+
if node.type == :class and !node.children[1].nil?
|
17
|
+
sc = unpack_name(node.children[1])
|
18
|
+
end
|
19
|
+
pins.push Solargraph::Pin::Namespace.new(get_node_location(node), tree[0..-2].join('::') || '', pack_name(node.children[0]).last.to_s, comments_for(node), node.type, visibility)
|
20
|
+
pins.push Pin::Reference::Superclass.new(pins.last.location, pins.last.path, sc) unless sc.nil?
|
21
|
+
process_children region.update(namespace: fqn, scope: :instance, visibility: :public)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class OrasgnNode < Base
|
5
|
+
def process
|
6
|
+
new_node = node.updated(node.children[0].type, node.children[0].children + [node.children[1]])
|
7
|
+
NodeProcessor.process(new_node, region, pins)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module Solargraph
|
2
|
+
class SourceMap
|
3
|
+
module NodeProcessor
|
4
|
+
class SendNode < Base
|
5
|
+
def process
|
6
|
+
if node.children[0].nil?
|
7
|
+
if [:private, :public, :protected].include?(node.children[1])
|
8
|
+
# @todo Smelly instance variable access
|
9
|
+
region.instance_variable_set(:@visibility, node.children[1])
|
10
|
+
elsif node.children[1] == :module_function
|
11
|
+
process_module_function
|
12
|
+
elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[1])
|
13
|
+
process_attribute
|
14
|
+
elsif node.children[1] == :include
|
15
|
+
process_include
|
16
|
+
elsif node.children[1] == :extend
|
17
|
+
process_extend
|
18
|
+
elsif node.children[1] == :require
|
19
|
+
process_require
|
20
|
+
elsif node.children[1] == :private_constant
|
21
|
+
process_private_constant
|
22
|
+
elsif node.children[1] == :alias_method && node.children[2] && node.children[2] && node.children[2].type == :sym && node.children[3] && node.children[3].type == :sym
|
23
|
+
process_alias_method
|
24
|
+
elsif node.children[1] == :private_class_method && node.children[2].kind_of?(AST::Node)
|
25
|
+
# Processing a private class can potentially handle children on its own
|
26
|
+
return if process_private_class_method
|
27
|
+
end
|
28
|
+
end
|
29
|
+
process_children
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def process_attribute
|
35
|
+
node.children[2..-1].each do |a|
|
36
|
+
if node.children[1] == :attr_reader || node.children[1] == :attr_accessor
|
37
|
+
pins.push Solargraph::Pin::Attribute.new(get_node_location(node), region.namespace, "#{a.children[0]}", comments_for(node), :reader, region.scope, region.visibility)
|
38
|
+
end
|
39
|
+
if node.children[1] == :attr_writer || node.children[1] == :attr_accessor
|
40
|
+
pins.push Solargraph::Pin::Attribute.new(get_node_location(node), region.namespace, "#{a.children[0]}=", comments_for(node), :writer, region.scope, region.visibility)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_include
|
46
|
+
if node.children[2].kind_of?(AST::Node) && node.children[2].type == :const
|
47
|
+
node.children[2..-1].each do |i|
|
48
|
+
nspin = pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.path == region.namespace}.last
|
49
|
+
unless nspin.nil?
|
50
|
+
pins.push Pin::Reference::Include.new(get_node_location(node), nspin.path, unpack_name(i))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def process_extend
|
57
|
+
node.children[2..-1].each do |i|
|
58
|
+
nspin = pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.path == region.namespace}.last
|
59
|
+
unless nspin.nil?
|
60
|
+
ref = nil
|
61
|
+
if i.type == :self
|
62
|
+
ref = Pin::Reference::Extend.new(get_node_location(node), nspin.path, nspin.path)
|
63
|
+
elsif i.type == :const
|
64
|
+
ref = Pin::Reference::Extend.new(get_node_location(node), nspin.path, unpack_name(i))
|
65
|
+
end
|
66
|
+
pins.push ref unless ref.nil?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_require
|
72
|
+
if node.children[2].kind_of?(AST::Node) && node.children[2].type == :str
|
73
|
+
pins.push Pin::Reference::Require.new(get_node_location(node), node.children[2].children[0].to_s)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def process_module_function
|
78
|
+
if node.children[2].nil?
|
79
|
+
# @todo Smelly instance variable access
|
80
|
+
region.instance_variable_set(:@visibility, :module_function)
|
81
|
+
elsif node.children[2].type == :sym || node.children[2].type == :str
|
82
|
+
# @todo What to do about references?
|
83
|
+
node.children[2..-1].each do |x|
|
84
|
+
cn = x.children[0].to_s
|
85
|
+
ref = pins.select{|p| p.namespace == region.namespace and p.name == cn}.first
|
86
|
+
unless ref.nil?
|
87
|
+
pins.delete ref
|
88
|
+
mm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, :class, :public, ref.parameters, ref.node)
|
89
|
+
cm = Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, :instance, :private, ref.parameters, ref.node)
|
90
|
+
pins.push mm, cm
|
91
|
+
pins.select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context == ref.context}.each do |ivar|
|
92
|
+
pins.delete ivar
|
93
|
+
pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.comments, ivar.signature, ivar.instance_variable_get(:@literal), mm)
|
94
|
+
pins.push Solargraph::Pin::InstanceVariable.new(ivar.location, ivar.namespace, ivar.name, ivar.comments, ivar.signature, ivar.instance_variable_get(:@literal), cm)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
elsif node.children[2].type == :def
|
99
|
+
NodeProcessor.process node.children[2], region.update(visibility: :module_function), pins
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def process_private_constant
|
104
|
+
if node.children[2] && (node.children[2].type == :sym || node.children[2].type == :str)
|
105
|
+
# @todo What to do about references?
|
106
|
+
cn = node.children[2].children[0].to_s
|
107
|
+
ref = pins.select{|p| p.namespace == region.namespace and p.name == cn}.first
|
108
|
+
unless ref.nil?
|
109
|
+
pins.delete ref
|
110
|
+
# Might be either a namespace or constant
|
111
|
+
if ref.kind == Pin::CONSTANT
|
112
|
+
pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.signature, ref.return_type, ref.context, :private)
|
113
|
+
else
|
114
|
+
# pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private, (ref.superclass_reference.nil? ? nil : ref.superclass_reference.name))
|
115
|
+
pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def process_alias_method
|
122
|
+
pin = pins.select{|p| p.name == node.children[3].children[0].to_s && p.namespace == region.namespace && p.scope == region.scope}.first
|
123
|
+
if pin.nil?
|
124
|
+
pins.push Solargraph::Pin::MethodAlias.new(get_node_location(node), region.namespace, node.children[2].children[0].to_s, region.scope, node.children[3].children[0].to_s)
|
125
|
+
else
|
126
|
+
if pin.is_a?(Solargraph::Pin::Method)
|
127
|
+
pins.push Solargraph::Pin::Method.new(get_node_location(node), pin.namespace, node.children[2].children[0].to_s, comments_for(node) || pin.comments, pin.scope, pin.visibility, pin.parameters, pin.node)
|
128
|
+
elsif pin.is_a?(Solargraph::Pin::Attribute)
|
129
|
+
pins.push Solargraph::Pin::Attribute.new(get_node_location(node), pin.namespace, node.children[2].children[0].to_s, comments_for(node) || pin.comments, pin.access, pin.scope, pin.visibility)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def process_private_class_method
|
135
|
+
if node.children[2].type == :sym || node.children[2].type == :str
|
136
|
+
ref = pins.select{|p| p.namespace == region.namespace and p.name == node.children[2].children[0].to_s}.first
|
137
|
+
unless ref.nil?
|
138
|
+
pins.delete ref
|
139
|
+
pins.push Solargraph::Pin::Method.new(ref.location, ref.namespace, ref.name, ref.comments, ref.scope, :private, ref.parameters, ref.node)
|
140
|
+
end
|
141
|
+
false
|
142
|
+
else
|
143
|
+
process_children region.update(scope: :class, visibility: :private)
|
144
|
+
true
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|