solargraph 0.58.1 → 0.59.0.dev.1

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 (162) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.github/workflows/linting.yml +4 -5
  4. data/.github/workflows/plugins.yml +40 -36
  5. data/.github/workflows/rspec.yml +45 -13
  6. data/.github/workflows/typecheck.yml +2 -2
  7. data/.rubocop_todo.yml +27 -49
  8. data/README.md +3 -3
  9. data/Rakefile +1 -0
  10. data/lib/solargraph/api_map/cache.rb +110 -110
  11. data/lib/solargraph/api_map/constants.rb +289 -279
  12. data/lib/solargraph/api_map/index.rb +204 -193
  13. data/lib/solargraph/api_map/source_to_yard.rb +109 -97
  14. data/lib/solargraph/api_map/store.rb +387 -384
  15. data/lib/solargraph/api_map.rb +1000 -945
  16. data/lib/solargraph/complex_type/conformance.rb +176 -0
  17. data/lib/solargraph/complex_type/type_methods.rb +242 -228
  18. data/lib/solargraph/complex_type/unique_type.rb +632 -482
  19. data/lib/solargraph/complex_type.rb +549 -444
  20. data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
  21. data/lib/solargraph/convention/data_definition.rb +108 -105
  22. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
  23. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
  24. data/lib/solargraph/convention/struct_definition.rb +168 -164
  25. data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
  26. data/lib/solargraph/diagnostics/rubocop.rb +119 -118
  27. data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
  28. data/lib/solargraph/diagnostics/type_check.rb +56 -55
  29. data/lib/solargraph/doc_map.rb +200 -439
  30. data/lib/solargraph/equality.rb +34 -34
  31. data/lib/solargraph/gem_pins.rb +97 -98
  32. data/lib/solargraph/language_server/host/dispatch.rb +131 -130
  33. data/lib/solargraph/language_server/host/message_worker.rb +113 -112
  34. data/lib/solargraph/language_server/host/sources.rb +100 -99
  35. data/lib/solargraph/language_server/host.rb +883 -878
  36. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
  37. data/lib/solargraph/language_server/message/extended/document.rb +24 -23
  38. data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
  39. data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
  40. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
  41. data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
  42. data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
  43. data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
  44. data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
  45. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
  46. data/lib/solargraph/library.rb +729 -683
  47. data/lib/solargraph/location.rb +87 -82
  48. data/lib/solargraph/logging.rb +57 -37
  49. data/lib/solargraph/parser/comment_ripper.rb +76 -69
  50. data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
  51. data/lib/solargraph/parser/node_processor/base.rb +122 -92
  52. data/lib/solargraph/parser/node_processor.rb +63 -62
  53. data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
  54. data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
  55. data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -486
  56. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
  57. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
  58. data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
  59. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
  60. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
  61. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
  62. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
  63. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
  64. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
  65. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
  66. data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
  67. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
  68. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
  69. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
  70. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
  71. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
  72. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
  73. data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
  74. data/lib/solargraph/parser/region.rb +75 -69
  75. data/lib/solargraph/parser/snippet.rb +17 -17
  76. data/lib/solargraph/pin/base.rb +761 -729
  77. data/lib/solargraph/pin/base_variable.rb +418 -126
  78. data/lib/solargraph/pin/block.rb +126 -104
  79. data/lib/solargraph/pin/breakable.rb +13 -9
  80. data/lib/solargraph/pin/callable.rb +278 -231
  81. data/lib/solargraph/pin/closure.rb +68 -72
  82. data/lib/solargraph/pin/common.rb +94 -79
  83. data/lib/solargraph/pin/compound_statement.rb +55 -0
  84. data/lib/solargraph/pin/conversions.rb +124 -123
  85. data/lib/solargraph/pin/delegated_method.rb +131 -120
  86. data/lib/solargraph/pin/documenting.rb +115 -114
  87. data/lib/solargraph/pin/instance_variable.rb +38 -34
  88. data/lib/solargraph/pin/keyword.rb +16 -20
  89. data/lib/solargraph/pin/local_variable.rb +31 -75
  90. data/lib/solargraph/pin/method.rb +720 -672
  91. data/lib/solargraph/pin/method_alias.rb +42 -34
  92. data/lib/solargraph/pin/namespace.rb +121 -115
  93. data/lib/solargraph/pin/parameter.rb +338 -275
  94. data/lib/solargraph/pin/proxy_type.rb +40 -39
  95. data/lib/solargraph/pin/reference/override.rb +47 -47
  96. data/lib/solargraph/pin/reference/superclass.rb +17 -15
  97. data/lib/solargraph/pin/reference.rb +41 -39
  98. data/lib/solargraph/pin/search.rb +62 -61
  99. data/lib/solargraph/pin/signature.rb +69 -61
  100. data/lib/solargraph/pin/symbol.rb +53 -53
  101. data/lib/solargraph/pin/until.rb +18 -18
  102. data/lib/solargraph/pin/while.rb +18 -18
  103. data/lib/solargraph/pin.rb +46 -44
  104. data/lib/solargraph/pin_cache.rb +665 -245
  105. data/lib/solargraph/position.rb +118 -119
  106. data/lib/solargraph/range.rb +112 -112
  107. data/lib/solargraph/rbs_map/conversions.rb +846 -823
  108. data/lib/solargraph/rbs_map/core_map.rb +65 -58
  109. data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
  110. data/lib/solargraph/rbs_map.rb +217 -163
  111. data/lib/solargraph/shell.rb +397 -352
  112. data/lib/solargraph/source/chain/call.rb +372 -337
  113. data/lib/solargraph/source/chain/constant.rb +28 -26
  114. data/lib/solargraph/source/chain/hash.rb +35 -34
  115. data/lib/solargraph/source/chain/if.rb +29 -28
  116. data/lib/solargraph/source/chain/instance_variable.rb +34 -13
  117. data/lib/solargraph/source/chain/literal.rb +53 -48
  118. data/lib/solargraph/source/chain/or.rb +31 -23
  119. data/lib/solargraph/source/chain.rb +294 -291
  120. data/lib/solargraph/source/change.rb +89 -82
  121. data/lib/solargraph/source/cursor.rb +172 -166
  122. data/lib/solargraph/source/source_chainer.rb +204 -194
  123. data/lib/solargraph/source/updater.rb +59 -55
  124. data/lib/solargraph/source.rb +524 -498
  125. data/lib/solargraph/source_map/clip.rb +237 -226
  126. data/lib/solargraph/source_map/data.rb +37 -34
  127. data/lib/solargraph/source_map/mapper.rb +282 -259
  128. data/lib/solargraph/source_map.rb +220 -212
  129. data/lib/solargraph/type_checker/problem.rb +34 -32
  130. data/lib/solargraph/type_checker/rules.rb +157 -84
  131. data/lib/solargraph/type_checker.rb +895 -814
  132. data/lib/solargraph/version.rb +1 -1
  133. data/lib/solargraph/workspace/config.rb +257 -255
  134. data/lib/solargraph/workspace/gemspecs.rb +367 -0
  135. data/lib/solargraph/workspace/require_paths.rb +98 -97
  136. data/lib/solargraph/workspace.rb +362 -220
  137. data/lib/solargraph/yard_map/helpers.rb +45 -44
  138. data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
  139. data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
  140. data/lib/solargraph/yard_map/mapper.rb +84 -79
  141. data/lib/solargraph/yardoc.rb +97 -87
  142. data/lib/solargraph.rb +126 -105
  143. data/rbs/fills/rubygems/0/dependency.rbs +193 -0
  144. data/rbs/fills/tuple/tuple.rbs +28 -0
  145. data/rbs/shims/ast/0/node.rbs +5 -0
  146. data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
  147. data/rbs_collection.yaml +1 -1
  148. data/solargraph.gemspec +2 -1
  149. metadata +22 -17
  150. data/lib/solargraph/type_checker/checks.rb +0 -124
  151. data/lib/solargraph/type_checker/param_def.rb +0 -37
  152. data/lib/solargraph/yard_map/to_method.rb +0 -89
  153. data/sig/shims/ast/0/node.rbs +0 -5
  154. /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
  155. /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
  156. /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
  157. /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
  158. /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
  159. /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
  160. /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
  161. /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
  162. /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
