solargraph 0.52.0 → 0.53.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.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +40 -0
  3. data/.github/workflows/rspec.yml +1 -3
  4. data/.github/workflows/typecheck.yml +34 -0
  5. data/CHANGELOG.md +30 -0
  6. data/README.md +13 -16
  7. data/SPONSORS.md +1 -7
  8. data/lib/solargraph/api_map/cache.rb +59 -21
  9. data/lib/solargraph/api_map/store.rb +45 -9
  10. data/lib/solargraph/api_map.rb +152 -93
  11. data/lib/solargraph/bench.rb +2 -2
  12. data/lib/solargraph/cache.rb +29 -5
  13. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  14. data/lib/solargraph/complex_type/unique_type.rb +149 -59
  15. data/lib/solargraph/complex_type.rb +62 -9
  16. data/lib/solargraph/convention.rb +0 -1
  17. data/lib/solargraph/converters/dd.rb +5 -0
  18. data/lib/solargraph/converters/dl.rb +3 -0
  19. data/lib/solargraph/converters/dt.rb +3 -0
  20. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  21. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  22. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  23. data/lib/solargraph/diagnostics.rb +2 -2
  24. data/lib/solargraph/doc_map.rb +146 -0
  25. data/lib/solargraph/gem_pins.rb +64 -0
  26. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  27. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  28. data/lib/solargraph/language_server/host/dispatch.rb +10 -4
  29. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  30. data/lib/solargraph/language_server/host/sources.rb +7 -4
  31. data/lib/solargraph/language_server/host.rb +15 -6
  32. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  33. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  34. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  35. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  36. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  37. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  38. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  39. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  40. data/lib/solargraph/library.rb +58 -11
  41. data/lib/solargraph/location.rb +1 -0
  42. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  43. data/lib/solargraph/parser/node_methods.rb +47 -8
  44. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  45. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  46. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  47. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  48. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  49. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  53. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +1 -1
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  66. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  67. data/lib/solargraph/parser/parser_gem.rb +12 -0
  68. data/lib/solargraph/parser/snippet.rb +2 -0
  69. data/lib/solargraph/parser.rb +8 -11
  70. data/lib/solargraph/pin/base.rb +63 -8
  71. data/lib/solargraph/pin/base_variable.rb +6 -2
  72. data/lib/solargraph/pin/block.rb +11 -6
  73. data/lib/solargraph/pin/closure.rb +17 -2
  74. data/lib/solargraph/pin/common.rb +7 -3
  75. data/lib/solargraph/pin/conversions.rb +33 -3
  76. data/lib/solargraph/pin/documenting.rb +25 -34
  77. data/lib/solargraph/pin/instance_variable.rb +4 -0
  78. data/lib/solargraph/pin/local_variable.rb +13 -1
  79. data/lib/solargraph/pin/method.rb +109 -15
  80. data/lib/solargraph/pin/namespace.rb +16 -10
  81. data/lib/solargraph/pin/parameter.rb +41 -10
  82. data/lib/solargraph/pin/reference/override.rb +2 -2
  83. data/lib/solargraph/pin/reference.rb +8 -0
  84. data/lib/solargraph/pin/search.rb +3 -3
  85. data/lib/solargraph/pin/signature.rb +114 -2
  86. data/lib/solargraph/pin.rb +0 -1
  87. data/lib/solargraph/range.rb +2 -2
  88. data/lib/solargraph/rbs_map/conversions.rb +212 -25
  89. data/lib/solargraph/rbs_map/core_fills.rb +4 -26
  90. data/lib/solargraph/rbs_map/core_map.rb +1 -0
  91. data/lib/solargraph/rbs_map/core_signs.rb +2 -0
  92. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  93. data/lib/solargraph/rbs_map.rb +19 -9
  94. data/lib/solargraph/shell.rb +62 -59
  95. data/lib/solargraph/source/chain/array.rb +4 -1
  96. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  97. data/lib/solargraph/source/chain/call.rb +95 -26
  98. data/lib/solargraph/source/chain/constant.rb +15 -1
  99. data/lib/solargraph/source/chain/if.rb +23 -0
  100. data/lib/solargraph/source/chain/link.rb +7 -1
  101. data/lib/solargraph/source/chain/or.rb +1 -1
  102. data/lib/solargraph/source/chain/z_super.rb +2 -2
  103. data/lib/solargraph/source/chain.rb +20 -4
  104. data/lib/solargraph/source/change.rb +3 -0
  105. data/lib/solargraph/source/cursor.rb +2 -0
  106. data/lib/solargraph/source/source_chainer.rb +6 -5
  107. data/lib/solargraph/source.rb +15 -16
  108. data/lib/solargraph/source_map/clip.rb +11 -7
  109. data/lib/solargraph/source_map/mapper.rb +10 -0
  110. data/lib/solargraph/source_map.rb +13 -3
  111. data/lib/solargraph/type_checker/checks.rb +10 -2
  112. data/lib/solargraph/type_checker.rb +74 -19
  113. data/lib/solargraph/version.rb +1 -1
  114. data/lib/solargraph/workspace/config.rb +8 -6
  115. data/lib/solargraph/workspace.rb +1 -1
  116. data/lib/solargraph/yard_map/cache.rb +6 -0
  117. data/lib/solargraph/yard_map/helpers.rb +1 -1
  118. data/lib/solargraph/yard_map/mapper/to_method.rb +11 -1
  119. data/lib/solargraph/yard_map/to_method.rb +11 -4
  120. data/lib/solargraph/yard_map.rb +0 -292
  121. data/lib/solargraph/yardoc.rb +52 -0
  122. data/lib/solargraph.rb +4 -1
  123. data/solargraph.gemspec +2 -2
  124. metadata +35 -57
  125. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  126. data/lib/solargraph/documentor.rb +0 -76
  127. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  128. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  129. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  130. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  131. data/lib/solargraph/parser/legacy.rb +0 -12
  132. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  133. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  134. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  135. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  136. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  137. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  138. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  139. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  140. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  141. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  142. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  143. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  144. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  145. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  146. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  147. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  148. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  149. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  150. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  151. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  152. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  153. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  154. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  155. data/lib/solargraph/parser/rubyvm.rb +0 -40
