solargraph 0.51.2 → 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 (162) 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/.yardopts +2 -2
  6. data/CHANGELOG.md +55 -5
  7. data/README.md +13 -16
  8. data/SPONSORS.md +1 -7
  9. data/lib/solargraph/api_map/cache.rb +60 -20
  10. data/lib/solargraph/api_map/store.rb +47 -11
  11. data/lib/solargraph/api_map.rb +161 -95
  12. data/lib/solargraph/bench.rb +2 -2
  13. data/lib/solargraph/cache.rb +29 -5
  14. data/lib/solargraph/complex_type/type_methods.rb +54 -9
  15. data/lib/solargraph/complex_type/unique_type.rb +155 -58
  16. data/lib/solargraph/complex_type.rb +73 -16
  17. data/lib/solargraph/convention.rb +0 -1
  18. data/lib/solargraph/converters/dd.rb +5 -0
  19. data/lib/solargraph/converters/dl.rb +3 -0
  20. data/lib/solargraph/converters/dt.rb +3 -0
  21. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  22. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  23. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  24. data/lib/solargraph/diagnostics.rb +2 -2
  25. data/lib/solargraph/doc_map.rb +146 -0
  26. data/lib/solargraph/gem_pins.rb +64 -0
  27. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  28. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  29. data/lib/solargraph/language_server/host/dispatch.rb +10 -4
  30. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  31. data/lib/solargraph/language_server/host/sources.rb +7 -4
  32. data/lib/solargraph/language_server/host.rb +15 -6
  33. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  34. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  35. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  36. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  37. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  38. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  39. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  40. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  41. data/lib/solargraph/library.rb +70 -16
  42. data/lib/solargraph/location.rb +1 -0
  43. data/lib/solargraph/parser/comment_ripper.rb +4 -0
  44. data/lib/solargraph/parser/node_methods.rb +47 -7
  45. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  46. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -5
  47. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  48. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +49 -36
  49. data/lib/solargraph/parser/parser_gem/node_methods.rb +499 -0
  50. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  51. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  52. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  53. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +1 -1
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  65. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  66. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  67. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  68. data/lib/solargraph/parser/parser_gem.rb +12 -0
  69. data/lib/solargraph/parser/region.rb +1 -1
  70. data/lib/solargraph/parser/snippet.rb +2 -0
  71. data/lib/solargraph/parser.rb +8 -9
  72. data/lib/solargraph/pin/base.rb +64 -9
  73. data/lib/solargraph/pin/base_variable.rb +6 -2
  74. data/lib/solargraph/pin/block.rb +13 -8
  75. data/lib/solargraph/pin/closure.rb +17 -2
  76. data/lib/solargraph/pin/common.rb +7 -3
  77. data/lib/solargraph/pin/conversions.rb +33 -3
  78. data/lib/solargraph/pin/delegated_method.rb +1 -1
  79. data/lib/solargraph/pin/documenting.rb +25 -34
  80. data/lib/solargraph/pin/instance_variable.rb +4 -0
  81. data/lib/solargraph/pin/local_variable.rb +13 -1
  82. data/lib/solargraph/pin/method.rb +169 -18
  83. data/lib/solargraph/pin/namespace.rb +18 -5
  84. data/lib/solargraph/pin/parameter.rb +44 -14
  85. data/lib/solargraph/pin/reference/override.rb +2 -2
  86. data/lib/solargraph/pin/reference.rb +8 -0
  87. data/lib/solargraph/pin/search.rb +3 -3
  88. data/lib/solargraph/pin/signature.rb +123 -3
  89. data/lib/solargraph/pin.rb +0 -1
  90. data/lib/solargraph/range.rb +2 -2
  91. data/lib/solargraph/rbs_map/conversions.rb +287 -45
  92. data/lib/solargraph/rbs_map/core_fills.rb +6 -29
  93. data/lib/solargraph/rbs_map/core_map.rb +2 -1
  94. data/lib/solargraph/rbs_map/core_signs.rb +2 -0
  95. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  96. data/lib/solargraph/rbs_map.rb +20 -11
  97. data/lib/solargraph/shell.rb +62 -59
  98. data/lib/solargraph/source/chain/array.rb +32 -0
  99. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  100. data/lib/solargraph/source/chain/call.rb +99 -46
  101. data/lib/solargraph/source/chain/constant.rb +15 -1
  102. data/lib/solargraph/source/chain/if.rb +23 -0
  103. data/lib/solargraph/source/chain/link.rb +8 -2
  104. data/lib/solargraph/source/chain/or.rb +1 -1
  105. data/lib/solargraph/source/chain/z_super.rb +3 -3
  106. data/lib/solargraph/source/chain.rb +29 -14
  107. data/lib/solargraph/source/change.rb +3 -0
  108. data/lib/solargraph/source/cursor.rb +2 -0
  109. data/lib/solargraph/source/source_chainer.rb +8 -5
  110. data/lib/solargraph/source.rb +18 -19
  111. data/lib/solargraph/source_map/clip.rb +11 -23
  112. data/lib/solargraph/source_map/mapper.rb +12 -1
  113. data/lib/solargraph/source_map.rb +15 -5
  114. data/lib/solargraph/type_checker/checks.rb +10 -2
  115. data/lib/solargraph/type_checker.rb +92 -26
  116. data/lib/solargraph/version.rb +1 -1
  117. data/lib/solargraph/workspace/config.rb +8 -6
  118. data/lib/solargraph/workspace.rb +3 -2
  119. data/lib/solargraph/yard_map/cache.rb +6 -0
  120. data/lib/solargraph/yard_map/helpers.rb +1 -1
  121. data/lib/solargraph/yard_map/mapper/to_method.rb +11 -1
  122. data/lib/solargraph/yard_map/mapper.rb +1 -1
  123. data/lib/solargraph/yard_map/to_method.rb +11 -4
  124. data/lib/solargraph/yard_map.rb +1 -292
  125. data/lib/solargraph/yard_tags.rb +20 -0
  126. data/lib/solargraph/yardoc.rb +52 -0
  127. data/lib/solargraph.rb +6 -4
  128. data/solargraph.gemspec +3 -2
  129. metadata +51 -58
  130. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  131. data/lib/solargraph/documentor.rb +0 -76
  132. data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
  133. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  134. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  135. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  136. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  137. data/lib/solargraph/parser/legacy.rb +0 -12
  138. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -153
  139. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
  140. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  141. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  142. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  143. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  144. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  145. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  146. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  147. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  148. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  149. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  150. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  151. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  152. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  153. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  154. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  155. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  156. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  157. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  158. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  159. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  160. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  161. data/lib/solargraph/parser/rubyvm.rb +0 -40
  162. data/lib/yard-solargraph.rb +0 -33
@@ -22,7 +22,7 @@ module Solargraph
22
22
  attr_reader :api_map
23
23
 
24
24
  # @param filename [String]
25
- # @param api_map [ApiMap]
25
+ # @param api_map [ApiMap, nil]
26
26
  # @param level [Symbol]
27
27
  def initialize filename, api_map: nil, level: :normal
28
28
  @filename = filename
@@ -51,6 +51,7 @@ module Solargraph
51
51
 
52
52
  class << self
53
53
  # @param filename [String]
54
+ # @param level [Symbol]
54
55
  # @return [self]
55
56
  def load filename, level = :normal
56
57
  source = Solargraph::Source.load(filename)
@@ -61,6 +62,7 @@ module Solargraph
61
62
 
62
63
  # @param code [String]
63
64
  # @param filename [String, nil]
65
+ # @param level [Symbol]
64
66
  # @return [self]
65
67
  def load_string code, filename = nil, level = :normal
66
68
  source = Solargraph::Source.load_string(code, filename)
@@ -91,7 +93,12 @@ module Solargraph
91
93
  declared = pin.typify(api_map).self_to(pin.full_context.namespace)
92
94
  if declared.undefined?
93
95
  if pin.return_type.undefined? && rules.require_type_tags?
94
- result.push Problem.new(pin.location, "Missing @return tag for #{pin.path}", pin: pin)
96
+ if pin.attribute?
97
+ inferred = pin.probe(api_map).self_to(pin.full_context.namespace)
98
+ result.push Problem.new(pin.location, "Missing @return tag for #{pin.path}", pin: pin) unless inferred.defined?
99
+ else
100
+ result.push Problem.new(pin.location, "Missing @return tag for #{pin.path}", pin: pin)
101
+ end
95
102
  elsif pin.return_type.defined? && !resolved_constant?(pin)
96
103
  result.push Problem.new(pin.location, "Unresolved return type #{pin.return_type} for #{pin.path}", pin: pin)
