solargraph 0.59.0.dev.1 → 0.59.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 (175) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linting.yml +3 -1
  3. data/.github/workflows/plugins.yml +12 -3
  4. data/.github/workflows/rspec.yml +9 -54
  5. data/.github/workflows/typecheck.yml +2 -1
  6. data/.gitignore +1 -0
  7. data/.rubocop.yml +38 -6
  8. data/.rubocop_todo.yml +40 -931
  9. data/CHANGELOG.md +22 -1
  10. data/Gemfile +3 -1
  11. data/Rakefile +25 -23
  12. data/bin/solargraph +2 -1
  13. data/lib/solargraph/api_map/constants.rb +0 -1
  14. data/lib/solargraph/api_map/index.rb +11 -11
  15. data/lib/solargraph/api_map/source_to_yard.rb +9 -8
  16. data/lib/solargraph/api_map/store.rb +28 -20
  17. data/lib/solargraph/api_map.rb +70 -41
  18. data/lib/solargraph/bench.rb +44 -45
  19. data/lib/solargraph/complex_type/type_methods.rb +14 -16
  20. data/lib/solargraph/complex_type/unique_type.rb +56 -47
  21. data/lib/solargraph/complex_type.rb +70 -62
  22. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
  23. data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
  24. data/lib/solargraph/convention/data_definition.rb +1 -1
  25. data/lib/solargraph/convention/gemfile.rb +15 -15
  26. data/lib/solargraph/convention/gemspec.rb +23 -23
  27. data/lib/solargraph/convention/rakefile.rb +17 -17
  28. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
  29. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
  30. data/lib/solargraph/convention/struct_definition.rb +3 -3
  31. data/lib/solargraph/convention.rb +78 -78
  32. data/lib/solargraph/converters/dd.rb +19 -17
  33. data/lib/solargraph/converters/dl.rb +17 -15
  34. data/lib/solargraph/converters/dt.rb +17 -15
  35. data/lib/solargraph/converters/misc.rb +3 -1
  36. data/lib/solargraph/diagnostics/rubocop.rb +10 -10
  37. data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
  38. data/lib/solargraph/diagnostics/type_check.rb +10 -10
  39. data/lib/solargraph/diagnostics/update_errors.rb +37 -41
  40. data/lib/solargraph/doc_map.rb +370 -132
  41. data/lib/solargraph/equality.rb +3 -3
  42. data/lib/solargraph/gem_pins.rb +19 -18
  43. data/lib/solargraph/language_server/error_codes.rb +20 -20
  44. data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
  45. data/lib/solargraph/language_server/host/dispatch.rb +2 -3
  46. data/lib/solargraph/language_server/host/message_worker.rb +2 -2
  47. data/lib/solargraph/language_server/host/sources.rb +1 -1
  48. data/lib/solargraph/language_server/host.rb +24 -21
  49. data/lib/solargraph/language_server/message/base.rb +97 -97
  50. data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
  51. data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
  52. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
  53. data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
  54. data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
  55. data/lib/solargraph/language_server/message/extended/search.rb +20 -20
  56. data/lib/solargraph/language_server/message/initialize.rb +197 -191
  57. data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
  58. data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
  59. data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
  60. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
  61. data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
  62. data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
  63. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
  64. data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
  65. data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
  66. data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
  67. data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
  68. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
  69. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
  70. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
  71. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
  72. data/lib/solargraph/language_server/message.rb +94 -94
  73. data/lib/solargraph/language_server/request.rb +29 -27
  74. data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
  75. data/lib/solargraph/language_server/uri_helpers.rb +49 -49
  76. data/lib/solargraph/library.rb +68 -95
  77. data/lib/solargraph/location.rb +10 -12
  78. data/lib/solargraph/logging.rb +4 -6
  79. data/lib/solargraph/page.rb +92 -92
  80. data/lib/solargraph/parser/comment_ripper.rb +12 -4
  81. data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -44
  82. data/lib/solargraph/parser/node_processor/base.rb +4 -4
  83. data/lib/solargraph/parser/node_processor.rb +1 -1
  84. data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -6
  85. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
  86. data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
  87. data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
  88. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
  89. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -2
  90. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
  91. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
  92. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
  93. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
  94. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
  95. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
  96. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
  97. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
  98. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
  99. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
  100. data/lib/solargraph/parser/parser_gem.rb +14 -12
  101. data/lib/solargraph/parser/snippet.rb +2 -0
  102. data/lib/solargraph/parser.rb +25 -23
  103. data/lib/solargraph/pin/base.rb +76 -64
  104. data/lib/solargraph/pin/base_variable.rb +28 -71
  105. data/lib/solargraph/pin/block.rb +3 -2
  106. data/lib/solargraph/pin/breakable.rb +2 -0
  107. data/lib/solargraph/pin/callable.rb +23 -26
  108. data/lib/solargraph/pin/closure.rb +5 -4
  109. data/lib/solargraph/pin/common.rb +5 -2
  110. data/lib/solargraph/pin/compound_statement.rb +3 -3
  111. data/lib/solargraph/pin/constant.rb +43 -45
  112. data/lib/solargraph/pin/conversions.rb +9 -4
  113. data/lib/solargraph/pin/delegated_method.rb +4 -4
  114. data/lib/solargraph/pin/documenting.rb +3 -2
  115. data/lib/solargraph/pin/local_variable.rb +4 -4
  116. data/lib/solargraph/pin/method.rb +74 -70
  117. data/lib/solargraph/pin/namespace.rb +13 -12
  118. data/lib/solargraph/pin/parameter.rb +28 -27
  119. data/lib/solargraph/pin/proxy_type.rb +2 -0
  120. data/lib/solargraph/pin/reference/type_alias.rb +16 -0
  121. data/lib/solargraph/pin/reference.rb +18 -0
  122. data/lib/solargraph/pin/search.rb +2 -2
  123. data/lib/solargraph/pin/signature.rb +9 -14
  124. data/lib/solargraph/pin/symbol.rb +1 -0
  125. data/lib/solargraph/pin/until.rb +1 -3
  126. data/lib/solargraph/pin/while.rb +1 -3
  127. data/lib/solargraph/pin_cache.rb +71 -488
  128. data/lib/solargraph/position.rb +38 -17
  129. data/lib/solargraph/range.rb +10 -9
  130. data/lib/solargraph/rbs_map/conversions.rb +327 -221
  131. data/lib/solargraph/rbs_map/core_fills.rb +91 -84
  132. data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
  133. data/lib/solargraph/rbs_map.rb +5 -15
  134. data/lib/solargraph/server_methods.rb +16 -16
  135. data/lib/solargraph/shell.rb +224 -66
  136. data/lib/solargraph/source/chain/array.rb +39 -37
  137. data/lib/solargraph/source/chain/call.rb +49 -44
  138. data/lib/solargraph/source/chain/class_variable.rb +13 -13
  139. data/lib/solargraph/source/chain/constant.rb +3 -1
  140. data/lib/solargraph/source/chain/global_variable.rb +13 -13
  141. data/lib/solargraph/source/chain/hash.rb +8 -6
  142. data/lib/solargraph/source/chain/if.rb +11 -10
  143. data/lib/solargraph/source/chain/instance_variable.rb +3 -1
  144. data/lib/solargraph/source/chain/link.rb +99 -109
  145. data/lib/solargraph/source/chain/literal.rb +4 -6
  146. data/lib/solargraph/source/chain/or.rb +2 -4
  147. data/lib/solargraph/source/chain/q_call.rb +13 -11
  148. data/lib/solargraph/source/chain/variable.rb +15 -13
  149. data/lib/solargraph/source/chain/z_super.rb +28 -30
  150. data/lib/solargraph/source/chain.rb +26 -16
  151. data/lib/solargraph/source/change.rb +3 -3
  152. data/lib/solargraph/source/cursor.rb +18 -18
  153. data/lib/solargraph/source/encoding_fixes.rb +6 -7
  154. data/lib/solargraph/source/source_chainer.rb +46 -32
  155. data/lib/solargraph/source/updater.rb +1 -1
  156. data/lib/solargraph/source.rb +27 -29
  157. data/lib/solargraph/source_map/clip.rb +38 -30
  158. data/lib/solargraph/source_map/mapper.rb +51 -47
  159. data/lib/solargraph/source_map.rb +8 -4
  160. data/lib/solargraph/type_checker/rules.rb +8 -8
  161. data/lib/solargraph/type_checker.rb +95 -102
  162. data/lib/solargraph/version.rb +1 -1
  163. data/lib/solargraph/workspace/config.rb +11 -10
  164. data/lib/solargraph/workspace/gemspecs.rb +3 -3
  165. data/lib/solargraph/workspace.rb +45 -165
  166. data/lib/solargraph/yard_map/helpers.rb +6 -2
  167. data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
  168. data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
  169. data/lib/solargraph/yard_map/mapper.rb +12 -12
  170. data/lib/solargraph/yard_map.rb +17 -18
  171. data/lib/solargraph/yard_tags.rb +20 -20
  172. data/lib/solargraph/yardoc.rb +26 -33
  173. data/lib/solargraph.rb +7 -5
  174. data/solargraph.gemspec +36 -35
  175. metadata +33 -38
