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
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'yard'
4
4
  require 'solargraph/yard_tags'
5
- require 'rubygems/package'
6
- require 'set'
7
5
 
8
6
  module Solargraph
9
7
  # The YardMap provides access to YARD documentation for the Ruby core, the
@@ -14,297 +12,7 @@ module Solargraph
14
12
 
15
13
  autoload :Cache, 'solargraph/yard_map/cache'
16
14
  autoload :Mapper, 'solargraph/yard_map/mapper'
17
- autoload :RdocToYard, 'solargraph/yard_map/rdoc_to_yard'
18
15
  autoload :Helpers, 'solargraph/yard_map/helpers'
19
16
  autoload :ToMethod, 'solargraph/yard_map/to_method'
20
-
21
- include ApiMap::BundlerMethods
22
-
23
- # @return [Boolean]
24
- attr_writer :with_dependencies
25
-
26
- # @param required [Array<String>, Set<String>]
27
- # @param directory [String]
28
- # @param source_gems [Array<String>, Set<String>]
29
- # @param with_dependencies [Boolean]
30
- def initialize(required: [], directory: '', source_gems: [], with_dependencies: true)
31
- @with_dependencies = with_dependencies
32
- change required.to_set, directory, source_gems.to_set
33
- end
34
-
35
- # @return [Array<Solargraph::Pin::Base>]
36
- def pins
37
- @pins ||= []
38
- end
39
-
40
- def with_dependencies?
41
- @with_dependencies ||= true unless @with_dependencies == false
42
- @with_dependencies
43
- end
44
-
45
- # @param new_requires [Set<String>] Required paths to use for loading gems
46
- # @param new_directory [String] The workspace directory
47
- # @param new_source_gems [Set<String>] Gems under local development (i.e., part of the workspace)
48
- # @return [Boolean]
49
- def change new_requires, new_directory, new_source_gems
50
- return false if new_requires == base_required && new_directory == @directory && new_source_gems == @source_gems
51
- @gem_paths = {}
52
- base_required.replace new_requires
53
- required.replace new_requires
54
- # HACK: Hardcoded YAML handling
55
- required.add 'psych' if new_requires.include?('yaml')
56
- @source_gems = new_source_gems
57
- @directory = new_directory
58
- process_requires
59
- @rebindable_method_names = nil
60
- @pin_class_hash = nil
61
- @pin_select_cache = {}
62
- pins.each { |p| p.source = :yard }
63
- true
64
- end
65
-
66
- # @return [Set<String>]
67
- def rebindable_method_names
68
- @rebindable_method_names ||= pins_by_class(Pin::Method)
69
- .select { |pin| pin.comments && pin.comments.include?('@yieldreceiver') }
70
- .map(&:name)
71
- .concat(['instance_eval', 'instance_exec', 'class_eval', 'class_exec', 'module_eval', 'module_exec', 'define_method'])
72
- .to_set
73
- end
74
-
75
- # @return [Array<String>]
76
- def yardocs
77
- @yardocs ||= []
78
- end
79
-
80
- # @return [Set<String>]
81
- def required
82
- @required ||= Set.new
83
- end
84
-
85
- # @return [Array<String>]
86
- def unresolved_requires
87
- @unresolved_requires ||= []
88
- end
89
-
90
- # @return [Array<String>]
91
- def missing_docs
92
- @missing_docs ||= []
93
- end
94
-
95
- # @param y [String]
96
- # @return [YARD::Registry]
97
- def load_yardoc y
98
- if y.is_a?(Array)
99
- YARD::Registry.load y, true
100
- else
101
- YARD::Registry.load! y
102
- end
103
- rescue StandardError => e
104
- Solargraph::Logging.logger.warn "Error loading yardoc '#{y}' #{e.class} #{e.message}"
105
- yardocs.delete y
106
- nil
107
- end
108
-
109
- # @param path [String]
110
- # @return [Pin::Base]
111
- def path_pin path
112
- pins.select { |p| p.path == path }.first
113
- end
114
-
115
- # Get the location of a file referenced by a require path.
116
- #
117
- # @param path [String]
118
- # @return [Location]
119
- def require_reference path
120
- # @type [Gem::Specification]
121
- spec = spec_for_require(path)
122
- spec.full_require_paths.each do |rp|
123
- file = File.join(rp, path)
124
- file = [file, file + ".rb"].find { |file| File.file?(file) }
125
- next unless file
126
- return Solargraph::Location.new(file, Solargraph::Range.from_to(0, 0, 0, 0))
127
- end
128
- nil
129
- rescue Gem::LoadError
130
- nil
131
- end
132
-
133
- def base_required
134
- @base_required ||= Set.new
135
- end
136
-
137
- def directory
138
- @directory ||= ''
139
- end
140
-
141
- private
142
-
143
- # @return [YardMap::Cache]
144
- def cache
145
- @cache ||= YardMap::Cache.new
146
- end
147
-
148
- # @return [Hash{Class<Pin::Base> => Array<Pin::Base>}]
149
- def pin_class_hash
150
- @pin_class_hash ||= pins.to_set.classify(&:class).transform_values(&:to_a)
151
- end
152
-
153
- # @return [Array<Pin::Base>]
154
- def pins_by_class klass
155
- @pin_select_cache[klass] ||= pin_class_hash.select { |key, _| key <= klass }.values.flatten
156
- end
157
-
158
- # @param ns [YARD::CodeObjects::NamespaceObject]
159
- # @return [Array<YARD::CodeObjects::Base>]
160
- def recurse_namespace_object ns
161
- result = []
162
- ns.children.each do |c|
163
- result.push c
164
- result.concat recurse_namespace_object(c) if c.respond_to?(:children)
165
- end
166
- result
167
- end
168
-
169
- # @return [void]
170
- def process_requires
171
- @gemset = process_gemsets
172
- required.merge @gemset.keys if required.include?('bundler/require')
173
- pins.clear
174
- unresolved_requires.clear
175
- missing_docs.clear
176
- environ = Convention.for_global(self)
177
- done = []
178
- already_errored = []
179
- (required + environ.requires).each do |r|
180
- next if r.nil? || r.empty? || done.include?(r)
181
- done.push r
182
- cached = cache.get_path_pins(r)
183
- unless cached.nil?
184
- pins.concat cached
185
- next
186
- end
187
- result = pins_for_require r, already_errored
188
- result.delete_if(&:nil?)
189
- unless result.empty?
190
- cache.set_path_pins r, result
191
- pins.concat result
192
- end
193
- end
194
- if required.include?('yaml') && required.include?('psych')
195
- # HACK: Hardcoded YAML handling
196
- # @todo Why can't this be handled with an override or a virtual pin?
197
- pin = path_pin('YAML')
198
- pin.instance_variable_set(:@return_type, ComplexType.parse('Module<Psych>')) unless pin.nil?
199
- end
200
- pins.concat environ.pins
201
- end
202
-
203
- def process_error(req, result, already_errored, yd = 1)
204
- base = req.split('/').first
205
- return if already_errored.include?(base)
206
- already_errored.push base
207
- if yd.nil?
208
- missing_docs.push req
209
- else
210
- unresolved_requires.push req
211
- end
212
- end
213
-
214
- def process_gemsets
215
- return {} if directory.empty? || !File.file?(File.join(directory, 'Gemfile'))
216
- require_from_bundle(directory)
217
- end
218
-
219
- # @param r [String]
220
- def pins_for_require r, already_errored
221
- result = []
222
- begin
223
- name = r.split('/').first.to_s
224
- return [] if name.empty?
225
-
226
- spec = spec_for_require(r)
227
- return [] if @source_gems.include?(spec.name) || @gem_paths.key?(spec.name)
228
- @gem_paths[spec.name] = spec.full_gem_path
229
-
230
- yd = yardoc_file_for_spec(spec)
231
- # YARD detects gems for certain libraries that do not have a yardoc
232
- # but exist in the stdlib. `fileutils` is an example. Treat those
233
- # cases as errors and check the stdlib yardoc.
234
- if yd.nil?
235
- process_error(r, result, already_errored, nil)
236
- return []
237
- end
238
- unless yardocs.include?(yd)
239
- yardocs.unshift yd
240
- result.concat process_yardoc yd, spec
241
- if with_dependencies?
242
- (spec.dependencies - spec.development_dependencies).each do |dep|
243
- result.concat pins_for_require dep.name, already_errored
244
- end
245
- end
246
- end
247
- rescue Gem::LoadError, NoYardocError
248
- process_error(r, result, already_errored)
249
- end
250
- return result
251
- end
252
-
253
- # @param y [String, nil]
254
- # @param spec [Gem::Specification, nil]
255
- # @return [Array<Pin::Base>]
256
- def process_yardoc y, spec = nil
257
- return [] if y.nil?
258
- if spec
259
- cache = Solargraph::Cache.load('gems', "#{spec.name}-#{spec.version}.ser")
260
- return cache if cache
261
- end
262
- size = Dir.glob(File.join(y, '**', '*'))
263
- .map{ |f| File.size(f) }
264
- .inject(:+)
265
- if !size.nil? && size > 20_000_000
266
- Solargraph::Logging.logger.warn "Yardoc at #{y} is too large to process (#{size} bytes)"
267
- return []
268
- end
269
- Solargraph.logger.info "Loading #{spec.name} #{spec.version} from #{y}"
270
- load_yardoc y
271
- result = Mapper.new(YARD::Registry.all, spec).map
272
- raise NoYardocError, "Yardoc at #{y} is empty" if result.empty?
273
- if spec
274
- Solargraph::Cache.save 'gems', "#{spec.name}-#{spec.version}.ser", result
275
- end
276
- result
277
- end
278
-
279
- # @param spec [Gem::Specification]
280
- # @return [String]
281
- def yardoc_file_for_spec spec
282
- YARD::Registry.yardoc_file_for_gem(spec.name, "= #{spec.version}")
283
- end
284
-
285
- # @param path [String]
286
- # @return [Gem::Specification]
287
- def spec_for_require path
288
- relatives = path.split('/')
289
- spec = nil
290
- while spec.nil? && !relatives.empty?
291
- name = relatives.join('-')
292
- spec = Gem::Specification.find_by_name(name, @gemset[name])
293
- relatives.pop
294
- end
295
- raise Gem::LoadError if spec.nil?
296
-
297
- # Avoid loading the spec again if it's going to be skipped anyway
298
- return spec if @source_gems.include?(spec.name)
299
- # Avoid loading the spec again if it's already the correct version
300
- if @gemset[spec.name] && spec.version != @gemset[spec.name]
301
- begin
302
- return Gem::Specification.find_by_name(spec.name, "= #{@gemset[spec.name]}")
303
- rescue Gem::LoadError
304
- Solargraph.logger.warn "Unable to load #{spec.name} #{@gemset[spec.name]} specified by workspace, using #{spec.version} instead"
305
- end
306
- end
307
- spec
308
- end
309
17
  end
310
18
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ # Methods for caching and loading YARD documentation for gems.
5
+ #
6
+ module Yardoc
7
+ module_function
8
+
9
+ # Build and cache a gem's yardoc and return the path. If the cache already
10
+ # exists, do nothing and return the path.
11
+ #
12
+ # @param gemspec [Gem::Specification]
13
+ # @return [String] The path to the cached yardoc.
14
+ def cache(gemspec)
15
+ path = path_for(gemspec)
16
+ return path if cached?(gemspec)
17
+
18
+ Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
19
+ Dir.chdir gemspec.gem_dir do
20
+ `yardoc --db #{path} --no-output --plugin solargraph`
21
+ end
22
+ path
23
+ end
24
+
25
+ # True if the gem yardoc is cached.
26
+ #
27
+ # @param gemspec [Gem::Specification]
28
+ def cached?(gemspec)
29
+ yardoc = File.join(path_for(gemspec), 'complete')
30
+ File.exist?(yardoc)
31
+ end
32
+
33
+ # Get the absolute path for a cached gem yardoc.
34
+ #
35
+ # @param gemspec [Gem::Specification]
36
+ # @return [String]
37
+ def path_for(gemspec)
38
+ File.join(Solargraph::Cache.work_dir, 'gems', "#{gemspec.name}-#{gemspec.version}.yardoc")
39
+ end
40
+
41
+ # Load a gem's yardoc and return its code objects.
42
+ #
43
+ # @note This method modifies the global YARD registry.
44
+ #
45
+ # @param gemspec [Gem::Specification]
46
+ # @return [Array<YARD::CodeObjects::Base>]
47
+ def load!(gemspec)
48
+ YARD::Registry.load! path_for(gemspec)
49
+ YARD::Registry.all
50
+ end
51
+ end
52
+ end
data/lib/solargraph.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Encoding.default_external = 'UTF-8'
4
4
 