97
104
  elsif rules.must_tag_or_infer? && pin.probe(api_map).undefined?
@@ -121,11 +128,16 @@ module Solargraph
121
128
  # @return [Boolean]
122
129
  def resolved_constant? pin
123
130
  return true if pin.typify(api_map).defined?
124
- api_map.get_constants('', *pin.closure.gates)
125
- .select { |p| p.name == pin.return_type.namespace }
126
- .any? { |p| p.infer(api_map).defined? }
131
+ constant_pins = api_map.get_constants('', *pin.closure.gates)
132
+ .select { |p| p.name == pin.return_type.namespace }
133
+ return true if constant_pins.find { |p| p.typify(api_map).defined? }
134
+ # will need to probe when a constant name is assigned to a
135
+ # class/module (alias)
136
+ return true if constant_pins.find { |p| p.probe(api_map).defined? }
137
+ false
127
138
  end
128
139
 
140
+ # @param pin [Pin::Base]
129
141
  def virtual_pin? pin
130
142
  pin.location && source_map.source.comment_at?(pin.location.range.ending)
131
143
  end
@@ -141,12 +153,23 @@ module Solargraph
141
153
  sig.parameters.each do |par|
142
154
  break if par.decl == :restarg || par.decl == :kwrestarg || par.decl == :blockarg
143
155
  unless params[par.name]
144
- result.push Problem.new(pin.location, "Missing @param tag for #{par.name} on #{pin.path}", pin: pin)
156
+ if pin.attribute?
157
+ inferred = pin.probe(api_map).self_to(pin.full_context.namespace)
158
+ if inferred.undefined?
159
+ result.push Problem.new(pin.location, "Missing @param tag for #{par.name} on #{pin.path}", pin: pin)
160
+ end
161
+ else
162
+ result.push Problem.new(pin.location, "Missing @param tag for #{par.name} on #{pin.path}", pin: pin)
163
+ end
145
164
  end
146
165
  end
147
166
  end
148
167
  end
168
+ # @todo Should be able to probe type of name and data here
169
+ # @param name [String]
170
+ # @param data [Hash{Symbol => BasicObject}]
149
171
  params.each_pair do |name, data|
172
+ # @type [ComplexType]
150
173
  type = data[:qualified]
151
174
  if type.undefined?
152
175
  result.push Problem.new(pin.location, "Unresolved type #{data[:tagged]} for #{name} param on #{pin.path}", pin: pin)
@@ -155,6 +178,7 @@ module Solargraph
155
178
  result
156
179
  end
157
180
 
181
+ # @return [Array<Pin::Base>]
158
182
  def ignored_pins
159
183
  @ignored_pins ||= []
160
184
  end
@@ -202,6 +226,7 @@ module Solargraph
202
226
  source_map.pins_by_class(Pin::BaseVariable) + source_map.locals.select { |pin| pin.is_a?(Pin::LocalVariable) }
203
227
  end
204
228
 
229
+ # @return [Array<Problem>]
205
230
  def const_problems
206
231
  return [] unless rules.validate_consts?
207
232
  result = []
@@ -220,6 +245,7 @@ module Solargraph
220
245
  result
221
246
  end
222
247
 
248
+ # @return [Array<Problem>]
223
249
  def call_problems
224
250
  result = []
225
251
  Solargraph::Parser::NodeMethods.call_nodes_from(source_map.source.node).each do |call|
@@ -243,7 +269,7 @@ module Solargraph
243
269
  end
244
270
  closest = found.typify(api_map) if found
245
271
  if !found || found.is_a?(Pin::BaseVariable) || (closest.defined? && internal_or_core?(found))
246
- unless closest.parameterized? || ignored_pins.include?(found)
272
+ unless closest.generic? || ignored_pins.include?(found)
247
273
  result.push Problem.new(location, "Unresolved call to #{missing.links.last.word}")
248
274
  @marked_ranges.push rng
249
275
  end
@@ -259,6 +285,7 @@ module Solargraph
259
285
  # @param block_pin [Solargraph::Pin::Base]
260
286
  # @param locals [Array<Solargraph::Pin::Base>]
261
287
  # @param location [Solargraph::Location]
288
+ # @return [Array<Problem>]
262
289
  def argument_problems_for chain, api_map, block_pin, locals, location
263
290
  result = []
