solargraph 0.52.0 → 0.53.4

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 (157) 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 +53 -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/source_to_yard.rb +17 -10
  10. data/lib/solargraph/api_map/store.rb +45 -9
  11. data/lib/solargraph/api_map.rb +178 -113
  12. data/lib/solargraph/bench.rb +3 -2
  13. data/lib/solargraph/cache.rb +29 -5
  14. data/lib/solargraph/complex_type/type_methods.rb +53 -8
  15. data/lib/solargraph/complex_type/unique_type.rb +171 -58
  16. data/lib/solargraph/complex_type.rb +62 -9
  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 +171 -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 +15 -5
  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 +35 -7
  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 +71 -12
  42. data/lib/solargraph/location.rb +1 -0
  43. data/lib/solargraph/page.rb +6 -0
  44. data/lib/solargraph/parser/comment_ripper.rb +3 -0
  45. data/lib/solargraph/parser/node_methods.rb +47 -8
  46. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  47. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +29 -3
  48. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  49. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +42 -34
  50. data/lib/solargraph/parser/{legacy → parser_gem}/node_methods.rb +201 -29
  51. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  52. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/args_node.rb +4 -1
  53. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  54. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  55. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +2 -2
  56. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  57. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/def_node.rb +7 -20
  58. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  59. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  60. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  62. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  63. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  65. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sclass_node.rb +1 -1
  66. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  67. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/sym_node.rb +1 -1
  68. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  69. data/lib/solargraph/parser/parser_gem.rb +12 -0
  70. data/lib/solargraph/parser/snippet.rb +2 -0
  71. data/lib/solargraph/parser.rb +8 -11
  72. data/lib/solargraph/pin/base.rb +63 -8
  73. data/lib/solargraph/pin/base_variable.rb +7 -3
  74. data/lib/solargraph/pin/block.rb +26 -38
  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/documenting.rb +25 -34
  79. data/lib/solargraph/pin/instance_variable.rb +4 -0
  80. data/lib/solargraph/pin/local_variable.rb +13 -1
  81. data/lib/solargraph/pin/method.rb +110 -16
  82. data/lib/solargraph/pin/namespace.rb +16 -10
  83. data/lib/solargraph/pin/parameter.rb +41 -10
  84. data/lib/solargraph/pin/reference/override.rb +2 -2
  85. data/lib/solargraph/pin/reference.rb +8 -0
  86. data/lib/solargraph/pin/search.rb +3 -3
  87. data/lib/solargraph/pin/signature.rb +114 -2
  88. data/lib/solargraph/pin.rb +0 -1
  89. data/lib/solargraph/range.rb +2 -2
  90. data/lib/solargraph/rbs_map/conversions.rb +213 -61
  91. data/lib/solargraph/rbs_map/core_fills.rb +12 -28
  92. data/lib/solargraph/rbs_map/core_map.rb +2 -12
  93. data/lib/solargraph/rbs_map/stdlib_map.rb +2 -8
  94. data/lib/solargraph/rbs_map.rb +24 -12
  95. data/lib/solargraph/shell.rb +62 -59
  96. data/lib/solargraph/source/chain/array.rb +4 -1
  97. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  98. data/lib/solargraph/source/chain/call.rb +95 -26
  99. data/lib/solargraph/source/chain/constant.rb +15 -1
  100. data/lib/solargraph/source/chain/if.rb +23 -0
  101. data/lib/solargraph/source/chain/link.rb +7 -1
  102. data/lib/solargraph/source/chain/or.rb +1 -1
  103. data/lib/solargraph/source/chain/z_super.rb +2 -2
  104. data/lib/solargraph/source/chain.rb +20 -4
  105. data/lib/solargraph/source/change.rb +3 -0
  106. data/lib/solargraph/source/cursor.rb +2 -0
  107. data/lib/solargraph/source/source_chainer.rb +6 -5
  108. data/lib/solargraph/source.rb +15 -16
  109. data/lib/solargraph/source_map/clip.rb +14 -9
  110. data/lib/solargraph/source_map/mapper.rb +10 -0
  111. data/lib/solargraph/source_map.rb +12 -10
  112. data/lib/solargraph/type_checker/checks.rb +10 -2
  113. data/lib/solargraph/type_checker.rb +96 -21
  114. data/lib/solargraph/version.rb +1 -1
  115. data/lib/solargraph/workspace/config.rb +8 -6
  116. data/lib/solargraph/workspace.rb +15 -2
  117. data/lib/solargraph/yard_map/cache.rb +6 -0
  118. data/lib/solargraph/yard_map/helpers.rb +1 -1
  119. data/lib/solargraph/yard_map/mapper/to_method.rb +16 -3
  120. data/lib/solargraph/yard_map/to_method.rb +11 -4
  121. data/lib/solargraph/yard_map.rb +0 -292
  122. data/lib/solargraph/yardoc.rb +52 -0
  123. data/lib/solargraph.rb +4 -1
  124. data/solargraph.gemspec +2 -2
  125. metadata +35 -58
  126. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  127. data/lib/solargraph/documentor.rb +0 -76
  128. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  129. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  130. data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +0 -18
  131. data/lib/solargraph/parser/legacy/node_processors.rb +0 -55
  132. data/lib/solargraph/parser/legacy.rb +0 -12
  133. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -151
  134. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -163
  135. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -317
  136. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  137. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  138. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -33
  139. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  140. data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +0 -75
  141. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -68
  142. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  143. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  144. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  145. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  146. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  147. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  148. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  149. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  150. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -51
  151. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -32
  152. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  153. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -279
  154. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -64
  155. data/lib/solargraph/parser/rubyvm/node_wrapper.rb +0 -47
  156. data/lib/solargraph/parser/rubyvm.rb +0 -40
  157. data/lib/solargraph/rbs_map/core_signs.rb +0 -33