5
+ require 'set'
5
6
  require 'yard-solargraph'
6
7
  require 'solargraph/yard_tags'
7
8
  require 'solargraph/version'
@@ -26,8 +27,10 @@ module Solargraph
26
27
  autoload :Source, 'solargraph/source'
27
28
  autoload :SourceMap, 'solargraph/source_map'
28
29
  autoload :ApiMap, 'solargraph/api_map'
30
+ autoload :Yardoc, 'solargraph/yardoc'
29
31
  autoload :YardMap, 'solargraph/yard_map'
30
32
  autoload :Pin, 'solargraph/pin'
33
+ autoload :DocMap, 'solargraph/doc_map'
31
34
  autoload :ServerMethods, 'solargraph/server_methods'
32
35
  autoload :LanguageServer, 'solargraph/language_server'
33
36
  autoload :Workspace, 'solargraph/workspace'
@@ -40,9 +43,9 @@ module Solargraph
40
43
  autoload :TypeChecker, 'solargraph/type_checker'
41
44
  autoload :Environ, 'solargraph/environ'
42
45
  autoload :Convention, 'solargraph/convention'
43
- autoload :Documentor, 'solargraph/documentor'
44
46
  autoload :Parser, 'solargraph/parser'
45
47
  autoload :RbsMap, 'solargraph/rbs_map'
