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
@@ -1,16 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
3
  require 'pathname'
5
4
  require 'observer'
6
5
  require 'open3'
7
6
 
8
- # @!parse
9
- # class ::Gem::Specification
10
- # # @return [String]
11
- # def name; end
12
- # end
13
-
14
7
  module Solargraph
15
8
  # A Library handles coordination between a Workspace and an ApiMap.
16
9
  #
@@ -40,7 +33,6 @@ module Solargraph
40
33
  # @type [Source, nil]
41
34
  @current = nil
42
35
  @sync_count = 0
43
- @cache_progress = nil
44
36
  end
45
37
 
46
38
  def inspect
@@ -65,12 +57,11 @@ module Solargraph
65
57
  # @param source [Source, nil]
66
58
  # @return [void]
67
59
  def attach source
68
- # @sg-ignore Need to add nil check here
69
- if @current && (!source || @current.filename != source.filename) && source_map_hash.key?(@current.filename) && !workspace.has_file?(@current.filename)
70
- # @sg-ignore Need to add nil check here
71
- source_map_hash.delete @current.filename
72
- # @sg-ignore Need to add nil check here
73
- source_map_external_require_hash.delete @current.filename
60
+ # @type [String, nil]
61
+ current_filename = @current&.filename
62
+ if @current && (!source || current_filename != source.filename) && current_filename && source_map_hash.key?(current_filename) && !workspace.has_file?(current_filename)
63
+ source_map_hash.delete current_filename
64
+ source_map_external_require_hash.delete current_filename
74
65
  @external_requires = nil
75
66
  end
76
67
  changed = source && @current != source
@@ -127,8 +118,8 @@ module Solargraph
127
118
  # @return [Boolean] True if at least one file was added to the workspace.
128
119
  def create_from_disk *filenames
129
120
  sources = filenames
130
- .reject { |filename| File.directory?(filename) || !File.exist?(filename) }
131
- .map { |filename| Solargraph::Source.load_string(File.read(filename), filename) }
121
+ .reject { |filename| File.directory?(filename) || !File.exist?(filename) }
122
+ .map { |filename| Solargraph::Source.load_string(File.read(filename), filename) }
132
123
  result = workspace.merge(*sources)
133
124
  sources.each { |source| maybe_map source }
134
125
  result
@@ -193,14 +184,12 @@ module Solargraph
193
184
  if cursor.comment?
194
185
  source = read(filename)
195
186
  offset = Solargraph::Position.to_offset(source.code, Solargraph::Position.new(line, column))
196
- # @sg-ignore Need to add nil check here
197
187
  # @type [MatchData, nil]
198
- lft = source.code[0..offset-1].match(/\[[a-z0-9_:<, ]*?([a-z0-9_:]*)\z/i)
199
- # @sg-ignore Need to add nil check here
188
+ lft = source.code[0..(offset - 1)]&.match(/\[[a-z0-9_:<, ]*?([a-z0-9_:]*)\z/i)
200
189
  # @type [MatchData, nil]
201
- rgt = source.code[offset..-1].match(/^([a-z0-9_]*)(:[a-z0-9_:]*)?[\]>, ]/i)
190
+ rgt = source.code[offset..]&.match(/^([a-z0-9_]*)(:[a-z0-9_:]*)?[\]>, ]/i)
202
191
  if lft && rgt
203
- # @sg-ignore Need to add nil check here
192
+ # @sg-ignore lft and rgt are checked for nil above
204
193
  tag = (lft[1] + rgt[1]).sub(/:+$/, '')
205
194
  clip = mutex.synchronize { api_map.clip(cursor) }
206
195
  clip.translate tag
@@ -262,28 +251,25 @@ module Solargraph
262
251
  clip = mutex.synchronize { api_map.clip(cursor) }
263
252
  pin = clip.define.first
264
253
  return [] unless pin
254
+
265
255
  result = []
266
256
  files = if only
