solargraph 0.34.1 → 0.34.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4eb4c1116693acd8fdccf9caf8d077a14ab577566285871238dd57ac382f9c5b
4
- data.tar.gz: f7379357d36bb6cb0b90364aa5f8a1e2936d9f86c4d597da30cc15f301f74992
3
+ metadata.gz: e432b35fd7f9c1466edf9d2f3ae54bcf210ebfaaa79473458b33ba700c6bf902
4
+ data.tar.gz: a4bb6dbe4b7e6ce15bf1177c75ecce9fe13fc10a499527622b5675893bdb0053
5
5
  SHA512:
6
- metadata.gz: 6431b185d1e23f3e6d1d667e3c3622284420e77fc0575e6ca2664b5c83af2f69316b062c4589cf595b4aadf452db19a37ecef6ccc2802967758b0f5f60492c0c
7
- data.tar.gz: 6396d5d67d5ee605b445b3e1b3ffd881f789caa5c3d11edf49c516948c2db58515808e29f928b22fdf1346906cf26885fc3f97c48679da29cd5e06753f119b0d
6
+ metadata.gz: d05491b24576660461f939eb763d10b6247ec47140ecceef8e0c4f1387074a427850c0d25c0a3624641b42e66e4964782e369c89738aec2ee067d9d2c9aafdb4
7
+ data.tar.gz: b0f8d060d9f19810789f1b4190758afe45b608cc4da25e92eed3797550f096f9fa2352723a9c3954e2b3b3bcc3368ca505903476cb36991c337b654fd1fd2ce4
@@ -4,14 +4,12 @@ rvm:
4
4
  - 2.2
5
5
  - 2.3
6
6
  - 2.4
7
- - 2.5.1
8
- - 2.5.3
9
- - 2.6.0
10
- - 2.6.1
7
+ - 2.5
8
+ - 2.6
11
9
  - jruby-9.2
12
10
  matrix:
13
11
  include:
14
- - rvm: 2.4
12
+ - rvm: 2.5
15
13
  os: osx
16
14
  # Update RubyGems and Bundler due to error with Bundler 1.16.1 and RubyGems 2.7.3
17
15
  # See https://github.com/travis-ci/travis-ci/issues/8978
