solargraph 0.38.6 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/SPONSORS.md +9 -0
  3. data/lib/solargraph.rb +1 -0
  4. data/lib/solargraph/api_map.rb +24 -13
  5. data/lib/solargraph/api_map/bundler_methods.rb +3 -0
  6. data/lib/solargraph/api_map/source_to_yard.rb +1 -6
  7. data/lib/solargraph/api_map/store.rb +19 -3
  8. data/lib/solargraph/complex_type/type_methods.rb +4 -4
  9. data/lib/solargraph/convention/base.rb +0 -5
  10. data/lib/solargraph/core_fills.rb +28 -2
  11. data/lib/solargraph/diagnostics/base.rb +1 -0
  12. data/lib/solargraph/diagnostics/type_check.rb +13 -13
  13. data/lib/solargraph/language_server/host.rb +11 -2
  14. data/lib/solargraph/language_server/host/sources.rb +20 -11
  15. data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -11
  16. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  17. data/lib/solargraph/library.rb +3 -3
  18. data/lib/solargraph/parser.rb +26 -0
  19. data/lib/solargraph/parser/comment_ripper.rb +52 -0
  20. data/lib/solargraph/parser/legacy.rb +12 -0
  21. data/lib/solargraph/parser/legacy/class_methods.rb +105 -0
  22. data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
  23. data/lib/solargraph/parser/legacy/node_chainer.rb +115 -0
  24. data/lib/solargraph/parser/legacy/node_methods.rb +289 -0
  25. data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
  26. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
  27. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
  28. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
  29. data/lib/solargraph/parser/legacy/node_processors/block_node.rb +22 -0
  30. data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +25 -0
  31. data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
  32. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
  33. data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
  34. data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
  35. data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
  36. data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
  37. data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
  38. data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
  39. data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
  40. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +21 -0
  41. data/lib/solargraph/parser/legacy/node_processors/send_node.rb +232 -0
  42. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
  43. data/lib/solargraph/parser/node_methods.rb +43 -0
  44. data/lib/solargraph/parser/node_processor.rb +43 -0
  45. data/lib/solargraph/parser/node_processor/base.rb +77 -0
  46. data/lib/solargraph/{source_map → parser}/region.rb +11 -6
  47. data/lib/solargraph/parser/rubyvm.rb +40 -0
  48. data/lib/solargraph/parser/rubyvm/class_methods.rb +146 -0
  49. data/lib/solargraph/parser/rubyvm/node_chainer.rb +133 -0
  50. data/lib/solargraph/parser/rubyvm/node_methods.rb +279 -0
  51. data/lib/solargraph/parser/rubyvm/node_processors.rb +60 -0
  52. data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
  53. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +62 -0
  54. data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
  55. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +22 -0
  56. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +22 -0
  57. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
  58. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +64 -0
  59. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +57 -0
  60. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
  61. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
  62. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +34 -0
  63. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
  64. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
  65. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
  66. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
  67. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
  68. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
  69. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +21 -0
  70. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
  71. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +292 -0
  72. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
  73. data/lib/solargraph/parser/snippet.rb +13 -0
  74. data/lib/solargraph/pin/attribute.rb +8 -0
  75. data/lib/solargraph/pin/base.rb +1 -1
  76. data/lib/solargraph/pin/base_method.rb +26 -4
  77. data/lib/solargraph/pin/base_variable.rb +7 -8
  78. data/lib/solargraph/pin/block.rb +1 -1
  79. data/lib/solargraph/pin/constant.rb +16 -0
  80. data/lib/solargraph/pin/conversions.rb +2 -2
  81. data/lib/solargraph/pin/method.rb +26 -14
  82. data/lib/solargraph/pin/parameter.rb +56 -2
  83. data/lib/solargraph/pin/reference.rb +1 -0
  84. data/lib/solargraph/pin/reference/override.rb +2 -0
  85. data/lib/solargraph/pin/reference/prepend.rb +10 -0
  86. data/lib/solargraph/pin/yard_pin/constant.rb +2 -4
  87. data/lib/solargraph/pin/yard_pin/method.rb +34 -18
  88. data/lib/solargraph/pin/yard_pin/namespace.rb +3 -11
  89. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +3 -12
  90. data/lib/solargraph/range.rb +8 -2
  91. data/lib/solargraph/shell.rb +17 -11
  92. data/lib/solargraph/source.rb +114 -135
  93. data/lib/solargraph/source/chain.rb +11 -3
  94. data/lib/solargraph/source/chain/call.rb +1 -2
  95. data/lib/solargraph/source/chain/constant.rb +44 -8
  96. data/lib/solargraph/source/chain/link.rb +1 -0
  97. data/lib/solargraph/source/cursor.rb +2 -28
  98. data/lib/solargraph/source/source_chainer.rb +12 -6
  99. data/lib/solargraph/source/updater.rb +2 -0
  100. data/lib/solargraph/source_map.rb +0 -2
  101. data/lib/solargraph/source_map/clip.rb +24 -17
  102. data/lib/solargraph/source_map/mapper.rb +34 -29
  103. data/lib/solargraph/type_checker.rb +367 -275
  104. data/lib/solargraph/type_checker/checks.rb +95 -0
  105. data/lib/solargraph/type_checker/param_def.rb +2 -17
  106. data/lib/solargraph/type_checker/rules.rb +53 -0
  107. data/lib/solargraph/version.rb +1 -1
  108. data/lib/solargraph/views/environment.erb +5 -3
  109. data/lib/solargraph/workspace.rb +17 -2
  110. data/lib/solargraph/workspace/config.rb +15 -7
  111. data/lib/solargraph/yard_map.rb +89 -49
  112. data/lib/solargraph/yard_map/core_docs.rb +1 -1
  113. data/solargraph.gemspec +2 -1
  114. metadata +88 -32
  115. data/OVERVIEW.md +0 -37
  116. data/lib/solargraph/source/flawed_builder.rb +0 -15
  117. data/lib/solargraph/source/node_chainer.rb +0 -111
  118. data/lib/solargraph/source/node_methods.rb +0 -240
  119. data/lib/solargraph/source_map/node_processor.rb +0 -85
  120. data/lib/solargraph/source_map/node_processor/alias_node.rb +0 -21
  121. data/lib/solargraph/source_map/node_processor/args_node.rb +0 -24
  122. data/lib/solargraph/source_map/node_processor/base.rb +0 -103
  123. data/lib/solargraph/source_map/node_processor/begin_node.rb +0 -13
  124. data/lib/solargraph/source_map/node_processor/block_node.rb +0 -21
  125. data/lib/solargraph/source_map/node_processor/casgn_node.rb +0 -21
  126. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +0 -21
  127. data/lib/solargraph/source_map/node_processor/def_node.rb +0 -62
  128. data/lib/solargraph/source_map/node_processor/defs_node.rb +0 -33
  129. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +0 -21
  130. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +0 -34
  131. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +0 -24
  132. data/lib/solargraph/source_map/node_processor/namespace_node.rb +0 -35
  133. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +0 -14
  134. data/lib/solargraph/source_map/node_processor/resbody_node.rb +0 -32
  135. data/lib/solargraph/source_map/node_processor/sclass_node.rb +0 -19
  136. data/lib/solargraph/source_map/node_processor/send_node.rb +0 -217
  137. data/lib/solargraph/source_map/node_processor/sym_node.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 061561cbbc7728685d8db8a482d16004254b6abcefde23ad1c8666f1dc8d37fb
4
- data.tar.gz: 5c2a8991b9b2a7264a63337fb2d427b0c62c96843c6014202b2247d6c727558b
3
+ metadata.gz: 71e5d6fa6baec1130d64df74ed6fcf49c6c41df2f1386cb5cd2760a7605a9e48
4
+ data.tar.gz: 91d9d6c695a63a0defab2c31967b2828907c800a94eb220c9210db9b672f2f27
5
5
  SHA512:
6
- metadata.gz: fc5d80cf77ad1c3b505ea3ecfbaaf514d2c49c7b93654b1e1fbd3b692266e045f4578e7bb15f5594842f677709f0a91b568379950648141012c694597b969686
7
- data.tar.gz: '09e24fd600309f0b4f76391d33ba929bc6d153224acef25c384639f1072b5f9cd999102bdcd63b46e4238ee4089423068ff25d5b93af57c64d40d425cf884008'
6
+ metadata.gz: 2b37f7a917d8c865063f14c62e185e919cb88f221219fdc611ef003aa0a17af99bdd762fd4d4fc36105f37c36b0bdd4017500abe17b3aa1506423df8b16ee55a
7
+ data.tar.gz: 60110bec4c847690cecdfa0d73d0495d09340a56ddf650dfbfc737e1f8b62682e1cce3de568edec7e52f4d4ff052e4c4746a2ec907c20320b6b133de610b6f3a
@@ -0,0 +1,9 @@
1
+ # Sponsors
2
+
3
+ Solargraph is developed and maintained by [Castwide Technologies](https://castwide.com).
4
+
5
+ The following people and organizations provide funding or other resources. [Become a sponsor](https://patreon.com/castwide)
6
+
7
+ ## Named Sponsors
8
+
9
+ - Emily Strickland
@@ -38,6 +38,7 @@ module Solargraph
38
38
  autoload :Environ, 'solargraph/environ'
39
39
  autoload :Convention, 'solargraph/convention'
40
40
  autoload :Documentor, 'solargraph/documentor'
41
+ autoload :Parser, 'solargraph/parser'
41
42
 
42
43
  dir = File.dirname(__FILE__)
43
44
  YARDOC_PATH = File.realpath(File.join(dir, '..', 'yardoc'))
@@ -149,7 +149,7 @@ module Solargraph
149
149
  # @return [Source::Cursor]
150
150
  def cursor_at filename, position
151
151
  position = Position.normalize(position)
152
- raise "File not found: #{filename}" unless source_map_hash.has_key?(filename)
152
+ raise FileNotFoundError, "File not found: #{filename}" unless source_map_hash.has_key?(filename)
153
153
  source_map_hash[filename].cursor_at(position)
154
154
  end
155
155
 
@@ -215,7 +215,7 @@ module Solargraph
215
215
  contexts.push '' if contexts.empty?
216
216
  cached = cache.get_constants(namespace, contexts)
217
217
  return cached.clone unless cached.nil?
218
- skip = []
218
+ skip = Set.new
219
219
  result = []
220
220
  contexts.each do |context|
221
221
  fqns = qualify(namespace, context)
@@ -238,9 +238,9 @@ module Solargraph
238
238
  cached = cache.get_qualified_namespace(namespace, context)
239
239
  return cached.clone unless cached.nil?
240
240
  result = if namespace.start_with?('::')
241
- inner_qualify(namespace[2..-1], '', [])
241
+ inner_qualify(namespace[2..-1], '', Set.new)
242
242
  else
243
- inner_qualify(namespace, context, [])
243
+ inner_qualify(namespace, context, Set.new)
244
244
  end
245
245
  cache.set_qualified_namespace(namespace, context, result)
246
246
  result
@@ -295,7 +295,7 @@ module Solargraph
295
295
  cached = cache.get_methods(fqns, scope, visibility, deep)
296
296
  return cached.clone unless cached.nil?
297
297
  result = []
298
- skip = []
298
+ skip = Set.new
299
299
  if fqns == ''
300
300
  # @todo Implement domains
301
301
  implicit.domains.each do |domain|
@@ -308,6 +308,7 @@ module Solargraph
308
308
  result.concat inner_get_methods('Kernel', :instance, visibility, deep, skip)
309
309
  else
310
310
  result.concat inner_get_methods(fqns, scope, visibility, deep, skip)
311
+ result.concat inner_get_methods('Kernel', :instance, [:public], deep, skip) if visibility.include?(:private)
311
312
  end
312
313
  resolved = resolve_method_aliases(result, visibility)
313
314
  cache.set_methods(fqns, scope, visibility, deep, resolved)
@@ -551,15 +552,21 @@ module Solargraph
551
552
  # @param scope [Symbol] :class or :instance
552
553
  # @param visibility [Array<Symbol>] :public, :protected, and/or :private
553
554
  # @param deep [Boolean]
554
- # @param skip [Array<String>]
555
+ # @param skip [Set<String>]
555
556
  # @param no_core [Boolean] Skip core classes if true
556
557
  # @return [Array<Pin::Base>]
557
558
  def inner_get_methods fqns, scope, visibility, deep, skip, no_core = false
558
559
  return [] if no_core && fqns =~ /^(Object|BasicObject|Class|Module|Kernel)$/
559
560
  reqstr = "#{fqns}|#{scope}|#{visibility.sort}|#{deep}"
560
561
  return [] if skip.include?(reqstr)
561
- skip.push reqstr
562
+ skip.add reqstr
562
563
  result = []
564
+ if deep && scope == :instance
565
+ store.get_prepends(fqns).reverse.each do |im|
566
+ fqim = qualify(im, fqns)
567
+ result.concat inner_get_methods(fqim, scope, visibility, deep, skip, true) unless fqim.nil?
568
+ end
569
+ end
563
570
  result.concat store.get_methods(fqns, scope: scope, visibility: visibility).sort{ |a, b| a.name <=> b.name }
564
571
  if deep
565
572
  if scope == :instance
@@ -596,12 +603,16 @@ module Solargraph
596
603
 
597
604
  # @param fqns [String]
598
605
  # @param visibility [Array<Symbol>]
599
- # @param skip [Array<String>]
606
+ # @param skip [Set<String>]
600
607
  # @return [Array<Pin::Base>]
601
608
  def inner_get_constants fqns, visibility, skip
602
609
  return [] if fqns.nil? || skip.include?(fqns)
603
- skip.push fqns
604
- result = store.get_constants(fqns, visibility)
610
+ skip.add fqns
611
+ result = []
612
+ store.get_prepends(fqns).each do |is|
613
+ result.concat inner_get_constants(qualify(is, fqns), [:public], skip)
614
+ end
615
+ result.concat store.get_constants(fqns, visibility)
605
616
  .sort { |a, b| a.name <=> b.name }
606
617
  store.get_includes(fqns).each do |is|
607
618
  result.concat inner_get_constants(qualify(is, fqns), [:public], skip)
@@ -636,12 +647,12 @@ module Solargraph
636
647
 
637
648
  # @param name [String]
638
649
  # @param root [String]
639
- # @param skip [Array<String>]
650
+ # @param skip [Set<String>]
640
651
  # @return [String, nil]
641
652
  def inner_qualify name, root, skip
642
653
  return nil if name.nil?
643
654
  return nil if skip.include?(root)
644
- skip.push root
655
+ skip.add root
645
656
  if name == ''
646
657
  if root == ''
647
658
  return ''
@@ -727,7 +738,7 @@ module Solargraph
727
738
  comments: origin.comments,
728
739
  scope: origin.scope,
729
740
  visibility: origin.visibility,
730
- args: origin.parameters
741
+ parameters: origin.parameters
731
742
  )
732
743
  end
733
744
  end
@@ -6,6 +6,8 @@ module Solargraph
6
6
  module BundlerMethods
7
7
  module_function
8
8
 
9
+ # @param directory [String]
10
+ # @return [Hash]
9
11
  def require_from_bundle directory
10
12
  @require_from_bundle ||= begin
11
13
  Solargraph.logger.info "Loading gems for bundler/require"
@@ -16,6 +18,7 @@ module Solargraph
16
18
  end
17
19
  end
18
20
 
21
+ # @return [void]
19
22
  def reset_require_from_bundle
20
23
  @require_from_bundle = nil
21
24
  end
@@ -60,12 +60,7 @@ module Solargraph
60
60
  code_object_map[pin.path].docstring = pin.docstring
61
61
  code_object_map[pin.path].visibility = pin.visibility || :public
62
62
  code_object_map[pin.path].parameters = pin.parameters.map do |p|
63
- n = p.match(/^[a-z0-9_]*:?/i)[0]
64
- v = nil
65
- if p.length > n.length
66
- v = p[n.length..-1].gsub(/^ = /, '')
67
- end
68
- [n, v]
63
+ [p.name, p.asgn_code]
69
64
  end
70
65
  end
71
66
  end
@@ -19,7 +19,7 @@ module Solargraph
19
19
  # @return [Array<Solargraph::Pin::Base>]
20
20
  def get_constants fqns, visibility = [:public]
21
21
  namespace_children(fqns).select { |pin|
22
- !pin.name.empty? and (pin.is_a?(Pin::Namespace) || pin.is_a?(Pin::Constant)) && visibility.include?(pin.visibility)
22
+ !pin.name.empty? && (pin.is_a?(Pin::Namespace) || pin.is_a?(Pin::Constant)) && visibility.include?(pin.visibility)
23
23
  }
24
24
  end
25
25
 
@@ -34,7 +34,7 @@ module Solargraph
34
34
  end
35
35
 
36
36
  # @param fqns [String]
37
- # @return [String]
37
+ # @return [String, nil]
38
38
  def get_superclass fqns
39
39
  return superclass_references[fqns].first if superclass_references.key?(fqns)
40
40
  return 'Object' if fqns != 'BasicObject' && namespace_exists?(fqns)
@@ -48,6 +48,12 @@ module Solargraph
48
48
  include_references[fqns] || []
49
49
  end
50
50
 
51
+ # @param fqns [String]
52
+ # @return [Array<String>]
53
+ def get_prepends fqns
54
+ prepend_references[fqns] || []
55
+ end
56
+
51
57
  # @param fqns [String]
52
58
  # @return [Array<String>]
53
59
  def get_extends fqns
@@ -172,6 +178,10 @@ module Solargraph
172
178
  @include_references ||= {}
173
179
  end
174
180
 
181
+ def prepend_references
182
+ @prepend_references ||= {}
183
+ end
184
+
175
185
  def extend_references
176
186
  @extend_references ||= {}
177
187
  end
@@ -210,13 +220,16 @@ module Solargraph
210
220
  pins.each do |pin|
211
221
  namespace_map[pin.namespace] ||= []
212
222
  namespace_map[pin.namespace].push pin
213
- namespaces.add pin.path if pin.is_a?(Pin::Namespace) and !pin.path.empty?
223
+ namespaces.add pin.path if pin.is_a?(Pin::Namespace) && !pin.path.empty?
214
224
  namespace_pins.push pin if pin.is_a?(Pin::Namespace)
215
225
  method_pins.push pin if pin.is_a?(Pin::BaseMethod)
216
226
  symbols.push pin if pin.is_a?(Pin::Symbol)
217
227
  if pin.is_a?(Pin::Reference::Include)
218
228
  include_references[pin.namespace] ||= []
219
229
  include_references[pin.namespace].push pin.name
230
+ elsif pin.is_a?(Pin::Reference::Prepend)
231
+ prepend_references[pin.namespace] ||= []
232
+ prepend_references[pin.namespace].push pin.name
220
233
  elsif pin.is_a?(Pin::Reference::Extend)
221
234
  extend_references[pin.namespace] ||= []
222
235
  extend_references[pin.namespace].push pin.name
@@ -245,6 +258,9 @@ module Solargraph
245
258
  pin.docstring.add_tag(tag)
246
259
  end
247
260
  end
261
+ # @todo This is probably not the best place for these overrides
262
+ superclass_references['Integer'] = ['Numeric']
263
+ superclass_references['Float'] = ['Numeric']
248
264
  end
249
265
  end
250
266
  end
@@ -113,13 +113,13 @@ module Solargraph
113
113
  t.qualify api_map, context
114
114
  end
115
115
  if list_parameters?
116
- Solargraph::ComplexType.parse("#{fqns}<#{rtypes.map(&:tag).join(', ')}>").first
116
+ Solargraph::ComplexType.parse("#{fqns}<#{rtypes.map(&:tag).join(', ')}>")
117
117
  elsif fixed_parameters?
118
- Solargraph::ComplexType.parse("#{fqns}(#{rtypes.map(&:tag).join(', ')})").first
118
+ Solargraph::ComplexType.parse("#{fqns}(#{rtypes.map(&:tag).join(', ')})")
119
119
  elsif hash_parameters?
120
- Solargraph::ComplexType.parse("#{fqns}{#{ltypes.map(&:tag).join(', ')} => #{rtypes.map(&:tag).join(', ')}}").first
120
+ Solargraph::ComplexType.parse("#{fqns}{#{ltypes.map(&:tag).join(', ')} => #{rtypes.map(&:tag).join(', ')}}")
121
121
  else
122
- Solargraph::ComplexType.parse(fqns).first
122
+ Solargraph::ComplexType.parse(fqns)
123
123
  end
124
124
  end
125
125
  end
@@ -13,11 +13,6 @@ module Solargraph
13
13
  false
14
14
  end
15
15
 
16
- # @return [Environ]
17
- def process
18
- match? ? EMPTY_ENVIRON : environ
19
- end
20
-
21
16
  # The Environ for this convention.
22
17
  # Subclasses should override this method.
23
18
  #
@@ -65,11 +65,13 @@ module Solargraph
65
65
  @return [self]
66
66
  @return_single_parameter
67
67
  )),
68
+ Override.method_return('Array#uniq', 'self'),
68
69
 
69
70
  Override.from_comment('BasicObject#==', %(
70
71
  @param other [BasicObject]
71
72
  @return [Boolean]
72
73
  )),
74
+ Override.method_return('BasicObject#initialize', 'void'),
73
75
 
74
76
  Override.method_return('Class#new', 'self'),
75
77
  Override.method_return('Class.new', 'Class<Object>'),
@@ -84,6 +86,11 @@ module Solargraph
84
86
  Override.method_return('File.extname', 'String'),
85
87
  Override.method_return('File.join', 'String'),
86
88
 
89
+ Override.from_comment('Float#+', %(
90
+ @param y [Numeric]
91
+ @return [Numeric]
92
+ )),
93
+
87
94
  Override.from_comment('Hash#[]', %(
88
95
  @return_value_parameter
89
96
  )),
@@ -94,9 +101,25 @@ module Solargraph
94
101
  @param_tuple
95
102
  )),
96
103
 
104
+ Override.from_comment('Integer#+', %(
105
+ @param y [Numeric]
106
+ @return [Numeric]
107
+ )),
108
+
109
+ Override.method_return('Kernel#puts', 'nil'),
110
+
111
+ # Override.method_return('Module#attr_reader', 'void'),
112
+ # Override.method_return('Module#attr_writer', 'void'),
113
+ # Override.method_return('Module#attr_accessor', 'void'),
114
+
115
+ Override.from_comment('Numeric#+', %(
116
+ @param y [Numeric]
117
+ @return [Numeric]
118
+ )),
119
+
97
120
  Override.method_return('Object#!', 'Boolean'),
98
121
  Override.method_return('Object#clone', 'self', delete: [:overload]),
99
- Override.method_return('Object#dup', 'self'),
122
+ Override.method_return('Object#dup', 'self', delete: [:overload]),
100
123
  Override.method_return('Object#freeze', 'self', delete: [:overload]),
101
124
  Override.method_return('Object#inspect', 'String'),
102
125
  Override.method_return('Object#taint', 'self'),
@@ -121,7 +144,10 @@ module Solargraph
121
144
 
122
145
  Override.method_return('String#freeze', 'self'),
123
146
  Override.method_return('String#split', 'Array<String>'),
124
- Override.method_return('String#lines', 'Array<String>')
147
+ Override.method_return('String#lines', 'Array<String>'),
148
+ Override.from_comment('String#each_line', %(
149
+ @yieldparam [String]
150
+ ))
125
151
  ].concat(
126
152
  methods_with_yieldparam_subtypes.map do |path|
127
153
  Override.from_comment(path, %(
@@ -5,6 +5,7 @@ module Solargraph
5
5
  # The base class for diagnostics reporters.
6
6
  #
7
7
  class Base
8
+ # @return [Array<String>]
8
9
  attr_reader :args
9
10
 
10
11
  def initialize *args
@@ -8,19 +8,19 @@ module Solargraph
8
8
  class TypeCheck < Base
9
9
  def diagnose source, api_map
10
10
  return [] unless args.include?('always') || api_map.workspaced?(source.filename)
11
- severity = (args.include?('strict') ? Diagnostics::Severities::ERROR : Diagnostics::Severities::WARNING)
12
- checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map)
13
- result = checker.return_type_problems + checker.param_type_problems
14
- result.concat checker.strict_type_problems if args.include?('strict')
15
- result.sort! { |a, b| a.location.range.start.line <=> b.location.range.start.line }
16
- result.map do |problem|
17
- {
18
- range: extract_first_line(problem.location, source),
19
- severity: severity,
20
- source: 'Typecheck',
21
- message: problem.message
22
- }
23
- end
11
+ severity = Diagnostics::Severities::ERROR
12
+ level = (args.reverse.find { |a| ['normal', 'typed', 'strict', 'strong'].include?(a) }) || :normal
13
+ checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map, level: level.to_sym)
14
+ checker.problems
15
+ .sort { |a, b| a.location.range.start.line <=> b.location.range.start.line }
16
+ .map do |problem|
17
+ {
18
+ range: extract_first_line(problem.location, source),
19
+ severity: severity,
20
+ source: 'Typecheck',
21
+ message: problem.message
22
+ }
23
+ end
24
24
  end
25
25
 
26
26
  private
@@ -207,6 +207,15 @@ module Solargraph
207
207
  type: LanguageServer::MessageTypes::ERROR,
208
208
  message: "Error in diagnostics: #{e.message}"
209
209
  }
210
+ rescue FileNotFoundError => e
211
+ # @todo This appears to happen when an external file is open and
212
+ # scheduled for diagnosis, but the file was closed (i.e., the
213
+ # editor moved to a different file) before diagnosis started
214
+ logger.warn "Unable to diagnose #{uri} : #{e.message}"
215
+ send_notification 'textDocument/publishDiagnostics', {
216
+ uri: uri,
217
+ diagnostics: []
218
+ }
210
219
  end
211
220
  else
212
221
  logger.info "Deferring diagnosis of #{uri}"
@@ -245,7 +254,7 @@ module Solargraph
245
254
  #
246
255
  # @return [String] The most recent data or an empty string.
247
256
  def flush
248
- tmp = nil
257
+ tmp = ''
249
258
  @buffer_semaphore.synchronize do
250
259
  tmp = @buffer.clone
251
260
  @buffer.clear
@@ -539,7 +548,7 @@ module Solargraph
539
548
  end
540
549
 
541
550
  # @param query [String]
542
- # @return [String]
551
+ # @return [Array]
543
552
  def document query
544
553
  result = []
545
554
  libraries.each { |lib| result.concat lib.document(query) }
@@ -12,7 +12,9 @@ module Solargraph
12
12
  include UriHelpers
13
13
 
14
14
  def initialize
15
+ @mutex = Mutex.new
15
16
  @stopped = true
17
+ @has_uri = ConditionVariable.new
16
18
  end
17
19
 
18
20
  def stopped?
@@ -24,17 +26,14 @@ module Solargraph
24
26
  return unless @stopped
25
27
  @stopped = false
26
28
  Thread.new do
27
- until stopped?
28
- tick
29
- sleep 0.25 if queue.empty?
30
- end
29
+ tick until stopped?
31
30
  end
32
31
  end
33
32
 
34
33
  # @return [void]
35
34
  def tick
36
- return if queue.empty?
37
- uri = mutex.synchronize { queue.shift }
35
+ uri = mutex.synchronize { next_uri }
36
+
38
37
  return if queue.include?(uri)
39
38
  mutex.synchronize do
40
39
  nxt = open_source_hash[uri].finish_synchronize
@@ -44,6 +43,18 @@ module Solargraph
44
43
  end
45
44
  end
46
45
 
46
+ # @return [void]
47
+ def add_uri(uri)
48
+ queue.push(uri)
49
+ @has_uri.signal
50
+ end
51
+
52
+ # @return [String]
53
+ def next_uri
54
+ @has_uri.wait(mutex) if queue.empty?
55
+ queue.shift
56
+ end
57
+
47
58
  # @return [void]
48
59
  def stop
49
60
  @stopped = true
@@ -87,7 +98,7 @@ module Solargraph
87
98
  src = find(uri)
88
99
  mutex.synchronize do
89
100
  open_source_hash[uri] = src.start_synchronize(updater)
90
- queue.push uri
101
+ add_uri(uri)
91
102
  end
92
103
  changed
93
104
  notify_observers uri
@@ -125,15 +136,13 @@ module Solargraph
125
136
 
126
137
  private
127
138
 
128
- # @return [Array<Source>]
139
+ # @return [Hash]
129
140
  def open_source_hash
130
141
  @open_source_hash ||= {}
131
142
  end
132
143
 
133
144
  # @return [Mutex]
134
- def mutex
135
- @mutex ||= Mutex.new
136
- end
145
+ attr_reader :mutex
137
146
 
138
147
  # An array of source URIs that are waiting to finish synchronizing.
139
148
  #