267
- [api_map.source_map(filename)]
268
- else
269
- (workspace.sources + (@current ? [@current] : []))
270
- end
257
+ [api_map.source_map(filename)]
258
+ else
259
+ (workspace.sources + (@current ? [@current] : []))
260
+ end
271
261
  files.uniq(&:filename).each do |source|
272
262
  found = source.references(pin.name)
273
263
  found.select! do |loc|
274
- # @sg-ignore Need to add nil check here
275
- # @type [Solargraph::Pin::Base, nil]
276
- referenced = definitions_at(loc.filename, loc.range.ending.line, loc.range.ending.character).first
264
+ referenced = definitions_at(loc.filename, loc.range.ending.line, loc.range.ending.character)&.first
277
265
  referenced&.path == pin.path
278
266
  end
279
267
  if pin.path == 'Class#new'
280
- # @todo flow sensitive typing should allow shadowing of Kernel#caller
281
268
  caller = cursor.chain.base.infer(api_map, clip.send(:closure), clip.locals).first
282
269
  if caller.defined?
283
270
  found.select! do |loc|
284
271
  clip = api_map.clip_at(loc.filename, loc.range.start)
285
272
  other = clip.send(:cursor).chain.base.infer(api_map, clip.send(:closure), clip.locals).first
286
- # @todo flow sensitive typing should allow shadowing of Kernel#caller
287
273
  caller == other
288
274
  end
289
275
  else
@@ -291,15 +277,15 @@ module Solargraph
291
277
  end
292
278
  end
293
279
  # HACK: for language clients that exclude special characters from the start of variable names
294
- if strip && match = cursor.word.match(/^[^a-z0-9_]+/i)
280
+ if strip && (match = cursor.word.match(/^[^a-z0-9_]+/i))
295
281
  found.map! do |loc|
296
- Solargraph::Location.new(loc.filename,
297
- # @sg-ignore flow sensitive typing needs to handle if foo = bar
298
- Solargraph::Range.from_to(loc.range.start.line, loc.range.start.column + match[0].length, loc.range.ending.line,
299
- loc.range.ending.column))
282
+ # @sg-ignore Unresolved call to []
283
+ Solargraph::Location.new(loc.filename, Solargraph::Range.from_to(loc.range.start.line, loc.range.start.column + match[0].length, loc.range.ending.line, loc.range.ending.column))
300
284
  end
301
285
  end
302
- result.concat(found.sort { |a, b| a.range.start.line <=> b.range.start.line })
286
+ result.concat(found.sort do |a, b|
287
+ a.range.start.line <=> b.range.start.line
288
+ end)
303
289
  end
304
290
  result.uniq
305
291
  end
@@ -320,17 +306,18 @@ module Solargraph
320
306
  def locate_ref location
321
307
  map = source_map_hash[location.filename]
322
308
  return if map.nil?
323
- # @sg-ignore Need to add nil check here
324
- pin = map.requires.select { |p| p.location.range.contain?(location.range.start) }.first
309
+ pin = map.requires.select { |p| p.location&.range&.contain?(location.range.start) }.first
325
310
  return nil if pin.nil?
326
311
  # @param full [String]
327
312
  return_if_match = proc do |full|
328
- return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0)) if source_map_hash.key?(full)
313
+ if source_map_hash.key?(full)
314
+ return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0))
315
+ end
329
316
  end
330
317
  workspace.require_paths.each do |path|
331
318
  full = File.join path, pin.name
332
- return_if_match.(full)
333
- return_if_match.(full << ".rb")
319
+ return_if_match.call(full)
320
+ return_if_match.call(full << '.rb')
334
321
  end
335
322
  nil
336
323
  rescue FileNotFoundError
@@ -423,17 +410,17 @@ module Solargraph
423
410
  workspace.config.reporters.each do |line|
424
411
  if line == 'all!'
425
412
  Diagnostics.reporters.each do |reporter_name|