data/README.md CHANGED
@@ -85,7 +85,7 @@ See [https://solargraph.org/guides](https://solargraph.org/guides) for more tips
85
85
 
86
86
  ### Bug Reports and Feature Requests
87
87
 
88
- [https://github.com/castwide/solargraph/issues](GitHub Issues) are the best place to ask questions, report problems, and suggest improvements.
88
+ [GitHub Issues](https://github.com/castwide/solargraph/issues) are the best place to ask questions, report problems, and suggest improvements.
89
89
 
90
90
  ### Development
91
91
 
@@ -15,6 +15,7 @@ module Solargraph
15
15
  class SourceNotAvailableError < StandardError; end
16
16
  class ComplexTypeError < StandardError; end
17
17
  class WorkspaceTooLargeError < RuntimeError; end
18
+ class BundleNotFoundError < StandardError; end
18
19
 
19
20
  autoload :Position, 'solargraph/position'
20
21
  autoload :Range, 'solargraph/range'
@@ -116,8 +116,9 @@ module Solargraph
116
116
  end
117
117
  reqs.concat implicit.requires
118
118
  pins.concat implicit.overrides
119
- reqs.concat require_from_bundle(bundle.workspace.directory) if reqs.include?('bundler/require')
120
- yard_map.change(reqs)
119
+ br = reqs.include?('bundler/require') ? require_from_bundle(bundle.workspace.directory) : {}
120
+ reqs.concat br.keys
121
+ yard_map.change(reqs, br)
121
122
  new_store = Store.new(pins + yard_map.pins)
122
123
  @mutex.synchronize {
123
124
  @cache.clear
@@ -9,14 +9,10 @@ module Solargraph
9
9
  def require_from_bundle directory
10
10
  @require_from_bundle ||= begin
11
11
  Solargraph.logger.info "Loading gems for bundler/require"
12
- Bundler.with_clean_env do
13
- specs = `cd #{Shellwords.escape(directory)} && bundle exec ruby -e "require 'bundler'; puts Bundler.definition.specs_for([:default]).map(&:name)"`
14
- if specs
15
- specs.lines.map(&:strip).reject(&:nil?)
16
- else
17
- []
18
- end
19
- end
12
+ Documentor.specs_from_bundle(directory)
13
+ rescue BundleNotFoundError => e
14
+ Solargraph.logger.warn e.message
15
+ {}
20
16
  end
21
17
  end
22
18
 
@@ -20,6 +20,7 @@ module Solargraph
20
20
  # @param store [ApiMap::Store] ApiMap pin store
21
21
  # @return [void]
22
22
  def rake_yard store
23
+ YARD::Registry.clear
23
24
  code_object_map.clear
24
25
  store.namespace_pins.each do |pin|
25
26
  next if pin.path.nil? || pin.path.empty?
@@ -13,6 +13,7 @@ module Solargraph
13
13
  domains: ['RSpec::Matchers', 'RSpec::ExpectationGroups'],
14
14
  # This override is necessary due to an erroneous @return tag in
15
15
  # rspec's YARD documentation.
16
+ # @todo The return types have been fixed (https://github.com/rspec/rspec-expectations/pull/1121)
16
17
  overrides: [
17
18
  Solargraph::Pin::Reference::Override.method_return('RSpec::Matchers#expect', 'RSpec::Expectations::ExpectationTarget')
18
19
  ]
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler'
4
+ require 'json'
5
+ require 'open3'
6
+ require 'shellwords'
7
+ require 'yard'
4
8
 
5
9
  module Solargraph
6
10
  class Documentor
@@ -9,45 +13,61 @@ module Solargraph
9
13
  activejob activemodel activerecord activestorage activesupport railties
10
14
  ]
11
15
 
12
- def initialize directory, rebuild: false
16
+ def initialize directory, rebuild: false, out: File.new(File::NULL, 'w')
13
17
  @directory = directory
14
18
  @rebuild = rebuild
19
+ @out = out
15
20
  end
16
21
 
17
22
  # @return [Boolean] True if all specs were found and documented.
18
23
  def document
19
24
  failures = 0
20
- Dir.chdir @directory do
21
- Bundler.with_clean_env do
22
- Bundler.reset!
23
- lockfile = Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))
24
- # @param spec [Gem::Specification]
25
- lockfile.specs.each do |spec|
26
- real = spec.__materialize__
27
- if real.nil?
28
- puts "WARNING: #{spec.name} #{spec.version} not found"
29
- failures += 1
30
- next
31
- end
32
- yd = YARD::Registry.yardoc_file_for_gem(real.name, real.version)
33
- if !yd || @rebuild
34
- puts "Documenting #{real.name} #{real.version}"
35
- `yard gems #{real.name} #{real.version} #{@rebuild ? '--rebuild' : ''}`
36
- end
37
- if RDOC_GEMS.include?(spec.name)
38
- cache = File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{real.name}-#{real.version}", 'yardoc')
39
- next if File.exist?(cache) && !@rebuild
40
- puts "Caching custom documentation for #{real.name} #{real.version}"
41
- Solargraph::YardMap::RdocToYard.run(real)
42
- end
25
+ Documentor.specs_from_bundle(@directory).each_pair do |name, version|
26
+ yd = YARD::Registry.yardoc_file_for_gem(name, "= #{version}")
27
+ if !yd || @rebuild
28
+ @out.puts "Documenting #{name} #{version}"
29
+ `yard gems #{name} #{version} #{@rebuild ? '--rebuild' : ''}`
30
+ yd = YARD::Registry.yardoc_file_for_gem(name, "= #{version}")
31
+ if !yd
32
+ @out.puts "#{name} #{version} YARD documentation failed"
33
+ failures += 1
34
+ end
35
+ end
36
+ if yd && RDOC_GEMS.include?(name)
37
+ cache = File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{name}-#{version}", 'yardoc')
38
+ if !File.exist?(cache) || @rebuild
39
+ @out.puts "Caching custom documentation for #{name} #{version}"
40
+ spec = Gem::Specification.find_by_name(name, "= #{version}")
41
+ Solargraph::YardMap::RdocToYard.run(spec)
43
42
  end
44
43
  end
45
44
  end
46
- Bundler.reset!
47
45
  if failures > 0
48
- puts "#{failures} spec#{failures == 1 ? '' : 's'} could not be found. You might need to run `bundle install` first."
46
+ @out.puts "#{failures} gem#{failures == 1 ? '' : 's'} could not be documented. You might need to run `bundle install`."
49
47
  end
50
48
  failures == 0
49
+ rescue Solargraph::BundleNotFoundError => e
50
+ @out.puts "[#{e.class}] #{e.message}"
51
+ @out.puts "No bundled gems are available in #{@directory}"
52
+ false
53
+ end
54
+
55
+ def self.specs_from_bundle directory
56
+ Bundler.with_clean_env do
57
+ Dir.chdir directory do
58
+ cmd = [
59
+ 'bundle', 'exec', 'ruby', '-e',
60
+ "require 'bundler'; require 'json'; puts Bundler.definition.specs_for([:default]).map { |spec| [spec.name, spec.version] }.to_h.to_json"
61
+ ]
62
+ o, e, s = Open3.capture3(*cmd)
63
+ if s.success?
64
+ o && !o.empty? ? JSON.parse(o) : {}
65
+ else
66
+ Solargraph.logger.warn e
67
+ raise BundleNotFoundError, "Failed to load gems from bundle at #{directory}"
68
+ end
69
+ end
70
+ end
51
71
  end
52
72
  end
53
73
  end
@@ -183,7 +183,7 @@ module Solargraph
183
183
  option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
184
184
  option :rebuild, type: :boolean, aliases: :r, desc: 'Rebuild existing documentation', default: false
185
185
  def bundle
186
- Documentor.new(options[:directory]).document
186
+ Documentor.new(options[:directory], rebuild: options[:rebuild], out: STDOUT).document
187
187
  end
188
188
 
189
189
  desc 'rdoc GEM [VERSION]', 'Use RDoc to cache documentation'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solargraph
4
- VERSION = '0.34.1'
4
+ VERSION = '0.34.2'
5
5
  end
@@ -159,15 +159,18 @@ module Solargraph
159
159
  # HACK: Evaluating gemspec files violates the goal of not running
160
160
  # workspace code, but this is how Gem::Specification.load does it
161
161
  # anyway.
162
- begin
163
- spec = eval(File.read(file), binding, file)
164
- next unless Gem::Specification === spec
165
- result.concat(spec.require_paths.map { |path| File.join(base, path) })
166
- rescue Exception => e
167
- # Don't die if we have an error during eval-ing a gem spec.
168
- # Concat the default lib directory instead.
169
- Solargraph.logger.warn "Error reading #{file}: [#{e.class}] #{e.message}"
170
- result.push File.join(base, 'lib')
162
+ Dir.chdir base do
163
+ begin
164
+ # @type [Gem::Specification]
165
+ spec = eval(File.read(file), binding, file)
166
+ next unless Gem::Specification === spec
167
+ result.concat(spec.require_paths.map { |path| File.join(base, path) })
168
+ rescue Exception => e
169
+ # Don't die if we have an error during eval-ing a gem spec.
170
+ # Concat the default lib directory instead.
171
+ Solargraph.logger.warn "Error reading #{file}: [#{e.class}] #{e.message}"
172
+ result.push File.join(base, 'lib')
173
+ end
171
174
  end
172
175
  end
173
176
  result.concat config.require_paths
@@ -30,14 +30,18 @@ module Solargraph
30
30
 
31
31
  attr_writer :with_dependencies
32
32
 
33
+ attr_reader :gemset
34
+
33
35
  # @param required [Array<String>]
36
+ # @param gemset [Hash{String => String}]
34
37
  # @param with_dependencies [Boolean]
35
- def initialize(required: [], with_dependencies: true)
38
+ def initialize(required: [], gemset: {}, with_dependencies: true)
36
39
  # HACK: YardMap needs its own copy of this array
37
40
  @required = required.clone
38
41
  @with_dependencies = with_dependencies
39
42
  @gem_paths = {}
40
43
  @stdlib_namespaces = []
44
+ @gemset = gemset
41
45
  process_requires
42
46
  yardocs.uniq!
43
47
  end
@@ -54,12 +58,13 @@ module Solargraph
54
58
 
55
59
  # @param new_requires [Array<String>]
56
60
  # @return [Boolean]
57
- def change new_requires
58
- if new_requires.uniq.sort == required.uniq.sort
61
+ def change new_requires, new_gemset
62
+ if new_requires.uniq.sort == required.uniq.sort && new_gemset == gemset
59
63
  false
60
64
  else
61
65
  required.clear
62
66
  required.concat new_requires
67
+ @gemset = new_gemset
63
68
  process_requires
64
69
  true
65
70
  end
@@ -120,7 +125,7 @@ module Solargraph
120
125
  # @return [Location]
121
126
  def require_reference path
122
127
  # @type [Gem::Specification]
123
- spec = Gem::Specification.find_by_path(path) || Gem::Specification.find_by_name(path.split('/').first)
128
+ spec = spec_for_require(path)
124
129
  spec.full_require_paths.each do |rp|
125
130
  file = File.join(rp, "#{path}.rb")
126
131
  next unless File.file?(file)
@@ -165,7 +170,7 @@ module Solargraph
165
170
  end
166
171
  result = []
167
172
  begin
168
- spec = Gem::Specification.find_by_path(r) || Gem::Specification.find_by_name(r.split('/').first)
173
+ spec = spec_for_require(r)
169
174
  ver = spec.version.to_s
170
175
  ver = ">= 0" if ver.empty?
171
176
  yd = yardoc_file_for_spec(spec)
@@ -271,24 +276,20 @@ module Solargraph
271
276
  Solargraph.logger.info "Using cached documentation for #{spec.name} at #{cache_dir}"
272
277
  cache_dir
273
278
  else
274
- YARD::Registry.yardoc_file_for_gem(spec.name, spec.version)
279
+ YARD::Registry.yardoc_file_for_gem(spec.name, "= #{spec.version}")
275
280
  end
276
281
  end
277
- end
278
- end
279
- def bundler_require directory
280
- Solargraph.logger.info "Using bundler/require"
281
- result = Dir.chdir directory do
282
- # @type [Array<Gem::Specification>]
283
- specs = Bundler.with_original_env do
284
- Bundler.reset!
285
- Bundler.definition.specs_for([:default])
282
+
283
+ def spec_for_require path
284
+ spec = Gem::Specification.find_by_path(path) || Gem::Specification.find_by_name(path.split('/').first)
285
+ if @gemset[spec.name]
286
+ begin
287
+ return Gem::Specification.find_by_name(spec.name, "= #{@gemset[spec.name]}")
288
+ rescue Gem::LoadError
289
+ Solargraph.logger.warn "Unable to load #{spec.name} #{@gemset[spec.name]} specified by workspace, using #{spec.version} instead"
290
+ end
291
+ end
292
+ spec
286
293
  end
287
- specs.map(&:name)
288
294
  end
289
- Bundler.reset!
290
- result
291
- rescue Bundler::GemfileNotFound => e
292
- Solargraph.logger.info "Ignoring bundler/require: #{e.message}"
293
- []
294
295
  end
@@ -4,7 +4,8 @@
4
4
  # each job.
5
5
 
6
6
  if RUBY_VERSION =~ /^2\.(1|2)\./
7
- exec "gem install bundler -v '< 2'"
7
+ `gem install bundler -v '< 2'`
8
8
  else
9
- exec "gem install bundler"
9
+ `gem update --system`
10
+ `gem install bundler`
10
11
  end
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.34.1
4
+ version: 0.34.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: 2019-06-26 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport