solargraph 0.54.0 → 0.55.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -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 +75 -122
  6. data/lib/solargraph/api_map.rb +109 -41
  7. data/lib/solargraph/bench.rb +17 -1
  8. data/lib/solargraph/complex_type/type_methods.rb +17 -11
  9. data/lib/solargraph/complex_type/unique_type.rb +181 -17
  10. data/lib/solargraph/complex_type.rb +103 -24
  11. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +51 -0
  12. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +100 -0
  13. data/lib/solargraph/convention/struct_definition.rb +101 -0
  14. data/lib/solargraph/convention.rb +2 -0
  15. data/lib/solargraph/doc_map.rb +43 -18
  16. data/lib/solargraph/equality.rb +33 -0
  17. data/lib/solargraph/language_server/host/message_worker.rb +51 -5
  18. data/lib/solargraph/language_server/host.rb +13 -11
  19. data/lib/solargraph/language_server/message/base.rb +19 -12
  20. data/lib/solargraph/language_server/message/initialize.rb +3 -1
  21. data/lib/solargraph/language_server/message/text_document/completion.rb +0 -3
  22. data/lib/solargraph/language_server/message/text_document/definition.rb +3 -3
  23. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +3 -3
  24. data/lib/solargraph/language_server/message/text_document/formatting.rb +4 -0
  25. data/lib/solargraph/language_server/message/text_document/hover.rb +1 -1
  26. data/lib/solargraph/language_server/message/text_document/type_definition.rb +3 -3
  27. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -2
  28. data/lib/solargraph/language_server/progress.rb +19 -2
  29. data/lib/solargraph/library.rb +31 -41
  30. data/lib/solargraph/location.rb +29 -1
  31. data/lib/solargraph/parser/comment_ripper.rb +11 -6
  32. data/lib/solargraph/parser/flow_sensitive_typing.rb +226 -0
  33. data/lib/solargraph/parser/node_methods.rb +15 -1
  34. data/lib/solargraph/parser/parser_gem/class_methods.rb +11 -6
  35. data/lib/solargraph/parser/parser_gem/node_chainer.rb +10 -10
  36. data/lib/solargraph/parser/parser_gem/node_methods.rb +6 -4
  37. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
  38. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +23 -19
  39. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +21 -1
  40. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +21 -0
  41. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +8 -2
  42. data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +26 -5
  43. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +41 -0
  44. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +1 -1
  45. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +28 -0
  46. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +28 -0
  47. data/lib/solargraph/parser/parser_gem/node_processors.rb +10 -0
  48. data/lib/solargraph/parser.rb +3 -5
  49. data/lib/solargraph/pin/base.rb +47 -17
  50. data/lib/solargraph/pin/base_variable.rb +11 -4
  51. data/lib/solargraph/pin/block.rb +8 -26
  52. data/lib/solargraph/pin/breakable.rb +9 -0
  53. data/lib/solargraph/pin/callable.rb +147 -0
  54. data/lib/solargraph/pin/closure.rb +8 -3
  55. data/lib/solargraph/pin/common.rb +2 -6
  56. data/lib/solargraph/pin/conversions.rb +3 -2
  57. data/lib/solargraph/pin/instance_variable.rb +2 -2
  58. data/lib/solargraph/pin/local_variable.rb +7 -1
  59. data/lib/solargraph/pin/method.rb +76 -48
  60. data/lib/solargraph/pin/namespace.rb +14 -11
  61. data/lib/solargraph/pin/parameter.rb +24 -17
  62. data/lib/solargraph/pin/proxy_type.rb +13 -7
  63. data/lib/solargraph/pin/signature.rb +3 -129
  64. data/lib/solargraph/pin/until.rb +18 -0
  65. data/lib/solargraph/pin/while.rb +18 -0
  66. data/lib/solargraph/pin.rb +7 -1
  67. data/lib/solargraph/position.rb +7 -0
  68. data/lib/solargraph/range.rb +9 -4
  69. data/lib/solargraph/rbs_map/conversions.rb +84 -45
  70. data/lib/solargraph/rbs_map/core_fills.rb +16 -9
  71. data/lib/solargraph/rbs_map.rb +1 -0
  72. data/lib/solargraph/shell.rb +19 -2
  73. data/lib/solargraph/source/chain/array.rb +10 -8
  74. data/lib/solargraph/source/chain/block_symbol.rb +1 -1
  75. data/lib/solargraph/source/chain/block_variable.rb +1 -1
  76. data/lib/solargraph/source/chain/call.rb +125 -61
  77. data/lib/solargraph/source/chain/constant.rb +1 -1
  78. data/lib/solargraph/source/chain/hash.rb +8 -2
  79. data/lib/solargraph/source/chain/if.rb +5 -0
  80. data/lib/solargraph/source/chain/link.rb +28 -5
  81. data/lib/solargraph/source/chain/literal.rb +27 -2
  82. data/lib/solargraph/source/chain/or.rb +1 -1
  83. data/lib/solargraph/source/chain/z_super.rb +1 -1
  84. data/lib/solargraph/source/chain.rb +131 -63
  85. data/lib/solargraph/source/cursor.rb +3 -2
  86. data/lib/solargraph/source/source_chainer.rb +2 -2
  87. data/lib/solargraph/source.rb +104 -86
  88. data/lib/solargraph/source_map/clip.rb +8 -6
  89. data/lib/solargraph/source_map/data.rb +30 -0
  90. data/lib/solargraph/source_map.rb +28 -16
  91. data/lib/solargraph/type_checker/checks.rb +4 -0
  92. data/lib/solargraph/type_checker/rules.rb +6 -1
  93. data/lib/solargraph/type_checker.rb +48 -21
  94. data/lib/solargraph/version.rb +1 -1
  95. data/lib/solargraph/views/environment.erb +3 -5
  96. data/lib/solargraph/workspace/config.rb +7 -3
  97. data/lib/solargraph/workspace.rb +1 -1
  98. data/lib/solargraph/yard_map/mapper/to_constant.rb +1 -0
  99. data/lib/solargraph/yard_map/mapper/to_method.rb +42 -15
  100. data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -0
  101. data/lib/solargraph/yard_map/mapper.rb +1 -0
  102. data/lib/solargraph/yardoc.rb +1 -1
  103. data/lib/solargraph.rb +1 -0
  104. data/solargraph.gemspec +5 -5
  105. metadata +41 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39ad27afe3afb59299f8701f9a7ea3f25a9f95379ef68e53ac0e22eb60f50e21
4
- data.tar.gz: 1f01a9d5cdf4aec5b50c245a25b1f7d83e5d6762e5b8f65bc9ce3555654e21ed
3
+ metadata.gz: c8e98755e559a9524b7d057c860e1ebb6d8a46eeb73dd567744f7562a4d49a64
4
+ data.tar.gz: 33943305fcf0c4c534fd4abf5eb24a937f6390021e681017296aac7bb9546592
5
5
  SHA512:
6
- metadata.gz: 788f17e92a54e782ea1dcf03cb44245df823ba33b4fe866d1afa5d06c7171b40a4e1f93c97c8b26c13b58be7478b9b07cd75d6735da65ecef21ab6a4a61dbb0e
7
- data.tar.gz: 742f43fcdce4a592a80ebe8e3acbd020f39f569cf323621a527e626ae8c6154f7dedb32739b8b62f38e98997ed414ec30471160332ecfb4a2fe5d5052e871333
6
+ metadata.gz: 37c0b331d67d299a865e4201c030dec6c1fd4ca14955012d702a44849bece0497c70449a3594ce8cdfe56669b93fbc80d1b291331a540453409a990344464ac1
7
+ data.tar.gz: c91397eeb5d2f10c551e97a741acb9a1e8fbae371b810bf375cc6024fc5985d6e2e581fb1d39c62ba9dd7f71b2cc6fa0ca801fcb74c89b5b8717beeaf8af10f0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,61 @@
1
+ ## 0.55.0 - June 3, 2025
2
+ - Flow-sensitive typing - automatically downcast from is_a? calls (#856)
3
+ - Tuple enabler: infer literal types and use them for signature selection (#836)
4
+ - Signature selection improvements (#907)
5
+ - Add support for Ruby Structs (#939)
6
+ - [regression] Fix interface change breaking solargraph-rails (#940)
7
+ - [regression] Add back bundler/require support for solargraph-rails (#941)
8
+ - Add specs for initialize capabilities (#955)
9
+ - Create MethodAlias pins from YARD (#945)
10
+ - MessageWorker prioritizes synchronization (#956)
11
+ - initialize/new method pin cleanups (#949)
12
+ - Clip rebinds blocks when cursor is not part of receiver (#958)
13
+
14
+ ## 0.54.5 - May 17, 2025
15
+ - Repair unknown encoding errors (#936, #935)
16
+ - Index arbitrary pinsets (#937)
17
+ - Separate YARD cache from doc map cache (#938)
18
+
19
+ ## 0.54.4 - May 14, 2025
20
+ - Delete files from Library hash (#932)
21
+ - Clip#define returns variable pins (#934, #933)
22
+
23
+ ## 0.54.3 - May 13, 2025
24
+ - Improve inspect()/desc()/to_s() methods for better debugging output (#913)
25
+ - Fix generic resolution in Hash types (#906)
26
+ - Stop parsing RBS type parameter constraints as the type name (#918)
27
+ - Fix pin inference stack (#922)
28
+ - Refactor pin equality for performance (#925)
29
+ - Improve ApiMap catalog speed by preserving static pin indexes (#930)
30
+ - Update jaro_winkler dependency (#931)
31
+
32
+ ## 0.54.2 - April 28, 2025
33
+ - Resolve generics correctly on mixin inclusion (#898)
34
+ - Pick correct String#split overload (#905)
35
+ - Fix type sent into YARD method (#912)
36
+ - Early CancelRequest handling (#914)
37
+ - Destructure partial yield types (#915)
38
+ - Dependency versions (#916)
39
+
40
+ ## 0.54.1 - April 26, 2025
41
+ - Retire more RubyVM-specific code (#797)
42
+ - Add additional docs for key classes, modules and methods (#802)
43
+ - Populate location information from RBS files (#768)
44
+ - Consolidate parameter handling into Pin::Callable (#844)
45
+ - Adjust local variable presence to start after assignment, not before (#864)
46
+ - Resolve params from ref tags (#872)
47
+ - Reduce use of ComplexType.parse() to preserve rooted? information (#870)
48
+ - Ensure yield return types are qualified (#886)
49
+ - Understand type of 'def foo; @foo ||= bar; end' reader methods (#888)
50
+ - Improvements to #inspect output on pins and chains (#895)
51
+ - Block method resolution improvements (#885)
52
+ - Understand mass assignment into instance variables (#893)
53
+ - Library sync and cache invalidation (#903)
54
+ - Handle super and yield scenarios from blocks (#891)
55
+ - Allow core and stdlib documentation to be uncached (#899)
56
+ - Surface variable names in LSP, e.g., textDocument/hover (#910)
57
+ - Keep idle progress notifications alive (#911)
58
+
1
59
  ## 0.54.0 - April 14, 2025
2
60
  - Add support for simple block argument destructuring (#821)
3
61
  - Benchmark the typecheck command (#852)
@@ -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,16 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  module Solargraph
5
4
  class ApiMap
5
+ # Queryable collection of Pins representing a Workspace, gems and the Ruby
6
+ # core.
7
+ #
6
8
  class Store
9
+ # @param pinsets [Array<Enumerable<Pin::Base>>]
10
+ def initialize *pinsets
11
+ catalog pinsets
12
+ end
13
+
7
14
  # @return [Array<Solargraph::Pin::Base>]
8
- 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
9
41
 
10
- # @param pins [Enumerable<Solargraph::Pin::Base>]
11
- def initialize pins = []
12
- @pins = pins
13
- index
42
+ def to_s
43
+ self.class.to_s
44
+ end
45
+
46
+ def inspect
47
+ to_s
14
48
  end
15
49
 
16
50
  # @param fqns [String]
@@ -35,9 +69,12 @@ module Solargraph
35
69
  # @param fqns [String]
36
70
  # @return [String, nil]
37
71
  def get_superclass fqns
72
+ raise "Do not prefix fully qualified namespaces with '::' - #{fqns.inspect}" if fqns.start_with?('::')
38
73
  return superclass_references[fqns].first if superclass_references.key?(fqns)
39
74
  return 'Object' if fqns != 'BasicObject' && namespace_exists?(fqns)
40
75
  return 'Object' if fqns == 'Boolean'
76
+ simplified_literal_name = ComplexType.parse("#{fqns}").simplify_literals.name
77
+ return simplified_literal_name if simplified_literal_name != fqns
41
78
  nil
42
79
  end
43
80
 
@@ -62,11 +99,7 @@ module Solargraph
62
99
  # @param path [String]
63
100
  # @return [Array<Solargraph::Pin::Base>]
64
101
  def get_path_pins path
65
- path_pin_hash[path] || []
66
- end
67
-
68
- def cacheable_pins
69
- @cacheable_pins ||= pins_by_class(Pin::Namespace) + pins_by_class(Pin::Constant) + pins_by_class(Pin::Method) + pins_by_class(Pin::Reference)
102
+ index.path_pin_hash[path]
70
103
  end
71
104
 
72
105
  # @param fqns [String]
@@ -81,7 +114,7 @@ module Solargraph
81
114
  # @param fqns [String]
82
115
  # @return [Enumerable<Solargraph::Pin::Base>]
83
116
  def get_class_variables(fqns)
84
- namespace_children(fqns).select{|pin| pin.is_a?(Pin::ClassVariable)}
117
+ namespace_children(fqns).select { |pin| pin.is_a?(Pin::ClassVariable)}
85
118
  end
86
119
 
87
120
  # @return [Enumerable<Solargraph::Pin::Base>]
@@ -97,10 +130,10 @@ module Solargraph
97
130
 
98
131
  # @return [Set<String>]
99
132
  def namespaces
100
- @namespaces ||= Set.new
133
+ index.namespaces
101
134
  end
102
135
 
103
- # @return [Array<Solargraph::Pin::Base>]
136
+ # @return [Enumerable<Solargraph::Pin::Namespace>]
104
137
  def namespace_pins
105
138
  pins_by_class(Solargraph::Pin::Namespace)
106
139
  end
@@ -139,18 +172,11 @@ module Solargraph
139
172
  pins_by_class(Pin::Block)
140
173
  end
141
174
 
142
- def inspect
143
- # Avoid insane dumps in specs
144
- to_s
145
- end
146
-
147
175
  # @generic T
148
- # @param klass [Class<T>]
149
- # @return [Array<T>]
176
+ # @param klass [Class<generic<T>>]
177
+ # @return [Set<generic<T>>]
150
178
  def pins_by_class klass
151
- # @type [Set<Solargraph::Pin::Base>]
152
- s = Set.new
153
- @pin_select_cache[klass] ||= @pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
179
+ index.pins_by_class klass
154
180
  end
155
181
 
156
182
  # @param fqns [String]
@@ -170,6 +196,23 @@ module Solargraph
170
196
 
171
197
  private
172
198
 
199
+ def index
200
+ @indexes.last
201
+ end
202
+
203
+ def catalog pinsets
204
+ @pinsets = pinsets
205
+ @indexes = []
206
+ pinsets.each do |pins|
207
+ if @indexes.last && pins.empty?
208
+ @indexes.push @indexes.last
209
+ else
210
+ @indexes.push(@indexes.last&.merge(pins) || Solargraph::ApiMap::Index.new(pins))
211
+ end
212
+ end
213
+ true
214
+ end
215
+
173
216
  # @return [Hash{::Array(String, String) => ::Array<Pin::Namespace>}]
174
217
  def fqns_pins_map
175
218
  @fqns_pins_map ||= Hash.new do |h, (base, name)|
@@ -180,129 +223,39 @@ module Solargraph
180
223
 
181
224
  # @return [Enumerable<Solargraph::Pin::Symbol>]
182
225
  def symbols
183
- pins_by_class(Pin::Symbol)
226
+ index.pins_by_class(Pin::Symbol)
184
227
  end
185
228
 
186
229
  # @return [Hash{String => Array<String>}]
187
230
  def superclass_references
188
- @superclass_references ||= {}
231
+ index.superclass_references
189
232
  end
190
233
 
191
234
  # @return [Hash{String => Array<String>}]
192
235
  def include_references
193
- @include_references ||= {}
236
+ index.include_references
194
237
  end
195
238
 
196
239
  # @return [Hash{String => Array<String>}]
197
240
  def prepend_references
198
- @prepend_references ||= {}
241
+ index.prepend_references
199
242
  end
200
243
 
201
244
  # @return [Hash{String => Array<String>}]
202
245
  def extend_references
203
- @extend_references ||= {}
246
+ index.extend_references
204
247
  end
205
248
 
206
249
  # @param name [String]
207
250
  # @return [Enumerable<Solargraph::Pin::Base>]
208
251
  def namespace_children name
209
- namespace_map[name] || []
210
- end
211
-
212
- # @return [Hash{String => Enumerable<Pin::Base>}
213
- def namespace_map
214
- @namespace_map ||= {}
252
+ return [] unless index.namespace_hash.key?(name)
253
+ index.namespace_hash[name]
215
254
  end
216
255
 
217
256
  # @return [Enumerable<Pin::InstanceVariable>]
218
257
  def all_instance_variables
219
- pins_by_class(Pin::InstanceVariable)
220
- end
221
-
222
- # @return [Hash{String => Array<Pin::Base>}]
223
- def path_pin_hash
224
- @path_pin_hash ||= {}
225
- end
226
-
227
- # Add references to a map
228
- #
229
- # @param h [Hash{String => Pin:Base}]
230
- # @param reference_pin [Pin::Reference]
231
- #
232
- # @return [void]
233
- def store_parametric_reference(h, reference_pin)
234
- referenced_ns = reference_pin.name
235
- referenced_tag_params = reference_pin.generic_values
236
- referenced_tag = referenced_ns +
237
- if referenced_tag_params && referenced_tag_params.length > 0
238
- "<" + referenced_tag_params.join(', ') + ">"
239
- else
240
- ''
241
- end
242
- referencing_ns = reference_pin.namespace
243
- h[referencing_ns] ||= []
244
- h[referencing_ns].push referenced_tag
245
- end
246
-
247
- # @return [void]
248
- def index
249
- set = pins.to_set
250
- @pin_class_hash = set.classify(&:class).transform_values(&:to_a)
251
- # @type [Hash{Class => ::Array<Solargraph::Pin::Base>}]
252
- @pin_select_cache = {}
253
- @namespace_map = set.classify(&:namespace)
254
- @path_pin_hash = set.classify(&:path)
255
- @namespaces = @path_pin_hash.keys.compact.to_set
256
- pins_by_class(Pin::Reference::Include).each do |pin|
257
- store_parametric_reference(include_references, pin)
258
- end
259
- # @todo move the rest of these reference pins over to use
260
- # generic types, adding rbs_map/conversions.rb code to
261
- # populate type parameters and adding related specs ensuring
262
- # the generics get resolved, along with any api_map.rb
263
- # changes needed in
264
- pins_by_class(Pin::Reference::Prepend).each do |pin|
265
- prepend_references[pin.namespace] ||= []
266
- prepend_references[pin.namespace].push pin.name
267
- end
268
- pins_by_class(Pin::Reference::Extend).each do |pin|
269
- extend_references[pin.namespace] ||= []
270
- extend_references[pin.namespace].push pin.name
271
- end
272
- pins_by_class(Pin::Reference::Superclass).each do |pin|
273
- superclass_references[pin.namespace] ||= []
274
- superclass_references[pin.namespace].push pin.name
275
- end
276
- pins_by_class(Pin::Reference::Override).each do |ovr|
277
- pin = get_path_pins(ovr.name).first
278
- next if pin.nil?
279
- new_pin = if pin.path.end_with?('#initialize')
280
- get_path_pins(pin.path.sub(/#initialize/, '.new')).first
281
- end
282
- (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
283
- pin.docstring.delete_tags tag.to_sym
284
- new_pin.docstring.delete_tags tag.to_sym if new_pin
285
- end
286
- ovr.tags.each do |tag|
287
- pin.docstring.add_tag(tag)
288
- redefine_return_type pin, tag
289
- if new_pin
290
- new_pin.docstring.add_tag(tag)
291
- redefine_return_type new_pin, tag
292
- end
293
- end
294
- end
295
- end
296
-
297
- # @param pin [Pin::Base]
298
- # @param tag [String]
299
- # @return [void]
300
- def redefine_return_type pin, tag
301
- return unless pin && tag.tag_name == 'return'
302
- pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
303
- pin.signatures.each do |sig|
304
- sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
305
- end
258
+ index.pins_by_class(Pin::InstanceVariable)
306
259
  end
307
260
  end
308
261
  end