426
- # @sg-ignore Need to add nil check here
427
- repargs[Diagnostics.reporter(reporter_name)] ||= []
413
+ r = Diagnostics.reporter(reporter_name)
414
+ repargs[r] ||= [] if r
428
415
  end
429
416
  else
430
417
  args = line.split(':').map(&:strip)
431
418
  name = args.shift
432
419
  reporter = Diagnostics.reporter(name)
433
420
  raise DiagnosticsError, "Diagnostics reporter #{name} does not exist" if reporter.nil?
434
- # @sg-ignore flow sensitive typing needs to handle 'raise if'
421
+ # @sg-ignore Hash errors
435
422
  repargs[reporter] ||= []
436
- # @sg-ignore flow sensitive typing needs to handle 'raise if'
423
+ # @sg-ignore Hash errors
437
424
  repargs[reporter].concat args
438
425
  end
439
426
  end
@@ -456,7 +443,7 @@ module Solargraph
456
443
  source_maps: source_map_hash.values,
457
444
  workspace: workspace,
458
445
  external_requires: external_requires,
459
- # @sg-ignore Need to add nil check here
446
+ # @sg-ignore OK if @current.filename is nil
460
447
  live_map: @current ? source_map_hash[@current.filename] : nil
461
448
  )
462
449
  end
@@ -493,13 +480,12 @@ module Solargraph
493
480
  # @return [SourceMap, Boolean]
494
481
  def next_map
495
482
  return false if mapped?
496
- # @sg-ignore Need to add nil check here
497
483
  src = workspace.sources.find { |s| !source_map_hash.key?(s.filename) }
498
484
  if src
499
485
  Logging.logger.debug "Mapping #{src.filename}"
500
- # @sg-ignore Need to add nil check here
486
+ # @sg-ignore OK if src.filename is nil
501
487
  source_map_hash[src.filename] = Solargraph::SourceMap.map(src)
502
- # @sg-ignore Need to add nil check here
488
+ # @sg-ignore OK if src.filename is nil
503
489
  source_map_hash[src.filename]
504
490
  else
505
491
  false
@@ -509,9 +495,9 @@ module Solargraph
509
495
  # @return [self]
510
496
  def map!
511
497
  workspace.sources.each do |src|
512
- # @sg-ignore Need to add nil check here
498
+ # @sg-ignore OK if src.filename is nil
513
499
  source_map_hash[src.filename] = Solargraph::SourceMap.map(src)
514
- # @sg-ignore Need to add nil check here
500
+ # @sg-ignore OK if src.filename is nil
515
501
  find_external_requires source_map_hash[src.filename]
516
502
  end
517
503
  self
@@ -529,11 +515,6 @@ module Solargraph
529
515
 
530
516
  private
531
517
 
532
- # @return [PinCache]
533
- def pin_cache
534
- workspace.pin_cache
535
- end
536
-
537
518
  # @return [Hash{String => Array<String>}]
538
519
  def source_map_external_require_hash
539
520
  @source_map_external_require_hash ||= {}
@@ -543,15 +524,14 @@ module Solargraph
543
524
  # @return [void]
544
525
  def find_external_requires source_map
545
526
  # @type [Set<String>]
546
- new_set = source_map.requires.map(&:name).to_set
547
- # return if new_set == source_map_external_require_hash[source_map.filename]
527
+ new_set = source_map.requires.to_set(&:name)
548
528
  _filenames = nil
549
- filenames = ->{ _filenames ||= workspace.filenames.to_set }
550
- # @sg-ignore Need to add nil check here
529
+ filenames = -> { _filenames ||= workspace.filenames.to_set }
530
+ # @sg-ignore OK if source_map.filename is nil
551
531
  source_map_external_require_hash[source_map.filename] = new_set.reject do |path|
552
532
  workspace.require_paths.any? do |base|
553
533
  full = File.join(base, path)
554
- filenames[].include?(full) or filenames[].include?(full << ".rb")
534
+ filenames[].include?(full) or filenames[].include?(full << '.rb')
555
535
  end
556
536
  end
557
537
  @external_requires = nil
@@ -585,27 +565,23 @@ module Solargraph
585
565
  # @param error [FileNotFoundError]
586
566
  # @return [nil]
587
567
  def handle_file_not_found filename, error
588
- if workspace.source(filename)
589
- Solargraph.logger.debug "#{filename} is not cataloged in the ApiMap"
590
- nil
591
- else
592
- raise error
593
- end
568
+ raise error unless workspace.source(filename)
569
+ Solargraph.logger.debug "#{filename} is not cataloged in the ApiMap"
570
+ nil
594
571
  end
595
572
 
596
573
  # @param source [Source, nil]
597
574
  # @return [void]
598
575
  def maybe_map source
599
576
  return unless source
600
- # @sg-ignore Need to add nil check here
577
+ # @sg-ignore Wrong argument type for Solargraph::Workspace#has_file?: filename expected String, received String, nil
601
578
  return unless @current == source || workspace.has_file?(source.filename)
602
- # @sg-ignore Need to add nil check here
603
579
  if source_map_hash.key?(source.filename)
604
580
  new_map = Solargraph::SourceMap.map(source)
605
- # @sg-ignore Need to add nil check here
581
+ # @sg-ignore OK if source.filename is nil
606
582
  source_map_hash[source.filename] = new_map
607
583
  else
608
- # @sg-ignore Need to add nil check here
584
+ # @sg-ignore OK if source.filename is nil
609
585
  source_map_hash[source.filename] = Solargraph::SourceMap.map(source)
610
586
  end
611
587
  end
@@ -624,7 +600,7 @@ module Solargraph
624
600
 
625
601
  pending = api_map.uncached_gemspecs.length - cache_errors.length - 1
626
602
 
627
- if pin_cache.yardoc_processing?(spec)
603
+ if Yardoc.processing?(spec)
628
604
  logger.info "Enqueuing cache of #{spec.name} #{spec.version} (already being processed)"
629
605
  queued_gemspec_cache.push(spec)
630
606
  return if pending - queued_gemspec_cache.length < 1
@@ -635,10 +611,7 @@ module Solargraph
635
611
  logger.info "Caching #{spec.name} #{spec.version}"
636
612
  Thread.new do
637
613
  report_cache_progress spec.name, pending
638
- kwargs = {}
639
- kwargs[:chdir] = workspace.directory.to_s if workspace.directory && !workspace.directory.empty?
640
- _o, e, s = Open3.capture3(workspace.command_path, 'cache', spec.name, spec.version.to_s,
641
- **kwargs)
614
+ _o, e, s = Open3.capture3(workspace.command_path, 'cache', spec.name, spec.version.to_s)
642
615
  if s.success?
643
616
  logger.info "Cached #{spec.name} #{spec.version}"
644
617
  else
@@ -655,7 +628,8 @@ module Solargraph
655
628
 
656
629
  # @return [Array<Gem::Specification>]
657
630
  def cacheable_specs
658
- cacheable = api_map.uncached_gemspecs +
631
+ cacheable = api_map.uncached_yard_gemspecs +
632
+ api_map.uncached_rbs_collection_gemspecs -
659
633
  queued_gemspec_cache -
660
634
  cache_errors.to_a
661
635
  return cacheable unless cacheable.empty?
@@ -673,32 +647,30 @@ module Solargraph
673
647
  # @return [void]
674
648
  def report_cache_progress gem_name, pending
675
649
  @total ||= pending
676
- # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
650
+ # @sg-ignore Wrong argument type for Integer#>: arg_0 expected Numeric, received Integer, nil
677
651
  @total = pending if pending > @total
678
- # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
652
+ # @sg-ignore Unresolved call to - on Integer, nil
679
653
  finished = @total - pending
680
- # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
654
+ # @sg-ignore @total should always be an Integer
681
655
  pct = if @total.zero?
