solargraph 0.55.4 → 0.56.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +2 -0
  3. data/.github/workflows/typecheck.yml +2 -0
  4. data/.gitignore +2 -0
  5. data/CHANGELOG.md +17 -0
  6. data/README.md +13 -3
  7. data/lib/solargraph/api_map/index.rb +23 -15
  8. data/lib/solargraph/api_map/store.rb +2 -1
  9. data/lib/solargraph/api_map.rb +53 -27
  10. data/lib/solargraph/complex_type/type_methods.rb +5 -1
  11. data/lib/solargraph/complex_type/unique_type.rb +7 -0
  12. data/lib/solargraph/convention/base.rb +3 -3
  13. data/lib/solargraph/convention.rb +3 -3
  14. data/lib/solargraph/doc_map.rb +200 -43
  15. data/lib/solargraph/gem_pins.rb +53 -38
  16. data/lib/solargraph/language_server/host.rb +9 -1
  17. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +1 -0
  18. data/lib/solargraph/language_server/message/extended/document.rb +5 -2
  19. data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
  20. data/lib/solargraph/library.rb +6 -3
  21. data/lib/solargraph/location.rb +13 -0
  22. data/lib/solargraph/parser/parser_gem/class_methods.rb +5 -8
  23. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -2
  24. data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +2 -2
  25. data/lib/solargraph/pin/base.rb +268 -24
  26. data/lib/solargraph/pin/base_variable.rb +9 -8
  27. data/lib/solargraph/pin/callable.rb +69 -0
  28. data/lib/solargraph/pin/closure.rb +12 -0
  29. data/lib/solargraph/pin/local_variable.rb +8 -5
  30. data/lib/solargraph/pin/method.rb +134 -17
  31. data/lib/solargraph/pin/parameter.rb +43 -6
  32. data/lib/solargraph/pin/signature.rb +38 -0
  33. data/lib/solargraph/pin_cache.rb +185 -0
  34. data/lib/solargraph/position.rb +9 -0
  35. data/lib/solargraph/range.rb +9 -0
  36. data/lib/solargraph/rbs_map/conversions.rb +19 -8
  37. data/lib/solargraph/rbs_map/core_map.rb +31 -9
  38. data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
  39. data/lib/solargraph/rbs_map.rb +74 -17
  40. data/lib/solargraph/shell.rb +16 -18
  41. data/lib/solargraph/source_map.rb +0 -17
  42. data/lib/solargraph/version.rb +1 -1
  43. data/lib/solargraph/views/_method.erb +10 -10
  44. data/lib/solargraph/views/_namespace.erb +3 -3
  45. data/lib/solargraph/views/document.erb +10 -10
  46. data/lib/solargraph/workspace.rb +15 -5
  47. data/lib/solargraph/yardoc.rb +6 -9
  48. data/lib/solargraph.rb +10 -12
  49. data/rbs_collection.yaml +19 -0
  50. data/solargraph.gemspec +1 -0
  51. metadata +19 -7
  52. data/lib/solargraph/cache.rb +0 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e00ddc5e4b665c4527099b496d2caf414a0fe5c1cdb44e71b4af16a7c5521d34
4
- data.tar.gz: 494b003c5260150a4c66952c0e4c512374197a52b528249027100b48a3deb4c5
3
+ metadata.gz: 6f8c351394fab745041193e5d33cd582f0131e6d0f2d30f210767bd273376f24
4
+ data.tar.gz: 9d7a3c46740bd9fa040190d00f0e17cab638bde681da5998337dd41e6a924ff6
5
5
  SHA512:
6
- metadata.gz: b56ff99aecf4a656722a8a55cdcf521b9dba1066c53e22dd344840f173dfb302fb560daba2b828af01ad0789f7defab7976511509484613df13687854b90bf77
7
- data.tar.gz: 2cc74269454a5290c0c98e89f55942bdc36f916b622bfc37a42d4aeaf30d023f497a6be585f725b4397991a5083fdc43dedf90c05526a3739bb2c4a78266daf0
6
+ metadata.gz: 0fefbe369014891f339463c19a198ab0b9c1d918fb70662b496d90f79871e7ab03d3b4e7bf853fee19f7bbd467817690b29e506ca340518156667e986685c92e
7
+ data.tar.gz: e92af09e57129e47e6c4b685642460c514bc7c26a015f93c7eb81d917b12717cfac0621181fc36dcc481770ce6b3d93a611f5acd5aee64b1730c8dde4b63b949
@@ -34,6 +34,8 @@ jobs:
34
34
  bundle exec solargraph config
35
35
  yq -yi '.plugins += ["solargraph-rails"]' .solargraph.yml
36
36
  yq -yi '.plugins += ["solargraph-rspec"]' .solargraph.yml
37
+ - name: Install gem types
38
+ run: bundle exec rbs collection install
37
39
  - name: Ensure typechecking still works
38
40
  run: bundle exec solargraph typecheck --level typed
39
41
  - name: Ensure specs still run
@@ -30,5 +30,7 @@ jobs:
30
30
  bundler-cache: false
31
31
  - name: Install gems
32
32
  run: bundle install
33
+ - name: Install gem types
34
+ run: bundle exec rbs collection install
33
35
  - name: Typecheck self
34
36
  run: SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ /.gem_rbs_collection
2
+ /rbs_collection.lock.yaml
1
3
  /Gemfile.lock
2
4
  .Gemfile
3
5
  .idea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.56.0 - July 1, 2025
2
+ - [regression] Gem caching perf and logging fixes #983
3
+
4
+ ## 0.55.5 - July 1, 2025
5
+ - Flatten results of DocMap external bundle query (#981)
6
+ - [breaking] Reimplement global conventions (#877)
7
+ - GemPins pin merging improvements (#946)
8
+ - Support class-scoped aliases and attributes from RBS (#952)
9
+ - Restructure ComplexType specs towards YARD doc compliance (#969)
10
+ - Use Prism (#974)
11
+ - Document pages (#977)
12
+ - Enable disabled-but-working specs (#978)
13
+ - Map RBS 'untyped' type (RBS::Types::Bases::Any) to 'undefined' (#979)
14
+ - Re-enable support for .gem_rbs_collection directories (#942)
15
+ - [breaking] Comply with YARD documentation on Hash tag format (#968)
16
+ - Ignore directory paths in Workspace#would_require? (#988)
17
+
1
18
  ## 0.55.4 - June 27, 2025
2
19
  - Flatten results of DocMap external bundle query (#981)
3
20
 
data/README.md CHANGED
@@ -63,12 +63,22 @@ The RSpec framework is supported via [solargraph-rspec](https://github.com/lekem
63
63
 
64
64
  **Note: Before version 0.53.0, it was recommended to run `yard gems` periodically or automate it with `yard config` to ensure that Solargraph had access to gem documentation. These steps are no longer necessary. Solargraph maintains its own gem documentation cache independent of the yardocs in your gem installations.**
65
65
 
66
- Solargraph automatically generates code maps from installed gems. You can also manage your cached gem documentation with the `solargraph gems` command.
67
-
68
- When editing code, a `require` call that references a gem will pull the documentation into the code maps and include the gem's API in code completion and intellisense.
66
+ When editing code, a `require` call that references a gem will pull the documentation into the code maps and include the gem's API in code completion and intellisense. Solargraph automatically generates code maps from installed gems, based on the YARD or RBS type information inside the gem. You can also eagerly cache gem documentation with the `solargraph gems` command.
69
67
 
70
68
  If your project automatically requires bundled gems (e.g., `require 'bundler/require'`), Solargraph will add all of the Gemfile's default dependencies to the map.
71
69
 
70
+ To ensure you have types for gems which contain neither RBS nor YARD
71
+ information, use
72
+ [gem\_rbs\_collection](https://github.com/ruby/gem_rbs_collection) to
73
+ install a community-supported set of RBS types for various gems:
74
+
75
+ ```sh
76
+ bundle exec rbs collection init
77
+ bundle exec rbs collection install
78
+ ```
79
+
80
+ Once installed, you can also insert your own local overrides and definitions in RBS in a directory configured in the `rbs_collection.yaml` that the above commands create.
81
+
72
82
  ### Type Checking
73
83
 
74
84
  As of version 0.33.0, Solargraph includes a [type checker](https://github.com/castwide/solargraph/issues/192) that uses a combination of YARD tags and code analysis to report missing type definitions. In strict mode, it performs type inference to determine whether the tags match the types it detects from code.
@@ -3,6 +3,8 @@
3
3
  module Solargraph
4
4
  class ApiMap
5
5
  class Index
6
+ include Logging
7
+
6
8
  # @param pins [Array<Pin::Base>]
7
9
  def initialize pins = []
8
10
  catalog pins
@@ -132,21 +134,24 @@ module Solargraph
132
134
  # @return [void]
133
135
  def map_overrides
134
136
  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
137
+ logger.debug { "ApiMap::Index#map_overrides: Looking at override #{ovr} for #{ovr.name}" }
138
+ pins = path_pin_hash[ovr.name]
139
+ logger.debug { "ApiMap::Index#map_overrides: pins for path=#{ovr.name}: #{pins}" }
140
+ pins.each do |pin|
141
+ new_pin = if pin.path.end_with?('#initialize')
142
+ path_pin_hash[pin.path.sub(/#initialize/, '.new')].first
143
+ end
144
+ (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
145
+ pin.docstring.delete_tags tag
146
+ new_pin.docstring.delete_tags tag if new_pin
147
+ end
148
+ ovr.tags.each do |tag|
149
+ pin.docstring.add_tag(tag)
150
+ redefine_return_type pin, tag
151
+ if new_pin
152
+ new_pin.docstring.add_tag(tag)
153
+ redefine_return_type new_pin, tag
154
+ end
150
155
  end
151
156
  end
152
157
  end
@@ -156,11 +161,14 @@ module Solargraph
156
161
  # @param tag [YARD::Tags::Tag]
157
162
  # @return [void]
158
163
  def redefine_return_type pin, tag
164
+ # @todo can this be made to not mutate existing pins and use
165
+ # proxy() / proxy_with_signatures() instead?
159
166
  return unless pin && tag.tag_name == 'return'
160
167
  pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
161
168
  pin.signatures.each do |sig|
162
169
  sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
163
170
  end
171
+ pin.reset_generated!
164
172
  end
165
173
  end
166
174
  end
@@ -61,9 +61,10 @@ module Solargraph
61
61
  # @param visibility [Array<Symbol>]
62
62
  # @return [Enumerable<Solargraph::Pin::Method>]
63
63
  def get_methods fqns, scope: :instance, visibility: [:public]
64
- namespace_children(fqns).select do |pin|
64
+ all_pins = namespace_children(fqns).select do |pin|
65
65
  pin.is_a?(Pin::Method) && pin.scope == scope && visibility.include?(pin.visibility)
66
66
  end
67
+ GemPins.combine_method_pins_by_path(all_pins)
67
68
  end
68
69
 
69
70
  # @param fq_tag [String]
@@ -93,9 +93,13 @@ module Solargraph
93
93
  implicit.merge map.environ
94
94
  end
95
95
  unresolved_requires = (bench.external_requires + implicit.requires + bench.workspace.config.required).to_a.compact.uniq
96
- if @unresolved_requires != unresolved_requires || @doc_map&.uncached_gemspecs&.any?
96
+ recreate_docmap = @unresolved_requires != unresolved_requires ||
97
+ @doc_map&.uncached_yard_gemspecs&.any? ||
98
+ @doc_map&.uncached_rbs_collection_gemspecs&.any? ||
99
+ @doc_map&.rbs_collection_path != bench.workspace.rbs_collection_path
100
+ if recreate_docmap
97
101
  @doc_map = DocMap.new(unresolved_requires, [], bench.workspace) # @todo Implement gem preferences
98
- @unresolved_requires = unresolved_requires
102
+ @unresolved_requires = @doc_map.unresolved_requires
99
103
  end
100
104
  @cache.clear if store.update(@@core_map.pins, @doc_map.pins, implicit.pins, iced_pins, live_pins)
101
105
  @missing_docs = [] # @todo Implement missing docs
@@ -109,11 +113,25 @@ module Solargraph
109
113
  [self.class, @source_map_hash, implicit, @doc_map, @unresolved_requires]
110
114
  end
111
115
 
116
+ def doc_map
117
+ @doc_map ||= DocMap.new([], [])
118
+ end
119
+
112
120
  # @return [::Array<Gem::Specification>]
113
121
  def uncached_gemspecs
114
122
  @doc_map&.uncached_gemspecs || []
115
123
  end
116
124
 
125
+ # @return [::Array<Gem::Specification>]
126
+ def uncached_rbs_collection_gemspecs
127
+ @doc_map.uncached_rbs_collection_gemspecs
128
+ end
129
+
130
+ # @return [::Array<Gem::Specification>]
131
+ def uncached_yard_gemspecs
132
+ @doc_map.uncached_yard_gemspecs
133
+ end
134
+
117
135
  # @return [Array<Pin::Base>]
118
136
  def core_pins
119
137
  @@core_map.pins
@@ -168,6 +186,18 @@ module Solargraph
168
186
  api_map
169
187
  end
170
188
 
189
+ def cache_all!(out)
190
+ @doc_map.cache_all!(out)
191
+ end
192
+
193
+ def cache_gem(gemspec, rebuild: false, out: nil)
194
+ @doc_map.cache(gemspec, rebuild: rebuild, out: out)
195
+ end
196
+
197
+ class << self
198
+ include Logging
199
+ end
200
+
171
201
  # Create an ApiMap with a workspace in the specified directory and cache
172
202
  # any missing gems.
173
203
  #
@@ -178,15 +208,14 @@ module Solargraph
178
208
  # @param directory [String]
179
209
  # @param out [IO] The output stream for messages
180
210
  # @return [ApiMap]
181
- def self.load_with_cache directory, out = IO::NULL
211
+ def self.load_with_cache directory, out
182
212
  api_map = load(directory)
183
- return api_map if api_map.uncached_gemspecs.empty?
184
-
185
- api_map.uncached_gemspecs.each do |gemspec|
186
- out.puts "Caching gem #{gemspec.name} #{gemspec.version}"
187
- pins = GemPins.build(gemspec)
188
- Solargraph::Cache.save('gems', "#{gemspec.name}-#{gemspec.version}.ser", pins)
213
+ if api_map.uncached_gemspecs.empty?
214
+ logger.info { "All gems cached for #{directory}" }
215
+ return api_map
189
216
  end
217
+
218
+ api_map.cache_all!(out)
190
219
  load(directory)
191
220
  end
192
221
 
@@ -527,13 +556,8 @@ module Solargraph
527
556
  .select { |path| path.downcase.include?(query.downcase) }
528
557
  end
529
558
 
530
- # Get YARD documentation for the specified path.
531
- #
532
- # @example
533
- # api_map.document('String#split')
534
- #
535
- # @todo This method is likely superfluous. Calling get_path_pins directly
536
- # should be sufficient.
559
+ # @deprecated This method is likely superfluous. Calling #get_path_pins
560
+ # directly should be sufficient.
537
561
  #
538
562
  # @param path [String] The path to find
539
563
  # @return [Enumerable<Pin::Base>]
@@ -627,6 +651,19 @@ module Solargraph
627
651
  store.get_includes(host_ns).map { |inc_tag| ComplexType.parse(inc_tag).name }.include?(module_ns)
628
652
  end
629
653
 
654
+ # @param pins [Enumerable<Pin::Base>]
655
+ # @param visibility [Enumerable<Symbol>]
656
+ # @return [Array<Pin::Base>]
657
+ def resolve_method_aliases pins, visibility = [:public, :private, :protected]
658
+ with_resolved_aliases = pins.map do |pin|
659
+ resolved = resolve_method_alias(pin)
660
+ next nil if resolved.respond_to?(:visibility) && !visibility.include?(resolved.visibility)
661
+ resolved
662
+ end.compact
663
+ logger.debug { "ApiMap#resolve_method_aliases(pins=#{pins.map(&:name)}, visibility=#{visibility}) => #{with_resolved_aliases.map(&:name)}" }
664
+ GemPins.combine_method_pins_by_path(with_resolved_aliases)
665
+ end
666
+
630
667
  private
631
668
 
632
669
  # A hash of source maps with filename keys.
@@ -859,17 +896,6 @@ module Solargraph
859
896
  result + nil_pins
860
897
  end
861
898
 
862
- # @param pins [Enumerable<Pin::Base>]
863
- # @param visibility [Enumerable<Symbol>]
864
- # @return [Array<Pin::Base>]
865
- def resolve_method_aliases pins, visibility = [:public, :private, :protected]
866
- pins.map do |pin|
867
- resolved = resolve_method_alias(pin)
868
- next pin if resolved.respond_to?(:visibility) && !visibility.include?(resolved.visibility)
869
- resolved
870
- end.compact
871
- end
872
-
873
899
  # @param pin [Pin::MethodAlias, Pin::Base]
874
900
  # @return [Pin::Method]
875
901
  def resolve_method_alias pin
@@ -172,7 +172,11 @@ module Solargraph
172
172
  elsif fixed_parameters?
173
173
  "(#{subtypes_str})"
174
174
  else
175
- "<#{subtypes_str}>"
175
+ if name == 'Hash'
176
+ "<#{key_types_str}, #{subtypes_str}>"
177
+ else
178
+ "<#{key_types_str}#{subtypes_str}>"
179
+ end
176
180
  end
177
181
  end
178
182
 
@@ -55,6 +55,13 @@ module Solargraph
55
55
  key_types.concat(subs[0].map { |u| ComplexType.new([u]) })
56
56
  # @sg-ignore
57
57
  subtypes.concat(subs[1].map { |u| ComplexType.new([u]) })
58
+ elsif parameters_type == :list && name == 'Hash'
59
+ # Treat Hash<A, B> as Hash{A => B}
60
+ if subs.length != 2
61
+ raise ComplexTypeError, "Bad hash type: name=#{name}, substring=#{substring} - must have exactly two parameters"
62
+ end
63
+ key_types.concat(subs[0].map { |u| ComplexType.new([u]) })
64
+ subtypes.concat(subs[1].map { |u| ComplexType.new([u]) })
58
65
  else
59
66
  subtypes.concat subs
60
67
  end
@@ -20,12 +20,12 @@ module Solargraph
20
20
  EMPTY_ENVIRON
21
21
  end
22
22
 
23
- # The Environ for a YARD map.
23
+ # The Environ for a DocMap.
24
24
  # Subclasses can override this method.
25
25
  #
26
- # @param yard_map [YardMap]
26
+ # @param doc_map [DocMap]
27
27
  # @return [Environ]
28
- def global yard_map
28
+ def global doc_map
29
29
  EMPTY_ENVIRON
30
30
  end
31
31
  end
@@ -31,12 +31,12 @@ module Solargraph
31
31
  result
32
32
  end
33
33
 
34
- # @param yard_map [YardMap]
34
+ # @param yard_map [DocMap]
35
35
  # @return [Environ]
36
- def self.for_global(yard_map)
36
+ def self.for_global(doc_map)
37
37
  result = Environ.new
38
38
  @@conventions.each do |conv|
39
- result.merge conv.global(yard_map)
39
+ result.merge conv.global(doc_map)
40
40
  end
41
41
  result
42
42
  end