@@ -12,17 +12,17 @@ module Solargraph
12
12
 
13
13
  # @param node [Parser::AST::Node]
14
14
  # @return [String]
15
- def unpack_name(node)
16
- pack_name(node).join("::")
15
+ def unpack_name node
16
+ pack_name(node).join('::')
17
17
  end
18
18
 
19
19
  # @param node [Parser::AST::Node]
20
20
  # @return [Array<String>]
21
- def pack_name(node)
21
+ def pack_name node
22
22
  # @type [Array<String>]
23
23
  parts = []
24
24
  if node.is_a?(AST::Node)
25
- node.children.each { |n|
25
+ node.children.each do |n|
26
26
  if n.is_a?(AST::Node)
27
27
  if n.type == :cbase
28
28
  parts = [''] + pack_name(n)
@@ -32,7 +32,7 @@ module Solargraph
32
32
  else
33
33
  parts.push n unless n.nil?
34
34
  end
35
- }
35
+ end
36
36
  end
37
37
  parts
38
38
  end
@@ -41,7 +41,7 @@ module Solargraph
41
41
  # @return [String, nil]
42
42
  def infer_literal_node_type node
43
43
  return nil unless node.is_a?(AST::Node)
44
- if node.type == :str || node.type == :dstr
44
+ if %i[str dstr].include?(node.type)
45
45
  return '::String'