48
+ autoload :GemPins, 'solargraph/gem_pins'
46
49
  autoload :Cache, 'solargraph/cache'
47
50
 
48
51
  dir = File.dirname(__FILE__)
data/solargraph.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.metadata["changelog_uri"] = "https://github.com/castwide/solargraph/blob/master/CHANGELOG.md"
22
22
  s.metadata["source_code_uri"] = "https://github.com/castwide/solargraph"
23
23
 
24
- s.required_ruby_version = '>= 2.6'
24
+ s.required_ruby_version = '>= 3.0'
25
25
 
26
26
  s.add_runtime_dependency 'backport', '~> 1.2'
27
27
  s.add_runtime_dependency 'benchmark'
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_runtime_dependency 'observer', '~> 0.1'
35
35
  s.add_runtime_dependency 'ostruct', '~> 0.6'
36
36
  s.add_runtime_dependency 'parser', '~> 3.0'
37
- s.add_runtime_dependency 'rbs', '~> 3.0'
37
+ s.add_runtime_dependency 'rbs', '~> 3.3'
38
38
  s.add_runtime_dependency 'reverse_markdown', '>= 2.0', '< 4'
39
39
  s.add_runtime_dependency 'rubocop', '~> 1.38'
40
40
  s.add_runtime_dependency 'thor', '~> 1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solargraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.52.0
4
+ version: 0.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-28 00:00:00.000000000 Z
11
+ date: 2025-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '3.0'
173
+ version: '3.3'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '3.0'
180
+ version: '3.3'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: reverse_markdown
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -380,7 +380,9 @@ extensions: []
380
380
  extra_rdoc_files: []
