docscribe 1.3.2 → 1.3.3

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: 765dd81d49b3cbf47c90f83f9e533a367da6590f84b15ca7e49de66c6140b5e1
4
- data.tar.gz: b7c0607de2fb6e2344be24d4da58c1e03ab33755175783e1e6de8c934a8f2cdc
3
+ metadata.gz: 755d272674fe454b80cc008acb50a879da920def321442cdc8cdd7c450b91f52
4
+ data.tar.gz: 92aa2320a36162272acfa2b430bfa9cccf5a4582770885a996bc61d7a4198bb6
5
5
  SHA512:
6
- metadata.gz: f30b33860317c5b9914e6b6c633df75c35f11883d7524c3b832365431a5f47760eaaeb4daab3b20f358bad8cb088015b173d6848bf65b3d7cbba18a69fda5154
7
- data.tar.gz: 66ac534ba8452880ee778ae1bf72ce571e9ea4bba481e5595172314df1f809eb62db87ec8b77cd4efb8c8cd37c85dd0c937b7fa8c263938ab46734ae03f5acda
6
+ metadata.gz: 9268725904b6644b4d46a89c72cda271c4d1b5fedc5066396af1515fa955fecb864fad10406db81582391f81d5265595c7c2bb6fe5793bfc1c7b465395937577
7
+ data.tar.gz: e8012b3c09ec75e8bd7bbed32f51b297edb2d081b65b2bdf849667e1c7cdb5469862697ddc060c8194b4bf08cc671cb61b6b94507ca382841745e27923963513
@@ -53,7 +53,7 @@ module Docscribe
53
53
  require 'docscribe/types/rbs/collection_loader'
54
54
  collection_path = Docscribe::Types::RBS::CollectionLoader.resolve
55
55
  if collection_path
56
- raw['rbs']['sig_dirs'] = Array(raw['rbs']['sig_dirs']) + [collection_path]
56
+ raw['rbs']['collection_dirs'] = Array(raw['rbs']['collection_dirs']) + [collection_path]
57
57
  else
58
58
  warn 'Docscribe: rbs_collection.lock.yaml not found or collection not installed. ' \
59
59
  'Run `bundle exec rbs collection install` first.'
@@ -62,6 +62,7 @@ module Docscribe
62
62
  'enabled' => false,
63
63
  'collection' => false,
64
64
  'sig_dirs' => ['sig'],
65
+ 'collection_dirs' => [],
65
66
  'collapse_generics' => false
66
67
  },