46
46
  elsif node.type == :array
47
47
  return '::Array'
@@ -53,30 +53,30 @@ module Solargraph
53
53
  return '::Integer'
54
54
  elsif node.type == :float
55
55
  return '::Float'
56
- elsif node.type == :sym || node.type == :dsym
56
+ elsif %i[sym dsym].include?(node.type)
57
57
  return '::Symbol'
58
58
  elsif node.type == :regexp
59
59
  return '::Regexp'
60
60
  elsif node.type == :irange
61
61
  return '::Range'
62
- elsif node.type == :true || node.type == :false
62
+ elsif %i[true false].include?(node.type)
63
63
  return '::Boolean'
64
64
  # @todo Support `nil` keyword in types
65
- # elsif node.type == :nil
66
- # return 'NilClass'
65
+ # elsif node.type == :nil
66
+ # return 'NilClass'
67
67
  end
68
68
  nil
69
69
  end
70
70
 
71
71
  # @param node [Parser::AST::Node]
72
72
  # @return [Position]
73
- def get_node_start_position(node)
73
+ def get_node_start_position node
74
74
  Position.new(node.loc.line, node.loc.column)
75
75
  end
76
76
 
77
77
  # @param node [Parser::AST::Node]
78
78
  # @return [Position]
79
- def get_node_end_position(node)
79
+ def get_node_end_position node
80
80
  Position.new(node.loc.last_line, node.loc.last_column)
81
81
  end
82
82
 
@@ -86,19 +86,15 @@ module Solargraph
86
86
  # @return [String]
87
87
  def drill_signature node, signature
88
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
89
+ if %i[const cbase].include?(node.type)
90
+ signature += drill_signature(node.children[0], signature) unless node.children[0].nil?
93
91
  signature += '::' unless signature.empty?
94
92
  signature += node.children[1].to_s
95
- elsif node.type == :lvar or node.type == :ivar or node.type == :cvar
93
+ elsif %i[lvar ivar cvar].include?(node.type)
96
94
  signature += '.' unless signature.empty?
97
95
  signature += node.children[0].to_s
98
96
  elsif node.type == :send