381
381
  files:
382
382
  - ".github/FUNDING.yml"
383
+ - ".github/workflows/plugins.yml"
383
384
  - ".github/workflows/rspec.yml"
385
+ - ".github/workflows/typecheck.yml"
384
386
  - ".gitignore"
385
387
  - ".rspec"
386
388
  - ".yardopts"
@@ -394,7 +396,6 @@ files:
394
396
  - lib/.rubocop.yml
395
397
  - lib/solargraph.rb
396
398
  - lib/solargraph/api_map.rb
397
- - lib/solargraph/api_map/bundler_methods.rb
398
399
  - lib/solargraph/api_map/cache.rb
399
400
  - lib/solargraph/api_map/source_to_yard.rb
400
401
  - lib/solargraph/api_map/store.rb
@@ -420,8 +421,9 @@ files:
420
421
  - lib/solargraph/diagnostics/severities.rb
421
422
  - lib/solargraph/diagnostics/type_check.rb
422
423
  - lib/solargraph/diagnostics/update_errors.rb
423
- - lib/solargraph/documentor.rb
424
+ - lib/solargraph/doc_map.rb
424
425
  - lib/solargraph/environ.rb
426
+ - lib/solargraph/gem_pins.rb
425
427
  - lib/solargraph/language_server.rb
426
428
  - lib/solargraph/language_server/completion_item_kinds.rb
427
429
  - lib/solargraph/language_server/error_codes.rb
@@ -489,60 +491,33 @@ files:
489
491
  - lib/solargraph/page.rb
490
492
  - lib/solargraph/parser.rb
491
493
  - lib/solargraph/parser/comment_ripper.rb
492
- - lib/solargraph/parser/legacy.rb
493
- - lib/solargraph/parser/legacy/class_methods.rb
494
- - lib/solargraph/parser/legacy/flawed_builder.rb
495
- - lib/solargraph/parser/legacy/node_chainer.rb
496
- - lib/solargraph/parser/legacy/node_methods.rb
497
- - lib/solargraph/parser/legacy/node_processors.rb
498
- - lib/solargraph/parser/legacy/node_processors/alias_node.rb
499
- - lib/solargraph/parser/legacy/node_processors/args_node.rb
500
- - lib/solargraph/parser/legacy/node_processors/begin_node.rb
501
- - lib/solargraph/parser/legacy/node_processors/block_node.rb
502
- - lib/solargraph/parser/legacy/node_processors/casgn_node.rb
503
- - lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb
504
- - lib/solargraph/parser/legacy/node_processors/def_node.rb
505
- - lib/solargraph/parser/legacy/node_processors/defs_node.rb
506
- - lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb
507
- - lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb
508
- - lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb
509
- - lib/solargraph/parser/legacy/node_processors/namespace_node.rb
510
- - lib/solargraph/parser/legacy/node_processors/orasgn_node.rb
511
- - lib/solargraph/parser/legacy/node_processors/resbody_node.rb
512
- - lib/solargraph/parser/legacy/node_processors/sclass_node.rb
513
- - lib/solargraph/parser/legacy/node_processors/send_node.rb
514
- - lib/solargraph/parser/legacy/node_processors/sym_node.rb
515
494
  - lib/solargraph/parser/node_methods.rb
516
495
  - lib/solargraph/parser/node_processor.rb
517
496
  - lib/solargraph/parser/node_processor/base.rb
497
+ - lib/solargraph/parser/parser_gem.rb
498
+ - lib/solargraph/parser/parser_gem/class_methods.rb
499
+ - lib/solargraph/parser/parser_gem/flawed_builder.rb
500
+ - lib/solargraph/parser/parser_gem/node_chainer.rb
501
+ - lib/solargraph/parser/parser_gem/node_methods.rb
502
+ - lib/solargraph/parser/parser_gem/node_processors.rb
503
+ - lib/solargraph/parser/parser_gem/node_processors/alias_node.rb
504
+ - lib/solargraph/parser/parser_gem/node_processors/args_node.rb
505
+ - lib/solargraph/parser/parser_gem/node_processors/begin_node.rb
506
+ - lib/solargraph/parser/parser_gem/node_processors/block_node.rb
507
+ - lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb
508
+ - lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb
509
+ - lib/solargraph/parser/parser_gem/node_processors/def_node.rb
510
+ - lib/solargraph/parser/parser_gem/node_processors/defs_node.rb
511
+ - lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb
512
+ - lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb
513
+ - lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb
514
+ - lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb
515
+ - lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb
516
+ - lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb
517
+ - lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb
518
+ - lib/solargraph/parser/parser_gem/node_processors/send_node.rb
519
+ - lib/solargraph/parser/parser_gem/node_processors/sym_node.rb
518
520
  - lib/solargraph/parser/region.rb
519
- - lib/solargraph/parser/rubyvm.rb
520
- - lib/solargraph/parser/rubyvm/class_methods.rb
521
- - lib/solargraph/parser/rubyvm/node_chainer.rb
522
- - lib/solargraph/parser/rubyvm/node_methods.rb
523
- - lib/solargraph/parser/rubyvm/node_processors.rb
524
- - lib/solargraph/parser/rubyvm/node_processors/alias_node.rb
525
- - lib/solargraph/parser/rubyvm/node_processors/args_node.rb
526
- - lib/solargraph/parser/rubyvm/node_processors/begin_node.rb
527
- - lib/solargraph/parser/rubyvm/node_processors/block_node.rb
528
- - lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb
529
- - lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb
530
- - lib/solargraph/parser/rubyvm/node_processors/def_node.rb
531
- - lib/solargraph/parser/rubyvm/node_processors/defs_node.rb
532
- - lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb
533
- - lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb
534
- - lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb
535
- - lib/solargraph/parser/rubyvm/node_processors/lit_node.rb
536
- - lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb
537
- - lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb
538
- - lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb
539
- - lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb
540
- - lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb
541
- - lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb
542
- - lib/solargraph/parser/rubyvm/node_processors/scope_node.rb
543
- - lib/solargraph/parser/rubyvm/node_processors/send_node.rb
544
- - lib/solargraph/parser/rubyvm/node_processors/sym_node.rb
545
- - lib/solargraph/parser/rubyvm/node_wrapper.rb
546
521
  - lib/solargraph/parser/snippet.rb
547
522
  - lib/solargraph/pin.rb
548
523
  - lib/solargraph/pin/base.rb
@@ -590,6 +565,7 @@ files:
590
565
  - lib/solargraph/source.rb
591
566
  - lib/solargraph/source/chain.rb
592
567
  - lib/solargraph/source/chain/array.rb
568
+ - lib/solargraph/source/chain/block_symbol.rb
593
569
  - lib/solargraph/source/chain/block_variable.rb
594
570
  - lib/solargraph/source/chain/call.rb
595
571
  - lib/solargraph/source/chain/class_variable.rb
@@ -597,6 +573,7 @@ files:
597
573
  - lib/solargraph/source/chain/global_variable.rb
598
574
  - lib/solargraph/source/chain/hash.rb
599
575
  - lib/solargraph/source/chain/head.rb
576
+ - lib/solargraph/source/chain/if.rb
600
577
  - lib/solargraph/source/chain/instance_variable.rb
601
578
  - lib/solargraph/source/chain/link.rb
602
579
  - lib/solargraph/source/chain/literal.rb
@@ -637,6 +614,7 @@ files:
637
614
  - lib/solargraph/yard_map/mapper/to_namespace.rb
638
615
  - lib/solargraph/yard_map/to_method.rb
639
616
  - lib/solargraph/yard_tags.rb
617
+ - lib/solargraph/yardoc.rb
640
618
  - solargraph.gemspec
641
619
  homepage: https://solargraph.org
642
620
  licenses:
@@ -654,7 +632,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
654
632
  requirements:
