solargraph 0.38.6 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/SPONSORS.md +9 -0
  3. data/lib/solargraph.rb +1 -0
  4. data/lib/solargraph/api_map.rb +24 -13
  5. data/lib/solargraph/api_map/bundler_methods.rb +3 -0
  6. data/lib/solargraph/api_map/source_to_yard.rb +1 -6
  7. data/lib/solargraph/api_map/store.rb +19 -3
  8. data/lib/solargraph/complex_type/type_methods.rb +4 -4
  9. data/lib/solargraph/convention/base.rb +0 -5
  10. data/lib/solargraph/core_fills.rb +28 -2
  11. data/lib/solargraph/diagnostics/base.rb +1 -0
  12. data/lib/solargraph/diagnostics/type_check.rb +13 -13
  13. data/lib/solargraph/language_server/host.rb +11 -2
  14. data/lib/solargraph/language_server/host/sources.rb +20 -11
  15. data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -11
  16. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  17. data/lib/solargraph/library.rb +3 -3
  18. data/lib/solargraph/parser.rb +26 -0
  19. data/lib/solargraph/parser/comment_ripper.rb +52 -0
  20. data/lib/solargraph/parser/legacy.rb +12 -0
  21. data/lib/solargraph/parser/legacy/class_methods.rb +105 -0
  22. data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
  23. data/lib/solargraph/parser/legacy/node_chainer.rb +115 -0
  24. data/lib/solargraph/parser/legacy/node_methods.rb +289 -0
  25. data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
  26. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
  27. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
  28. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
  29. data/lib/solargraph/parser/legacy/node_processors/block_node.rb +22 -0
  30. data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +25 -0
  31. data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
  32. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
  33. data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
  34. data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
  35. data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
  36. data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
  37. data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
  38. data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
  39. data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
  40. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +21 -0
  41. data/lib/solargraph/parser/legacy/node_processors/send_node.rb +232 -0
  42. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
  43. data/lib/solargraph/parser/node_methods.rb +43 -0
  44. data/lib/solargraph/parser/node_processor.rb +43 -0
  45. data/lib/solargraph/parser/node_processor/base.rb +77 -0
  46. data/lib/solargraph/{source_map → parser}/region.rb +11 -6
  47. data/lib/solargraph/parser/rubyvm.rb +40 -0
  48. data/lib/solargraph/parser/rubyvm/class_methods.rb +146 -0
  49. data/lib/solargraph/parser/rubyvm/node_chainer.rb +133 -0
  50. data/lib/solargraph/parser/rubyvm/node_methods.rb +279 -0
  51. data/lib/solargraph/parser/rubyvm/node_processors.rb +60 -0
  52. data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
  53. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +62 -0
  54. data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
  55. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +22 -0
  56. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +22 -0
  57. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
  58. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +64 -0
  59. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +57 -0
  60. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
  61. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
  62. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +34 -0
  63. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
  64. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
  65. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
  66. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
  67. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
  68. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
  69. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +21 -0
  70. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
  71. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +292 -0
  72. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
  73. data/lib/solargraph/parser/snippet.rb +13 -0
  74. data/lib/solargraph/pin/attribute.rb +8 -0
  75. data/lib/solargraph/pin/base.rb +1 -1
  76. data/lib/solargraph/pin/base_method.rb +26 -4
  77. data/lib/solargraph/pin/base_variable.rb +7 -8
  78. data/lib/solargraph/pin/block.rb +1 -1
  79. data/lib/solargraph/pin/constant.rb +16 -0
  80. data/lib/solargraph/pin/conversions.rb +2 -2
  81. data/lib/solargraph/pin/method.rb +26 -14
  82. data/lib/solargraph/pin/parameter.rb +56 -2
  83. data/lib/solargraph/pin/reference.rb +1 -0
  84. data/lib/solargraph/pin/reference/override.rb +2 -0
  85. data/lib/solargraph/pin/reference/prepend.rb +10 -0
  86. data/lib/solargraph/pin/yard_pin/constant.rb +2 -4
  87. data/lib/solargraph/pin/yard_pin/method.rb +34 -18
  88. data/lib/solargraph/pin/yard_pin/namespace.rb +3 -11
  89. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +3 -12
  90. data/lib/solargraph/range.rb +8 -2
  91. data/lib/solargraph/shell.rb +17 -11
  92. data/lib/solargraph/source.rb +114 -135
  93. data/lib/solargraph/source/chain.rb +11 -3
  94. data/lib/solargraph/source/chain/call.rb +1 -2
  95. data/lib/solargraph/source/chain/constant.rb +44 -8
  96. data/lib/solargraph/source/chain/link.rb +1 -0
  97. data/lib/solargraph/source/cursor.rb +2 -28
  98. data/lib/solargraph/source/source_chainer.rb +12 -6
  99. data/lib/solargraph/source/updater.rb +2 -0
  100. data/lib/solargraph/source_map.rb +0 -2
  101. data/lib/solargraph/source_map/clip.rb +24 -17
  102. data/lib/solargraph/source_map/mapper.rb +34 -29
  103. data/lib/solargraph/type_checker.rb +367 -275
  104. data/lib/solargraph/type_checker/checks.rb +95 -0
  105. data/lib/solargraph/type_checker/param_def.rb +2 -17
  106. data/lib/solargraph/type_checker/rules.rb +53 -0
  107. data/lib/solargraph/version.rb +1 -1
  108. data/lib/solargraph/views/environment.erb +5 -3
  109. data/lib/solargraph/workspace.rb +17 -2
  110. data/lib/solargraph/workspace/config.rb +15 -7
  111. data/lib/solargraph/yard_map.rb +89 -49
  112. data/lib/solargraph/yard_map/core_docs.rb +1 -1
  113. data/solargraph.gemspec +2 -1
  114. metadata +88 -32
  115. data/OVERVIEW.md +0 -37
  116. data/lib/solargraph/source/flawed_builder.rb +0 -15
  117. data/lib/solargraph/source/node_chainer.rb +0 -111
  118. data/lib/solargraph/source/node_methods.rb +0 -240
  119. data/lib/solargraph/source_map/node_processor.rb +0 -85
  120. data/lib/solargraph/source_map/node_processor/alias_node.rb +0 -21
  121. data/lib/solargraph/source_map/node_processor/args_node.rb +0 -24
  122. data/lib/solargraph/source_map/node_processor/base.rb +0 -103
  123. data/lib/solargraph/source_map/node_processor/begin_node.rb +0 -13
  124. data/lib/solargraph/source_map/node_processor/block_node.rb +0 -21
  125. data/lib/solargraph/source_map/node_processor/casgn_node.rb +0 -21
  126. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +0 -21
  127. data/lib/solargraph/source_map/node_processor/def_node.rb +0 -62
  128. data/lib/solargraph/source_map/node_processor/defs_node.rb +0 -33
  129. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +0 -21
  130. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +0 -34
  131. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +0 -24
  132. data/lib/solargraph/source_map/node_processor/namespace_node.rb +0 -35
  133. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +0 -14
  134. data/lib/solargraph/source_map/node_processor/resbody_node.rb +0 -32
  135. data/lib/solargraph/source_map/node_processor/sclass_node.rb +0 -19
  136. data/lib/solargraph/source_map/node_processor/send_node.rb +0 -217
  137. data/lib/solargraph/source_map/node_processor/sym_node.rb +0 -16
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class LitNode < Parser::NodeProcessor::Base
8
+ def process
9
+ if node.children[0].is_a?(Symbol)
10
+ pins.push Solargraph::Pin::Symbol.new(
11
+ get_node_location(node),
12
+ ":#{node.children[0]}"
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class LvasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ # here = get_node_start_position(node)
10
+ here = Position.new(node.first_lineno - 1, node.first_column)
11
+ presence = Range.new(here, region.closure.location.range.ending)
12
+ loc = get_node_location(node)
13
+ locals.push Solargraph::Pin::LocalVariable.new(
14
+ location: loc,
15
+ closure: region.closure,
16
+ name: node.children[0].to_s,
17
+ assignment: node.children[1],
18
+ comments: comments_for(node),
19
+ presence: presence
20
+ )
21
+ process_children
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class NamespaceNode < Parser::NodeProcessor::Base
8
+ include NodeMethods
9
+
10
+ def process
11
+ sc = nil
12
+ if node.type == :CLASS && !node.children[1].nil?
13
+ sc = unpack_name(node.children[1])
14
+ end
15
+ loc = get_node_location(node)
16
+ nspin = Solargraph::Pin::Namespace.new(
17
+ type: node.type.to_s.downcase.to_sym,
18
+ location: loc,
19
+ closure: region.closure,
20
+ name: unpack_name(node.children[0]),
21
+ comments: comments_for(node),
22
+ visibility: :public,
23
+ gates: region.closure.gates.freeze
24
+ )
25
+ pins.push nspin
26
+ unless sc.nil?
27
+ pins.push Pin::Reference::Superclass.new(
28
+ location: loc,
29
+ closure: pins.last,
30
+ name: sc
31
+ )
32
+ end
33
+ process_children region.update(closure: nspin, visibility: :public)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class OptArgNode < Parser::NodeProcessor::Base
8
+ def process
9
+ locals.push Solargraph::Pin::Parameter.new(
10
+ location: region.closure.location,
11
+ closure: region.closure,
12
+ comments: comments_for(node),
13
+ name: node.children[0].children[0].to_s,
14
+ assignment: node.children[0].children[1],
15
+ asgn_code: node.children[0].children[1] ? region.code_for(node.children[0].children[1]) : nil,
16
+ presence: region.closure.location.range,
17
+ decl: :optarg
18
+ )
19
+ region.closure.parameters.push locals.last
20
+ node.children[1] && NodeProcessor.process(node.children[1], region, pins, locals)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class OrasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ NodeProcessor.process(node.children[2], region, pins, locals)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class ResbodyNode < Parser::NodeProcessor::Base
8
+ include Rubyvm::NodeMethods
9
+
10
+ def process
11
+ presence = Range.from_node(node)
12
+ loc = get_node_location(node.children[1])
13
+ if node.children[1] && node.children[1].children.first
14
+ types = if !node.children.first || node.children.first.children.empty?
15
+ ['Exception']
16
+ else
17
+ node.children.first.children[0..-2].map do |child|
18
+ unpack_name(child)
19
+ end
20
+ end
21
+ if exception_variable?
22
+ locals.push Solargraph::Pin::LocalVariable.new(
23
+ location: loc,
24
+ closure: region.closure,
25
+ name: node.children[1].children.first.children.first.to_s,
26
+ comments: "@type [#{types.join(',')}]",
27
+ presence: presence
28
+ )
29
+ end
30
+ end
31
+ NodeProcessor.process(node.children[1], region, pins, locals)
32
+ end
33
+
34
+ private
35
+
36
+ def exception_variable?
37
+ Parser.is_ast_node?(node.children[1]) &&
38
+ Parser.is_ast_node?(node.children[1].children.first) &&
39
+ node.children[1].children.first.type == :LASGN
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class SclassNode < Parser::NodeProcessor::Base
8
+ def process
9
+ # @todo Temporarily skipping remote metaclasses
10
+ return unless node.children[0].is_a?(RubyVM::AbstractSyntaxTree::Node) && node.children[0].type == :SELF
11
+ pins.push Solargraph::Pin::Singleton.new(
12
+ location: get_node_location(node),
13
+ closure: region.closure
14
+ )
15
+ process_children region.update(visibility: :public, scope: :class, closure: pins.last)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class ScopeNode < Parser::NodeProcessor::Base
8
+ def process
9
+ process_children region.update(lvars: node.children[0])
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,292 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module Rubyvm
6
+ module NodeProcessors
7
+ class SendNode < Parser::NodeProcessor::Base
8
+ include Rubyvm::NodeMethods
9
+
10
+ def process
11
+ if [:private, :public, :protected].include?(node.children[0])
12
+ if (node.type == :FCALL && node.children.last.children.length > 1)
13
+ node.children.last.children[0..-2].each do |child|
14
+ # next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
15
+ next unless child.type == :LIT || child.type == :STR
16
+ name = child.children[0].to_s
17
+ matches = pins.select{ |pin| pin.is_a?(Pin::BaseMethod) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
18
+ matches.each do |pin|
19
+ # @todo Smelly instance variable access
20
+ pin.instance_variable_set(:@visibility, node.children[0])
21
+ end
22
+ end
23
+ else
24
+ # @todo Smelly instance variable access
25
+ region.instance_variable_set(:@visibility, node.children[0])
26
+ end
27
+ elsif node.children[0] == :module_function
28
+ process_module_function
29
+ elsif node.children[0] == :require
30
+ process_require
31
+ elsif node.children[0] == :alias_method
32
+ process_alias_method
33
+ elsif node.children[0] == :private_class_method && Parser.is_ast_node?(node)
34
+ # Processing a private class can potentially handle children on its own
35
+ return if process_private_class_method
36
+ elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[0])
37
+ process_attribute
38
+ elsif node.children[0] == :include
39
+ process_include
40
+ elsif node.children[0] == :extend
41
+ process_extend
42
+ elsif node.children[0] == :prepend
43
+ process_prepend
44
+ elsif node.children[0] == :private_constant
45
+ process_private_constant
46
+ end
47
+ process_children
48
+ return
49
+ # @todo Get rid of legacy
50
+ if node.children[0].nil?
51
+ if [:private, :public, :protected].include?(node.children[1])
52
+ if (node.children.length > 2)
53
+ node.children[2..-1].each do |child|
54
+ next unless child.is_a?(AST::Node) && (child.type == :sym || child.type == :str)
55
+ name = child.children[0].to_s
56
+ matches = pins.select{ |pin| pin.is_a?(Pin::BaseMethod) && pin.name == name && pin.namespace == region.closure.full_context.namespace && pin.context.scope == (region.scope || :instance)}
57
+ matches.each do |pin|
58
+ # @todo Smelly instance variable access
59
+ pin.instance_variable_set(:@visibility, node.children[1])
60
+ end
61
+ end
62
+ else
63
+ # @todo Smelly instance variable access
64
+ region.instance_variable_set(:@visibility, node.children[1])
65
+ end
66
+ elsif node.children[1] == :module_function
67
+ process_module_function
68
+ elsif [:attr_reader, :attr_writer, :attr_accessor].include?(node.children[1])
69
+ process_attribute
70
+ elsif node.children[1] == :include
71
+ process_include
72
+ elsif node.children[1] == :extend
73
+ process_extend
74
+ elsif node.children[1] == :require
75
+ process_require
76
+ elsif node.children[1] == :private_constant
77
+ process_private_constant
78
+ 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
79
+ process_alias_method
80
+ elsif node.children[1] == :private_class_method && node.children[2].is_a?(AST::Node)
81
+ # Processing a private class can potentially handle children on its own
82
+ return if process_private_class_method
83
+ end
84
+ elsif node.children[1] == :require && node.children[0].to_s == '(const nil :Bundler)'
85
+ pins.push Pin::Reference::Require.new(Solargraph::Location.new(region.filename, Solargraph::Range.from_to(0, 0, 0, 0)), 'bundler/require')
86
+ end
87
+ process_children
88
+ end
89
+
90
+ private
91
+
92
+ # @return [void]
93
+ def process_attribute
94
+ return unless Parser.is_ast_node?(node.children[1])
95
+ node.children[1].children[0..-2].each do |a|
96
+ next unless a.type == :LIT
97
+ loc = get_node_location(node)
98
+ clos = region.closure
99
+ cmnt = comments_for(node)
100
+ if node.children[0] == :attr_reader || node.children[0] == :attr_accessor
101
+ pins.push Solargraph::Pin::Attribute.new(
102
+ location: loc,
103
+ closure: clos,
104
+ name: a.children[0].to_s,
105
+ comments: cmnt,
106
+ access: :reader,
107
+ scope: region.scope || :instance,
108
+ visibility: region.visibility
109
+ )
110
+ end
111
+ if node.children[0] == :attr_writer || node.children[0] == :attr_accessor
112
+ pins.push Solargraph::Pin::Attribute.new(
113
+ location: loc,
114
+ closure: clos,
115
+ name: "#{a.children[0]}=",
116
+ comments: cmnt,
117
+ access: :writer,
118
+ scope: region.scope || :instance,
119
+ visibility: region.visibility
120
+ )
121
+ end
122
+ end
123
+ end
124
+
125
+ # @return [void]
126
+ def process_include
127
+ return unless Parser.is_ast_node?(node.children.last)
128
+ node.children.last.children[0..-2].each do |i|
129
+ next unless [:COLON2, :COLON3, :CONST].include?(i.type)
130
+ pins.push Pin::Reference::Include.new(
131
+ location: get_node_location(i),
132
+ closure: region.closure,
133
+ name: unpack_name(i)
134
+ )
135
+ end
136
+ end
137
+
138
+ # @return [void]
139
+ def process_prepend
140
+ return unless Parser.is_ast_node?(node.children.last)
141
+ node.children.last.children[0..-2].each do |i|
142
+ next unless [:COLON2, :COLON3, :CONST].include?(i.type)
143
+ pins.push Pin::Reference::Prepend.new(
144
+ location: get_node_location(i),
145
+ closure: region.closure,
146
+ name: unpack_name(i)
147
+ )
148
+ end
149
+ end
150
+
151
+ # @return [void]
152
+ def process_extend
153
+ return unless Parser.is_ast_node?(node.children.last)
154
+ node.children.last.children[0..-2].each do |i|
155
+ next unless [:COLON2, :COLON3, :CONST, :SELF].include?(i.type)
156
+ loc = get_node_location(node)
157
+ if i.type == :SELF
158
+ pins.push Pin::Reference::Extend.new(
159
+ location: loc,
160
+ closure: region.closure,
161
+ name: region.closure.full_context.namespace
162
+ )
163
+ else
164
+ pins.push Pin::Reference::Extend.new(
165
+ location: loc,
166
+ closure: region.closure,
167
+ name: unpack_name(i)
168
+ )
169
+ end
170
+ end
171
+ end
172
+
173
+ # @return [void]
174
+ def process_require
175
+ return unless Parser.is_ast_node?(node.children[1])
176
+ node.children[1].children.each do |arg|
177
+ next unless Parser.is_ast_node?(arg)
178
+ if arg.type == :STR
179
+ pins.push Pin::Reference::Require.new(get_node_location(arg), arg.children[0])
180
+ end
181
+ end
182
+ end
183
+
184
+ # @return [void]
185
+ def process_module_function
186
+ if node.type == :VCALL
187
+ # @todo Smelly instance variable access
188
+ region.instance_variable_set(:@visibility, :module_function)
189
+ elsif node.children.last.children[0].type == :DEFN
190
+ NodeProcessor.process node.children.last.children[0], region.update(visibility: :module_function), pins, locals
191
+ else
192
+ node.children.last.children[0..-2].each do |x|
193
+ next unless [:LIT, :STR].include?(x.type)
194
+ cn = x.children[0].to_s
195
+ ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
196
+ unless ref.nil?
197
+ pins.delete ref
198
+ mm = Solargraph::Pin::Method.new(
199
+ location: ref.location,
200
+ closure: ref.closure,
201
+ name: ref.name,
202
+ comments: ref.comments,
203
+ scope: :class,
204
+ visibility: :public,
205
+ parameters: ref.parameters,
206
+ node: ref.node
207
+ )
208
+ cm = Solargraph::Pin::Method.new(
209
+ location: ref.location,
210
+ closure: ref.closure,
211
+ name: ref.name,
212
+ comments: ref.comments,
213
+ scope: :instance,
214
+ visibility: :private,
215
+ parameters: ref.parameters,
216
+ node: ref.node)
217
+ pins.push mm, cm
218
+ pins.select{|pin| pin.is_a?(Pin::InstanceVariable) && pin.closure.path == ref.path}.each do |ivar|
219
+ pins.delete ivar
220
+ pins.push Solargraph::Pin::InstanceVariable.new(
221
+ location: ivar.location,
222
+ closure: cm,
223
+ name: ivar.name,
224
+ comments: ivar.comments,
225
+ assignment: ivar.assignment
226
+ # scope: :instance
227
+ )
228
+ pins.push Solargraph::Pin::InstanceVariable.new(
229
+ location: ivar.location,
230
+ closure: mm,
231
+ name: ivar.name,
232
+ comments: ivar.comments,
233
+ assignment: ivar.assignment
234
+ # scope: :class
235
+ )
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ # @return [void]
243
+ def process_private_constant
244
+ node.children.last.children[0..-2].each do |child|
245
+ if [:LIT, :STR].include?(child.type)
246
+ cn = child.children[0].to_s
247
+ ref = pins.select{|p| [Solargraph::Pin::Namespace, Solargraph::Pin::Constant].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == cn}.first
248
+ # HACK: Smelly instance variable access
249
+ ref.instance_variable_set(:@visibility, :private) unless ref.nil?
250
+ end
251
+ end
252
+ end
253
+
254
+ # @return [void]
255
+ def process_alias_method
256
+ arr = node.children[1]
257
+ return if arr.nil?
258
+ first = arr.children[0]
259
+ second = arr.children[1]
260
+ return unless first && second && [:LIT, :STR].include?(first.type) && [:LIT, :STR].include?(second.type)
261
+ loc = get_node_location(node)
262
+ pins.push Solargraph::Pin::MethodAlias.new(
263
+ location: get_node_location(node),
264
+ closure: region.closure,
265
+ name: first.children[0].to_s,
266
+ original: second.children[0].to_s,
267
+ scope: region.scope || :instance
268
+ )
269
+ end
270
+
271
+ # @return [Boolean]
272
+ def process_private_class_method
273
+ if node.children.last.children.first.type == :DEFN
274
+ process_children region.update(scope: :class, visibility: :private)
275
+ true
276
+ else
277
+ node.children.last.children[0..-2].each do |child|
278
+ if child.type == :LIT && child.children.first.is_a?(::Symbol)
279
+ sym_name = child.children.first.to_s
280
+ ref = pins.select{|p| [Solargraph::Pin::Method, Solargraph::Pin::Attribute].include?(p.class) && p.namespace == region.closure.full_context.namespace && p.name == sym_name}.first
281
+ # HACK: Smelly instance variable access
282
+ ref.instance_variable_set(:@visibility, :private) unless ref.nil?
283
+ false
284
+ end
285
+ end
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end