682
- 0
683
- else
684
- # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
685
- ((finished.to_f / @total.to_f) * 100).to_i
686
- end
687
- message = "#{gem_name}#{pending > 0 ? " (+#{pending})" : ''}"
656
+ 0
657
+ else
658
+ # @sg-ignore Unresolved call to to_f
659
+ ((finished.to_f / @total) * 100).to_i
660
+ end
661
+ message = "#{gem_name}#{" (+#{pending})" if pending.positive?}"
688
662
  # "
689
- if @cache_progress
690
- @cache_progress.report(message, pct)
691
- else
663
+ unless @cache_progress
692
664
  @cache_progress = LanguageServer::Progress.new('Caching gem')
693
665
  # If we don't send both a begin and a report, the progress notification
694
666
  # might get stuck in the status bar forever
695
- # @sg-ignore flow sensitive typing should be able to handle redefinition
667
+ # @sg-ignore Unresolved call to begin
696
668
  @cache_progress.begin(message, pct)
697
669
  changed
698
670
  notify_observers @cache_progress
699
- # @sg-ignore flow sensitive typing should be able to handle redefinition
700
- @cache_progress.report(message, pct)
701
671
  end
672
+ # @sg-ignore Unresolved call to report
673
+ @cache_progress.report(message, pct)
702
674
  changed
703
675
  notify_observers @cache_progress
704
676
  end
@@ -713,14 +685,15 @@ module Solargraph
713
685
 
714
686
  # @return [void]
715
687
  def sync_catalog
716
- return if @sync_count == 0
688
+ return if @sync_count.zero?
717
689
 
718
690
  mutex.synchronize do
719
691
  logger.info "Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}"
720
- source_map_hash.values.each { |map| find_external_requires(map) }
692
+ source_map_hash.each_value { |map| find_external_requires(map) }
721
693
  api_map.catalog bench
722
694
  logger.info "Catalog complete (#{api_map.source_maps.length} files, #{api_map.pins.length} pins)"
723
- logger.info "#{api_map.uncached_gemspecs.length} uncached gemspecs"
695
+ logger.info "#{api_map.uncached_yard_gemspecs.length} uncached YARD gemspecs"
696
+ logger.info "#{api_map.uncached_rbs_collection_gemspecs.length} uncached RBS collection gemspecs"
724
697
  cache_next_gemspec
725
698
  @sync_count = 0
726
699
  end
@@ -17,18 +17,14 @@ module Solargraph
17
17
  # @param filename [String, nil]
18
18
  # @param range [Solargraph::Range]
19
19
  def initialize filename, range
20
- raise "Use nil to represent no-file" if filename&.empty?
20
+ raise 'Use nil to represent no-file' if filename&.empty?
21
21
 
22
22
  @filename = filename
23
23
  @range = range
24
24
  end
25
25
 
26
- protected def equality_fields
27
- [filename, range]
28
- end
29
-
30
26
  # @param other [self]
31
- def <=>(other)
27
+ def <=> other
32
28
  return nil unless other.is_a?(Location)
33
29
  if filename == other.filename
34
30
  range <=> other.range
@@ -46,10 +42,6 @@ module Solargraph
46
42
  range.contain?(location.range.start) && range.contain?(location.range.ending) && filename == location.filename
47
43
  end
48
44
 
49
- def inspect
50
- "<#{self.class.name}: filename=#{filename}, range=#{range.inspect}>"
51
- end
52
-
53
45
  def to_s
54
46
  inspect
55
47
  end
@@ -64,14 +56,14 @@ module Solargraph
64
56
 
65
57
  # @param node [Parser::AST::Node, nil]
66
58
  # @return [Location, nil]
67
- def self.from_node(node)
59
+ def self.from_node node
68
60
  return nil if node.nil? || node.loc.nil?
69
61
  filename = node.loc.expression.source_buffer.name
70
62
  # @sg-ignore flow sensitive typing needs to create separate ranges for postfix if
71
63
  filename = nil if filename.empty?
72
64
  range = Range.from_node(node)
73
65
  # @sg-ignore Need to add nil check here
74
- self.new(filename, range)
66
+ new(filename, range)
75
67
  end
76
68
 
77
69
  # @param other [BasicObject]
@@ -83,5 +75,11 @@ module Solargraph
83
75
  def inspect
84
76
  "#<#{self.class} #{filename}, #{range.inspect}>"
85
77
  end
78
+
79
+ protected
80
+
81
+ def equality_fields
82
+ [filename, range]
83
+ end
86
84
  end
87
85
  end
@@ -10,7 +10,7 @@ module Solargraph
10
10
  'warn' => Logger::WARN,
11
11
  'info' => Logger::INFO,
12
12
  'debug' => Logger::DEBUG
13
- }
13
+ }.freeze
14
14
  configured_level = ENV.fetch('SOLARGRAPH_LOG', nil)
15
15
  level = if LOG_LEVELS.keys.include?(configured_level)
16
16
  LOG_LEVELS.fetch(configured_level)
@@ -21,9 +21,9 @@ module Solargraph
21
21
  end
22
22
  DEFAULT_LOG_LEVEL
23
23
  end
24
- @@logger = Logger.new(STDERR, level: level)
24
+ @@logger = Logger.new($stderr, level: level)
25
25
  # @sg-ignore Fix cvar issue
26
- @@logger.formatter = proc do |severity, datetime, progname, msg|
26
+ @@logger.formatter = proc do |severity, _datetime, _progname, msg|
27
27
  "[#{severity}] #{msg}\n"
28
28
  end
29
29
 
@@ -45,10 +45,8 @@ module Solargraph
45
45
  @@logger
46
46
  else
47
47
  new_log_level = LOG_LEVELS[log_level.to_s]
48
- logger = Logger.new(STDERR, level: new_log_level)
48
+ logger = Logger.new($stderr, level: new_log_level)
49
49
 
50
- # @sg-ignore Wrong argument type for Logger#formatter=: arg_0
51
- # expected nil, received Logger::_Formatter, nil
52
50
  logger.formatter = @@logger.formatter
53
51
  logger
54
52
  end
@@ -1,92 +1,92 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ostruct'
4
- require 'tilt'
5
- require 'yard'
6
- require 'cgi'
7
-
8
- module Solargraph
9
- class Page
10
- # @todo This method directive is necessary because OpenStruct.new confuses
11
- # the typechecker.
12
- # @!method self.new(locals, render_method)
13
- # @param locals[Hash]
14
- # @param render_method [Proc]
15
- # @return [Binder]
16
- class Binder < OpenStruct
17
- # @param locals [Hash]
18
- # @param render_method [Proc]
19
- def initialize locals, render_method
20
- super(locals)
21
- define_singleton_method :render do |template, layout: false, locals: {}|
22
- render_method.call(template, layout: layout, locals: locals)
23
- end
24
- define_singleton_method :erb do |template, layout: false, locals: {}|
25
- render_method.call(template, layout: layout, locals: locals)
26
- end
27
- end
28
-
29
- # @param text [String]
30
- # @return [String]
31
- def htmlify text
32
- # @type [String]
33
- YARD::Templates::Helpers::Markup::RDocMarkup.new(text).to_html
34
- end
35
-
36
- # @param text [String]
37
- # @return [String]
38
- def escape text
39
- CGI.escapeHTML(text)
40
- end
41
-
42
- # @param code [String]
43
- # @return [String]
44
- def ruby_to_html code
45
- code
46
- end
47
- end
48
- private_constant :Binder
49
-
50
- # @param directory [String]
51
- def initialize directory = VIEWS_PATH
52
- directory = VIEWS_PATH if directory.nil? or !File.directory?(directory)
53
- directories = [directory]
54
- directories.push VIEWS_PATH if directory != VIEWS_PATH
55
- # @type [Proc]
56
- # @param template [String]
57
- # @param layout [Boolean]
58
- # @param locals [Hash]
59
- @render_method = proc { |template, layout: false, locals: {}|
60
- binder = Binder.new(locals, @render_method)
61
- if layout
62
- Tilt::ERBTemplate.new(Page.select_template(directories, 'layout')).render(binder) do
63
- Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
64
- end
65
- else
66
- Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
67
- end
68
- }
69
- end
70
-
71
- # @param template [String]
72
- # @param layout [Boolean]
73
- # @param locals [Hash]
74
- # @sg-ignore
75
- # @return [String]
76
- def render template, layout: true, locals: {}
77
- # @type [String]
78
- @render_method.call(template, layout: layout, locals: locals)
79
- end
80
-
81
- # @param directories [Array<String>]
82
- # @param name [String]
83
- # @return [String]
84
- def self.select_template directories, name
85
- directories.each do |dir|
86
- path = File.join(dir, "#{name}.erb")
87
- return path if File.file?(path)
88
- end
89
- raise FileNotFoundError, "Template not found: #{name}"
90
- end
91
- end
92
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+ require 'tilt'
5
+ require 'yard'
6
+ require 'cgi'
7
+
8
+ module Solargraph
9
+ class Page
10
+ # @todo This method directive is necessary because OpenStruct.new confuses
11
+ # the typechecker.
12
+ # @!method self.new(locals, render_method)
13
+ # @param locals[Hash]
14
+ # @param render_method [Proc]
15
+ # @return [Binder]
16
+ class Binder < OpenStruct
17
+ # @param locals [Hash]
18
+ # @param render_method [Proc]
19
+ def initialize locals, render_method
20
+ super(locals)
21
+ define_singleton_method :render do |template, layout: false, locals: {}|
22
+ render_method.call(template, layout: layout, locals: locals)
23
+ end
24
+ define_singleton_method :erb do |template, layout: false, locals: {}|
25
+ render_method.call(template, layout: layout, locals: locals)
26
+ end
27
+ end
28
+
29
+ # @param text [String]
30
+ # @return [String]
31
+ def htmlify text
32
+ # @type [String]
33
+ YARD::Templates::Helpers::Markup::RDocMarkup.new(text).to_html
34
+ end
35
+
36
+ # @param text [String]
37
+ # @return [String]
38
+ def escape text
39
+ CGI.escapeHTML(text)
40
+ end
41
+
42
+ # @param code [String]
43
+ # @return [String]
44
+ def ruby_to_html code
45
+ code
46
+ end
47
+ end
48
+ private_constant :Binder
49
+
50
+ # @param directory [String]
51
+ def initialize directory = VIEWS_PATH
52
+ directory = VIEWS_PATH if directory.nil? || !File.directory?(directory)
53
+ directories = [directory]
54
+ directories.push VIEWS_PATH if directory != VIEWS_PATH
55
+ # @type [Proc]
56
+ # @param template [String]
57
+ # @param layout [Boolean]
58
+ # @param locals [Hash]
59
+ @render_method = proc { |template, layout: false, locals: {}|
60
+ binder = Binder.new(locals, @render_method)
61
+ if layout
62
+ Tilt::ERBTemplate.new(Page.select_template(directories, 'layout')).render(binder) do
63
+ Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
64
+ end
65
+ else
66
+ Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
67
+ end
68
+ }
69
+ end
70
+
71
+ # @param template [String]
72
+ # @param layout [Boolean]
73
+ # @param locals [Hash]
74
+ # @sg-ignore
75
+ # @return [String]
76
+ def render template, layout: true, locals: {}
77
+ # @type [String]
78
+ @render_method.call(template, layout: layout, locals: locals)
79
+ end
80
+
81
+ # @param directories [Array<String>]
82
+ # @param name [String]
83
+ # @return [String]
84
+ def self.select_template directories, name
85
+ directories.each do |dir|
86
+ path = File.join(dir, "#{name}.erb")
87
+ return path if File.file?(path)
88
+ end
89
+ raise FileNotFoundError, "Template not found: #{name}"
90
+ end
91
+ end
92
+ end