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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 755d272674fe454b80cc008acb50a879da920def321442cdc8cdd7c450b91f52
|
|
4
|
+
data.tar.gz: 92aa2320a36162272acfa2b430bfa9cccf5a4582770885a996bc61d7a4198bb6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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']['
|
|
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.'
|
data/lib/docscribe/config/rbs.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
82
|
-
@builder = ::RBS::DefinitionBuilder.new(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.
|
data/lib/docscribe/version.rb
CHANGED