264
291
  base = chain
@@ -279,12 +306,16 @@ module Solargraph
279
306
  result.concat ap
280
307
  break
281
308
  end
282
- break unless rules.validate_calls?
309
+ break if !rules.validate_calls? || base.links.first.is_a?(Solargraph::Source::Chain::ZSuper)
310
+
283
311
  params = first_param_hash(pins)
284
312
 
285
313
  all_errors = []
286
314
  pin.signatures.sort { |sig| sig.parameters.length }.each do |sig|
287
315
  errors = []
316
+ # @todo these should be able to be probed
317
+ # @param par [Parameter]
318
+ # @param idx [Integer]
288
319
  sig.parameters.each_with_index do |par, idx|
289
320
  argchain = base.links.last.arguments[idx]
290
321
  if argchain.nil?
@@ -298,7 +329,7 @@ module Solargraph
298
329
  end
299
330
  if argchain
300
331
  if par.decl != :arg
301
- errors.concat kwarg_problems_for argchain, api_map, block_pin, locals, location, pin, params, idx
332
+ errors.concat kwarg_problems_for sig, argchain, api_map, block_pin, locals, location, pin, params, idx
302
333
  next
303
334
  else
304
335
  ptype = params.key?(par.name) ? params[par.name][:qualified] : ComplexType::UNDEFINED
@@ -330,10 +361,21 @@ module Solargraph
330
361
  result
331
362
  end
332
363
 
333
- def kwarg_problems_for argchain, api_map, block_pin, locals, location, pin, params, idx
364
+ # @param sig [Pin::Signature]
365
+ # @param argchain [Source::Chain]
366
+ # @param api_map [ApiMap]
367
+ # @param block_pin [Pin::Block]
368
+ # @param locals [Array<Pin::LocalVariable>]
369
+ # @param location [Location]
370
+ # @param pin [Pin::Method]
371
+ # @param params [Hash{String => [nil, Hash]}]
372
+ # @param idx [Integer]
373
+ #
374
+ # @return [Array<Problem>]
375
+ def kwarg_problems_for sig, argchain, api_map, block_pin, locals, location, pin, params, idx
334
376
  result = []
335
377
  kwargs = convert_hash(argchain.node)
336
- par = pin.signatures.first.parameters[idx]
378
+ par = sig.parameters[idx]
337
379
  argchain = kwargs[par.name.to_sym]
338
380
  if par.decl == :kwrestarg || (par.decl == :optarg && idx == pin.parameters.length - 1 && par.asgn_code == '{}')
339
381
  result.concat kwrestarg_problems_for(api_map, block_pin, locals, location, pin, params, kwargs)
@@ -358,6 +400,14 @@ module Solargraph
358
400
  result
359
401
  end
360
402
 
403
+ # @param api_map [ApiMap]
404
+ # @param block_pin [Pin::Block]
405
+ # @param locals [Array<Pin::LocalVariable>]
406
+ # @param location [Location]
407
+ # @param pin [Pin::Method]
408
+ # @param params [Hash{String => [nil, Hash]}]
409
+ # @param kwargs [Hash{Symbol => Source::Chain}]
410
+ # @return [Array<Problem>]
361
411
  def kwrestarg_problems_for(api_map, block_pin, locals, location, pin, params, kwargs)
362
412
  result = []
363
413
  kwargs.each_pair do |pname, argchain|
@@ -371,8 +421,8 @@ module Solargraph
371
421
  result
372
422
  end
373
423
 
374
- # @param [Pin::Method]
375
- # @return [Hash]
424
+ # @param pin [Pin::Method]
425
+ # @return [Hash{String => Hash{Symbol => BaseObject}}]
376
426
  def param_hash(pin)
377
427
  tags = pin.docstring.tags(:param)
378
428
  return {} if tags.empty?
@@ -387,10 +437,12 @@ module Solargraph
387
437
  result
388
438
  end
389
439
 
390
- # @param [Array<Pin::Method>]
391
- # @return [Hash]
440
+ # @param pins [Array<Pin::Method>]
441
+ # @return [Hash{String => Hash{Symbol => BasicObject}}]
392
442
  def first_param_hash(pins)
393
443
  pins.each do |pin|
444
+ # @todo this assignment from parametric use of Hash should not lose its generic
445
+ # @type [Hash{String => Hash{Symbol => BasicObject}]
394
446
  result = param_hash(pin)
395
447
  return result unless result.empty?
396
448
  end
@@ -404,6 +456,7 @@ module Solargraph
404
456
  end
405
457
 
406
458
  # True if the pin is either internal (part of the workspace) or from the core/stdlib
459
+ # @param pin [Pin::Base]
407
460
  def internal_or_core? pin
408
461
  # @todo RBS pins are not necessarily core/stdlib pins
409
462
  internal?(pin) || pin.source == :rbs
@@ -414,6 +467,7 @@ module Solargraph
414
467
  !internal? pin
415
468
  end
416
469
 
470
+ # @param pin [Pin::Base]
417
471
  def declared_externally? pin
418
472
  return true if pin.assignment.nil?
419
473
  chain = Solargraph::Parser.chain(pin.assignment, filename)
@@ -441,6 +495,10 @@ module Solargraph
441
495
  true
442
496
  end
443
497
 
498
+ # @param pin [Pin::Method]
499
+ # @param arguments [Array<Source::Chain>]
500
+ # @param location [Location]
501
+ # @return [Array<Problem>]
444
502
  def arity_problems_for pin, arguments, location
445
503
  results = pin.signatures.map do |sig|
446
504
  r = parameterized_arity_problems_for(pin, sig.parameters, arguments, location)
@@ -450,16 +508,15 @@ module Solargraph
450
508
  results.first
451
509
  end
452
510
 
511
+ # @param pin [Pin::Method]
512
+ # @param parameters [Array<Pin::Parameter>]
513
+ # @param arguments [Array<Source::Chain>]
514
+ # @param location [Location]
515
+ # @return [Array<Problem>]
453
516
  def parameterized_arity_problems_for(pin, parameters, arguments, location)
454
517
  return [] unless pin.explicit?
455
518
  return [] if parameters.empty? && arguments.empty?
456
519
  return [] if pin.anon_splat?
457
- if parameters.empty?
458
- # Functions tagged param_tuple accepts two arguments (e.g., Hash#[]=)
459
- return [] if pin.docstring.tag(:param_tuple) && arguments.length == 2
460
- return [] if arguments.length == 1 && arguments.last.links.last.is_a?(Source::Chain::BlockVariable)
461
- return [Problem.new(location, "Too many arguments to #{pin.path}")]
462
- end
463
520
  unchecked = arguments.clone
464
521
  add_params = 0
465
522
  if unchecked.empty? && parameters.any? { |param| param.decl == :kwarg }
@@ -499,9 +556,6 @@ module Solargraph
499
556
  return [] if parameters.any?(&:rest?)
500
557
  opt = optional_param_count(parameters)
501
558
  return [] if unchecked.length <= req + opt
502
- if unchecked.length == req + opt + 1 && unchecked.last.links.last.is_a?(Source::Chain::BlockVariable)
503
- return []
504
- end
505
559
  if req + add_params + 1 == unchecked.length && any_splatted_call?(unchecked.map(&:node)) && (parameters.map(&:decl) & [:kwarg, :kwoptarg, :kwrestarg]).any?
506
560
  return []
507
561
  end
@@ -517,20 +571,30 @@ module Solargraph
517
571
  []
518
572
  end
519
573
 
574
+ # @param parameters [Enumerable<Pin::Parameter>]
575
+ # @todo need to use generic types in method to choose correct
576
+ # signature and generate Integer as return type
577
+ # @sg-ignore
578
+ # @return [Integer]
520
579
  def required_param_count(parameters)
521
580
  parameters.sum { |param| %i[arg kwarg].include?(param.decl) ? 1 : 0 }
522
581
  end
523
582
 
583
+ # @param parameters [Enumerable<Pin::Parameter>]
524
584
  # @param pin [Pin::Method]
585
+ # @return [Integer]
525
586
  def optional_param_count(parameters)
526
587
  parameters.select { |p| p.decl == :optarg }.length
527
588
  end
528
589
 
590
+ # @param pin [Pin::Method]
529
591
  def abstract? pin
530
- pin.docstring.has_tag?(:abstract) ||
531
- (pin.closure && pin.closure.docstring.has_tag?(:abstract))
592
+ pin.docstring.has_tag?('abstract') ||
593
+ (pin.closure && pin.closure.docstring.has_tag?('abstract'))
532
594
  end
533
595
 