@@ -22,33 +22,17 @@ module Solargraph
22
22
  closure: Solargraph::Pin::Namespace.new(name: 'Object'), comments: '@return [Class<self>]')
23
23
  ]
24
24
 
25
- YIELDPARAMS = [
26
- Override.from_comment('Object#tap', %(
27
- @return [self]
28
- @yieldparam [self]
29
- )),
30
- Override.from_comment('String#each_line', %(
31
- @yieldparam [String]
32
- ))
33
- ]
34
-
35
- methods_with_yieldparam_subtypes = %w[
36
- Array#each Array#map Array#map! Array#any? Array#all? Array#index
37
- Array#keep_if Array#delete_if
38
- Enumerable#each_entry Enumerable#map Enumerable#any? Enumerable#all?
39
- Enumerable#select Enumerable#reject
40
- Set#each
41
- ]
42
-
43
- YIELDPARAM_SINGLE_PARAMETERS = methods_with_yieldparam_subtypes.map do |path|
44
- Override.from_comment(path, <<~DOC
45
- @yieldparam [generic<Elem>]
46
- DOC
47
- )
48
- end
49
-
50
- CLASS_RETURN_TYPES = [
51
- Override.method_return('Class#allocate', 'self'),
25
+ OVERRIDES = [
26
+ Override.from_comment('BasicObject#instance_eval', '@yieldreceiver [self]'),
27
+ Override.from_comment('BasicObject#instance_exec', '@yieldreceiver [self]'),
28
+ Override.from_comment('Module#define_method', '@yieldreceiver [Object<self>]'),
29
+ Override.from_comment('Module#class_eval', '@yieldreceiver [Class<self>]'),
30
+ Override.from_comment('Module#class_exec', '@yieldreceiver [Class<self>]'),
31
+ Override.from_comment('Module#module_eval', '@yieldreceiver [Module<self>]'),
32
+ Override.from_comment('Module#module_exec', '@yieldreceiver [Module<self>]'),
33
+ # RBS does not define Class with a generic, so all calls to
34
+ # generic() return an 'untyped'. We can do better:
35
+ Override.method_return('Class#allocate', 'self')
52
36
  ]
53
37
 
54
38
  # HACK: Add Errno exception classes
@@ -60,7 +44,7 @@ module Solargraph
60
44
  end
61
45
  ERRNOS = errnos
62
46
 
63
- ALL = KEYWORDS + MISSING + YIELDPARAMS + YIELDPARAM_SINGLE_PARAMETERS + CLASS_RETURN_TYPES + ERRNOS
47
+ ALL = KEYWORDS + MISSING + OVERRIDES + ERRNOS
64
48
  end
65
49
  end
66
50
  end
@@ -13,26 +13,16 @@ module Solargraph
13
13
  pins.replace cache
14
14
  else
15
15
  loader = RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
16
- environment = RBS::Environment.from_loader(loader).resolve_type_names
16
+ RBS::Environment.from_loader(loader).resolve_type_names
17
17
  load_environment_to_pins(loader)
18
18
  pins.concat RbsMap::CoreFills::ALL
19
19
  processed = ApiMap::Store.new(pins).pins.reject { |p| p.is_a?(Solargraph::Pin::Reference::Override) }
20
+ processed.each { |pin| pin.source = :rbs }
20
21
  pins.replace processed
21
22
 
22
23
  Cache.save('core.ser', pins)
23
24
  end
24
25
  end
25
-
26
- def method_def_to_sigs decl, pin
27
- stubs = CoreSigns.sign(pin.path)
28
- return super unless stubs
29
- stubs.map do |stub|
30
- Pin::Signature.new(
31
- [],
32
- ComplexType.try_parse(stub.return_type)
33
- )
34
- end
35
- end
36
26
  end
37
27
  end
38
28
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rbs'
4
- require 'set'
5
4
 
6
5
  module Solargraph
7
6
  class RbsMap
@@ -16,11 +15,10 @@ module Solargraph
16
15
  cache = Cache.load('stdlib', "#{library}.ser")
17
16
  if cache
18
17
  pins.replace cache
18
+ @resolved = true
19
19
  else
20
20
  super
21
- if library == 'yaml'
22
- pins.push Solargraph::Pin::Constant.new(name: 'YAML', comments: '@return [Module<Psych>]', closure: Pin::ROOT_PIN)
23
- end
21
+ return unless resolved?
24
22
  Cache.save('stdlib', "#{library}.ser", pins)
25
23
  end
26
24
  end
@@ -30,10 +28,6 @@ module Solargraph
30
28
  def self.load library
31
29
  @stdlib_maps_hash[library] ||= StdlibMap.new(library)
32
30
  end
33
-
34
- def repository
35
- @repository ||= RBS::Repository.new
36
- end
37
31
  end
38
32
  end
39
33
  end
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rbs'
4
- require 'set'
5
4
 
6
5
  module Solargraph
7
6
  class RbsMap
8
7
  autoload :Conversions, 'solargraph/rbs_map/conversions'
9
8
  autoload :CoreMap, 'solargraph/rbs_map/core_map'
10
9
  autoload :CoreFills, 'solargraph/rbs_map/core_fills'
11
- autoload :CoreSigns, 'solargraph/rbs_map/core_signs'
12
10
  autoload :StdlibMap, 'solargraph/rbs_map/stdlib_map'
13
11
 
14
12
  include Conversions
@@ -19,18 +17,27 @@ module Solargraph
19
17
  attr_reader :library
20
18
 
21
19
  # @param library [String]
22
- def initialize library
20
+ def initialize library, version = nil
23
21
  @library = library
22
+ @version = version
23
+ @collection = nil
24
24
  loader = RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
25
- add_library loader, library
25
+ add_library loader, library, version
26
26
  return unless resolved?
27
27
  load_environment_to_pins(loader)
28
28
  end
29
29
 
30
- def path_pin path
31
- pins.find { |p| p.path == path }
30
+ # @generic T
31
+ # @param path [String]
32
+ # @param klass [Class<generic<T>>]
33
+ # @return [generic<T>, nil]
34
+ def path_pin path, klass = Pin::Base
35
+ pin = pins.find { |p| p.path == path }
36
+ pin if pin&.is_a?(klass)
32
37
  end
33
38
 
39
+ # @param path [String]
40
+ # @return [Array<Pin::Base>]
34
41
  def path_pins path
35
42
  pins.select { |p| p.path == path }
36
43
  end
@@ -39,14 +46,18 @@ module Solargraph
39
46
  @resolved
40
47
  end
41
48
 
49
+ def repository
50
+ @repository ||= RBS::Repository.new(no_stdlib: false)
51
+ end
52
+
42
53
  # @param library [String]
43
54
  # @return [RbsMap]
44
55
  def self.load library
45
56
  @@rbs_maps_hash[library] ||= RbsMap.new(library)
46
57
  end
47
58
 
48
- def repository
49
- @repository ||= RBS::Repository.new(no_stdlib: true)
59
+ def self.from_gemspec(gemspec)
60
+ RbsMap.new(gemspec.name, gemspec.version)
50
61
  end
51
62
 
52
63
  private
@@ -54,17 +65,18 @@ module Solargraph
54
65
  # @param loader [RBS::EnvironmentLoader]
55
66
  # @param library [String]
56
67
  # @return [Boolean] true if adding the library succeeded
57
- def add_library loader, library
58
- @resolved = if loader.has_library?(library: library, version: nil)
59
- loader.add library: library, version: nil
68
+ def add_library loader, library, version
69
+ @resolved = if loader.has_library?(library: library, version: version)
70
+ loader.add library: library, version: version
60
71
  Solargraph.logger.info "#{short_name} successfully loaded library #{library}"
61
72
  true
62
73
  else
63
- Solargraph.logger.info "#{short_name} failed to load library #{library}"
74
+ Solargraph.logger.debug "#{short_name} failed to load library #{library}"
64
75
  false
65
76
  end
66
77
  end
67
78
 
79
+ # @return [String]
68
80
  def short_name
69
81
  self.class.name.split('::').last
70
82
  end
@@ -1,14 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'thor'
4
+ require 'yard'
4
5
 
5
6
  module Solargraph
6
7
  class Shell < Thor
7
8
  include Solargraph::ServerMethods
8
9
 
10
+ # Tell Thor to ensure the process exits with status 1 if any error happens.
11
+ def self.exit_on_failure?
12
+ true
13
+ end
14
+
9
15
  map %w[--version -v] => :version
10
16
 
11
17
  desc "--version, -v", "Print the version"
18
+ # @return [void]
12
19
  def version
13
20
  puts Solargraph::VERSION
14
21
  end
@@ -16,6 +23,7 @@ module Solargraph
16
23
  desc 'socket', 'Run a Solargraph socket server'
17
24
  option :host, type: :string, aliases: :h, desc: 'The server host', default: '127.0.0.1'
18
25
  option :port, type: :numeric, aliases: :p, desc: 'The server port', default: 7658
26
+ # @return [void]
19
27
  def socket
20
28
  require 'backport'
21
29
  port = options[:port]
@@ -33,6 +41,7 @@ module Solargraph
33
41
  end
34
42
 
35
43
  desc 'stdio', 'Run a Solargraph stdio server'
44
+ # @return [void]
36
45
  def stdio
37
46
  require 'backport'
38
47
  Backport.run do
@@ -49,6 +58,8 @@ module Solargraph
49
58
 
50
59
  desc 'config [DIRECTORY]', 'Create or overwrite a default configuration file'
51
60
  option :extensions, type: :boolean, aliases: :e, desc: 'Add installed extensions', default: true
61
+ # @param directory [String]
62
+ # @return [void]
52
63
  def config(directory = '.')
53
64
  matches = []
54
65
  if options[:extensions]
@@ -71,43 +82,11 @@ module Solargraph
71
82
  STDOUT.puts "Configuration file initialized."
72
83
  end
73
84
 
74
- desc 'download-core [VERSION]', 'Download core documentation [deprecated]', hide: true
75
- long_desc %(
76
- The `download-core` command is deprecated. Current versions of Solargraph
77
- use RBS for core and stdlib documentation.
78
- )
79
- # @deprecated
80
- def download_core _version = nil
81
- puts 'The `download-core` command is deprecated.'
82
- puts 'Current versions of Solargraph use RBS for core and stdlib documentation.'
83
- end
84
-
85
- desc 'list-cores', 'List the local documentation versions [deprecated]', hide: true
86
- long_desc %(
87
- The `list-cores` command is deprecated. Current versions of Solargraph use
88
- RBS for core and stdlib documentation.
89
- )
90
- # @deprecated
91
- def list_cores
92
- puts 'The `list-cores` command is deprecated.'
93
- puts 'Current versions of Solargraph use RBS for core and stdlib documentation.'
94
- end
95
-
96
- desc 'available-cores', 'List available documentation versions [deprecated]', hide: true
97
- long_desc %(
98
- The `available-cores` command is deprecated. Current versions of Solargraph
99
- use RBS for core and stdlib documentation.
100
- )
101
- # @deprecated
102
- def available_cores
103
- puts 'The `available-cores` command is deprecated.'
104
- puts 'Current versions of Solargraph use RBS for core and stdlib documentation.'
105
- end
106
-
107
85
  desc 'clear', 'Delete all cached documentation'
108
86
  long_desc %(
109
87
  This command will delete all core and gem documentation from the cache.
110
88
  )
89
+ # @return [void]
111
90
  def clear
112
91
  puts "Deleting the cached documentation"
113
92
  Solargraph::Cache.clear
@@ -115,18 +94,45 @@ module Solargraph
115
94
  map 'clear-cache' => :clear
116
95
  map 'clear-cores' => :clear
117
96
 
97
+ desc 'cache', 'Cache a gem', hide: true
98
+ # @return [void]
99
+ # @param gem [String]
100
+ # @param version [String, nil]
101
+ def cache gem, version = nil
102
+ spec = Gem::Specification.find_by_name(gem, version)
103
+ pins = GemPins.build(spec)
104
+ Cache.save('gems', "#{spec.name}-#{spec.version}.ser", pins)
105
+ end
106
+
118
107
  desc 'uncache GEM [...GEM]', "Delete cached gem documentation"
108
+ # @return [void]
119
109
  def uncache *gems
120
110
  raise ArgumentError, 'No gems specified.' if gems.empty?
121
111
  gems.each do |gem|
122
- Dir[File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{gem}-*")].each do |dir|
123
- puts "Deleting cache: #{dir}"
124
- FileUtils.remove_entry_secure dir
112
+ spec = Gem::Specification.find_by_name(gem)
113
+ Cache.uncache('gems', "#{spec.name}-#{spec.version}.ser")
114
+ Cache.uncache('gems', "#{spec.name}-#{spec.version}.yardoc")
115
+ end
116
+ end
117
+
118
+ desc 'gems [GEM[=VERSION]]', 'Cache documentation for installed gems'
119
+ option :rebuild, type: :boolean, desc: 'Rebuild existing documentation', default: false
120
+ # @return [void]
121
+ def gems *names
122
+ if names.empty?
123
+ Gem::Specification.to_a.each { |spec| do_cache spec }
124
+ else
125
+ names.each do |name|
126
+ spec = Gem::Specification.find_by_name(*name.split('='))
127
+ do_cache spec
128
+ rescue Gem::MissingSpecError
129
+ warn "Gem '#{name}' not found"
125
130
  end
126
131
  end
127
132
  end
128
133
 
129
134
  desc 'reporters', 'Get a list of diagnostics reporters'
135
+ # @return [void]
130
136
  def reporters
131
137
  puts Solargraph::Diagnostics.reporters
132
138
  end
@@ -140,9 +146,10 @@ module Solargraph
140
146
  )
141
147
  option :level, type: :string, aliases: [:mode, :m, :l], desc: 'Type checking level', default: 'normal'
142
148
  option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
149
+ # @return [void]
143
150
  def typecheck *files
144
151
  directory = File.realpath(options[:directory])
145
- api_map = Solargraph::ApiMap.load(directory)
152
+ api_map = Solargraph::ApiMap.load_with_cache(directory)
146
153
  if files.empty?
147
154
  files = api_map.source_maps.map(&:filename)
148
155
  else
@@ -160,6 +167,7 @@ module Solargraph
160
167
  probcount += problems.length
161
168
  end
162
169
  puts "#{probcount} problem#{probcount != 1 ? 's' : ''} found#{files.length != 1 ? " in #{filecount} of #{files.length} files" : ''}."
170
+ # "
163
171
  exit 1 if probcount > 0
164
172
  end
165
173
 
@@ -172,12 +180,13 @@ module Solargraph
172
180
  )
173
181
  option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
174
182
  option :verbose, type: :boolean, aliases: :v, desc: 'Verbose output', default: false
183
+ # @return [void]
175
184
  def scan
176
185
  require 'benchmark'
177
186
  directory = File.realpath(options[:directory])
178
187
  api_map = nil
179
188
  time = Benchmark.measure {
180
- api_map = Solargraph::ApiMap.load(directory)
189
+ api_map = Solargraph::ApiMap.load_with_cache(directory)
181
190
  api_map.pins.each do |pin|
182
191
  begin
183
192
  puts pin_description(pin) if options[:verbose]
@@ -197,32 +206,13 @@ module Solargraph
197
206
  desc 'list', 'List the files in the workspace and the total count'
198
207
  option :count, type: :boolean, aliases: :c, desc: 'Display the file count only', default: false
199
208
  option :directory, type: :string, aliases: :d, desc: 'The directory to read', default: '.'
209
+ # @return [void]
200
210
  def list
201
211
  workspace = Solargraph::Workspace.new(options[:directory])
202
- unless options[:count]
203
- workspace.filenames.each { |f| puts f }
204
- end
212
+ puts workspace.filenames unless options[:count]
205
213
  puts "#{workspace.filenames.length} files total."
206
214
  end
207
215
 
208
- desc 'bundle', 'Generate documentation for bundled gems [deprecated]', hide: true
209
- long_desc %(
210
- The `bundle` command is deprecated. Solargraph currently uses RBS instead.
211
- )
212
- option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
213
- option :rebuild, type: :boolean, aliases: :r, desc: 'Rebuild existing documentation', default: false
214
- def bundle
215
- puts 'The `bundle` command is deprecated. Solargraph currently uses RBS instead.'
216
- end
217
-
218
- desc 'rdoc GEM [VERSION]', 'Use RDoc to cache documentation [deprecated]', hide: true
219
- long_desc %(
220
- The `rdoc` command is deprecated. Solargraph currently uses RBS instead.
221
- )
222
- def rdoc _gem, _version = '>= 0'
223
- puts 'The `rdoc` command is deprecated. Solargraph currently uses RBS instead.'
224
- end
225
-
226
216
  private
227
217
 
228
218
  # @param pin [Solargraph::Pin::Base]
@@ -240,5 +230,18 @@ module Solargraph
240
230
  desc += " (#{pin.location.filename} #{pin.location.range.start.line})" if pin.location
241
231
  desc
242
232
  end
233
+
234
+ # @param gemspec [Gem::Specification]
235
+ # @return [void]
236
+ def do_cache gemspec
237
+ cached = Yardoc.cached?(gemspec)
238
+ if cached && !options.rebuild
239
+ puts "Cache already exists for #{gemspec.name} #{gemspec.version}"
240
+ else
241
+ puts "#{cached ? 'Rebuilding' : 'Caching'} gem documentation for #{gemspec.name} #{gemspec.version}"
242
+ pins = GemPins.build(gemspec)
243
+ Cache.save('gems', "#{gemspec.name}-#{gemspec.version}.ser", pins)
244
+ end
245
+ end
243
246
  end
244
247
  end
@@ -2,7 +2,7 @@ module Solargraph
2
2
  class Source
3
3
  class Chain
4
4
  class Array < Literal
5
- # @param type [String]
5
+ # @param children [::Array<Chain>]
6
6
  def initialize children
7
7
  super('::Array')
8
8
  @children = children
@@ -12,6 +12,9 @@ module Solargraph
12
12
  @word ||= "<#{@type}>"
13
13
  end
14
14
 
15
+ # @param api_map [ApiMap]
16
+ # @param name_pin [Pin::Base]
17
+ # @param locals [Enumerable<Pin::LocalVariable>]
15
18
  def resolve api_map, name_pin, locals
16
19
  child_types = @children.map do |child|
17
20
  child.infer(api_map, name_pin, locals).tag
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class Source
5
+ class Chain
6
+ class BlockSymbol < Link
7
+ def resolve api_map, name_pin, locals
8
+ [Pin::ProxyType.anonymous(ComplexType.try_parse('Proc'))]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end