@@ -1,317 +0,0 @@
1
- module Solargraph
2
- module Parser
3
- module Rubyvm
4
- module NodeMethods
5
- module_function
6
-
7
- # @param node [RubyVM::AbstractSyntaxTree::Node]
8
- # @return [String]
9
- def unpack_name node
10
- pack_name(node).join('::')
11
- end
12
-
13
- # @param node [RubyVM::AbstractSyntaxTree::Node]
14
- # @return [Array<String>]
15
- def pack_name(node)
16
- parts = []
17
- if node.is_a?(RubyVM::AbstractSyntaxTree::Node)
18
- parts.push '' if node.type == :COLON3
19
- node.children.each { |n|
20
- if n.is_a?(RubyVM::AbstractSyntaxTree::Node)
21
- parts += pack_name(n)
22
- else
23
- parts.push n unless n.nil?
24
- end
25
- }
26
- end
27
- parts
28
- end
29
-
30
- # @param node [RubyVM::AbstractSyntaxTree::Node]
31
- # @return [String, nil]
32
- def infer_literal_node_type node
33
- return nil unless Parser.is_ast_node?(node)
34
- case node.type
35
- when :LIT, :STR, :SYM
36
- "::#{node.children.first.class.to_s}"
37
- when :DSTR
38
- "::String"
39
- when :INTEGER
40
- '::Integer'
41
- when :ARRAY, :ZARRAY, :LIST, :ZLIST
42
- '::Array'
43
- when :HASH
44
- '::Hash'
45
- when :DOT2, :DOT3
46
- '::Range'
47
- when :TRUE, :FALSE
48
- '::Boolean'
49
- when :SCOPE
50
- infer_literal_node_type(node.children[2])
51
- end
52
- end
53
-
54
- def returns_from node
55
- return [] unless Parser.is_ast_node?(node)
56
- if node.type == :SCOPE
57
- # node.children.select { |n| n.is_a?(RubyVM::AbstractSyntaxTree::Node) }.map { |n| DeepInference.get_return_nodes(n) }.flatten
58
- DeepInference.get_return_nodes(node.children[2])
59
- else
60
- DeepInference.get_return_nodes(node)
61
- end
62
- end
63
-
64
- def const_nodes_from node
65
- return [] unless Parser.is_ast_node?(node)
66
- result = []
67
- if [:CONST, :COLON2, :COLON3].include?(node.type)
68
- result.push node
69
- else
70
- node.children.each { |child| result.concat const_nodes_from(child) }
71
- end
72
- result
73
- end
74
-
75
- def call_nodes_from node
76
- return [] unless Parser.is_ast_node?(node)
77
- result = []
78
- if node.type == :ITER
79
- result.push node.children[0]
80
- node.children[1..-1].each { |child| result.concat call_nodes_from(child) }
81
- elsif node.type == :MASGN
82
- # @todo We're treating a mass assignment as a call node, but the
83
- # type checker still needs the logic to handle it.
84
- result.push node
85
- elsif [:CALL, :VCALL, :FCALL, :ATTRASGN, :OPCALL].include?(node.type)
86
- result.push node
87
- node.children.each { |child| result.concat call_nodes_from(child) }
88
- else
89
- node.children.each { |child| result.concat call_nodes_from(child) }
90
- end
91
- result
92
- end
93
-
94
- def convert_hash node
95
- return {} unless node?(node) && node.type == :HASH
96
- return convert_hash(node.children[0].children[1]) if splatted_hash?(node)
97
- return {} unless node?(node.children[0])
98
- result = {}
99
- index = 0
100
- until index > node.children[0].children.length - 2
101
- k = node.children[0].children[index]
102
- return {} unless node?(k)
103
- v = node.children[0].children[index + 1]
104
- result[k.children[0]] = Solargraph::Parser.chain(v)
105
- index += 2
106
- end
107
- result
108
- end
109
-
110
- def splatted_hash? node
111
- splatted_node?(node) && node.children[0].children[1].type == :HASH
112
- end
113
-
114
- def splatted_node? node
115
- node?(node.children[0]) &&
116
- [:ARRAY, :LIST].include?(node.children[0].type) &&
117
- node.children[0].children[0].nil? &&
118
- node?(node.children[0].children[1])
119
- end
120
-
121
- def splatted_call? node
122
- return false unless Parser.is_ast_node?(node)
123
- splatted_node?(node) && node.children[0].children[1].type != :HASH
124
- end
125
-
126
- def any_splatted_call?(nodes)
127
- nodes.any? { |n| splatted_call?(n) }
128
- end
129
-
130
- def node? node
131
- node.is_a?(RubyVM::AbstractSyntaxTree::Node)
132
- end
133
-
134
- # @param cursor [Solargraph::Source::Cursor]
135
- def find_recipient_node cursor
136
- if cursor.source.synchronized?
137
- NodeMethods.synchronized_find_recipient_node cursor
138
- else
139
- NodeMethods.unsynchronized_find_recipient_node cursor
140
- end
141
- end
142
-
143
- class << self
144
- protected
145
-
146
- # @param cursor [Source::Cursor]
147
- # @return [RubyVM::AbstractSyntaxTree::Node, nil]
148
- def synchronized_find_recipient_node cursor
149
- cursor = maybe_adjust_cursor(cursor)
150
- source = cursor.source
151
- position = cursor.position
152
- offset = cursor.offset
153
- tree = source.tree_at(position.line, position.column)
154
- .select { |n| [:FCALL, :VCALL, :CALL].include?(n.type) }
155
- unless source.repaired?
156
- tree.shift while tree.first && !source.code_for(tree.first).strip.end_with?(')')
157
- end
158
- return tree.first if source.repaired? || source.code[0..offset-1] =~ /\(\s*$/
159
- tree.each do |node|
160
- args = node.children.find { |c| Parser.is_ast_node?(c) && [:ARRAY, :ZARRAY, :LIST].include?(c.type) }
161
- if args
162
- match = source.code[0..offset-1].match(/,[^\)]*\z/)
163
- rng = Solargraph::Range.from_node(args)
164
- if match
165
- rng = Solargraph::Range.new(rng.start, position)
166
- end
167
- return node if rng.contain?(position)
168
- end
169
- end
170
- nil
171
- end
172
-
173
- # @param cursor [Source::Cursor]
174
- # @return [Source::Cursor]
175
- def maybe_adjust_cursor cursor
176
- return cursor unless (cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '(') || [',', ' '].include?(cursor.source.code[cursor.offset - 1])
177
- cursor.source.cursor_at([cursor.position.line, cursor.position.column - 1])
178
- end
179
-
180
- def unsynchronized_find_recipient_node cursor
181
- source = cursor.source
182
- position = cursor.position
183
- offset = cursor.offset
184
- if source.code[0..offset-1] =~ /\([A-Zaz0-9_\s]*\z$/
185
- tree = source.tree_at(position.line, position.column - 1)
186
- if tree.first && [:FCALL, :VCALL, :CALL].include?(tree.first.type)
187
- return tree.first
188
- else
189
- return nil
190
- end
191
- else
192
- match = source.code[0..offset-1].match(/[\(,][A-Zaz0-9_\s]*\z/)
193
- if match
194
- moved = Position.from_offset(source.code, offset - match[0].length)
195
- tree = source.tree_at(moved.line, moved.column)
196
- tree.shift if match[0].start_with?(',')
197
- tree.shift while tree.first && ![:FCALL, :VCALL, :CALL].include?(tree.first.type)
198
- if tree.first && [:FCALL, :VCALL, :CALL].include?(tree.first.type)
199
- return tree.first
200
- end
201
- end
202
- return nil
203
- end
204
- end
205
- end
206
-
207
- module DeepInference
208
- class << self
209
- CONDITIONAL = [:IF, :UNLESS]
210
- REDUCEABLE = [:BLOCK]
211
- SKIPPABLE = [:DEFN, :DEFS, :CLASS, :SCLASS, :MODULE]
212
-
213
- # @param node [Parser::AST::Node]
214
- # @return [Array<Parser::AST::Node>]
215
- def get_return_nodes node
216
- return [] unless node.is_a?(RubyVM::AbstractSyntaxTree::Node)
217
- result = []
218
- if REDUCEABLE.include?(node.type)
219
- result.concat get_return_nodes_from_children(node)
220
- elsif CONDITIONAL.include?(node.type)
221
- result.concat reduce_to_value_nodes(node.children[1..-1])
222
- elsif node.type == :RESCUE
223
- result.concat reduce_to_value_nodes([node.children[0]])
224
- result.concat reduce_to_value_nodes(node.children[1..-2])
225
- elsif node.type == :OR
226
- result.concat reduce_to_value_nodes(node.children)
227
- elsif node.type == :RETURN
228
- result.concat reduce_to_value_nodes([node.children[0]])
229
- elsif node.type == :ITER
230
- result.push node
231
- result.concat get_return_nodes_only(node.children[1])
232
- elsif node.type == :CASE
233
- node.children[1..-1].each do |cc|
234
- result.concat reduce_to_value_nodes(cc.children[1..-1])
235
- end
236
- else
237
- result.push node
238
- end
239
- result
240
- end
241
-
242
- private
243
-
244
- def get_return_nodes_from_children parent
245
- result = []
246
- nodes = parent.children.select{|n| n.is_a?(RubyVM::AbstractSyntaxTree::Node)}
247
- nodes.each_with_index do |node, idx|
248
- if node.type == :BLOCK
249
- result.concat get_return_nodes_only(node.children[2])
250
- elsif SKIPPABLE.include?(node.type)
251
- next
252
- elsif CONDITIONAL.include?(node.type)
253
- result.concat get_return_nodes_only(node)
254
- elsif node.type == :RETURN
255
- result.concat reduce_to_value_nodes([node.children[0]])
256
- # Return the result here because the rest of the code is
257
- # unreachable
258
- return result
259
- else
260
- result.concat get_return_nodes_only(node)
261
- end
262
- result.concat reduce_to_value_nodes([nodes.last]) if idx == nodes.length - 1
263
- end
264
- result
265
- end
266
-
267
- def get_return_nodes_only parent
268
- return [] unless parent.is_a?(RubyVM::AbstractSyntaxTree::Node)
269
- result = []
270
- nodes = parent.children.select{|n| n.is_a?(RubyVM::AbstractSyntaxTree::Node)}
271
- nodes.each do |node|
272
- next if SKIPPABLE.include?(node.type)
273
- if node.type == :RETURN
274
- result.concat reduce_to_value_nodes([node.children[0]])
275
- # Return the result here because the rest of the code is
276
- # unreachable
277
- return result
278
- else
279
- result.concat get_return_nodes_only(node)
280
- end
281
- end
282
- result
283
- end
284
-
285
- def reduce_to_value_nodes nodes
286
- result = []
287
- nodes.each do |node|
288
- if !node.is_a?(RubyVM::AbstractSyntaxTree::Node)
289
- result.push nil
290
- elsif REDUCEABLE.include?(node.type)
291
- result.concat get_return_nodes_from_children(node)
292
- elsif CONDITIONAL.include?(node.type)
293
- result.concat reduce_to_value_nodes(node.children[1..-1])
294
- elsif node.type == :RETURN
295
- if node.children[0].nil?
296
- result.push nil
297
- else
298
- result.concat get_return_nodes(node.children[0])
299
- end
300
- elsif node.type == :OR
301
- result.concat reduce_to_value_nodes(node.children)
302
- elsif node.type == :BLOCK
303
- result.concat get_return_nodes_only(node.children[2])
304
- elsif node.type == :RESBODY
305
- result.concat reduce_to_value_nodes([node.children[1]])
306
- else
307
- result.push node
308
- end
309
- end
310
- result
311
- end
312
- end
313
- end
314
- end
315
- end
316
- end
317
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class ArgsNode < Parser::NodeProcessor::Base
8
- def process
9
- if region.closure.is_a?(Pin::Method) || region.closure.is_a?(Pin::Block)
10
- if region.lvars[0].nil?
11
- node.children[0].times do |i|
12
- locals.push Solargraph::Pin::Parameter.new(
13
- location: region.closure.location,
14
- closure: region.closure,
15
- comments: comments_for(node),
16
- name: extract_name(node.children[i + 1]),
17
- presence: region.closure.location.range,
18
- decl: :arg
19
- )
20
- region.closure.parameters.push locals.last
21
- end
22
- else
23
- node.children[0].times do |i|
24
- locals.push Solargraph::Pin::Parameter.new(
25
- location: region.closure.location,
26
- closure: region.closure,
27
- comments: comments_for(node),
28
- name: region.lvars[i].to_s,
29
- presence: region.closure.location.range,
30
- decl: :arg
31
- )
32
- region.closure.parameters.push locals.last
33
- end
34
- end
35
- if node.children[6]
36
- locals.push Solargraph::Pin::Parameter.new(
37
- location: region.closure.location,
38
- closure: region.closure,
39
- comments: comments_for(node),
40
- name: node.children[6].to_s,
41
- presence: region.closure.location.range,
42
- decl: :restarg
43
- )
44
- region.closure.parameters.push locals.last
45
- end
46
- if node.children[8] && node.children[8].children.first
47
- locals.push Solargraph::Pin::Parameter.new(
48
- location: region.closure.location,
49
- closure: region.closure,
50
- comments: comments_for(node),
51
- name: node.children[8].children.first.to_s,
52
- presence: region.closure.location.range,
53
- decl: :kwrestarg
54
- )
55
- region.closure.parameters.push locals.last
56
- end
57
- end
58
- process_children
59
- if node.children.last
60
- locals.push Solargraph::Pin::Parameter.new(
61
- location: region.closure.location,
62
- closure: region.closure,
63
- comments: comments_for(node),
64
- name: node.children.last.to_s,
65
- presence: region.closure.location.range,
66
- decl: :blockarg
67
- )
68
- region.closure.parameters.push locals.last
69
- end
70
- end
71
-
72
- private
73
-
74
- def extract_name var
75
- if Parser.is_ast_node?(var)
76
- var.children[0].to_s
77
- else
78
- var.to_s
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class BlockNode < Parser::NodeProcessor::Base
8
- include NodeMethods
9
-
10
- def process
11
- location = get_node_location(node)
12
- parent = if other_class_eval?
13
- Solargraph::Pin::Namespace.new(
14
- location: location,
15
- type: :class,
16
- name: unpack_name(node.children[0].children[0])
17
- )
18
- else
19
- region.closure
20
- end
21
- pins.push Solargraph::Pin::Block.new(
22
- location: location,
23
- closure: parent,
24
- receiver: node.children[0],
25
- comments: comments_for(node),
26
- scope: region.scope || region.closure.context.scope
27
- )
28
- process_children region.update(closure: pins.last)
29
- end
30
-
31
- private
32
-
33
- def other_class_eval?
34
- node.children[0].type == :CALL &&
35
- node.children[0].children[1] == :class_eval &&
36
- [:COLON2, :CONST].include?(node.children[0].children[0].type)
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class CasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- pins.push Solargraph::Pin::Constant.new(
10
- location: get_node_location(node),
11
- closure: region.closure,
12
- name: const_name,
13
- comments: comments_for(node),
14
- assignment: node.children[2] || node.children[1]
15
- )
16
- process_children
17
- end
18
-
19
- private
20
-
21
- # @return [String]
22
- def const_name
23
- if Parser.is_ast_node?(node.children[0])
24
- Parser::NodeMethods.unpack_name(node.children[0])
25
- else
26
- node.children[0].to_s
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class CvasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- loc = get_node_location(node)
10
- pins.push Solargraph::Pin::ClassVariable.new(
11
- location: loc,
12
- closure: region.closure,
13
- name: node.children[0].to_s,
14
- comments: comments_for(node),
15
- assignment: node.children[1]
16
- )
17
- process_children
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class DefNode < Parser::NodeProcessor::Base
8
- def process
9
- anon_splat = node_has_anon_splat?
10
-
11
- methpin = Solargraph::Pin::Method.new(
12
- location: get_node_location(node),
13
- closure: region.closure,
14
- name: node.children[0].to_s,
15
- comments: comments_for(node),
16
- scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
17
- visibility: region.visibility,
18
- node: node,
19
- anon_splat: anon_splat
20
- )
21
- if methpin.name == 'initialize' && methpin.scope == :instance
22
- pins.push Solargraph::Pin::Method.new(
23
- location: methpin.location,
24
- closure: methpin.closure,
25
- name: 'new',
26
- comments: methpin.comments,
27
- scope: :class,
28
- parameters: methpin.parameters,
29
- anon_splat: anon_splat
30
- )
31
- # @todo Smelly instance variable access.
32
- pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
33
- pins.push methpin
34
- # @todo Smelly instance variable access.
35
- methpin.instance_variable_set(:@visibility, :private)
36
- methpin.instance_variable_set(:@return_type, ComplexType::VOID)
37
- elsif region.visibility == :module_function
38
- pins.push Solargraph::Pin::Method.new(
39
- location: methpin.location,
40
- closure: methpin.closure,
41
- name: methpin.name,
42
- comments: methpin.comments,
43
- scope: :class,
44
- visibility: :public,
45
- parameters: methpin.parameters,
46
- node: methpin.node,
47
- anon_splat: anon_splat
48
- )
49
- pins.push Solargraph::Pin::Method.new(
50
- location: methpin.location,
51
- closure: methpin.closure,
52
- name: methpin.name,
53
- comments: methpin.comments,
54
- scope: :instance,
55
- visibility: :private,
56
- parameters: methpin.parameters,
57
- node: methpin.node,
58
- anon_splat: anon_splat
59
- )
60
- else
61
- pins.push methpin
62
- end
63
- process_children region.update(closure: methpin, scope: methpin.scope)
64
- end
65
-
66
- private
67
-
68
- def node_has_anon_splat?
69
- node.children[1]&.children&.first == [nil]
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class DefsNode < DefNode
8
- include NodeMethods
9
-
10
- def process
11
- s_visi = region.visibility
12
- s_visi = :public if region.scope != :class
13
- loc = get_node_location(node)
14
- anon_splat = node_has_anon_splat?
15
-
16
- if node.children[0].is_a?(RubyVM::AbstractSyntaxTree::Node) && node.children[0].type == :SELF
17
- closure = region.closure
18
- else
19
- closure = Solargraph::Pin::Namespace.new(
20
- name: unpack_name(node.children[0])
21
- )
22
- end
23
- if s_visi == :module_function
24
- pins.push Solargraph::Pin::Method.new(
25
- location: loc,
26
- closure: closure,
27
- name: node.children[1].to_s,
28
- comments: comments_for(node),
29
- scope: :class,
30
- visibility: :public,
31
- node: node,
32
- anon_splat: anon_splat
33
- )
34
- pins.push Solargraph::Pin::Method.new(
35
- location: loc,
36
- closure: closure,
37
- name: node.children[1].to_s,
38
- comments: comments_for(node),
39
- scope: :instance,
40
- visibility: :private,
41
- node: node,
42
- anon_splat: anon_splat
43
- )
44
- else
45
- pins.push Solargraph::Pin::Method.new(
46
- location: loc,
47
- closure: closure,
48
- name: node.children[1].to_s,
49
- comments: comments_for(node),
50
- scope: :class,
51
- visibility: s_visi,
52
- node: node,
53
- anon_splat: anon_splat
54
- )
55
- end
56
- process_children region.update(closure: pins.last, scope: :class)
57
- end
58
-
59
- private
60
-
61
- def node_has_anon_splat?
62
- node.children[2]&.children&.first == [nil]
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module Rubyvm
6
- module NodeProcessors
7
- class GvasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- loc = get_node_location(node)
10
- pins.push Solargraph::Pin::GlobalVariable.new(
11
- location: loc,
12
- closure: region.closure,
13
- name: node.children[0].to_s,
14
- comments: comments_for(node),
15
- assignment: node.children[1]
16
- )
17
- process_children
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end