99
- unless node.children[0].nil?
100
- signature += drill_signature(node.children[0], signature)
101
- end
97
+ signature += drill_signature(node.children[0], signature) unless node.children[0].nil?
102
98
  signature += '.' unless signature.empty?
103
99
  signature += node.children[1].to_s
104
100
  end
@@ -112,7 +108,10 @@ module Solargraph
112
108
  # @sg-ignore Translate to something flow sensitive typing understands
113
109
  return convert_hash(node.children[0]) if node.type == :kwsplat
114
110
  # @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
111
+ if Parser.is_ast_node?(node.children[0]) && node.children[0].type == :kwsplat
112
+ # @sg-ignore Translate to something flow sensitive typing understands
113
+ return convert_hash(node.children[0])
114
+ end
116
115
  # @sg-ignore Translate to something flow sensitive typing understands
117
116
  return {} unless node.type == :hash
118
117
  result = {}
@@ -151,7 +150,7 @@ module Solargraph
151
150
  end
152
151
 
153
152
  # @param nodes [Enumerable<Parser::AST::Node>]
154
- def any_splatted_call?(nodes)
153
+ def any_splatted_call? nodes
155
154
  nodes.any? { |n| splatted_call?(n) }
156
155
  end
157
156
 
@@ -165,16 +164,16 @@ module Solargraph
165
164
  result.push node
166
165
  if Parser.is_ast_node?(node.children[0]) && node.children[0].children.length > 2
167
166
  # @sg-ignore Need to add nil check here
168
- node.children[0].children[2..-1].each { |child| result.concat call_nodes_from(child) }
167
+ node.children[0].children[2..].each { |child| result.concat call_nodes_from(child) }
169
168
  end
170
169
  # @sg-ignore Need to add nil check here
171
- node.children[1..-1].each { |child| result.concat call_nodes_from(child) }
170
+ node.children[1..].each { |child| result.concat call_nodes_from(child) }
172
171
  elsif node.type == :send
173
172
  result.push node
174
173
  result.concat call_nodes_from(node.children.first)
175
174
  # @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)
175
+ node.children[2..].each { |child| result.concat call_nodes_from(child) }
176
+ elsif %i[super zsuper].include?(node.type)
178
177
  result.push node
179
178
  node.children.each { |child| result.concat call_nodes_from(child) }
180
179
  else
@@ -205,44 +204,44 @@ module Solargraph
205
204
  # @return [Array<AST::Node>] low-level value nodes in
206
205
  # value position. Does not include explicit return
207
206
  # statements
208
- def value_position_nodes_only(node)
207
+ def value_position_nodes_only node
209
208
  DeepInference.value_position_nodes_only(node).map { |n| n || NIL_NODE }
210
209
  end
211
210
 
212
211
  # @param cursor [Solargraph::Source::Cursor]
213
212
  # @return [Parser::AST::Node, nil]
214
213
  def find_recipient_node cursor
215
- return repaired_find_recipient_node(cursor) if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
214
+ if cursor.source.repaired? && cursor.source.code[cursor.offset - 1] == '('
215
+ return repaired_find_recipient_node(cursor)
216
+ end
216
217
  source = cursor.source
217
218
  position = cursor.position
218
219
  offset = cursor.offset
219
220
  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
221
+ # @sg-ignore Need to add nil check here
222
+ match = source.code[0..(offset - 1)].match(/,\s*\z/)
223
+ if match
224
+ # @sg-ignore Need to add nil check here
225
+ source.tree_at(position.line, position.column - match[0].length)
226
+ else
227
+ source.tree_at(position.line, position.column)
228
+ end
229
+ else
230
+ source.tree_at(position.line, position.column - 1)
231
+ end
231
232
  # @type [AST::Node, nil]
232
233
  prev = nil
233
234
  tree.each do |node|
234
235
  if node.type == :send
235
- args = node.children[2..-1]
236
+ args = node.children[2..]
236
237
  # @sg-ignore Need to add nil check here
237
238
  if !args.empty?
238
239
  # @sg-ignore Need to add nil check here
239
240
  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
241
+ elsif source.synchronized?
242
+ return node if source.code[0..(offset - 1)] =~ /\(\s*\z/ && source.code[offset..] =~ /^\s*\)/
243
+ elsif source.code[0..(offset - 1)] =~ /\([^(]*\z/
244
+ return node
246
245
  end
247
246
  end
248
247
  prev = node
@@ -255,7 +254,7 @@ module Solargraph
255
254
  def repaired_find_recipient_node cursor
256
255
  cursor = cursor.source.cursor_at([cursor.position.line, cursor.position.column - 1])
257
256
  node = cursor.source.tree_at(cursor.position.line, cursor.position.column).first
258
- return node if node && node.type == :send
257
+ node if node && node.type == :send
259
258
  end
260
259
 
261
260
  #
@@ -312,18 +311,15 @@ module Solargraph
312
311
  # statements in value positions.
313
312
  module DeepInference
314
313
  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]
314
+ CONDITIONAL_ALL_BUT_FIRST = %i[if unless].freeze
315
+ ONLY_ONE_CHILD = [:return].freeze
316
+ FIRST_TWO_CHILDREN = [:rescue].freeze
317
+ COMPOUND_STATEMENTS = %i[begin kwbegin].freeze
318
+ SKIPPABLE = %i[def defs class sclass module].freeze
319
+ FUNCTION_VALUE = [:block].freeze
320
+ CASE_STATEMENT = [:case].freeze
322
321
 
323
322
  # @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
323
  # @return [Array<AST::Node>] low-level value nodes from
328
324
  # both nodes in value position as well as explicit
329
325
  # return statements in the method's closure.
@@ -336,7 +332,7 @@ module Solargraph
336
332
  # @return [Array<AST::Node>] low-level value nodes in
337
333
  # value position. Does not include explicit return
338
334
  # statements
339
- def value_position_nodes_only(node)
335
+ def value_position_nodes_only node
340
336
  from_value_position_statement(node, include_explicit_returns: false)
341
337
  end
342
338
 
@@ -358,7 +354,7 @@ module Solargraph
358
354
  result.concat from_value_position_compound_statement node
359
355
  elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
360
356
  # @sg-ignore Need to add nil check here
361
- result.concat reduce_to_value_nodes(node.children[1..-1])
357
+ result.concat reduce_to_value_nodes(node.children[1..])
362
358
  # result.push NIL_NODE unless node.children[2]
363
359
  elsif ONLY_ONE_CHILD.include?(node.type)
364
360
  result.concat reduce_to_value_nodes([node.children[0]])
@@ -370,10 +366,12 @@ module Solargraph
370
366
  # @todo any explicit returns actually return from
371
367
  # scope in which the proc is run. This asssumes
372
368
  # that the function is executed here.
373
- result.concat explicit_return_values_from_compound_statement(node.children[2]) if include_explicit_returns
369
+ if include_explicit_returns
370
+ result.concat explicit_return_values_from_compound_statement(node.children[2])
371
+ end
374
372
  elsif CASE_STATEMENT.include?(node.type)
375
373
  # @sg-ignore Need to add nil check here
376
- node.children[1..-1].each do |cc|
374
+ node.children[1..].each do |cc|
377
375
  if cc.nil?
378
376
  result.push NIL_NODE
379
377
  elsif cc.type == :when
@@ -406,7 +404,7 @@ module Solargraph
406
404
  # @return [Array<Parser::AST::Node>]
407
405
  def from_value_position_compound_statement parent
408
406
  result = []
409
- nodes = parent.children.select{|n| n.is_a?(AST::Node)}
407
+ nodes = parent.children.select { |n| n.is_a?(AST::Node) }
410
408
  nodes.each_with_index do |node, idx|
411
409
  if node.type == :block
412
410
  result.concat explicit_return_values_from_compound_statement(node.children[2])
@@ -431,7 +429,10 @@ module Solargraph
431
429
  # value position. we already have the explicit values
432
430
  # from above; now we need to also gather the value
433
431
  # position nodes
434
- result.concat from_value_position_statement(nodes.last, include_explicit_returns: false) if idx == nodes.length - 1
432
+ if idx == nodes.length - 1
433
+ result.concat from_value_position_statement(nodes.last,
434
+ include_explicit_returns: false)
435
+ end
435
436
  end
436
437
  result
437
438
  end
@@ -447,7 +448,7 @@ module Solargraph
447
448
  def explicit_return_values_from_compound_statement parent
448
449
  return [] unless parent.is_a?(::Parser::AST::Node)
449
450
  result = []
450
- nodes = parent.children.select{|n| n.is_a?(::Parser::AST::Node)}
451
+ nodes = parent.children.select { |n| n.is_a?(::Parser::AST::Node) }
451
452
  nodes.each do |node|
452
453
  next if SKIPPABLE.include?(node.type)
453
454
  if node.type == :return
@@ -475,7 +476,7 @@ module Solargraph
475
476
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
476
477
  elsif CONDITIONAL_ALL_BUT_FIRST.include?(node.type)
477
478
  # @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
+ result.concat reduce_to_value_nodes(node.children[1..])
479
480
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
480
481
  elsif node.type == :return
481
482
  # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
@@ -14,17 +14,17 @@ module Solargraph
14
14
  node.children.each do |u|
15
15
  loc = get_node_location(u)
16
16
  locals.push Solargraph::Pin::Parameter.new(
17
- location: loc,
18
- closure: callable,
19
- comments: comments_for(node),
20
- name: u.children[0].to_s,
21
- assignment: u.children[1],
22
- asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
23
- # @sg-ignore Need to add nil check here
24
- presence: callable.location.range,
25
- decl: get_decl(u),
26
- source: :parser
27
- )
17
+ location: loc,
18
+ closure: callable,
19
+ comments: comments_for(node),
20
+ name: u.children[0].to_s,
21
+ assignment: u.children[1],
22
+ asgn_code: u.children[1] ? region.code_for(u.children[1]) : nil,
23
+ # @sg-ignore Need to add nil check here
24
+ presence: callable.location.range,
25
+ decl: get_decl(u),
26
+ source: :parser
27
+ )
28
28
  callable.parameters.push locals.last