@@ -1,486 +1,506 @@
1
- # frozen_string_literal: true
2
-
3
- require 'parser'
4
- require 'ast'
5
-
6
- # https://github.com/whitequark/parser
7
- module Solargraph
8
- module Parser
9
- module ParserGem
10
- module NodeMethods
11
- module_function
12
-
13
- # @param node [Parser::AST::Node]
14
- # @return [String]
15
- def unpack_name(node)
16
- pack_name(node).join("::")
17
- end
18
-
19
- # @param node [Parser::AST::Node]
20
- # @return [Array<String>]
21
- def pack_name(node)
22
- # @type [Array<String>]
23
- parts = []
24
- if node.is_a?(AST::Node)
25
- node.children.each { |n|
26
- if n.is_a?(AST::Node)
27
- if n.type == :cbase
28
- parts = [''] + pack_name(n)
29
- elsif n.type == :const
30
- parts += pack_name(n)
31
- end
32
- else
33
- parts.push n unless n.nil?
34
- end
35
- }
36
- end
37
- parts
38
- end
39
-
40
- # @param node [Parser::AST::Node]
41
- # @return [String, nil]
42
- def infer_literal_node_type node
43
- return nil unless node.is_a?(AST::Node)
44
- if node.type == :str || node.type == :dstr
45
- return '::String'
46
- elsif node.type == :array
47
- return '::Array'
48
- elsif node.type == :nil
49
- return '::NilClass'
50
- elsif node.type == :hash
51
- return '::Hash'
52
- elsif node.type == :int
53
- return '::Integer'
54
- elsif node.type == :float
55
- return '::Float'
56
- elsif node.type == :sym || node.type == :dsym
57
- return '::Symbol'
58
- elsif node.type == :regexp
59
- return '::Regexp'
60
- elsif node.type == :irange
61
- return '::Range'
62
- elsif node.type == :true || node.type == :false
63
- return '::Boolean'
64
- # @todo Support `nil` keyword in types
65
- # elsif node.type == :nil
66
- # return 'NilClass'
67
- end
68
- nil
69
- end
70
-
71
- # @param node [Parser::AST::Node]
72
- # @return [Position]
73
- def get_node_start_position(node)
74
- Position.new(node.loc.line, node.loc.column)
75
- end
76
-
77
- # @param node [Parser::AST::Node]
78
- # @return [Position]
79
- def get_node_end_position(node)
80
- Position.new(node.loc.last_line, node.loc.last_column)
81
- end
82
-
83
- # @param node [Parser::AST::Node]
84
- # @param signature [String]
85
- #
86
- # @return [String]
87
- def drill_signature node, signature
88
- return signature unless node.is_a?(AST::Node)
89
- if node.type == :const or node.type == :cbase
90
- unless node.children[0].nil?
91
- signature += drill_signature(node.children[0], signature)
92
- end
93
- signature += '::' unless signature.empty?
94
- signature += node.children[1].to_s
95
- elsif node.type == :lvar or node.type == :ivar or node.type == :cvar
96
- signature += '.' unless signature.empty?
97
- signature += node.children[0].to_s
98
- elsif node.type == :send
99
- unless node.children[0].nil?
100
- signature += drill_signature(node.children[0], signature)
101
- end
102
- signature += '.' unless signature.empty?
103
- signature += node.children[1].to_s
104
- end
105
- signature
106
- end
107
-
108
- # @param node [Parser::AST::Node]
109
- # @return [Hash{Symbol => Chain}]
110
- def convert_hash node
111
- return {} unless Parser.is_ast_node?(node)
112
- return convert_hash(node.children[0]) if node.type == :kwsplat
113
- return convert_hash(node.children[0]) if Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
114
- return {} unless node.type == :hash
115
- result = {}
116
- node.children.each do |pair|
117
- result[pair.children[0].children[0]] = Solargraph::Parser.chain(pair.children[1])
118
- end
119
- result
120
- end
121
-
122
- # @sg-ignore Wrong argument type for AST::Node.new: type expected AST::_ToSym, received :nil
123
- NIL_NODE = ::Parser::AST::Node.new(:nil)
124
-
125
- # @param node [Parser::AST::Node]
126
- #
127
- # @return [Array<Parser::AST::Node>]
128
- def const_nodes_from node
129
- return [] unless Parser.is_ast_node?(node)
130
- result = []
131
- if node.type == :const
132
- result.push node
133
- else
134
- node.children.each { |child| result.concat const_nodes_from(child) }
135
- end
136
- result
137
- end
138
-
139
- # @param node [Parser::AST::Node]
140
- def splatted_hash? node
141
- Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
142
- end
143
-
144
- # @param node [Parser::AST::Node]
145
- def splatted_call? node
146
- return false unless Parser.is_ast_node?(node)
147
- Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat && node.children[0].children[0].type != :hash
148
- end
149
-
150
- # @param nodes [Enumerable<Parser::AST::Node>]
151
- def any_splatted_call?(nodes)
152
- nodes.any? { |n| splatted_call?(n) }
153
- end
154
-
155
- # @todo Temporarily here for testing. Move to Solargraph::Parser.
156
- # @param node [Parser::AST::Node]
157
- # @return [Array<Parser::AST::Node>]
158
- def call_nodes_from node
159
- return [] unless node.is_a?(::Parser::AST::Node)
160
- result = []
161
- if node.type == :block
162
- result.push node
163
- if Parser.is_ast_node?(node.children[0]) && node.children[0].children.length > 2
164
- node.children[0].children[2..-1].each { |child| result.concat call_nodes_from(child) }
165
- end
166
- node.children[1..-1].each { |child| result.concat call_nodes_from(child) }
167
- elsif node.type == :send
168
- result.push node
169
- result.concat call_nodes_from(node.children.first)
170
- node.children[2..-1].each { |child| result.concat call_nodes_from(child) }
171
- elsif [:super, :zsuper].include?(node.type)
172
- result.push node
173
- node.children.each { |child| result.concat call_nodes_from(child) }
174
- else
175
- node.children.each { |child| result.concat call_nodes_from(child) }
176
- end
177
- result
178
- end
179
-
180
- # Find all the nodes within the provided node that potentially return a
181
- # value.
182
- #
183
- # The node parameter typically represents a method's logic, e.g., the
184
- # second child (after the :args node) of a :def node. A simple one-line
185
- # method would typically return itself, while a node with conditions
186
- # would return the resulting node from each conditional branch. Nodes
187
- # that follow a :return node are assumed to be unreachable. Nil values
188
- # are converted to nil node types.
189
- #
190
- # @param node [Parser::AST::Node]
191
- # @return [Array<Parser::AST::Node>]
192
- def returns_from_method_body node
193
- # @todo is the || NIL_NODE necessary?
194
- # STDERR.puts("Evaluating expression: #{node.inspect}")
195
- DeepInference.from_method_body(node).map { |n| n || NIL_NODE }
196
- end
197
-
198
- # @param node [Parser::AST::Node]
199
- # @return [Array<AST::Node>] low-level value nodes in
200
- # value position. Does not include explicit return
201
- # statements
202
- def value_position_nodes_only(node)
203
- DeepInference.value_position_nodes_only(node).map { |n| n || NIL_NODE }
204
- end
205
-
206
- # @param cursor [Solargraph::Source::Cursor]
207
- # @return [Parser::AST::Node, nil]
208
- def find_recipient_node cursor
209
- return repaired_find_recipient_node(cursor) if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
210
- source = cursor.source
211
- position = cursor.position
212
- offset = cursor.offset
213
- tree = if source.synchronized?
214
- match = source.code[0..offset-1].match(/,\s*\z/)
215
- if match
216
- source.tree_at(position.line, position.column - match[0].length)
217
- else
218
- source.tree_at(position.line, position.column)
219
- end
220
- else
221
- source.tree_at(position.line, position.column - 1)
222
- end
223
- # @type [AST::Node, nil]
224
- prev = nil
225
- tree.each do |node|
226
- if node.type == :send
227
- args = node.children[2..-1]
228
- if !args.empty?
229
- return node if prev && args.include?(prev)
230
- else
231
- if source.synchronized?
232
- return node if source.code[0..offset-1] =~ /\(\s*\z/ && source.code[offset..-1] =~ /^\s*\)/
233
- else
234
- return node if source.code[0..offset-1] =~ /\([^(]*\z/
235
- end
236
- end
237
- end
238
- prev = node
239
- end
240
- nil
241
- end
242
-
243
- # @param cursor [Solargraph::Source::Cursor]
244
- # @return [Parser::AST::Node, nil]
245
- def repaired_find_recipient_node cursor
246
- cursor = cursor.source.cursor_at([cursor.position.line, cursor.position.column - 1])
247
- node = cursor.source.tree_at(cursor.position.line, cursor.position.column).first
248
- return node if node && node.type == :send
249
- end
250
-
251
- #
252
- # Concepts:
253
- #
254
- # - statement - one single node in the AST. Generally used
255
- # synonymously with how the Parser gem uses the term
256
- # 'expression'. This may have side effects (e.g.,
257
- # registering a method in the namespace, modifying
258
- # variables or doing I/O). It may encapsulate multiple
259
- # other statements (see compound statement).
260
- #
261
- # - value - something that can be assigned to a variable by
262
- # evaluating a statement
263
- #
264
- # - value node - the 'lowest level' AST node whose return
265
- # type is a subset of the value type of the overall
266
- # statement. Might be a literal, a method call, etc - the
267
- # goal is to find the lowest level node, which we can use
268
- # Chains and Pins later on to determine the type of.
269
- #
270
- # e.g., if the node 'b ? 123 : 456' were a return value, we
271
- # know the actual return values possible are 123 and 456,
272
- # and can disregard the rest.
273
- #
274
- # - value type - the type representing the multiple possible
275
- # values that can result from evaluation of the statement.
276
- #
277
- # - return type - the type describing the values a statement
278
- # might evaluate to. When used with a method, the term
279
- # describes the values that may result from the method
280
- # being called, and includes explicit return statements
281
- # within the method body's closure.
282
- #
283
- # - method body - a compound statement with parameters whose
284
- # return value type must account both for the explicit
285
- # 'return' statemnts as well as the final statements
286
- # executed in any given control flow through the method.
287
- #
288
- # - explicit return statement - a statement which, when part of a
289
- # method body, is a possible value of a call to that method -
290
- # e.g., "return 123"
291
- #
292
- # - compound statement - a statement which can be expanded to
293
- # be multiple statements in a row, executed in the context
294
- # of a method which can be explicitly returned from.
295
- #
296
- # - value position - the positions in the AST where the
297
- # return type of the statement would be one of the return
298
- # types of any compound statements it is a part of. For a
299
- # compound statement, the last of the child statements
300
- # would be in return position. This concept can be applied
301
- # recursively through e.g. conditionals to find a list of
302
- # statements in value positions.
303
- module DeepInference
304
- class << self
305
- CONDITIONAL_ALL_BUT_FIRST = [:if, :unless]
306
- CONDITIONAL_ALL = [:or]
307
- ONLY_ONE_CHILD = [:return]
308
- FIRST_TWO_CHILDREN = [:rescue]
309
- COMPOUND_STATEMENTS = [:begin, :kwbegin]
310
- SKIPPABLE = [:def, :defs, :class, :sclass, :module]
311
- FUNCTION_VALUE = [:block]
312
- CASE_STATEMENT = [:case]
313
-
314
- # @param node [AST::Node] a method body compound statement
315
- # @param include_explicit_returns [Boolean] If true,
316
- # include the value nodes of the parameter of the
317
- # 'return' statements in the type returned.
318
- # @return [Array<AST::Node>] low-level value nodes from
319
- # both nodes in value position as well as explicit
320
- # return statements in the method's closure.
321
- def from_method_body node
322
- from_value_position_statement(node, include_explicit_returns: true)
323
- end
324
-
325
- # @param node [AST::Node] an individual statement, to be
326
- # evaluated outside the context of a containing method
327
- # @return [Array<AST::Node>] low-level value nodes in
328
- # value position. Does not include explicit return
329
- # statements
330
- def value_position_nodes_only(node)
331
- from_value_position_statement(node, include_explicit_returns: false)
332
- end
333
-
334
- # Look at known control statements and use them to find
335
- # more specific return nodes.
336
- #
337
- # @param node [Parser::AST::Node] Statement which is in
338
- # value position for a method body
339
- # @param include_explicit_returns [Boolean] If true,
340
- # include the value nodes of the parameter of the
341
- # 'return' statements in the type returned.
342
- # @return [Array<Parser::AST::Node>]
343
- def from_value_position_statement node, include_explicit_returns: true
344
- # STDERR.puts("from_expression called on #{node.inspect}")
345
- return [] unless node.is_a?(::Parser::AST::Node)
346
- # @type [Array<Parser::AST::Node>]
347
- result = []
348
- if COMPOUND_STATEMENTS.include?(node.type)
349
- result.concat from_value_position_compound_statement node
350
- elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
351
- result.concat reduce_to_value_nodes(node.children[1..-1])
352
- # result.push NIL_NODE unless node.children[2]
353
- elsif CONDITIONAL_ALL.include?(node.type)
354
- result.concat reduce_to_value_nodes(node.children)
355
- elsif ONLY_ONE_CHILD.include?(node.type)
356
- result.concat reduce_to_value_nodes([node.children[0]])
357
- elsif FIRST_TWO_CHILDREN.include?(node.type)
358
- result.concat reduce_to_value_nodes([node.children[0], node.children[1]])
359
- elsif FUNCTION_VALUE.include?(node.type)
360
- # the block itself is a first class value that could be returned
361
- result.push node
362
- # @todo any explicit returns actually return from
363
- # scope in which the proc is run. This asssumes
364
- # that the function is executed here.
365
- result.concat explicit_return_values_from_compound_statement(node.children[2]) if include_explicit_returns
366
- elsif CASE_STATEMENT.include?(node.type)
367
- node.children[1..-1].each do |cc|
368
- if cc.nil?
369
- result.push NIL_NODE
370
- elsif cc.type == :when
371
- result.concat reduce_to_value_nodes([cc.children.last])
372
- else
373
- # else clause in case
374
- result.concat reduce_to_value_nodes([cc])
375
- end
376
- end
377
- elsif node.type == :resbody
378
- result.concat reduce_to_value_nodes([node.children[2]])
379
- else
380
- result.push node
381
- end
382
- result
383
- end
384
-
385
- # Treat parent as as a begin block and use the last node's
386
- # return node plus any explicit return nodes' return nodes. e.g.,
387
- #
388
- # 123
389
- # 456
390
- # return 'a' if foo == bar
391
- # 789
392
- #
393
- # would return 'a' and 789.
394
- #
395
- # @param parent [Parser::AST::Node]
396
- #
397
- # @return [Array<Parser::AST::Node>]
398
- def from_value_position_compound_statement parent
399
- result = []
400
- nodes = parent.children.select{|n| n.is_a?(AST::Node)}
401
- nodes.each_with_index do |node, idx|
402
- if node.type == :block
403
- result.concat explicit_return_values_from_compound_statement(node.children[2])
404
- elsif node.type == :rescue
405
- # body statements
406
- result.concat from_value_position_statement(node.children[0])
407
- # rescue statements
408
- result.concat from_value_position_statement(node.children[1])
409
- elsif SKIPPABLE.include?(node.type)
410
- next
411
- elsif node.type == :resbody
412
- result.concat reduce_to_value_nodes([node.children[2]])
413
- elsif node.type == :return
414
- result.concat reduce_to_value_nodes([node.children[0]])
415
- # Return here because the rest of the code is
416
- # unreachable and shouldn't be looked at
417
- return result
418
- else
419
- result.concat explicit_return_values_from_compound_statement(node)
420
- end
421
- # handle last line of compound statements, which is in
422
- # value position. we already have the explicit values
423
- # from above; now we need to also gather the value
424
- # position nodes
425
- result.concat from_value_position_statement(nodes.last, include_explicit_returns: false) if idx == nodes.length - 1
426
- end
427
- result
428
- end
429
-
430
- private
431
-
432
- # Useful when this statement isn't in value position, but
433
- # we care explicit return statements nonetheless.
434
- #
435
- # @param parent [Parser::AST::Node]
436
- #
437
- # @return [Array<Parser::AST::Node>]
438
- def explicit_return_values_from_compound_statement parent
439
- return [] unless parent.is_a?(::Parser::AST::Node)
440
- result = []
441
- nodes = parent.children.select{|n| n.is_a?(::Parser::AST::Node)}
442
- nodes.each do |node|
443
- next if SKIPPABLE.include?(node.type)
444
- if node.type == :return
445
- result.concat reduce_to_value_nodes([node.children[0]])
446
- # Return the result here because the rest of the code is
447
- # unreachable
448
- return result
449
- else
450
- result.concat explicit_return_values_from_compound_statement(node)
451
- end
452
- end
453
- result
454
- end
455
-
456
- # @param nodes [Enumerable<Parser::AST::Node, BasicObject>]
457
- # @return [Array<Parser::AST::Node, nil>]
458
- def reduce_to_value_nodes nodes
459
- result = []
460
- nodes.each do |node|
461
- if !node.is_a?(::Parser::AST::Node)
462
- result.push nil
463
- elsif COMPOUND_STATEMENTS.include?(node.type)
464
- result.concat from_value_position_compound_statement(node)
465
- elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
466
- result.concat reduce_to_value_nodes(node.children[1..-1])
467
- elsif node.type == :return
468
- result.concat reduce_to_value_nodes([node.children[0]])
469
- elsif node.type == :or
470
- result.concat reduce_to_value_nodes(node.children)
471
- elsif node.type == :block
472
- result.concat explicit_return_values_from_compound_statement(node.children[2])
473
- elsif node.type == :resbody
474
- result.concat reduce_to_value_nodes([node.children[2]])
475
- else
476
- result.push node
477
- end
478
- end
479
- result
480
- end
481
- end
482
- end
483
- end
484
- end
485
- end
486
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'parser'
4
+ require 'ast'
5
+
6
+ # https://github.com/whitequark/parser
7
+ module Solargraph
8
+ module Parser
9
+ module ParserGem
10
+ module NodeMethods
11
+ module_function
12
+
13
+ # @param node [Parser::AST::Node]
14
+ # @return [String]
15
+ def unpack_name(node)
16
+ pack_name(node).join("::")
17
+ end
18
+
19
+ # @param node [Parser::AST::Node]
20
+ # @return [Array<String>]
21
+ def pack_name(node)
22
+ # @type [Array<String>]
23
+ parts = []
24
+ if node.is_a?(AST::Node)
25
+ node.children.each { |n|
26
+ if n.is_a?(AST::Node)
27
+ if n.type == :cbase
28
+ parts = [''] + pack_name(n)
29
+ elsif n.type == :const
30
+ parts += pack_name(n)
31
+ end
32
+ else
33
+ parts.push n unless n.nil?
34
+ end
35
+ }
36
+ end
37
+ parts
38
+ end
39
+
40
+ # @param node [Parser::AST::Node, nil]
41
+ # @return [String, nil]
42
+ def infer_literal_node_type node
43
+ return nil unless node.is_a?(AST::Node)
44
+ if node.type == :str || node.type == :dstr
45
+ return '::String'
46
+ elsif node.type == :array
47
+ return '::Array'
48
+ elsif node.type == :nil
49
+ return '::NilClass'
50
+ elsif node.type == :hash
51
+ return '::Hash'
52
+ elsif node.type == :int
53
+ return '::Integer'
54
+ elsif node.type == :float
55
+ return '::Float'
56
+ elsif node.type == :sym || node.type == :dsym
57
+ return '::Symbol'
58
+ elsif node.type == :regexp
59
+ return '::Regexp'
60
+ elsif node.type == :irange
61
+ return '::Range'
62
+ elsif node.type == :true || node.type == :false
63
+ return '::Boolean'
64
+ # @todo Support `nil` keyword in types
65
+ # elsif node.type == :nil
66
+ # return 'NilClass'
67
+ end
68
+ nil
69
+ end
70
+
71
+ # @param node [Parser::AST::Node]
72
+ # @return [Position]
73
+ def get_node_start_position(node)
74
+ Position.new(node.loc.line, node.loc.column)
75
+ end
76
+
77
+ # @param node [Parser::AST::Node]
78
+ # @return [Position]
79
+ def get_node_end_position(node)
80
+ Position.new(node.loc.last_line, node.loc.last_column)
81
+ end
82
+
83
+ # @param node [Parser::AST::Node]
84
+ # @param signature [String]
85
+ #
86
+ # @return [String]
87
+ def drill_signature node, signature
88
+ return signature unless node.is_a?(AST::Node)
89
+ if node.type == :const or node.type == :cbase
90
+ unless node.children[0].nil?
91
+ signature += drill_signature(node.children[0], signature)
92
+ end
93
+ signature += '::' unless signature.empty?
94
+ signature += node.children[1].to_s
95
+ elsif node.type == :lvar or node.type == :ivar or node.type == :cvar
96
+ signature += '.' unless signature.empty?
97
+ signature += node.children[0].to_s
98
+ elsif node.type == :send
99
+ unless node.children[0].nil?
100
+ signature += drill_signature(node.children[0], signature)
101
+ end
102
+ signature += '.' unless signature.empty?
103
+ signature += node.children[1].to_s
104
+ end
105
+ signature
106
+ end
107
+
108
+ # @param node [Parser::AST::Node, nil]
109
+ # @return [Hash{Symbol => Chain}]
110
+ def convert_hash node
111
+ return {} unless Parser.is_ast_node?(node)
112
+ # @sg-ignore Translate to something flow sensitive typing understands
113
+ return convert_hash(node.children[0]) if node.type == :kwsplat
114
+ # @sg-ignore Translate to something flow sensitive typing understands
115
+ return convert_hash(node.children[0]) if Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
116
+ # @sg-ignore Translate to something flow sensitive typing understands
117
+ return {} unless node.type == :hash
118
+ result = {}
119
+ # @sg-ignore Translate to something flow sensitive typing understands
120
+ node.children.each do |pair|
121
+ result[pair.children[0].children[0]] = Solargraph::Parser.chain(pair.children[1])
122
+ end
123
+ result
124
+ end
125
+
126
+ NIL_NODE = ::Parser::AST::Node.new(:nil)
127
+
128
+ # @param node [Parser::AST::Node]
129
+ #
130
+ # @return [Array<Parser::AST::Node>]
131
+ def const_nodes_from node
132
+ return [] unless Parser.is_ast_node?(node)
133
+ result = []
134
+ if node.type == :const
135
+ result.push node
136
+ else
137
+ node.children.each { |child| result.concat const_nodes_from(child) }
138
+ end
139
+ result
140
+ end
141
+
142
+ # @param node [Parser::AST::Node]
143
+ def splatted_hash? node
144
+ Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
145
+ end
146
+
147
+ # @param node [Parser::AST::Node]
148
+ def splatted_call? node
149
+ return false unless Parser.is_ast_node?(node)
150
+ Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat && node.children[0].children[0].type != :hash
151
+ end
152
+
153
+ # @param nodes [Enumerable<Parser::AST::Node>]
154
+ def any_splatted_call?(nodes)
155
+ nodes.any? { |n| splatted_call?(n) }
156
+ end
157
+
158
+ # @todo Temporarily here for testing. Move to Solargraph::Parser.
159
+ # @param node [Parser::AST::Node]
160
+ # @return [Array<Parser::AST::Node>]
161
+ def call_nodes_from node
162
+ return [] unless node.is_a?(::Parser::AST::Node)
163
+ result = []
164
+ if node.type == :block
165
+ result.push node
166
+ if Parser.is_ast_node?(node.children[0]) && node.children[0].children.length > 2
167
+ # @sg-ignore Need to add nil check here
168
+ node.children[0].children[2..-1].each { |child| result.concat call_nodes_from(child) }
169
+ end
170
+ # @sg-ignore Need to add nil check here
171
+ node.children[1..-1].each { |child| result.concat call_nodes_from(child) }
172
+ elsif node.type == :send
173
+ result.push node
174
+ result.concat call_nodes_from(node.children.first)
175
+ # @sg-ignore Need to add nil check here
176
+ node.children[2..-1].each { |child| result.concat call_nodes_from(child) }
177
+ elsif [:super, :zsuper].include?(node.type)
178
+ result.push node
179
+ node.children.each { |child| result.concat call_nodes_from(child) }
180
+ else
181
+ node.children.each { |child| result.concat call_nodes_from(child) }
182
+ end
183
+ result
184
+ end
185
+
186
+ # Find all the nodes within the provided node that potentially return a
187
+ # value.
188
+ #
189
+ # The node parameter typically represents a method's logic, e.g., the
190
+ # second child (after the :args node) of a :def node. A simple one-line
191
+ # method would typically return itself, while a node with conditions
192
+ # would return the resulting node from each conditional branch. Nodes
193
+ # that follow a :return node are assumed to be unreachable. Nil values
194
+ # are converted to nil node types.
195
+ #
196
+ # @param node [Parser::AST::Node]
197
+ # @return [Array<Parser::AST::Node>]
198
+ def returns_from_method_body node
199
+ # @todo is the || NIL_NODE necessary?
200
+ # STDERR.puts("Evaluating expression: #{node.inspect}")
201
+ DeepInference.from_method_body(node).map { |n| n || NIL_NODE }
202
+ end
203
+
204
+ # @param node [Parser::AST::Node]
205
+ # @return [Array<AST::Node>] low-level value nodes in
206
+ # value position. Does not include explicit return
207
+ # statements
208
+ def value_position_nodes_only(node)
209
+ DeepInference.value_position_nodes_only(node).map { |n| n || NIL_NODE }
210
+ end
211
+
212
+ # @param cursor [Solargraph::Source::Cursor]
213
+ # @return [Parser::AST::Node, nil]
214
+ def find_recipient_node cursor
215
+ return repaired_find_recipient_node(cursor) if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
216
+ source = cursor.source
217
+ position = cursor.position
218
+ offset = cursor.offset
219
+ tree = if source.synchronized?
220
+ # @sg-ignore Need to add nil check here
221
+ match = source.code[0..offset-1].match(/,\s*\z/)
222
+ if match
223
+ # @sg-ignore Need to add nil check here
224
+ source.tree_at(position.line, position.column - match[0].length)
225
+ else
226
+ source.tree_at(position.line, position.column)
227
+ end
228
+ else
229
+ source.tree_at(position.line, position.column - 1)
230
+ end
231
+ # @type [AST::Node, nil]
232
+ prev = nil
233
+ tree.each do |node|
234
+ if node.type == :send
235
+ args = node.children[2..-1]
236
+ # @sg-ignore Need to add nil check here
237
+ if !args.empty?
238
+ # @sg-ignore Need to add nil check here
239
+ return node if prev && args.include?(prev)
240
+ else
241
+ if source.synchronized?
242
+ return node if source.code[0..offset-1] =~ /\(\s*\z/ && source.code[offset..-1] =~ /^\s*\)/
243
+ else
244
+ return node if source.code[0..offset-1] =~ /\([^(]*\z/
245
+ end
246
+ end
247
+ end
248
+ prev = node
249
+ end
250
+ nil
251
+ end
252
+
253
+ # @param cursor [Solargraph::Source::Cursor]
254
+ # @return [Parser::AST::Node, nil]
255
+ def repaired_find_recipient_node cursor
256
+ cursor = cursor.source.cursor_at([cursor.position.line, cursor.position.column - 1])
257
+ node = cursor.source.tree_at(cursor.position.line, cursor.position.column).first
258
+ return node if node && node.type == :send
259
+ end
260
+
261
+ #
262
+ # Concepts:
263
+ #
264
+ # - statement - one single node in the AST. Generally used
265
+ # synonymously with how the Parser gem uses the term
266
+ # 'expression'. This may have side effects (e.g.,
267
+ # registering a method in the namespace, modifying
268
+ # variables or doing I/O). It may encapsulate multiple
269
+ # other statements (see compound statement).
270
+ #
271
+ # - value - something that can be assigned to a variable by
272
+ # evaluating a statement
273
+ #
274
+ # - value node - the 'lowest level' AST node whose return
275
+ # type is a subset of the value type of the overall
276
+ # statement. Might be a literal, a method call, etc - the
277
+ # goal is to find the lowest level node, which we can use
278
+ # Chains and Pins later on to determine the type of.
279
+ #
280
+ # e.g., if the node 'b ? 123 : 456' were a return value, we
281
+ # know the actual return values possible are 123 and 456,
282
+ # and can disregard the rest.
283
+ #
284
+ # - value type - the type representing the multiple possible
285
+ # values that can result from evaluation of the statement.
286
+ #
287
+ # - return type - the type describing the values a statement
288
+ # might evaluate to. When used with a method, the term
289
+ # describes the values that may result from the method
290
+ # being called, and includes explicit return statements
291
+ # within the method body's closure.
292
+ #
293
+ # - method body - a compound statement with parameters whose
294
+ # return value type must account both for the explicit
295
+ # 'return' statemnts as well as the final statements
296
+ # executed in any given control flow through the method.
297
+ #
298
+ # - explicit return statement - a statement which, when part of a
299
+ # method body, is a possible value of a call to that method -
300
+ # e.g., "return 123"
301
+ #
302
+ # - compound statement - a statement which can be expanded to
303
+ # be multiple statements in a row, executed in the context
304
+ # of a method which can be explicitly returned from.
305
+ #
306
+ # - value position - the positions in the AST where the
307
+ # return type of the statement would be one of the return
308
+ # types of any compound statements it is a part of. For a
309
+ # compound statement, the last of the child statements
310
+ # would be in return position. This concept can be applied
311
+ # recursively through e.g. conditionals to find a list of
312
+ # statements in value positions.
313
+ module DeepInference
314
+ class << self
315
+ CONDITIONAL_ALL_BUT_FIRST = [:if, :unless]
316
+ ONLY_ONE_CHILD = [:return]
317
+ FIRST_TWO_CHILDREN = [:rescue]
318
+ COMPOUND_STATEMENTS = [:begin, :kwbegin]
319
+ SKIPPABLE = [:def, :defs, :class, :sclass, :module]
320
+ FUNCTION_VALUE = [:block]
321
+ CASE_STATEMENT = [:case]
322
+
323
+ # @param node [AST::Node] a method body compound statement
324
+ # @param include_explicit_returns [Boolean] If true,
325
+ # include the value nodes of the parameter of the
326
+ # 'return' statements in the type returned.
327
+ # @return [Array<AST::Node>] low-level value nodes from
328
+ # both nodes in value position as well as explicit
329
+ # return statements in the method's closure.
330
+ def from_method_body node
331
+ from_value_position_statement(node, include_explicit_returns: true)
332
+ end
333
+
334
+ # @param node [AST::Node] an individual statement, to be
335
+ # evaluated outside the context of a containing method
336
+ # @return [Array<AST::Node>] low-level value nodes in
337
+ # value position. Does not include explicit return
338
+ # statements
339
+ def value_position_nodes_only(node)
340
+ from_value_position_statement(node, include_explicit_returns: false)
341
+ end
342
+
343
+ # Look at known control statements and use them to find
344
+ # more specific return nodes.
345
+ #
346
+ # @param node [AST::Node] Statement which is in
347
+ # value position for a method body
348
+ # @param include_explicit_returns [Boolean] If true,
349
+ # include the value nodes of the parameter of the
350
+ # 'return' statements in the type returned.
351
+ # @return [Array<Parser::AST::Node>]
352
+ def from_value_position_statement node, include_explicit_returns: true
353
+ # STDERR.puts("from_expression called on #{node.inspect}")
354
+ return [] unless node.is_a?(::Parser::AST::Node)
355
+ # @type [Array<Parser::AST::Node>]
356
+ result = []
357
+ if COMPOUND_STATEMENTS.include?(node.type)
358
+ result.concat from_value_position_compound_statement node
359
+ elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
360
+ # @sg-ignore Need to add nil check here
361
+ result.concat reduce_to_value_nodes(node.children[1..-1])
362
+ # result.push NIL_NODE unless node.children[2]
363
+ elsif ONLY_ONE_CHILD.include?(node.type)
364
+ result.concat reduce_to_value_nodes([node.children[0]])
365
+ elsif FIRST_TWO_CHILDREN.include?(node.type)
366
+ result.concat reduce_to_value_nodes([node.children[0], node.children[1]])
367
+ elsif FUNCTION_VALUE.include?(node.type)
368
+ # the block itself is a first class value that could be returned
369
+ result.push node
370
+ # @todo any explicit returns actually return from
371
+ # scope in which the proc is run. This asssumes
372
+ # that the function is executed here.
373
+ result.concat explicit_return_values_from_compound_statement(node.children[2]) if include_explicit_returns
374
+ elsif CASE_STATEMENT.include?(node.type)
375
+ # @sg-ignore Need to add nil check here
376
+ node.children[1..-1].each do |cc|
377
+ if cc.nil?
378
+ result.push NIL_NODE
379
+ elsif cc.type == :when
380
+ result.concat reduce_to_value_nodes([cc.children.last])
381
+ else
382
+ # else clause in case
383
+ result.concat reduce_to_value_nodes([cc])
384
+ end
385
+ end
386
+ elsif node.type == :resbody
387
+ result.concat reduce_to_value_nodes([node.children[2]])
388
+ else
389
+ result.push node
390
+ end
391
+ result
392
+ end
393
+
394
+ # Treat parent as as a begin block and use the last node's
395
+ # return node plus any explicit return nodes' return nodes. e.g.,
396
+ #
397
+ # 123
398
+ # 456
399
+ # return 'a' if foo == bar
400
+ # 789
401
+ #
402
+ # would return 'a' and 789.
403
+ #
404
+ # @param parent [Parser::AST::Node]
405
+ #
406
+ # @return [Array<Parser::AST::Node>]
407
+ def from_value_position_compound_statement parent
408
+ result = []
409
+ nodes = parent.children.select{|n| n.is_a?(AST::Node)}
410
+ nodes.each_with_index do |node, idx|
411
+ if node.type == :block
412
+ result.concat explicit_return_values_from_compound_statement(node.children[2])
413
+ elsif node.type == :rescue
414
+ # body statements
415
+ result.concat from_value_position_statement(node.children[0])
416
+ # rescue statements
417
+ result.concat from_value_position_statement(node.children[1])
418
+ elsif SKIPPABLE.include?(node.type)
419
+ next
420
+ elsif node.type == :resbody
421
+ result.concat reduce_to_value_nodes([node.children[2]])
422
+ elsif node.type == :return
423
+ result.concat reduce_to_value_nodes([node.children[0]])
424
+ # Return here because the rest of the code is
425
+ # unreachable and shouldn't be looked at
426
+ return result
427
+ else
428
+ result.concat explicit_return_values_from_compound_statement(node)
429
+ end
430
+ # handle last line of compound statements, which is in
431
+ # value position. we already have the explicit values
432
+ # from above; now we need to also gather the value
433
+ # position nodes
434
+ result.concat from_value_position_statement(nodes.last, include_explicit_returns: false) if idx == nodes.length - 1
435
+ end
436
+ result
437
+ end
438
+
439
+ private
440
+
441
+ # Useful when this statement isn't in value position, but
442
+ # we care explicit return statements nonetheless.
443
+ #
444
+ # @param parent [Parser::AST::Node]
445
+ #
446
+ # @return [Array<Parser::AST::Node>]
447
+ def explicit_return_values_from_compound_statement parent
448
+ return [] unless parent.is_a?(::Parser::AST::Node)
449
+ result = []
450
+ nodes = parent.children.select{|n| n.is_a?(::Parser::AST::Node)}
451
+ nodes.each do |node|
452
+ next if SKIPPABLE.include?(node.type)
453
+ if node.type == :return
454
+ result.concat reduce_to_value_nodes([node.children[0]])
455
+ # Return the result here because the rest of the code is
456
+ # unreachable
457
+ return result
458
+ else
459
+ result.concat explicit_return_values_from_compound_statement(node)
460
+ end
461
+ end
462
+ result
463
+ end
464
+
465
+ # @param nodes [Enumerable<Parser::AST::Node, BasicObject>]
466
+ # @return [Array<Parser::AST::Node, nil>]
467
+ def reduce_to_value_nodes nodes
468
+ result = []
469
+ nodes.each do |node|
470
+ if !node.is_a?(::Parser::AST::Node)
471
+ result.push nil
472
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
473
+ elsif COMPOUND_STATEMENTS.include?(node.type)
474
+ result.concat from_value_position_compound_statement(node)
475
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
476
+ elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
477
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
478
+ result.concat reduce_to_value_nodes(node.children[1..-1])
479
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
480
+ elsif node.type == :return
481
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
482
+ result.concat reduce_to_value_nodes([node.children[0]])
483
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
484
+ elsif node.type == :or
485
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
486
+ result.concat reduce_to_value_nodes(node.children)
487
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
488
+ elsif node.type == :block
489
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
490
+ result.concat explicit_return_values_from_compound_statement(node.children[2])
491
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
492
+ elsif node.type == :resbody
493
+ # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
494
+ result.concat reduce_to_value_nodes([node.children[2]])
495
+ else
496
+ result.push node
497
+ end
498
+ end
499
+ result
500
+ end
501
+ end
502
+ end
503
+ end
504
+ end
505
+ end
506
+ end