67
68
  'sorbet' => {
@@ -17,6 +17,7 @@ module Docscribe
17
17
  require 'docscribe/types/rbs/provider'
18
18
  Docscribe::Types::RBS::Provider.new(
19
19
  sig_dirs: rbs_sig_dirs,
20
+ collection_dirs: rbs_collection_dirs,
20
21
  collapse_generics: rbs_collapse_generics?
21
22
  )
22
23
  rescue LoadError
@@ -73,6 +74,18 @@ module Docscribe
73
74
  Array(raw.dig('rbs', 'sig_dirs') || DEFAULT.dig('rbs', 'sig_dirs')).map(&:to_s)
74
75
  end
75
76
 
77
+ # RBS collection directories (auto-discovered from rbs_collection.lock.yaml).
78
+ #
79
+ # Loaded separately from user sig_dirs so that collection-related
80
+ # RBS environment errors (e.g. duplicate declarations against core
81
+ # stdlib types) do not silence all RBS lookups.
82
+ #
83
+ # @private
84
+ # @return [Array<String>]
85
+ def rbs_collection_dirs
86
+ Array(raw.dig('rbs', 'collection_dirs')).map(&:to_s)
87
+ end
88
+
76
89
  # Whether generic RBS types should be collapsed to simpler container names.
77
90
  #
78
91
  # Examples:
@@ -86,6 +86,7 @@ module Docscribe
86
86
  # Use RBS signatures for better types (requires `gem "rbs"`)
87
87
  enabled: false
88
88
  sig_dirs: ["sig"]
89
+ collection_dirs: [] # auto-discovered from --rbs-collection
89
90
  collapse_generics: false # Hash<Symbol, String> => Hash
90
91
  collection: false # auto-discover from rbs_collection.lock.yaml
91
92
 
@@ -15,16 +15,21 @@ module Docscribe
15
15
  # the pipeline can stay independent of the underlying signature source.
16
16
  class Provider
17
17
  # @param [Array<String>] sig_dirs directories containing `.rbs` files
18
+ # @param [Array<String>] collection_dirs RBS collection directories
19
+ # (loaded separately; on error they are silently dropped and only
20
+ # user sig_dirs are used)
18
21
  # @param [Boolean] collapse_generics whether generic container types
19
22
  # should be simplified during formatting
20
23
  # @return [Object]
21
- def initialize(sig_dirs:, collapse_generics: false)
24
+ def initialize(sig_dirs:, collection_dirs: [], collapse_generics: false)
22
25
  require 'rbs'
23
26
  @sig_dirs = Array(sig_dirs).map(&:to_s)
27
+ @collection_dirs = Array(collection_dirs).map(&:to_s)
24
28
  @collapse_generics = !!collapse_generics
25
29
  @env = nil
26
30
  @builder = nil
27
31
  @warned = false
32
+ @collection_dropped = false
28
33
  end
29
34
 
30
35
  # Look up a normalized method signature from loaded RBS definitions.
@@ -64,22 +69,48 @@ module Docscribe
64
69
 
65
70
  # Lazily load and resolve the RBS environment.
66
71
  #
72
+ # Tries to load collection dirs together with user sig_dirs.
73
+ # If the combined environment raises a load error (e.g. duplicate
74
+ # declarations between collection and core stdlib types), collection
75
+ # dirs are dropped and only user sig_dirs are used.
76
+ #
67
77
  # @private
78
+ # @raise [::RBS::BaseError]
79
+ # @raise [StandardError]
68
80
  # @return [void]
69
81
  def load_env!
70
82
  return if @env && @builder
71
83
 
84
+ @env = build_env(@sig_dirs + @collection_dirs)
85
+ rescue ::RBS::BaseError => e
86
+ raise unless @collection_dirs.any? && !@collection_dropped
87
+
88
+ @collection_dropped = true
89
+ if ENV['DOCSCRIBE_RBS_DEBUG'] == '1'
90
+ warn "Docscribe: RBS collection error (#{e.class}), dropping collection dirs. " \
91
+ 'Set DOCSCRIBE_RBS_DEBUG=1 for details.'
92
+ end
93
+ @env = build_env(@sig_dirs)
94
+ end
95
+
96
+ # Build an RBS environment from the given directories.
97
+ #
98
+ # @private
99
+ # @param [Array<String>] dirs
100
+ # @return [::RBS::Environment]
101
+ def build_env(dirs)
72
102
  loader = ::RBS::EnvironmentLoader.new
73
103
  # Load core types transitively
74
104
  loader.add(library: 'rbs')
75
105
 
76
- @sig_dirs.each do |dir|
106
+ dirs.each do |dir|
77
107
  path = Pathname(dir)
78
108
  loader.add(path: path) if path.directory?
79
109
  end
80
110
 
81
- @env = ::RBS::Environment.from_loader(loader).resolve_type_names
82
- @builder = ::RBS::DefinitionBuilder.new(env: @env)
111
+ env = ::RBS::Environment.from_loader(loader).resolve_type_names
112
+ @builder = ::RBS::DefinitionBuilder.new(env: env)
113
+ env
83
114
  end
84
115
 
85
116
  # Build the appropriate instance or singleton definition for a container.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Docscribe
4
- VERSION = '1.3.2'
4
+ VERSION = '1.3.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docscribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - unurgunite