29
29
  end
30
30
  end
@@ -36,7 +36,7 @@ module Solargraph
36
36
 
37
37
  # @param callable [Pin::Callable]
38
38
  # @return [void]
39
- def forward(callable)
39
+ def forward callable
40
40
  loc = get_node_location(node)
41
41
  locals.push Solargraph::Pin::Parameter.new(
42
42
  location: loc,
@@ -36,8 +36,7 @@ module Solargraph
36
36
  def other_class_eval?
37
37
  node.children[0].type == :send &&
38
38
  node.children[0].children[1] == :class_eval &&
39
- # @sg-ignore Need to add nil check here
40
- [:cbase, :const].include?(node.children[0].children[0]&.type)
39
+ %i[cbase const].include?(node.children[0].children[0]&.type)
41
40
  end
42
41
  end
43
42
  end
@@ -21,7 +21,7 @@ module Solargraph
21
21
  scope: scope,
22
22
  visibility: scope == :instance && name == 'initialize' ? :private : region.visibility,
23
23
  node: node,
24
- source: :parser,
24
+ source: :parser
25
25
  )
26
26
  if region.visibility == :module_function
27
27
  pins.push Solargraph::Pin::Method.new(
@@ -34,7 +34,7 @@ module Solargraph
34
34
  visibility: :public,
35
35
  parameters: methpin.parameters,
36
36
  node: methpin.node,
37
- source: :parser,
37
+ source: :parser
38
38
  )
39
39
  pins.push Solargraph::Pin::Method.new(
40
40
  location: methpin.location,
@@ -46,7 +46,7 @@ module Solargraph
46
46
  visibility: :private,
47
47
  parameters: methpin.parameters,
48
48
  node: methpin.node,
49
- source: :parser,
49
+ source: :parser
50
50
  )
51
51
  else
52
52
  pins.push methpin
