solargraph 0.55.1 → 0.55.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2f834e0f42bbdee3defc50d5365e754c168a7ccfe9f5b9b059013dc2a5221b3
4
- data.tar.gz: 67abd2be10bd9562c53db394d13da52ae76016814bc3d3d1b17cb2010c645851
3
+ metadata.gz: 8a2f6018173b0c7fb772fb29ddcfac606af3bdc3495793eb88c35573164ba64d
4
+ data.tar.gz: 622be262bbfda497e13caf68d769cd30d4de62ff1aa6ee04ec80f7627af1af43
5
5
  SHA512:
6
- metadata.gz: dd2e5c2424a217ba140cee3561bf007fd71f0fbfb0810a00f4d45bbb03c95a98cb9a0f5efc43bc31166e5e68e8009ac15f3843ed4144c990d23811c6540c6207
7
- data.tar.gz: 306eeaf5080e35f9ab04841e1b349c94bffcf56d183487b574718c3561fbfd74742667f839ad6cdc6971594ef16ff65b84851341b5ac92e606edb3898e9a6fbf
6
+ metadata.gz: 4c0f53c95bacfd15f7e1d90a160df31799777ebbfd6a5728dcef38cab0e9a88741b1ce4a392a5dd5ccbec0a395867b17c766b08fce4dadd9000c51bdb36edae3
7
+ data.tar.gz: '08298eef6f231bbf2379186b8d9a37885386774f164c16f45897d3d0c1347f44460b2eb997bbc5410b01a503b92bc141549724692a38414f9e4fc386177a22c6'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.55.2 - June 21, 2025
2
+ - Require external bundle (#972)
3
+
1
4
  ## 0.55.1 - June 8, 2025
2
5
  - Fix inline Struct definition (#962)
3
6
  - Ensure DocMap requires bundler when loading gemspecs (#963)
@@ -94,7 +94,7 @@ module Solargraph
94
94
  end
95
95
  unresolved_requires = (bench.external_requires + implicit.requires + bench.workspace.config.required).to_a.compact.uniq
96
96
  if @unresolved_requires != unresolved_requires || @doc_map&.uncached_gemspecs&.any?
97
- @doc_map = DocMap.new(unresolved_requires, [], bench.workspace.rbs_collection_path) # @todo Implement gem preferences
97
+ @doc_map = DocMap.new(unresolved_requires, [], bench.workspace) # @todo Implement gem preferences
98
98
  @unresolved_requires = unresolved_requires
99
99
  end
100
100
  @cache.clear if store.update(@@core_map.pins, @doc_map.pins, implicit.pins, iced_pins, live_pins)
@@ -18,13 +18,16 @@ module Solargraph
18
18
  # @return [Array<Gem::Specification>]
19
19
  attr_reader :uncached_gemspecs
20
20
 
21
+ # @return [Workspace, nil]
22
+ attr_reader :workspace
23
+
21
24
  # @param requires [Array<String>]
22
25
  # @param preferences [Array<Gem::Specification>]
23
- # @param rbs_path [String, Pathname, nil]
24
- def initialize(requires, preferences, rbs_path = nil)
26
+ # @param workspace [Workspace, nil]
27
+ def initialize(requires, preferences, workspace = nil)
25
28
  @requires = requires.compact
26
29
  @preferences = preferences.compact
27
- @rbs_path = rbs_path
30
+ @workspace = workspace
28
31
  generate
29
32
  end
30
33
 
@@ -118,10 +121,10 @@ module Solargraph
118
121
 
119
122
  # @param gemspec [Gem::Specification]
120
123
  def update_from_collection gemspec, gempins
121
- return gempins unless @rbs_path && File.directory?(@rbs_path)
124
+ return gempins unless workspace&.rbs_collection_path && File.directory?(workspace&.rbs_collection_path)
122
125
  return gempins if RbsMap.new(gemspec.name, gemspec.version).resolved?
123
126
 
124
- rbs_map = RbsMap.new(gemspec.name, gemspec.version, directories: [@rbs_path])
127
+ rbs_map = RbsMap.new(gemspec.name, gemspec.version, directories: [workspace&.rbs_collection_path])
125
128
  return gempins unless rbs_map.resolved?
126
129
 
127
130
  Solargraph.logger.info "Updating #{gemspec.name} #{gemspec.version} from collection"
@@ -132,29 +135,7 @@ module Solargraph
132
135
  # @return [::Array<Gem::Specification>, nil]
133
136
  def resolve_path_to_gemspecs path
134
137
  return nil if path.empty?
135
-
136
- if path == 'bundler/require'
137
- # @todo Quick fix for cases when Solargraph is running without Bundler.
138
- # The next goal is to enable loading of external bundles, i.e.,
139
- # finding gems that are defined in the workspace's bundle when
140
- # Solargraph is running in a different environment.
141
- # See https://github.com/castwide/vscode-solargraph/issues/279
142
- require 'bundler'
143
-
144
- # find only the gems bundler is now using
145
- gemspecs = Bundler.definition.locked_gems.specs.flat_map do |lazy_spec|
146
- logger.info "Handling #{lazy_spec.name}:#{lazy_spec.version} from #{path}"
147
- [Gem::Specification.find_by_name(lazy_spec.name, lazy_spec.version)]
148
- rescue Gem::MissingSpecError => e
149
- logger.info("Could not find #{lazy_spec.name}:#{lazy_spec.version} with find_by_name, falling back to guess")
150
- # can happen in local filesystem references
151
- specs = resolve_path_to_gemspecs lazy_spec.name
152
- logger.info "Gem #{lazy_spec.name} #{lazy_spec.version} from bundle not found: #{e}" if specs.nil?
153
- next specs
154
- end.compact
155
-
156
- return gemspecs
157
- end
138
+ return gemspecs_required_from_bundler if path == 'bundler/require'
158
139
 
159
140
  gemspec = Gem::Specification.find_by_path(path)
160
141
  if gemspec.nil?
@@ -215,5 +196,53 @@ module Solargraph
215
196
  def only_runtime_dependencies gemspec
216
197
  gemspec.dependencies - gemspec.development_dependencies
217
198
  end
199
+
200
+ def gemspecs_required_from_bundler
201
+ if workspace&.directory && Bundler.definition&.lockfile&.to_s&.start_with?(workspace.directory)
202
+ # Find only the gems bundler is now using
203
+ Bundler.definition.locked_gems.specs.flat_map do |lazy_spec|
204
+ logger.info "Handling #{lazy_spec.name}:#{lazy_spec.version}"
205
+ [Gem::Specification.find_by_name(lazy_spec.name, lazy_spec.version)]
206
+ rescue Gem::MissingSpecError => e
207
+ logger.info("Could not find #{lazy_spec.name}:#{lazy_spec.version} with find_by_name, falling back to guess")
208
+ # can happen in local filesystem references
209
+ specs = resolve_path_to_gemspecs lazy_spec.name
210
+ logger.info "Gem #{lazy_spec.name} #{lazy_spec.version} from bundle not found: #{e}" if specs.nil?
211
+ next specs
212
+ end.compact
213
+ else
214
+ logger.info 'Fetching gemspecs required from Bundler (bundler/require)'
215
+ gemspecs_required_from_external_bundle
216
+ end
217
+ end
218
+
219
+ def gemspecs_required_from_external_bundle
220
+ logger.info 'Fetching gemspecs required from external bundle'
221
+ return [] unless workspace&.directory
222
+
223
+ Solargraph.with_clean_env do
224
+ cmd = [
225
+ 'ruby', '-e',
226
+ "require 'bundler'; require 'json'; Dir.chdir('#{workspace&.directory}') { puts Bundler.definition.locked_gems.specs.map { |spec| [spec.name, spec.version] }.to_h.to_json }"
227
+ ]
228
+ o, e, s = Open3.capture3(*cmd)
229
+ if s.success?
230
+ Solargraph.logger.debug "External bundle: #{o}"
231
+ hash = o && !o.empty? ? JSON.parse(o.split("\n").last) : {}
232
+ hash.map do |name, version|
233
+ Gem::Specification.find_by_name(name, version)
234
+ rescue Gem::MissingSpecError => e
235
+ logger.info("Could not find #{name}:#{version} with find_by_name, falling back to guess")
236
+ # can happen in local filesystem references
237
+ specs = resolve_path_to_gemspecs name
238
+ logger.info "Gem #{name} #{version} from bundle not found: #{e}" if specs.nil?
239
+ next specs
240
+ end.compact
241
+ else
242
+ Solargraph.logger.warn e
243
+ raise BundleNotFoundError, "Failed to load gems from bundle at #{workspace&.directory}"
244
+ end
245
+ end
246
+ end
218
247
  end
219
248
  end
@@ -152,7 +152,9 @@ module Solargraph
152
152
  # @param isa_node [Parser::AST::Node]
153
153
  # @return [Array(String, String)]
154
154
  def parse_isa(isa_node)
155
- return unless isa_node.type == :send && isa_node.children[1] == :is_a?
155
+ # @todo A nil guard might be good enough here, but we might want to
156
+ # see if the callers are checking for nils instead.
157
+ return unless isa_node&.type == :send && isa_node.children[1] == :is_a?
156
158
  # Check if conditional node follows this pattern:
157
159
  # s(:send,
158
160
  # s(:send, nil, :foo), :is_a?,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solargraph
4
- VERSION = '0.55.1'
4
+ VERSION = '0.55.2'
5
5
  end
data/lib/solargraph.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Encoding.default_external = 'UTF-8'
4
4
 
5
+ require 'bundler'
5
6
  require 'set'
6
7
  require 'yard-solargraph'
7
8
  require 'solargraph/yard_tags'
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.55.1
4
+ version: 0.55.2
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-06-08 00:00:00.000000000 Z
11
+ date: 2025-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport