solargraph 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +40 -0
  3. data/.github/workflows/rspec.yml +1 -3
  4. data/.github/workflows/typecheck.yml +34 -0
  5. data/CHANGELOG.md +30 -0
  6. data/README.md +13 -16
  7. data/SPONSORS.md +1 -7
  8. data/lib/solargraph/api_map/cache.rb +59 -21
  9. data/lib/solargraph/api_map/store.rb +45 -9
  10. data/lib/solargraph/api_map.rb +152 -93
  11. data/lib/solargraph/bench.rb +2 -2
  12. data/lib/solargraph/cache.rb +29 -5
  13. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  14. data/lib/solargraph/complex_type/unique_type.rb +149 -59
  15. data/lib/solargraph/complex_type.rb +62 -9
  16. data/lib/solargraph/convention.rb +0 -1
  17. data/lib/solargraph/converters/dd.rb +5 -0
  18. data/lib/solargraph/converters/dl.rb +3 -0
  19. data/lib/solargraph/converters/dt.rb +3 -0
  20. data/lib/solargraph/diagnostics/rubocop.rb +8 -7
  21. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -0
  22. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  23. data/lib/solargraph/diagnostics.rb +2 -2
  24. data/lib/solargraph/doc_map.rb +146 -0
  25. data/lib/solargraph/gem_pins.rb +64 -0
  26. data/lib/solargraph/language_server/host/cataloger.rb +1 -0
  27. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  28. data/lib/solargraph/language_server/host/dispatch.rb +10 -4
  29. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  30. data/lib/solargraph/language_server/host/sources.rb +7 -4
  31. data/lib/solargraph/language_server/host.rb +15 -6
  32. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  33. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  34. data/lib/solargraph/language_server/message/initialize.rb +5 -2
  35. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  36. data/lib/solargraph/language_server/message/text_document.rb +0 -1
  37. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  38. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  39. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  40. data/lib/solargraph/library.rb +58 -11
  41. data/lib/solargraph/location.rb +1 -0
  42. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  43. data/lib/solargraph/parser/node_methods.rb +47 -8
  44. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  45. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  46. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  47. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  48. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  49. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  53. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +1 -1
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  66. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  67. data/lib/solargraph/parser/parser_gem.rb +12 -0
  68. data/lib/solargraph/parser/snippet.rb +2 -0
  69. data/lib/solargraph/parser.rb +8 -11
  70. data/lib/solargraph/pin/base.rb +63 -8
  71. data/lib/solargraph/pin/base_variable.rb +6 -2
  72. data/lib/solargraph/pin/block.rb +11 -6
  73. data/lib/solargraph/pin/closure.rb +17 -2
  74. data/lib/solargraph/pin/common.rb +7 -3
  75. data/lib/solargraph/pin/conversions.rb +33 -3
  76. data/lib/solargraph/pin/documenting.rb +25 -34
  77. data/lib/solargraph/pin/instance_variable.rb +4 -0
  78. data/lib/solargraph/pin/local_variable.rb +13 -1
  79. data/lib/solargraph/pin/method.rb +109 -15
  80. data/lib/solargraph/pin/namespace.rb +16 -10
  81. data/lib/solargraph/pin/parameter.rb +41 -10
  82. data/lib/solargraph/pin/reference/override.rb +2 -2
  83. data/lib/solargraph/pin/reference.rb +8 -0
  84. data/lib/solargraph/pin/search.rb +3 -3
  85. data/lib/solargraph/pin/signature.rb +114 -2
  86. data/lib/solargraph/pin.rb +0 -1
  87. data/lib/solargraph/range.rb +2 -2
  88. data/lib/solargraph/rbs_map/conversions.rb +212 -25
  89. data/lib/solargraph/rbs_map/core_fills.rb +4 -26
  90. data/lib/solargraph/rbs_map/core_map.rb +1 -0
  91. data/lib/solargraph/rbs_map/core_signs.rb +2 -0
  92. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  93. data/lib/solargraph/rbs_map.rb +19 -9
  94. data/lib/solargraph/shell.rb +62 -59
  95. data/lib/solargraph/source/chain/array.rb +4 -1
  96. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  97. data/lib/solargraph/source/chain/call.rb +95 -26
  98. data/lib/solargraph/source/chain/constant.rb +15 -1
  99. data/lib/solargraph/source/chain/if.rb +23 -0
  100. data/lib/solargraph/source/chain/link.rb +7 -1
  101. data/lib/solargraph/source/chain/or.rb +1 -1
  102. data/lib/solargraph/source/chain/z_super.rb +2 -2
  103. data/lib/solargraph/source/chain.rb +20 -4
  104. data/lib/solargraph/source/change.rb +3 -0
  105. data/lib/solargraph/source/cursor.rb +2 -0
  106. data/lib/solargraph/source/source_chainer.rb +6 -5
  107. data/lib/solargraph/source.rb +15 -16
  108. data/lib/solargraph/source_map/clip.rb +11 -7
  109. data/lib/solargraph/source_map/mapper.rb +10 -0
  110. data/lib/solargraph/source_map.rb +13 -3
  111. data/lib/solargraph/type_checker/checks.rb +10 -2
  112. data/lib/solargraph/type_checker.rb +74 -19
  113. data/lib/solargraph/version.rb +1 -1
  114. data/lib/solargraph/workspace/config.rb +8 -6
  115. data/lib/solargraph/workspace.rb +1 -1
  116. data/lib/solargraph/yard_map/cache.rb +6 -0
  117. data/lib/solargraph/yard_map/helpers.rb +1 -1
  118. data/lib/solargraph/yard_map/mapper/to_method.rb +11 -1
  119. data/lib/solargraph/yard_map/to_method.rb +11 -4
  120. data/lib/solargraph/yard_map.rb +0 -292
  121. data/lib/solargraph/yardoc.rb +52 -0
  122. data/lib/solargraph.rb +4 -1
  123. data/solargraph.gemspec +2 -2
  124. metadata +35 -57
  125. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  126. data/lib/solargraph/documentor.rb +0 -76
  127. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  128. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  129. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  130. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  131. data/lib/solargraph/parser/legacy.rb +0 -12
  132. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  133. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  134. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  135. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  136. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  137. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  138. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  139. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  140. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  141. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  142. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  143. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  144. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  145. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  146. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  147. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  148. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  149. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  150. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  151. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  152. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  153. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  154. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  155. data/lib/solargraph/parser/rubyvm.rb +0 -40