655
633
  - - ">="
656
634
  - !ruby/object:Gem::Version
657
- version: '2.6'
635
+ version: '3.0'
658
636
  required_rubygems_version: !ruby/object:Gem::Requirement
659
637
  requirements:
660
638
  - - ">="
@@ -1,22 +0,0 @@
1
- require 'bundler'
2
- require 'shellwords'
3
-
4
- module Solargraph
5
- class ApiMap
6
- module BundlerMethods
7
- module_function
8
-
9
- # @param directory [String]
10
- # @return [Hash]
11
- def require_from_bundle directory
12
- begin
13
- Solargraph.logger.info "Loading gems for bundler/require"
14
- Documentor.specs_from_bundle(directory)
15
- rescue BundleNotFoundError => e
16
- Solargraph.logger.warn e.message
17
- {}
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler'
4
- require 'json'
5
- require 'open3'
6
- require 'shellwords'
7
- require 'yard'
8
- require 'fileutils'
9
-
10
- module Solargraph
11
- class Documentor
12
- RDOC_GEMS = %w[
13
- actioncable actionmailbox actionmailer actionpack actiontext actionview
14
- activejob activemodel activerecord activestorage activesupport railties
15
- ]
16
-
17
- def initialize directory, rebuild: false, out: File.new(File::NULL, 'w')
18
- @directory = directory
19
- @rebuild = rebuild
20
- @out = out
21
- end
22
-
23
- # @return [Boolean] True if all specs were found and documented.
24
- def document
25
- failures = 0
26
- Documentor.specs_from_bundle(@directory).each_pair do |name, version|
27
- yd = YARD::Registry.yardoc_file_for_gem(name, "= #{version}")
28
- if !yd || @rebuild
29
- FileUtils.safe_unlink File.join(YardMap::CoreDocs.cache_dir, 'gems', "#{name}-#{version}.ser")
30
- @out.puts "Documenting #{name} #{version}"
31
- `yard gems #{name} #{version} #{@rebuild ? '--rebuild' : ''}`
32
- yd = YARD::Registry.yardoc_file_for_gem(name, "= #{version}")
33
- # HACK: Ignore errors documenting bundler
34
- if !yd && name != 'bundler'
35
- @out.puts "#{name} #{version} YARD documentation failed"
36
- failures += 1
37
- end
38
- end
39
- if yd && RDOC_GEMS.include?(name)
40
- cache = File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{name}-#{version}", 'yardoc')
41
- if !File.exist?(cache) || @rebuild
42
- @out.puts "Caching custom documentation for #{name} #{version}"
43
- spec = Gem::Specification.find_by_name(name, "= #{version}")
44
- Solargraph::YardMap::RdocToYard.run(spec)
45
- end
46
- end
47
- end
48
- if failures > 0
49
- @out.puts "#{failures} gem#{failures == 1 ? '' : 's'} could not be documented. You might need to run `bundle install`."
50
- end
51
- failures == 0
52
- rescue Solargraph::BundleNotFoundError => e
53
- @out.puts "[#{e.class}] #{e.message}"
54
- @out.puts "No bundled gems are available in #{@directory}"
55
- false
56
- end
57
-
58
- # @param directory [String]
59
- # @return [Hash{String => BasicObject}]
60
- def self.specs_from_bundle directory
61
- Solargraph.with_clean_env do
62
- cmd = [
63
- 'ruby', '-e',
64
- "require 'bundler'; require 'json'; Dir.chdir('#{directory}') { puts Bundler.definition.specs_for([:default]).map { |spec| [spec.name, spec.version] }.to_h.to_json }"
65
- ]
66
- o, e, s = Open3.capture3(*cmd)
67
- if s.success?
68
- o && !o.empty? ? JSON.parse(o.split("\n").last) : {}
69
- else
70
- Solargraph.logger.warn e
71
- raise BundleNotFoundError, "Failed to load gems from bundle at #{directory}"
72
- end
73
- end
74
- end
75
- end
76
- end