596
+ # @param pin [Pin::Base]
597
+ # @return [Array<Source::Chain>]
534
598
  def fake_args_for(pin)
535
599
  args = []
536
600
  with_opts = false
@@ -551,6 +615,8 @@ module Solargraph
551
615
  args
552
616
  end
553
617
 
618
+ # @param problems [Array<Problem>]
619
+ # @return [Array<Problem>]
554
620
  def without_ignored problems
555
621
  problems.reject do |problem|
556
622
  node = source_map.source.node_at(problem.location.range.start.line, problem.location.range.start.column)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solargraph
4
- VERSION = '0.51.2'
4
+ VERSION = '0.53.0'
5
5
  end
@@ -14,7 +14,7 @@ module Solargraph
14
14
  # @return [String]
15
15
  attr_reader :directory
16
16
 
17
- # @return [Hash]
17
+ # @return [Hash{String => BasicObject}]
18
18
  attr_reader :raw_data
19
19
 
20
20
  # @param directory [String]
@@ -41,6 +41,7 @@ module Solargraph
41
41
  @excluded ||= process_exclusions(@raw_data['exclude'])
42
42
  end
43
43
 
44
+ # @param filename [String]
44
45
  def allow? filename
45
46
  filename = File.absolute_path(filename, directory)
46
47
  filename.start_with?(directory) &&
@@ -111,7 +112,7 @@ module Solargraph
111
112
 
112
113
  # @return [String]
113
114
  def global_config_path
114
- ENV['SOLARGRAPH_GLOBAL_CONFIG'] ||
115
+ ENV['SOLARGRAPH_GLOBAL_CONFIG'] ||
115
116
  File.join(Dir.home, '.config', 'solargraph', 'config.yml')
116
117
  end
117
118
 
@@ -121,7 +122,7 @@ module Solargraph
121
122
  File.join(@directory, '.solargraph.yml')
122
123
  end
123
124
 
124
- # @return [Hash]
125
+ # @return [Hash{String => Array, Hash, Integer}]
125
126
  def config_data
126
127
  workspace_config = read_config(workspace_config_path)
127
128
  global_config = read_config(global_config_path)
@@ -136,15 +137,15 @@ module Solargraph
136
137
 
137
138
  # Read a .solargraph yaml config
138
139
  #
139
- # @param directory [String]
140
- # @return [Hash, nil]
140
+ # @param config_path [String]
141
+ # @return [Hash{String => Array, Hash, Integer}, nil]
141
142
  def read_config config_path = ''
142
143
  return nil if config_path.empty?
143
144
  return nil unless File.file?(config_path)
144
145
  YAML.safe_load(File.read(config_path))
145
146
  end
146
147
 
147
- # @return [Hash]
148
+ # @return [Hash{String => Array, Hash, Integer}]
148
149
  def default_config
149
150
  {
150
151
  'include' => ['**/*.rb'],
@@ -222,6 +223,7 @@ module Solargraph
222
223
  glob.gsub(/(\/\*|\/\*\*\/\*\*?)$/, '')
223
224
  end
224
225
 
226
+ # @return [Array<String>]
225
227
  def excluded_directories
226
228
  @raw_data['exclude']
227
229
  .select { |g| glob_is_directory?(g) }
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'open3'
4
- require 'rubygems'
5
4
  require 'json'
6
5
 
7
6
  module Solargraph
@@ -104,7 +103,8 @@ module Solargraph
104
103
  # @return [Boolean]
105
104
  def would_require? path
106
105
  require_paths.each do |rp|
107
- return true if File.exist?(File.join(rp, "#{path}.rb"))
106
+ full = File.join rp, path
107
+ return true if File.exist?(full) or File.exist?(full << ".rb")
108
108
  end
109
109
  false
110
110
  end
@@ -199,6 +199,7 @@ module Solargraph
199
199
  config.require_paths.map{|p| File.join(directory, p)}
200
200
  end
201
201
 
202
+ # @return [void]
202
203
  def require_plugins
203
204
  config.plugins.each do |plugin|
204
205
  begin
@@ -4,13 +4,19 @@ module Solargraph
4
4
  class YardMap
5
5
  class Cache
6
6
  def initialize
7
+ # @type [Hash{String => Array<Solargraph::Pin::Base>}]
7
8
  @path_pins = {}
8
9
  end
9
10
 
11
+ # @param path [String]
12
+ # @param pins [Array<Solargraph::Pin::Base>]
13
+ # @return [Array<Solargraph::Pin::Base>]
10
14
  def set_path_pins path, pins
11
15
  @path_pins[path] = pins
12
16
  end
13
17
 
18
+ # @param path [String]
19
+ # @return [Array<Solargraph::Pin::Base>]
14
20
  def get_path_pins path
15
21
  @path_pins[path]
16
22
  end
@@ -4,7 +4,7 @@ module Solargraph
4
4
  module_function
5
5
 
6
6
  # @param code_object [YARD::CodeObjects::Base]
7
- # @param spec [Gem::Specification]
7
+ # @param spec [Gem::Specification, nil]
8
8
  # @return [Solargraph::Location, nil]
9
9
  def object_location code_object, spec
10
10
  return nil if spec.nil? || code_object.nil? || code_object.file.nil? || code_object.line.nil?
@@ -6,6 +6,13 @@ module Solargraph
6
6
  module ToMethod
7
7
  extend YardMap::Helpers
8
8
 
9
+ # @param code_object [YARD::CodeObjects::Base]
10
+ # @param name [String, nil]
11
+ # @param scope [Symbol, nil]
12
+ # @param visibility [Symbol, nil]
13
+ # @param closure [Solargraph::Pin::Namespace, nil]
14
+ # @param spec [Gem::Specification, nil]
15
+ # @return [Solargraph::Pin::Method]
9
16
  def self.make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
10
17
  closure ||= Solargraph::Pin::Namespace.new(
11
18
  name: code_object.namespace.to_s,
@@ -32,6 +39,9 @@ module Solargraph
32
39
  private
33
40
 
34
41
  # @param code_object [YARD::CodeObjects::Base]
42
+ # @param location [Location],
43
+ # @param comments [String]
44
+ # @param pin [Pin::Base]
35
45
  # @return [Array<Solargraph::Pin::Parameter>]
36
46
  def get_parameters code_object, location, comments, pin
37
47
  return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
@@ -51,7 +61,7 @@ module Solargraph
51
61
  end
52
62
  end
53
63
 
54
- # @param a [Array]
64
+ # @param a [Array<String>]
55
65
  # @return [String]
56
66
  def arg_name a
57
67
  a[0].gsub(/[^a-z0-9_]/i, '')
@@ -8,7 +8,7 @@ module Solargraph
8
8
  autoload :ToConstant, 'solargraph/yard_map/mapper/to_constant'
9
9
 
10
10
  # @param code_objects [Array<YARD::CodeObjects::Base>]
11
- # @param spec [Gem::Specification]
11
+ # @param spec [Gem::Specification, nil]
12
12
  def initialize code_objects, spec = nil
13
13
  @code_objects = code_objects
14
14
  @spec = spec
@@ -7,6 +7,8 @@ module Solargraph
7
7
  module_function
8
8
 
9
9
  # @param code_object [YARD::CodeObjects::Base]
10
+ # @param location [Solargraph::Location]
11
+ # @param comments [String]
10
12
  # @return [Array<Solargraph::Pin::Parameter>]
11
13
  def get_parameters code_object, location, comments
12
14
  return [] unless code_object.is_a?(YARD::CodeObjects::MethodObject)
@@ -26,7 +28,7 @@ module Solargraph
26
28
  end
27
29
  end
28
30
 
29
- # @param a [Array]
31
+ # @param a [Array<String>]
30
32
  # @return [String]
31
33
  def arg_name a
32
34
  a[0].gsub(/[^a-z0-9_]/i, '')
@@ -52,10 +54,15 @@ module Solargraph
52
54
  end
53
55
  private_constant :InnerMethods
54
56
 
55
- # include YardMixin
56
- # extend YardMixin
57
- extend Helpers
57
+ include Helpers
58
58
 
59
+ # @param code_object [YARD::CodeObjects::Base]
60
+ # @param name [String, nil]
61
+ # @param scope [Symbol, nil]
62
+ # @param visibility [Symbol, nil]
63
+ # @param closure [Solargraph::Pin::Base, nil]
64
+ # @param spec [Solargraph::Pin::Base, nil]
65
+ # @return [Solargraph::Pin::Method]
59
66
  def make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
60
67
  closure ||= Solargraph::Pin::Namespace.new(
61
68
  name: code_object.namespace.to_s,