@@ -19,8 +19,10 @@ module Solargraph
19
19
  autoload :GlobalVariable, 'solargraph/source/chain/global_variable'
20
20
  autoload :Literal, 'solargraph/source/chain/literal'
21
21
  autoload :Head, 'solargraph/source/chain/head'
22
+ autoload :If, 'solargraph/source/chain/if'
22
23
  autoload :Or, 'solargraph/source/chain/or'
23
24
  autoload :BlockVariable, 'solargraph/source/chain/block_variable'
25
+ autoload :BlockSymbol, 'solargraph/source/chain/block_symbol'
24
26
  autoload :ZSuper, 'solargraph/source/chain/z_super'
25
27
  autoload :Hash, 'solargraph/source/chain/hash'
26
28
  autoload :Array, 'solargraph/source/chain/array'
@@ -36,7 +38,9 @@ module Solargraph
36
38
 
37
39
  attr_reader :node
38
40
 
41
+ # @param node [Parser::AST::Node, nil]
39
42
  # @param links [::Array<Chain::Link>]
43
+ # @param splat [Boolean]
40
44
  def initialize links, node = nil, splat = false
41
45
  @links = links.clone
42
46
  @links.push UNDEFINED_CALL if @links.empty?
@@ -57,7 +61,8 @@ module Solargraph
57
61
 
58
62
  # @param api_map [ApiMap]
59
63
  # @param name_pin [Pin::Base]
60
- # @param locals [Array<Pin::Base>]
64
+ # @param locals [::Enumerable<Pin::LocalVariable>]
65
+ #
61
66
  # @return [::Array<Pin::Base>]
62
67
  def define api_map, name_pin, locals
63
68
  return [] if undefined?
@@ -74,7 +79,7 @@ module Solargraph
74
79
 
75
80
  # @param api_map [ApiMap]
76
81
  # @param name_pin [Pin::Base]
77
- # @param locals [Array<Pin::Base>]
82
+ # @param locals [::Enumerable<Pin::LocalVariable>]
78
83
  # @return [ComplexType]
79
84
  def infer api_map, name_pin, locals
80
85
  from_here = base.infer(api_map, name_pin, locals) unless links.length == 1
@@ -114,12 +119,16 @@ module Solargraph
114
119
 
115
120
  private
116
121
 
117
- # @param pins [Array<Pin::Base>]
122
+ # @param pins [::Array<Pin::Base>]
118
123
  # @param context [Pin::Base]
119
124
  # @param api_map [ApiMap]
125
+ # @param locals [::Enumerable<Pin::LocalVariable>]
120
126
  # @return [ComplexType]
121
127
  def infer_first_defined pins, context, api_map, locals
122
128
  possibles = []
129
+ # @todo this param tag shouldn't be needed to probe the type
130
+ # @todo ...but given it is needed, typecheck should complain that it is needed
131
+ # @param pin [Pin::Base]
123
132
  pins.each do |pin|
124
133
  # Avoid infinite recursion
125
134
  next if @@inference_stack.include?(pin.identity)
@@ -129,6 +138,9 @@ module Solargraph
129
138
  @@inference_stack.pop
130
139
  if type.defined?
131
140
  if type.generic?
141
+ # @todo even at strong, no typechecking complaint
142
+ # happens when a [Pin::Base,nil] is passed into a method
143
+ # that accepts only [Pin::Namespace] as an argument
132
144
  type = type.resolve_generics(pin.closure, context.return_type)
133
145
  end
134
146
  if type.defined?
@@ -142,6 +154,7 @@ module Solargraph
142
154
  return ComplexType::UNDEFINED if @@inference_depth >= 10 && pins.first.is_a?(Pin::Method)
143
155
 
144
156
  @@inference_depth += 1
157
+ # @param pin [Pin::Base]
145
158
  pins.each do |pin|
146
159
  # Avoid infinite recursion
147
160
  next if @@inference_stack.include?(pin.identity)
@@ -157,6 +170,7 @@ module Solargraph
157
170
  @@inference_depth -= 1
158
171
  end
159
172
  return ComplexType::UNDEFINED if possibles.empty?
173
+
160
174
  type = if possibles.length > 1
161
175
  sorted = possibles.map { |t| t.rooted? ? "::#{t}" : t.to_s }.sort { |a, _| a == 'nil' ? 1 : 0 }
162
176
  ComplexType.parse(*sorted)
@@ -164,10 +178,12 @@ module Solargraph
164
178
  ComplexType.parse(possibles.map(&:to_s).join(', '))
165
179
  end
166
180
  return type if context.nil? || context.return_type.undefined?
167
- type.self_to(context.return_type.namespace)
181
+
182
+ type.self_to(context.return_type.tag)
168
183
  end
169
184
 
170
185
  # @param type [ComplexType]
186
+ # @return [ComplexType]
171
187
  def maybe_nil type
172
188
  return type if type.undefined? || type.void? || type.nullable?
173
189
  return type unless nullable?
@@ -69,6 +69,9 @@ module Solargraph
69
69
 
70
70
  private
71
71
 
72
+ # @param text [String]
73
+ # @param insert [String]
74
+ # @return [String]
72
75
  def commit text, insert
73
76
  start_offset = Position.to_offset(text, range.start)
74
77
  end_offset = Position.to_offset(text, range.ending)
@@ -115,6 +115,7 @@ module Solargraph
115
115
  end
116
116
  alias receiver recipient
117
117
 
118
+ # @return [AST::Node]
118
119
  def node
119
120
  @node ||= source.node_at(position.line, position.column)
120
121
  end
@@ -135,6 +136,7 @@ module Solargraph
135
136
  end
136
137
  end
137
138
 
139
+ # @return [Parser::AST::Node, nil]
138
140
  def recipient_node
139
141
  @recipient_node ||= Solargraph::Parser::NodeMethods.find_recipient_node(self)
140
142
  end
@@ -14,10 +14,10 @@ module Solargraph
14
14
 
15
15
  class << self
16
16
  # @param source [Source]
17
- # @param position [Position]
17
+ # @param position [Position, Array(Integer, Integer)]
18
18
  # @return [Source::Chain]
19
19
  def chain source, position
20
- new(source, position).chain
20
+ new(source, Solargraph::Position.normalize(position)).chain
21
21
  end
22
22
  end
23
23
 
@@ -41,8 +41,6 @@ module Solargraph
41
41
  parent = nil
42
42
  if !source.repaired? && source.parsed? && source.synchronized?
43
43
  tree = source.tree_at(position.line, position.column)
44
- # node, parent = source.tree_at(position.line, position.column)[0..2]
45
- tree.shift while tree.length > 1 && tree.first.type == :SCOPE
46
44
  node, parent = tree[0..2]
47
45
  elsif source.parsed? && source.repaired? && end_of_phrase == '.'
48
46
  node, parent = source.tree_at(fixed_position.line, fixed_position.column)[0..2]
@@ -60,7 +58,7 @@ module Solargraph
60
58
  end
61
59
  return Chain.new([Chain::UNDEFINED_CALL]) if node.nil? || (node.type == :sym && !phrase.start_with?(':'))
62
60
  # chain = NodeChainer.chain(node, source.filename, parent && parent.type == :block)
63
- chain = Parser.chain(node, source.filename, parent && [:ITER, :block].include?(parent.type))
61
+ chain = Parser.chain(node, source.filename, parent)
64
62
  if source.repaired? || !source.parsed? || !source.synchronized?
65
63
  if end_of_phrase.strip == '.'
66
64
  chain.links.push Chain::UNDEFINED_CALL
@@ -128,10 +126,13 @@ module Solargraph
128
126
  Position.line_char_to_offset(@source.code, line, column)
129
127
  end
130
128
 
129
+ # @return [Integer]
131
130
  def signature_data
132
131
  @signature_data ||= get_signature_data_at(offset)
133
132
  end
134
133
 
134
+ # @param index [Integer]
135
+ # @return [Integer]
135
136
  def get_signature_data_at index
136
137
  brackets = 0
137
138
  squares = 0
@@ -8,7 +8,6 @@ module Solargraph
8
8
  class Source
9
9
  autoload :Updater, 'solargraph/source/updater'
10
10
  autoload :Change, 'solargraph/source/change'
11
- autoload :Mapper, 'solargraph/source/mapper'
12
11
  autoload :EncodingFixes, 'solargraph/source/encoding_fixes'
13
12
  autoload :Cursor, 'solargraph/source/cursor'
14
13
  autoload :Chain, 'solargraph/source/chain'
@@ -213,6 +212,7 @@ module Solargraph
213
212
  end
214
213
  end
215
214
 
215
+ # @return [::Array<Range>]
216
216
  def string_ranges
217
217
  @string_ranges ||= Parser.string_ranges(node)
218
218
  end
@@ -250,7 +250,7 @@ module Solargraph
250
250
  end
251
251
 
252
252
  # @param node [Parser::AST::Node]
253
- # @return [String]
253
+ # @return [String, nil]
254
254
  def comments_for node
255
255
  rng = Range.from_node(node)
256
256
  stringified_comments[rng.start.line] ||= begin
@@ -301,7 +301,7 @@ module Solargraph
301
301
 
302
302
  # Get a hash of comments grouped by the line numbers of the associated code.
303
303
  #
304
- # @return [Hash{Integer => Array<Parser::Source::Comment>}]
304
+ # @return [Hash{Integer => String}]
305
305
  def associated_comments
306
306
  @associated_comments ||= begin
307
307
  result = {}
@@ -323,6 +323,8 @@ module Solargraph
323
323
 
324
324
  private
325
325
 
326
+ # @param line [Integer]
327
+ # @return [Integer]
326
328
  def first_not_empty_from line
327
329
  cursor = line
328
330
  cursor += 1 while cursor < code_lines.length && code_lines[cursor].strip.empty?
@@ -411,7 +413,7 @@ module Solargraph
411
413
  result
412
414
  end
413
415
 
414
- # @param n [Parser::AST::Node]
416
+ # @param n [Parser::AST::Node, nil]
415
417
  # @return [Array<Parser::AST::Node>]
416
418
  def string_nodes_in n
417
419
  result = []
@@ -425,30 +427,23 @@ module Solargraph
425
427
  result
426
428
  end
427
429
 
428
- # @param node [Parser::AST::Node]
430
+ # @param node [Parser::AST::Node, nil]
429
431
  # @param position [Position]
430
432
  # @param stack [Array<Parser::AST::Node>]
431
433
  # @return [void]
432
434
  def inner_tree_at node, position, stack
433
435
  return if node.nil?
434
436
  here = Range.from_node(node)
435
- if here.contain?(position) || colonized(here, position, node)
437
+ if here.contain?(position)
436
438
  stack.unshift node
437
439
  node.children.each do |c|
438
440
  next unless Parser.is_ast_node?(c)
439
- next if !Parser.rubyvm? && c.loc.expression.nil?
441
+ next if c.loc.expression.nil?
440
442
  inner_tree_at(c, position, stack)
441
443
  end
442
444
  end
443
445
  end
444
446
 
445
- def colonized range, position, node
446
- node.type == :COLON2 &&
447
- range.ending.line == position.line &&
448
- range.ending.character == position.character - 2 &&
449
- code[Position.to_offset(code, Position.new(position.line, position.character - 2)), 2] == '::'
450
- end
451
-
452
447
  protected
453
448
 
454
449
  # @return [String]
@@ -464,7 +459,7 @@ module Solargraph
464
459
  @code = val
465
460
  end
466
461
 
467
- # @return [Parser::AST::Node]
462
+ # @return [Parser::AST::Node, nil]
468
463
  attr_writer :node
469
464
 
470
465
  # @return [Array<Range>]
@@ -476,7 +471,7 @@ module Solargraph
476
471
  # @return [Boolean]
477
472
  attr_writer :parsed
478
473
 
479
- # @return [Array<Parser::Source::Comment>]
474
+ # @return [Hash{Integer => String}
480
475
  attr_writer :comments
481
476
 
482
477
  # @return [Boolean]
@@ -516,6 +511,10 @@ module Solargraph
516
511
  # HACK: Pass a dummy code object to the parser for plugins that
517
512
  # expect it not to be nil
518
513
  YARD::Docstring.parser.parse(comments, YARD::CodeObjects::Base.new(:root, 'stub'))
514
+ rescue StandardError => e
515
+ Solargraph.logger.info "YARD failed to parse docstring: [#{e.class}] #{e.message}"
516
+ Solargraph.logger.debug "Unparsed comment: #{comments}"
517
+ YARD::Docstring.parser
519
518
  end
520
519
  end
521
520
  end
@@ -13,7 +13,7 @@ module Solargraph
13
13
  @cursor = cursor
14
14
  end
15
15
 
16
- # @return [Array<Pin::Base>]
16
+ # @return [Array<Pin::Base>] Relevant pins for infering the type of the Cursor's position
17
17
  def define
18
18
  return [] if cursor.comment? || cursor.chain.literal?
19
19
  result = cursor.chain.define(api_map, block, locals)
@@ -55,18 +55,19 @@ module Solargraph
55
55
  return ComplexType.try_parse('Object') if dfn && dfn.path == 'Class#new'
56
56
  end
57
57
  return result unless result.tag == 'self'
58
- ComplexType.try_parse(cursor.chain.base.infer(api_map, block, locals).namespace)
58
+ ComplexType.try_parse(cursor.chain.base.infer(api_map, block, locals).tag)
59
59
  end
60
60
 
61
61
  # Get an array of all the locals that are visible from the cursors's
62
62
  # position. Locals can be local variables, method parameters, or block
63
63
  # parameters. The array starts with the nearest local pin.
64
64
  #
65
- # @return [Array<Solargraph::Pin::Base>]
65
+ # @return [::Array<Solargraph::Pin::Base>]
66
66
  def locals
67
67
  @locals ||= source_map.locals_at(location)
68
68
  end
69
69
 
70
+ # @return [::Array<String>]
70
71
  def gates
71
72
  block.gates
72
73
  end
@@ -99,11 +100,12 @@ module Solargraph
99
100
  @source_map ||= api_map.source_map(cursor.filename)
100
101
  end
101
102
 
103
+ # @return [Location]
102
104
  def location
103
105
  Location.new(source_map.filename, Solargraph::Range.new(cursor.position, cursor.position))
104
106
  end
105
107
 
106
- # @return [Solargraph::Pin::Base]
108
+ # @return [Solargraph::Pin::Closure]
107
109
  def block
108
110
  @block ||= source_map.locate_block_pin(cursor.node_position.line, cursor.node_position.character)
109
111
  end
@@ -115,7 +117,7 @@ module Solargraph
115
117
  @context_pin ||= source_map.locate_named_path_pin(cursor.node_position.line, cursor.node_position.character)
116
118
  end
117
119
 
118
- # @return [Array<Pin::KeywordParam]
120
+ # @return [Array<Pin::KeywordParam>]
119
121
  def complete_keyword_parameters
120
122
  return [] unless cursor.argument? && cursor.chain.links.one? && cursor.word =~ /^[a-z0-9_]*:?$/
121
123
  pins = signify
@@ -139,7 +141,7 @@ module Solargraph
139
141
  result
140
142
  end
141
143
 
142
- # @param result [Array<Pin::Base>]
144
+ # @param result [Enumerable<Pin::Base>]
143
145
  # @return [Completion]
144
146
  def package_completions result
145
147
  frag_start = cursor.start_of_word.to_s.downcase
@@ -150,6 +152,7 @@ module Solargraph
150
152
  Completion.new(filtered, cursor.range)
151
153
  end
152
154
 
155
+ # @return [Completion]
153
156
  def tag_complete
154
157
  result = []
155
158
  match = source_map.code[0..cursor.offset-1].match(/[\[<, ]([a-z0-9_:]*)\z/i)
@@ -168,6 +171,7 @@ module Solargraph
168
171
  package_completions(result)
169
172
  end
170
173
 
174
+ # @return [Completion]
171
175
  def code_complete
172
176
  result = []
173
177
  result.concat complete_keyword_parameters
@@ -209,13 +213,13 @@ module Solargraph
209
213
  result.concat api_map.get_constants(context_pin.context.namespace, *gates)
210
214
  result.concat api_map.get_methods(block.binder.namespace, scope: block.binder.scope, visibility: [:public, :private, :protected])
211
215
  result.concat api_map.get_methods('Kernel')
212
- # result.concat ApiMap.keywords
213
216
  result.concat api_map.keyword_pins.to_a
214
217
  end
215
218
  end
216
219
  package_completions(result)
217
220
  end
218
221
 
222
+ # @return [Array<Pin::Base>]
219
223
  def file_global_methods
220
224
  return [] if cursor.word.empty?
221
225
  source_map.pins.select do |pin|
@@ -64,6 +64,10 @@ module Solargraph
64
64
  pins.select{|pin| pin.is_a?(Pin::Closure) and pin.location.range.contain?(position)}.last
65
65
  end
66
66
 
67
+ # @param source_position [Position]
68
+ # @param comment_position [Position]
69
+ # @param comment [String]
70
+ # @return [void]
67
71
  def process_comment source_position, comment_position, comment
68
72
  return unless comment.encode('UTF-8', invalid: :replace, replace: '?') =~ DIRECTIVE_REGEXP
69
73
  cmnt = remove_inline_comment_hashes(comment)
@@ -79,6 +83,8 @@ module Solargraph
79
83
  end
80
84
 
81
85
  # @param comment [String]
86
+ # @param tag [String]
87
+ # @param start [Integer]
82
88
  # @return [Integer]
83
89
  def find_directive_line_number comment, tag, start
84
90
  # Avoid overruning the index
@@ -204,10 +210,14 @@ module Solargraph
204
210
  end
205
211
  end
206
212
 
213
+ # @param line1 [Integer]
214
+ # @param line2 [Integer]
207
215
  def no_empty_lines?(line1, line2)
208
216
  @code.lines[line1..line2].none? { |line| line.strip.empty? }
209
217
  end
210
218
 
219
+ # @param comment [String]
220
+ # @return [String]
211
221
  def remove_inline_comment_hashes comment
212
222
  ctxt = ''
213
223
  num = nil
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'yard'
4
4
  require 'solargraph/yard_tags'
5
- require 'set'
6
5
 
7
6
  module Solargraph
8
7
  # An index of pins and other ApiMap-related data for a Source.
@@ -18,7 +17,7 @@ module Solargraph
18
17
  # @return [Array<Pin::Base>]
19
18
  attr_reader :pins
20
19
 
21
- # @return [Array<Pin::Base>]
20
+ # @return [Array<Pin::LocalVariable>]
22
21
  attr_reader :locals
23
22
 
24
23
  # @param source [Source]
@@ -35,10 +34,13 @@ module Solargraph
35
34
  @pin_select_cache = {}
36
35
  end
37
36
 
37
+ # @param klass [Class]
38
+ # @return [Array<Pin::Base>]
38
39
  def pins_by_class klass
39
40
  @pin_select_cache[klass] ||= @pin_class_hash.select { |key, _| key <= klass }.values.flatten
40
41
  end
41
42
 
43
+ # @return [Set<String>]
42
44
  def rebindable_method_names
43
45
  @rebindable_method_names ||= pins_by_class(Pin::Method)
44
46
  .select { |pin| pin.comments && pin.comments.include?('@yieldreceiver') }
@@ -99,10 +101,16 @@ module Solargraph
99
101
  (pins + locals).select { |pin| pin.location == location }
100
102
  end
101
103
 
104
+ # @param line [Integer]
105
+ # @param character [Integer]
106
+ # @return [Pin::Method,Pin::Namespace]
102
107
  def locate_named_path_pin line, character
103
108
  _locate_pin line, character, Pin::Namespace, Pin::Method
104
109
  end
105
110
 
111
+ # @param line [Integer]
112
+ # @param character [Integer]
113
+ # @return [Pin::Namespace,Pin::Method,Pin::Block]
106
114
  def locate_block_pin line, character
107
115
  _locate_pin line, character, Pin::Namespace, Pin::Method, Pin::Block
108
116
  end
@@ -166,6 +174,8 @@ module Solargraph
166
174
  @convention_pins || []
167
175
  end
168
176
 
177
+ # @param pins [Array<Pin::Base>]
178
+ # @return [Array<Pin::Base>]
169
179
  def convention_pins=(pins)
170
180
  # unmemoizing the document_symbols in case it was called from any of convnetions
171
181
  @document_symbols = nil
@@ -175,7 +185,7 @@ module Solargraph
175
185
  # @param line [Integer]
176
186
  # @param character [Integer]
177
187
  # @param klasses [Array<Class>]
178
- # @return [Pin::Base]
188
+ # @return [Pin::Base, nil]
179
189
  def _locate_pin line, character, *klasses
180
190
  position = Position.new(line, character)
181
191
  found = nil
@@ -51,8 +51,13 @@ module Solargraph
51
51
  # @return [Boolean]
52
52
  def any_types_match? api_map, expected, inferred
53
53
  return duck_types_match?(api_map, expected, inferred) if expected.duck_type?
54
+ # walk through the union expected type and see if any members
55
+ # of the union match the inferred type
54
56
  expected.each do |exp|
55
57
  next if exp.duck_type?
58
+ # @todo: there should be a level of typechecking where all
59
+ # unique types in the inferred must match one of the
60
+ # expected unique types
56
61
  inferred.each do |inf|
57
62
  # return true if exp == inf || api_map.super_and_sub?(fuzz(inf), fuzz(exp))
58
63
  return true if exp == inf || either_way?(api_map, inf, exp)
@@ -103,9 +108,12 @@ module Solargraph
103
108
  # @param cls2 [ComplexType::UniqueType]
104
109
  # @return [Boolean]
105
110
  def either_way?(api_map, cls1, cls2)
106
- f1 = fuzz(cls1)
107
- f2 = fuzz(cls2)
111
+ # @todo there should be a level of typechecking which uses the
112
+ # full tag with parameters to determine compatibility
113
+ f1 = cls1.name
114
+ f2 = cls2.name
108
115
  api_map.type_include?(f1, f2) || api_map.super_and_sub?(f1, f2) || api_map.super_and_sub?(f2, f1)
116
+ # api_map.type_include?(f1, f2) || api_map.super_and_sub?(f1, f2) || api_map.super_and_sub?(f2, f1)
109
117
  end
110
118
  end
111
119
  end