@@ -1,37 +1,38 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class DefsNode < DefNode
8
- include ParserGem::NodeMethods
9
-
10
- def process
11
- s_visi = region.visibility
12
- s_visi = :public if s_visi == :module_function || region.scope != :class
13
- loc = get_node_location(node)
14
- if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
15
- closure = region.closure
16
- else
17
- closure = Solargraph::Pin::Namespace.new(
18
- name: unpack_name(node.children[0])
19
- )
20
- end
21
- pins.push Solargraph::Pin::Method.new(
22
- location: loc,
23
- closure: closure,
24
- name: node.children[1].to_s,
25
- comments: comments_for(node),
26
- scope: :class,
27
- visibility: s_visi,
28
- node: node,
29
- source: :parser,
30
- )
31
- process_children region.update(closure: pins.last, scope: :class)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class DefsNode < DefNode
8
+ include ParserGem::NodeMethods
9
+
10
+ def process
11
+ s_visi = region.visibility
12
+ s_visi = :public if s_visi == :module_function || region.scope != :class
13
+ loc = get_node_location(node)
14
+ closure = if node.children[0].is_a?(AST::Node) && node.children[0].type == :self
15
+ region.closure
16
+ else
17
+ Solargraph::Pin::Namespace.new(
18
+ name: unpack_name(node.children[0]),
19
+ source: :parser
20
+ )
21
+ end
22
+ pins.push Solargraph::Pin::Method.new(
23
+ location: loc,
24
+ closure: closure,
25
+ name: node.children[1].to_s,
26
+ comments: comments_for(node),
27
+ scope: :class,
28
+ visibility: s_visi,
29
+ node: node,
30
+ source: :parser
31
+ )
32
+ process_children region.update(closure: pins.last, scope: :class)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -18,7 +18,7 @@ module Solargraph
18
18
  location: get_node_location(condition_node),
19
19
  closure: region.closure,
20
20
  node: condition_node,
21
- source: :parser,
21
+ source: :parser
22
22
  )
23
23
  NodeProcessor.process(condition_node, region, pins, locals, ivars)
24
24
  end
@@ -28,7 +28,7 @@ module Solargraph
28
28
  location: get_node_location(then_node),
29
29
  closure: region.closure,
30
30
  node: then_node,
31
- source: :parser,
31
+ source: :parser
32
32
  )
33
33
  NodeProcessor.process(then_node, region, pins, locals, ivars)
34
34
  end
@@ -39,7 +39,7 @@ module Solargraph
39
39
  location: get_node_location(else_node),
40
40
  closure: region.closure,
41
41
  node: else_node,
42
- source: :parser,
42
+ source: :parser
43
43
  )
44
44
  NodeProcessor.process(else_node, region, pins, locals, ivars)
45
45
  end
@@ -24,7 +24,8 @@ module Solargraph
24
24
  if named_path.is_a?(Pin::Method)
25
25
  ivars.push Solargraph::Pin::InstanceVariable.new(
26
26
  location: loc,
27
- closure: Pin::Namespace.new(type: :module, closure: region.closure.closure, name: region.closure.name),
27
+ closure: Pin::Namespace.new(type: :module, closure: region.closure.closure,
28
+ name: region.closure.name),
28
29
  name: node.children[0].to_s,
29
30
  comments: comments_for(node),
30
31
  assignment: node.children[1],
@@ -88,7 +88,7 @@ module Solargraph
88
88
  argument
89
89
  ]
90
90
  send_node = node.updated(:send, send_children)
91
- new_asgn = node.updated(asgn.type, [variable_name, send_node])
91
+ new_asgn = node.updated(asgn.type, [variable_name, send_node])
92
92
  NodeProcessor.process(new_asgn, region, pins, locals, ivars)
93
93
  end
94
94
  end
@@ -24,16 +24,14 @@ module Solargraph
24
24
  if sclass.children[0].nil? && names.last != sclass.children[1].to_s
25
25
  names << sclass.children[1].to_s
26
26
  else
27
- names.concat [NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s]
27
+ names.push NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s
28
28
  end
29
29
  name = names.reject(&:empty?).join('::')
30
30
  closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
31
31
  elsif sclass.is_a?(::Parser::AST::Node) && sclass.type == :const
32
32
  names = [region.closure.namespace, region.closure.name]
33
33
  also = NodeMethods.unpack_name(sclass)
34
- if also != region.closure.name
35
- names << also
36
- end
34
+ names << also if also != region.closure.name
37
35
  name = names.reject(&:empty?).join('::')
38
36
  closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location, source: :parser)
39
37
  else
@@ -42,7 +40,7 @@ module Solargraph
42
40
  pins.push Solargraph::Pin::Singleton.new(
43
41
  location: get_node_location(node),
44
42
  closure: closure,
45
- source: :parser,
43
+ source: :parser
46
44
  )
47
45
  process_children region.update(visibility: :public, scope: :class, closure: pins.last)
48
46
  end