solargraph 0.54.1 → 0.54.5

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/lib/solargraph/api_map/cache.rb +10 -1
  4. data/lib/solargraph/api_map/index.rb +167 -0
  5. data/lib/solargraph/api_map/store.rb +68 -121
  6. data/lib/solargraph/api_map.rb +79 -28
  7. data/lib/solargraph/bench.rb +17 -1
  8. data/lib/solargraph/complex_type/type_methods.rb +7 -0
  9. data/lib/solargraph/complex_type/unique_type.rb +21 -1
  10. data/lib/solargraph/complex_type.rb +13 -12
  11. data/lib/solargraph/convention.rb +1 -0
  12. data/lib/solargraph/doc_map.rb +1 -0
  13. data/lib/solargraph/equality.rb +33 -0
  14. data/lib/solargraph/language_server/host/message_worker.rb +23 -6
  15. data/lib/solargraph/language_server/host.rb +12 -11
  16. data/lib/solargraph/language_server/message/base.rb +19 -12
  17. data/lib/solargraph/language_server/message/initialize.rb +3 -1
  18. data/lib/solargraph/language_server/message/text_document/completion.rb +0 -3
  19. data/lib/solargraph/language_server/message/text_document/formatting.rb +4 -0
  20. data/lib/solargraph/library.rb +7 -8
  21. data/lib/solargraph/location.rb +7 -0
  22. data/lib/solargraph/parser/node_methods.rb +1 -1
  23. data/lib/solargraph/parser/node_processor.rb +1 -0
  24. data/lib/solargraph/parser/parser_gem/class_methods.rb +2 -6
  25. data/lib/solargraph/parser/parser_gem/node_chainer.rb +7 -13
  26. data/lib/solargraph/parser/parser_gem/node_methods.rb +2 -2
  27. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -2
  28. data/lib/solargraph/pin/base.rb +28 -18
  29. data/lib/solargraph/pin/base_variable.rb +3 -2
  30. data/lib/solargraph/pin/block.rb +1 -3
  31. data/lib/solargraph/pin/callable.rb +3 -3
  32. data/lib/solargraph/pin/method.rb +6 -0
  33. data/lib/solargraph/pin/namespace.rb +1 -1
  34. data/lib/solargraph/pin/parameter.rb +2 -1
  35. data/lib/solargraph/position.rb +7 -0
  36. data/lib/solargraph/range.rb +7 -0
  37. data/lib/solargraph/rbs_map/conversions.rb +8 -2
  38. data/lib/solargraph/rbs_map.rb +1 -0
  39. data/lib/solargraph/shell.rb +2 -0
  40. data/lib/solargraph/source/chain/array.rb +1 -1
  41. data/lib/solargraph/source/chain/call.rb +15 -8
  42. data/lib/solargraph/source/chain/hash.rb +5 -0
  43. data/lib/solargraph/source/chain/if.rb +5 -0
  44. data/lib/solargraph/source/chain/link.rb +17 -5
  45. data/lib/solargraph/source/chain/literal.rb +5 -0
  46. data/lib/solargraph/source/chain.rb +33 -19
  47. data/lib/solargraph/source/cursor.rb +1 -11
  48. data/lib/solargraph/source.rb +2 -1
  49. data/lib/solargraph/source_map/clip.rb +1 -1
  50. data/lib/solargraph/type_checker.rb +8 -8
  51. data/lib/solargraph/version.rb +1 -1
  52. data/lib/solargraph/workspace/config.rb +7 -3
  53. data/lib/solargraph/workspace.rb +1 -1
  54. data/lib/solargraph/yard_map/mapper/to_constant.rb +1 -0
  55. data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -0
  56. data/lib/solargraph/yard_map/mapper.rb +1 -0
  57. data/lib/solargraph/yardoc.rb +1 -1
  58. data/lib/solargraph.rb +1 -0
  59. data/solargraph.gemspec +5 -5
  60. metadata +27 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6619265fc1ba2cab9154e70c5f4a6626999b685d58e26a805ec606d6804f17b
4
- data.tar.gz: cfac32a13734ba9b392d27fcb8da7c76b180f0bf64189d17698b2246ce6e3773
3
+ metadata.gz: 155e6f0e4fc44166c0d4b3c1ba6691ff1d1629d229adf8d37f6d3fe4b5fc0c77
4
+ data.tar.gz: c33c4dab114c6a70b3c0dfbee6a5ccdc379cf284af3d34dae8a30473dbcdc517
5
5
  SHA512:
6
- metadata.gz: 8d1d40bf5d19b37f6a2ee8cce73e36027140ae402d27326c15e39a961217153e8b269722503ca0a8a3b592bee50cb6227fffcd812f62a1ec8a1bf94219270eea
7
- data.tar.gz: 627df7fb0bd23b641f0b1a40434a6384def8f32bf318b4f92d243266ee0c3145059adc29ea487dcdc30c914045e5737bca92bff6bd67fd06527f97c2e4690fb8
6
+ metadata.gz: 267350435fa9592fc49dc2c5b05f9f9157b576025ea4ed9abe3ebc58e4344d7412805ace58920585105fbb81eaa2bad246416c5456ce66656f22c8639054002d
7
+ data.tar.gz: 7a3860337657dc869e7a96f8b95509867ece49db13e89523e09c1567490b427ed41f5fc57c87e5d8477bfe3857cbe97512bd811598adbb53f4a2f617e724c44c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## 0.54.5 - May 17, 2025
2
+ - Repair unknown encoding errors (#936, #935)
3
+ - Index arbitrary pinsets (#937)
4
+ - Separate YARD cache from doc map cache (#938)
5
+
6
+ ## 0.54.4 - May 14, 2025
7
+ - Delete files from Library hash (#932)
8
+ - Clip#define returns variable pins (#934, #933)
9
+
10
+ ## 0.54.3 - May 13, 2025
11
+ - Improve inspect()/desc()/to_s() methods for better debugging output (#913)
12
+ - Fix generic resolution in Hash types (#906)
13
+ - Stop parsing RBS type parameter constraints as the type name (#918)
14
+ - Fix pin inference stack (#922)
15
+ - Refactor pin equality for performance (#925)
16
+ - Improve ApiMap catalog speed by preserving static pin indexes (#930)
17
+ - Update jaro_winkler dependency (#931)
18
+
19
+ ## 0.54.2 - April 28, 2025
20
+ - Resolve generics correctly on mixin inclusion (#898)
21
+ - Pick correct String#split overload (#905)
22
+ - Fix type sent into YARD method (#912)
23
+ - Early CancelRequest handling (#914)
24
+ - Destructure partial yield types (#915)
25
+ - Dependency versions (#916)
26
+
1
27
  ## 0.54.1 - April 26, 2025
2
28
  - Retire more RubyVM-specific code (#797)
3
29
  - Add additional docs for key classes, modules and methods (#802)
@@ -8,7 +8,7 @@ module Solargraph
8
8
  @methods = {}
9
9
  # @type [Hash{(String, Array<String>) => Array<Pin::Base>}]
10
10
  @constants = {}
11
- # @type [Hash{(String, String) => String}]
11
+ # @type [Hash{String => String}]
12
12
  @qualified_namespaces = {}
13
13
  # @type [Hash{String => Pin::Method}]
14
14
  @receiver_definitions = {}
@@ -16,6 +16,15 @@ module Solargraph
16
16
  @clips = {}
17
17
  end
18
18
 
19
+ def to_s
20
+ self.class.to_s
21
+ end
22
+
23
+ # avoid enormous dump
24
+ def inspect
25
+ to_s
26
+ end
27
+
19
28
  # @param fqns [String]
20
29
  # @param scope [Symbol]
21
30
  # @param visibility [Array<Symbol>]
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class ApiMap
5
+ class Index
6
+ # @param pins [Array<Pin::Base>]
7
+ def initialize pins = []
8
+ catalog pins
9
+ end
10
+
11
+ # @return [Array<Pin::Base>]
12
+ def pins
13
+ @pins ||= []
14
+ end
15
+
16
+ # @return [Hash{String => Array<Pin::Namespace>}]
17
+ def namespace_hash
18
+ @namespace_hash ||= Hash.new { |h, k| h[k] = [] }
19
+ end
20
+
21
+ # @return [Hash{String => Array<Pin::Base>}]
22
+ def pin_class_hash
23
+ @pin_class_hash ||= Hash.new { |h, k| h[k] = [] }
24
+ end
25
+
26
+ # @return [Hash{String => Array<Pin::Base>}]
27
+ def path_pin_hash
28
+ @path_pin_hash ||= Hash.new { |h, k| h[k] = [] }
29
+ end
30
+
31
+ # @generic T
32
+ # @param klass [Class<generic<T>>]
33
+ # @return [Set<generic<T>>]
34
+ def pins_by_class klass
35
+ # @type [Set<Solargraph::Pin::Base>]
36
+ s = Set.new
37
+ @pin_select_cache[klass] ||= pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
38
+ end
39
+
40
+ # @return [Hash{String => Array<Pin::Reference::Include>}]
41
+ def include_references
42
+ @include_references ||= Hash.new { |h, k| h[k] = [] }
43
+ end
44
+
45
+ # @return [Hash{String => Array<Pin::Reference::Extend>}]
46
+ def extend_references
47
+ @extend_references ||= Hash.new { |h, k| h[k] = [] }
48
+ end
49
+
50
+ # @return [Hash{String => Array<Pin::Reference::Prepend>}]
51
+ def prepend_references
52
+ @prepend_references ||= Hash.new { |h, k| h[k] = [] }
53
+ end
54
+
55
+ # @return [Hash{String => Array<Pin::Reference::Superclass>}]
56
+ def superclass_references
57
+ @superclass_references ||= Hash.new { |h, k| h[k] = [] }
58
+ end
59
+
60
+ # @param pins [Array<Pin::Base>]
61
+ def merge pins
62
+ deep_clone.catalog pins
63
+ end
64
+
65
+ protected
66
+
67
+ attr_writer :pins, :pin_select_cache, :namespace_hash, :pin_class_hash, :path_pin_hash, :include_references,
68
+ :extend_references, :prepend_references, :superclass_references
69
+
70
+ def deep_clone
71
+ Index.allocate.tap do |copy|
72
+ copy.pin_select_cache = {}
73
+ copy.pins = pins.clone
74
+ %i[
75
+ namespace_hash pin_class_hash path_pin_hash include_references extend_references prepend_references
76
+ superclass_references
77
+ ].each do |sym|
78
+ copy.send("#{sym}=", send(sym).clone)
79
+ copy.send(sym)&.transform_values!(&:clone)
80
+ end
81
+ end
82
+ end
83
+
84
+ # @param new_pins [Array<Pin::Base>]
85
+ def catalog new_pins
86
+ @pin_select_cache = {}
87
+ pins.concat new_pins
88
+ set = new_pins.to_set
89
+ set.classify(&:class)
90
+ .map { |k, v| pin_class_hash[k].concat v.to_a }
91
+ set.classify(&:namespace)
92
+ .map { |k, v| namespace_hash[k].concat v.to_a }
93
+ set.classify(&:path)
94
+ .map { |k, v| path_pin_hash[k].concat v.to_a }
95
+ @namespaces = path_pin_hash.keys.compact.to_set
96
+ map_references Pin::Reference::Include, include_references
97
+ map_references Pin::Reference::Prepend, prepend_references
98
+ map_references Pin::Reference::Extend, extend_references
99
+ map_references Pin::Reference::Superclass, superclass_references
100
+ map_overrides
101
+ self
102
+ end
103
+
104
+ # @param klass [Class<Pin::Reference>]
105
+ # @param hash [Hash{String => Array<Pin::Reference>}]
106
+ # @return [void]
107
+ def map_references klass, hash
108
+ pins_by_class(klass).each do |pin|
109
+ store_parametric_reference(hash, pin)
110
+ end
111
+ end
112
+
113
+ # Add references to a map
114
+ #
115
+ # @param hash [Hash{String => Array<Pin::Reference>}]
116
+ # @param reference_pin [Pin::Reference]
117
+ #
118
+ # @return [void]
119
+ def store_parametric_reference(hash, reference_pin)
120
+ referenced_ns = reference_pin.name
121
+ referenced_tag_params = reference_pin.generic_values
122
+ referenced_tag = referenced_ns +
123
+ if referenced_tag_params && referenced_tag_params.length > 0
124
+ "<" + referenced_tag_params.join(', ') + ">"
125
+ else
126
+ ''
127
+ end
128
+ referencing_ns = reference_pin.namespace
129
+ hash[referencing_ns].push referenced_tag
130
+ end
131
+
132
+ # @return [void]
133
+ def map_overrides
134
+ pins_by_class(Pin::Reference::Override).each do |ovr|
135
+ pin = path_pin_hash[ovr.name].first
136
+ next if pin.nil?
137
+ new_pin = if pin.path.end_with?('#initialize')
138
+ path_pin_hash[pin.path.sub(/#initialize/, '.new')].first
139
+ end
140
+ (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
141
+ pin.docstring.delete_tags tag
142
+ new_pin.docstring.delete_tags tag if new_pin
143
+ end
144
+ ovr.tags.each do |tag|
145
+ pin.docstring.add_tag(tag)
146
+ redefine_return_type pin, tag
147
+ if new_pin
148
+ new_pin.docstring.add_tag(tag)
149
+ redefine_return_type new_pin, tag
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ # @param pin [Pin::Method]
156
+ # @param tag [YARD::Tags::Tag]
157
+ # @return [void]
158
+ def redefine_return_type pin, tag
159
+ return unless pin && tag.tag_name == 'return'
160
+ pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
161
+ pin.signatures.each do |sig|
162
+ sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -1,19 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  module Solargraph
5
4
  class ApiMap
6
5
  # Queryable collection of Pins representing a Workspace, gems and the Ruby
7
6
  # core.
8
7
  #
9
8
  class Store
9
+ # @param pinsets [Array<Enumerable<Pin::Base>>]
10
+ def initialize *pinsets
11
+ catalog pinsets
12
+ end
13
+
10
14
  # @return [Array<Solargraph::Pin::Base>]
11
- attr_reader :pins
15
+ def pins
16
+ index.pins
17
+ end
18
+
19
+ # @param pinsets [Array<Enumerable<Pin::Base>>]
20
+ # @return [Boolean] True if the index was updated
21
+ def update *pinsets
22
+ return catalog(pinsets) if pinsets.length != @pinsets.length
23
+
24
+ changed = pinsets.find_index.with_index { |pinset, idx| @pinsets[idx] != pinset }
25
+ return false unless changed
26
+
27
+ # @todo Fix this map
28
+ @fqns_pins_map = nil
29
+ return catalog(pinsets) if changed == 0
30
+
31
+ pinsets[changed..].each_with_index do |pins, idx|
32
+ @pinsets[changed + idx] = pins
33
+ @indexes[changed + idx] = if pins.empty?
34
+ @indexes[changed + idx - 1]
35
+ else
36
+ @indexes[changed + idx - 1].merge(pins)
37
+ end
38
+ end
39
+ true
40
+ end
12
41
 
13
- # @param pins [Enumerable<Solargraph::Pin::Base>]
14
- def initialize pins = []
15
- @pins = pins
16
- index
42
+ def to_s
43
+ self.class.to_s
44
+ end
45
+
46
+ def inspect
47
+ to_s
17
48
  end
18
49
 
19
50
  # @param fqns [String]
@@ -66,11 +97,7 @@ module Solargraph
66
97
  # @param path [String]
67
98
  # @return [Array<Solargraph::Pin::Base>]
68
99
  def get_path_pins path
69
- path_pin_hash[path] || []
70
- end
71
-
72
- def cacheable_pins
73
- @cacheable_pins ||= pins_by_class(Pin::Namespace) + pins_by_class(Pin::Constant) + pins_by_class(Pin::Method) + pins_by_class(Pin::Reference)
100
+ index.path_pin_hash[path]
74
101
  end
75
102
 
76
103
  # @param fqns [String]
@@ -101,10 +128,10 @@ module Solargraph
101
128
 
102
129
  # @return [Set<String>]
103
130
  def namespaces
104
- @namespaces ||= Set.new
131
+ index.namespaces
105
132
  end
106
133
 
107
- # @return [Enumerable<Solargraph::Pin::Base>]
134
+ # @return [Enumerable<Solargraph::Pin::Namespace>]
108
135
  def namespace_pins
109
136
  pins_by_class(Solargraph::Pin::Namespace)
110
137
  end
@@ -143,18 +170,11 @@ module Solargraph
143
170
  pins_by_class(Pin::Block)
144
171
  end
145
172
 
146
- def inspect
147
- # Avoid insane dumps in specs
148
- to_s
149
- end
150
-
151
173
  # @generic T
152
- # @param klass [Class<T>]
153
- # @return [Set<T>]
174
+ # @param klass [Class<generic<T>>]
175
+ # @return [Set<generic<T>>]
154
176
  def pins_by_class klass
155
- # @type [Set<Solargraph::Pin::Base>]
156
- s = Set.new
157
- @pin_select_cache[klass] ||= @pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
177
+ index.pins_by_class klass
158
178
  end
159
179
 
160
180
  # @param fqns [String]
@@ -174,6 +194,23 @@ module Solargraph
174
194
 
175
195
  private
176
196
 
197
+ def index
198
+ @indexes.last
199
+ end
200
+
201
+ def catalog pinsets
202
+ @pinsets = pinsets
203
+ @indexes = []
204
+ pinsets.each do |pins|
205
+ if @indexes.last && pins.empty?
206
+ @indexes.push @indexes.last
207
+ else
208
+ @indexes.push(@indexes.last&.merge(pins) || Solargraph::ApiMap::Index.new(pins))
209
+ end
210
+ end
211
+ true
212
+ end
213
+
177
214
  # @return [Hash{::Array(String, String) => ::Array<Pin::Namespace>}]
178
215
  def fqns_pins_map
179
216
  @fqns_pins_map ||= Hash.new do |h, (base, name)|
@@ -184,129 +221,39 @@ module Solargraph
184
221
 
185
222
  # @return [Enumerable<Solargraph::Pin::Symbol>]
186
223
  def symbols
187
- pins_by_class(Pin::Symbol)
224
+ index.pins_by_class(Pin::Symbol)
188
225
  end
189
226
 
190
227
  # @return [Hash{String => Array<String>}]
191
228
  def superclass_references
192
- @superclass_references ||= {}
229
+ index.superclass_references
193
230
  end
194
231
 
195
232
  # @return [Hash{String => Array<String>}]
196
233
  def include_references
197
- @include_references ||= {}
234
+ index.include_references
198
235
  end
199
236
 
200
237
  # @return [Hash{String => Array<String>}]
201
238
  def prepend_references
202
- @prepend_references ||= {}
239
+ index.prepend_references
203
240
  end
204
241
 
205
242
  # @return [Hash{String => Array<String>}]
206
243
  def extend_references
207
- @extend_references ||= {}
244
+ index.extend_references
208
245
  end
209
246
 
210
247
  # @param name [String]
211
248
  # @return [Enumerable<Solargraph::Pin::Base>]
212
249
  def namespace_children name
213
- namespace_map[name] || []
214
- end
215
-
216
- # @return [Hash{String => Enumerable<Pin::Base>}
217
- def namespace_map
218
- @namespace_map ||= {}
250
+ return [] unless index.namespace_hash.key?(name)
251
+ index.namespace_hash[name]
219
252
  end
220
253
 
221
254
  # @return [Enumerable<Pin::InstanceVariable>]
222
255
  def all_instance_variables
223
- pins_by_class(Pin::InstanceVariable)
224
- end
225
-
226
- # @return [Hash{String => Array<Pin::Base>}]
227
- def path_pin_hash
228
- @path_pin_hash ||= {}
229
- end
230
-
231
- # Add references to a map
232
- #
233
- # @param h [Hash{String => Pin:Base}]
234
- # @param reference_pin [Pin::Reference]
235
- #
236
- # @return [void]
237
- def store_parametric_reference(h, reference_pin)
238
- referenced_ns = reference_pin.name
239
- referenced_tag_params = reference_pin.generic_values
240
- referenced_tag = referenced_ns +
241
- if referenced_tag_params && referenced_tag_params.length > 0
242
- "<" + referenced_tag_params.join(', ') + ">"
243
- else
244
- ''
245
- end
246
- referencing_ns = reference_pin.namespace
247
- h[referencing_ns] ||= []
248
- h[referencing_ns].push referenced_tag
249
- end
250
-
251
- # @return [void]
252
- def index
253
- set = pins.to_set
254
- @pin_class_hash = set.classify(&:class).transform_values(&:to_a)
255
- # @type [Hash{Class => ::Array<Solargraph::Pin::Base>}]
256
- @pin_select_cache = {}
257
- @namespace_map = set.classify(&:namespace)
258
- @path_pin_hash = set.classify(&:path)
259
- @namespaces = @path_pin_hash.keys.compact.to_set
260
- pins_by_class(Pin::Reference::Include).each do |pin|
261
- store_parametric_reference(include_references, pin)
262
- end
263
- # @todo move the rest of these reference pins over to use
264
- # generic types, adding rbs_map/conversions.rb code to
265
- # populate type parameters and adding related specs ensuring
266
- # the generics get resolved, along with any api_map.rb
267
- # changes needed in
268
- pins_by_class(Pin::Reference::Prepend).each do |pin|
269
- prepend_references[pin.namespace] ||= []
270
- prepend_references[pin.namespace].push pin.name
271
- end
272
- pins_by_class(Pin::Reference::Extend).each do |pin|
273
- extend_references[pin.namespace] ||= []
274
- extend_references[pin.namespace].push pin.name
275
- end
276
- pins_by_class(Pin::Reference::Superclass).each do |pin|
277
- superclass_references[pin.namespace] ||= []
278
- superclass_references[pin.namespace].push pin.name
279
- end
280
- pins_by_class(Pin::Reference::Override).each do |ovr|
281
- pin = get_path_pins(ovr.name).first
282
- next if pin.nil?
283
- new_pin = if pin.path.end_with?('#initialize')
284
- get_path_pins(pin.path.sub(/#initialize/, '.new')).first
285
- end
286
- (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
287
- pin.docstring.delete_tags tag.to_sym
288
- new_pin.docstring.delete_tags tag.to_sym if new_pin
289
- end
290
- ovr.tags.each do |tag|
291
- pin.docstring.add_tag(tag)
292
- redefine_return_type pin, tag
293
- if new_pin
294
- new_pin.docstring.add_tag(tag)
295
- redefine_return_type new_pin, tag
296
- end
297
- end
298
- end
299
- end
300
-
301
- # @param pin [Pin::Base]
302
- # @param tag [String]
303
- # @return [void]
304
- def redefine_return_type pin, tag
305
- return unless pin && tag.tag_name == 'return'
306
- pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
307
- pin.signatures.each do |sig|
308
- sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
309
- end
256
+ index.pins_by_class(Pin::InstanceVariable)
310
257
  end
311
258
  end
312
259
  end