rbs 0.15.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +8 -4
- data/CHANGELOG.md +29 -1
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/Rakefile +19 -1
- data/Steepfile +0 -1
- data/bin/test_runner.rb +15 -1
- data/{stdlib/builtin → core}/array.rbs +1 -1
- data/{stdlib/builtin → core}/basic_object.rbs +0 -0
- data/{stdlib/builtin → core}/binding.rbs +0 -0
- data/{stdlib/builtin → core}/builtin.rbs +2 -2
- data/{stdlib/builtin → core}/class.rbs +0 -0
- data/{stdlib/builtin → core}/comparable.rbs +0 -0
- data/{stdlib/builtin → core}/complex.rbs +0 -0
- data/{stdlib/builtin → core}/constants.rbs +0 -0
- data/{stdlib/builtin → core}/data.rbs +0 -0
- data/{stdlib/builtin → core}/deprecated.rbs +0 -0
- data/{stdlib/builtin → core}/dir.rbs +1 -1
- data/{stdlib/builtin → core}/encoding.rbs +0 -0
- data/{stdlib/builtin → core}/enumerable.rbs +41 -40
- data/{stdlib/builtin → core}/enumerator.rbs +5 -5
- data/{stdlib/builtin → core}/errno.rbs +0 -0
- data/{stdlib/builtin → core}/errors.rbs +0 -0
- data/{stdlib/builtin → core}/exception.rbs +0 -0
- data/{stdlib/builtin → core}/false_class.rbs +0 -0
- data/{stdlib/builtin → core}/fiber.rbs +0 -0
- data/{stdlib/builtin → core}/fiber_error.rbs +0 -0
- data/{stdlib/builtin → core}/file.rbs +0 -4
- data/{stdlib/builtin → core}/file_test.rbs +0 -0
- data/{stdlib/builtin → core}/float.rbs +0 -0
- data/{stdlib/builtin → core}/gc.rbs +0 -0
- data/{stdlib/builtin → core}/hash.rbs +8 -8
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +1 -1
- data/{stdlib/builtin → core}/kernel.rbs +0 -0
- data/{stdlib/builtin → core}/marshal.rbs +0 -0
- data/{stdlib/builtin → core}/match_data.rbs +0 -0
- data/{stdlib/builtin → core}/math.rbs +0 -0
- data/{stdlib/builtin → core}/method.rbs +0 -0
- data/{stdlib/builtin → core}/module.rbs +0 -0
- data/{stdlib/builtin → core}/nil_class.rbs +0 -0
- data/{stdlib/builtin → core}/numeric.rbs +0 -0
- data/{stdlib/builtin → core}/object.rbs +0 -0
- data/core/object_space.rbs +98 -0
- data/{stdlib/builtin → core}/proc.rbs +0 -0
- data/{stdlib/builtin → core}/process.rbs +0 -0
- data/{stdlib/builtin → core}/random.rbs +0 -0
- data/{stdlib/builtin → core}/range.rbs +1 -1
- data/{stdlib/builtin → core}/rational.rbs +0 -0
- data/{stdlib/builtin → core}/rb_config.rbs +0 -0
- data/{stdlib/builtin → core}/regexp.rbs +0 -0
- data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
- data/{stdlib/builtin → core}/signal.rbs +0 -0
- data/{stdlib/builtin → core}/string.rbs +0 -0
- data/{stdlib/builtin → core}/string_io.rbs +0 -0
- data/{stdlib/builtin → core}/struct.rbs +1 -1
- data/{stdlib/builtin → core}/symbol.rbs +0 -0
- data/{stdlib/builtin → core}/thread.rbs +0 -0
- data/{stdlib/builtin → core}/thread_group.rbs +0 -0
- data/{stdlib/builtin → core}/time.rbs +0 -0
- data/{stdlib/builtin → core}/trace_point.rbs +0 -0
- data/{stdlib/builtin → core}/true_class.rbs +0 -0
- data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
- data/{stdlib/builtin → core}/warning.rbs +0 -0
- data/docs/repo.md +125 -0
- data/lib/rbs.rb +1 -0
- data/lib/rbs/cli.rb +105 -103
- data/lib/rbs/definition.rb +9 -4
- data/lib/rbs/definition_builder.rb +48 -15
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/environment_walker.rb +70 -35
- data/lib/rbs/parser.rb +306 -301
- data/lib/rbs/parser.y +15 -8
- data/lib/rbs/prototype/rb.rb +150 -21
- data/lib/rbs/prototype/runtime.rb +1 -0
- data/lib/rbs/repository.rb +121 -0
- data/lib/rbs/test/hook.rb +25 -15
- data/lib/rbs/test/setup.rb +5 -3
- data/lib/rbs/test/type_check.rb +6 -1
- data/lib/rbs/type_name.rb +2 -1
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/sig/cli.rbs +58 -0
- data/sig/definition.rbs +8 -3
- data/sig/definition_builder.rbs +4 -1
- data/sig/environment_loader.rbs +92 -46
- data/sig/polyfill.rbs +42 -0
- data/sig/rbs.rbs +8 -0
- data/sig/repository.rbs +79 -0
- data/sig/vendorer.rbs +44 -0
- data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
- data/stdlib/base64/{base64.rbs → 0/base64.rbs} +0 -0
- data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +0 -0
- data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
- data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
- data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +0 -0
- data/stdlib/csv/{csv.rbs → 0/csv.rbs} +3 -3
- data/stdlib/date/{date.rbs → 0/date.rbs} +0 -0
- data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +0 -0
- data/stdlib/dbm/0/dbm.rbs +277 -0
- data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
- data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
- data/stdlib/find/{find.rbs → 0/find.rbs} +0 -0
- data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
- data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
- data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
- data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
- data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +0 -0
- data/stdlib/logger/{logger.rbs → 0/logger.rbs} +0 -0
- data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
- data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
- data/stdlib/monitor/0/monitor.rbs +119 -0
- data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
- data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +0 -0
- data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
- data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
- data/stdlib/pstore/{pstore.rbs → 0/pstore.rbs} +0 -0
- data/stdlib/pty/{pty.rbs → 0/pty.rbs} +0 -0
- data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
- data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
- data/stdlib/singleton/0/singleton.rbs +111 -0
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +0 -0
- data/stdlib/tsort/0/cyclic.rbs +4 -0
- data/stdlib/tsort/0/interfaces.rbs +19 -0
- data/stdlib/tsort/0/tsort.rbs +363 -0
- data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
- data/stdlib/uri/{generic.rbs → 0/generic.rbs} +0 -0
- data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
- data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
- data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
- data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
- data/stdlib/yaml/0/dbm.rbs +221 -0
- data/stdlib/yaml/0/store.rbs +53 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +9 -9
- metadata +108 -94
data/lib/rbs/test/hook.rb
CHANGED
@@ -27,26 +27,28 @@ module RBS
|
|
27
27
|
:>> => "rshift",
|
28
28
|
:~ => "tilda"
|
29
29
|
}
|
30
|
-
def self.alias_names(target)
|
30
|
+
def self.alias_names(target, random)
|
31
|
+
suffix = "#{RBS::Test.suffix}_#{random}"
|
32
|
+
|
31
33
|
case target
|
32
34
|
when *OPERATORS.keys
|
33
35
|
name = OPERATORS[target]
|
34
36
|
[
|
35
|
-
"#{name}____with__#{
|
36
|
-
"#{name}____without__#{
|
37
|
+
"#{name}____with__#{suffix}",
|
38
|
+
"#{name}____without__#{suffix}"
|
37
39
|
]
|
38
40
|
else
|
39
41
|
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
40
42
|
|
41
43
|
[
|
42
|
-
"#{aliased_target}__with__#{
|
43
|
-
"#{aliased_target}__without__#{
|
44
|
+
"#{aliased_target}__with__#{suffix}#{punctuation}",
|
45
|
+
"#{aliased_target}__without__#{suffix}#{punctuation}"
|
44
46
|
]
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
def self.setup_alias_method_chain(klass, target)
|
49
|
-
with_method, without_method = alias_names(target)
|
50
|
+
def self.setup_alias_method_chain(klass, target, random:)
|
51
|
+
with_method, without_method = alias_names(target, random)
|
50
52
|
|
51
53
|
RBS.logger.debug "alias name: #{target}, #{with_method}, #{without_method}"
|
52
54
|
|
@@ -65,12 +67,12 @@ module RBS
|
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
68
|
-
def self.hook_method_source(prefix, method_name, key)
|
69
|
-
with_name, without_name = alias_names(method_name)
|
70
|
+
def self.hook_method_source(prefix, method_name, key, random:)
|
71
|
+
with_name, without_name = alias_names(method_name, random)
|
70
72
|
full_method_name = "#{prefix}#{method_name}"
|
71
73
|
|
72
74
|
[__LINE__ + 1, <<RUBY]
|
73
|
-
def #{with_name}(*args)
|
75
|
+
def #{with_name}(*args, &block)
|
74
76
|
::RBS.logger.debug { "#{full_method_name} with arguments: [" + args.map(&:inspect).join(", ") + "]" }
|
75
77
|
|
76
78
|
begin
|
@@ -78,11 +80,17 @@ def #{with_name}(*args)
|
|
78
80
|
block_calls = []
|
79
81
|
|
80
82
|
if block_given?
|
83
|
+
receiver = self
|
81
84
|
result = __send__(:"#{without_name}", *args) do |*block_args|
|
82
85
|
return_from_block = false
|
83
86
|
|
84
87
|
begin
|
85
|
-
block_result =
|
88
|
+
block_result = if receiver.equal?(self)
|
89
|
+
yield(*block_args)
|
90
|
+
else
|
91
|
+
instance_exec(*block_args, &block)
|
92
|
+
end
|
93
|
+
|
86
94
|
return_from_block = true
|
87
95
|
ensure
|
88
96
|
exn = $!
|
@@ -154,17 +162,19 @@ RUBY
|
|
154
162
|
end
|
155
163
|
|
156
164
|
def self.hook_instance_method(klass, method, key:)
|
157
|
-
|
165
|
+
random = SecureRandom.hex(4)
|
166
|
+
line, source = hook_method_source("#{klass}#", method, key, random: random)
|
158
167
|
|
159
168
|
klass.module_eval(source, __FILE__, line)
|
160
|
-
setup_alias_method_chain klass, method
|
169
|
+
setup_alias_method_chain klass, method, random: random
|
161
170
|
end
|
162
171
|
|
163
172
|
def self.hook_singleton_method(klass, method, key:)
|
164
|
-
|
173
|
+
random = SecureRandom.hex(4)
|
174
|
+
line, source = hook_method_source("#{klass}.",method, key, random: random)
|
165
175
|
|
166
176
|
klass.singleton_class.module_eval(source, __FILE__, line)
|
167
|
-
setup_alias_method_chain klass.singleton_class, method
|
177
|
+
setup_alias_method_chain klass.singleton_class, method, random: random
|
168
178
|
end
|
169
179
|
end
|
170
180
|
end
|
data/lib/rbs/test/setup.rb
CHANGED
@@ -2,6 +2,7 @@ require "rbs"
|
|
2
2
|
require "rbs/test"
|
3
3
|
require "optparse"
|
4
4
|
require "shellwords"
|
5
|
+
require "rbs/cli"
|
5
6
|
|
6
7
|
include RBS::Test::SetupHelper
|
7
8
|
|
@@ -32,12 +33,13 @@ if filter.empty?
|
|
32
33
|
exit 1
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
+
options = RBS::CLI::LibraryOptions.new()
|
37
|
+
|
36
38
|
OptionParser.new do |opts|
|
37
|
-
|
38
|
-
opts.on("-I [DIR]") do |dir| loader.add(path: Pathname(dir)) end
|
39
|
+
options.setup_library_options(opts)
|
39
40
|
end.parse!(opts)
|
40
41
|
|
42
|
+
loader = options.loader
|
41
43
|
env = RBS::Environment.from_loader(loader).resolve_type_names
|
42
44
|
|
43
45
|
def match(filter, name)
|
data/lib/rbs/test/type_check.rb
CHANGED
@@ -288,7 +288,12 @@ module RBS
|
|
288
288
|
end
|
289
289
|
when Types::ClassSingleton
|
290
290
|
klass = get_class(type.name) or return false
|
291
|
-
|
291
|
+
singleton_class = begin
|
292
|
+
klass.singleton_class
|
293
|
+
rescue TypeError
|
294
|
+
return false
|
295
|
+
end
|
296
|
+
val.is_a?(singleton_class)
|
292
297
|
when Types::Interface
|
293
298
|
methods = Set.new(Test.call(val, METHODS))
|
294
299
|
if (definition = builder.build_interface(type.name))
|
data/lib/rbs/type_name.rb
CHANGED
data/lib/rbs/vendorer.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module RBS
|
2
2
|
class Vendorer
|
3
3
|
attr_reader :vendor_dir
|
4
|
+
attr_reader :loader
|
4
5
|
|
5
|
-
def initialize(vendor_dir:)
|
6
|
+
def initialize(vendor_dir:, loader:)
|
6
7
|
@vendor_dir = vendor_dir
|
8
|
+
@loader = loader
|
7
9
|
end
|
8
10
|
|
9
11
|
def ensure_dir
|
@@ -21,27 +23,47 @@ module RBS
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def copy!
|
27
|
+
# @type var paths: Set[[Pathname, Pathname]]
|
28
|
+
paths = Set[]
|
29
|
+
|
30
|
+
if core_root = loader.core_root
|
31
|
+
RBS.logger.info "Vendoring core RBSs in #{vendor_dir + "core"}..."
|
32
|
+
loader.each_file(core_root, immediate: false, skip_hidden: true) do |file_path|
|
33
|
+
paths << [file_path, Pathname("core") + file_path.relative_path_from(core_root)]
|
34
|
+
end
|
28
35
|
end
|
29
|
-
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
loader.libs.each do |lib|
|
38
|
+
case
|
39
|
+
when (spec, path = EnvironmentLoader.gem_sig_path(lib.name, lib.version))
|
40
|
+
dest_dir = Pathname("#{lib.name}-#{spec.version}")
|
41
|
+
|
42
|
+
RBS.logger.info "Vendoring #{lib.name}(#{spec.version}) RBSs in #{vendor_dir + dest_dir}..."
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
loader.each_file(path, skip_hidden: true, immediate: false) do |file_path|
|
45
|
+
paths << [file_path, dest_dir + file_path.relative_path_from(path)]
|
46
|
+
end
|
39
47
|
|
40
|
-
|
41
|
-
|
42
|
-
|
48
|
+
when (rbs, path = loader.repository.lookup_path(lib.name, lib.version))
|
49
|
+
dest_dir = Pathname("#{rbs.name}-#{path.version}")
|
50
|
+
|
51
|
+
RBS.logger.info "Vendoring #{lib.name}(#{path.version}) RBSs in #{vendor_dir + dest_dir}..."
|
52
|
+
|
53
|
+
loader.each_file(path.path, skip_hidden: true, immediate: false) do |file_path|
|
54
|
+
paths << [file_path, dest_dir + file_path.relative_path_from(path.path)]
|
55
|
+
end
|
56
|
+
else
|
57
|
+
RBS.logger.error "Couldn't find RBSs for #{lib.name} (#{lib.version}); skipping..."
|
43
58
|
end
|
44
59
|
end
|
60
|
+
|
61
|
+
paths.each do |from, to|
|
62
|
+
dest = vendor_dir + to
|
63
|
+
dest.parent.mkpath unless dest.parent.directory?
|
64
|
+
|
65
|
+
FileUtils.copy_file(from.to_s, dest.to_s)
|
66
|
+
end
|
45
67
|
end
|
46
68
|
end
|
47
69
|
end
|
data/lib/rbs/version.rb
CHANGED
data/sig/cli.rbs
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module RBS
|
2
|
+
class CLI
|
3
|
+
class LibraryOptions
|
4
|
+
attr_accessor core_root: Pathname?
|
5
|
+
|
6
|
+
attr_reader libs: Array[String]
|
7
|
+
attr_reader dirs: Array[String]
|
8
|
+
attr_reader repos: Array[String]
|
9
|
+
|
10
|
+
def initialize: () -> void
|
11
|
+
|
12
|
+
def loader: () -> EnvironmentLoader
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader stdout: IO
|
16
|
+
attr_reader stderr: IO
|
17
|
+
|
18
|
+
def initialize: (stdout: IO, stderr: IO) -> void
|
19
|
+
|
20
|
+
COMMANDS: Array[Symbol]
|
21
|
+
|
22
|
+
def library_parse: (OptionParser, options: LibraryOptions) -> void
|
23
|
+
|
24
|
+
def parse_logging_options: (OptionParser) -> void
|
25
|
+
|
26
|
+
def has_parser?: () -> bool
|
27
|
+
|
28
|
+
def run: (Array[String] args) -> void
|
29
|
+
|
30
|
+
def run_ast: (Array[String], LibraryOptions) -> void
|
31
|
+
|
32
|
+
def run_list: (Array[String], LibraryOptions) -> void
|
33
|
+
|
34
|
+
def run_ancestors: (Array[String], LibraryOptions) -> void
|
35
|
+
|
36
|
+
def run_methods: (Array[String], LibraryOptions) -> void
|
37
|
+
|
38
|
+
def run_method: (Array[String], LibraryOptions) -> void
|
39
|
+
|
40
|
+
def run_validate: (Array[String], LibraryOptions) -> void
|
41
|
+
|
42
|
+
def run_constant: (Array[String], LibraryOptions) -> void
|
43
|
+
|
44
|
+
def run_paths: (Array[String], LibraryOptions) -> void
|
45
|
+
|
46
|
+
def run_prototype: (Array[String], LibraryOptions) -> void
|
47
|
+
|
48
|
+
def run_prototype_file: (String format, Array[String]) -> void
|
49
|
+
|
50
|
+
def run_vendor: (Array[String], LibraryOptions) -> void
|
51
|
+
|
52
|
+
def run_parse: (Array[String], LibraryOptions) -> void
|
53
|
+
|
54
|
+
def run_test: (Array[String], LibraryOptions) -> void
|
55
|
+
|
56
|
+
def test_opt: (LibraryOptions) -> String?
|
57
|
+
end
|
58
|
+
end
|
data/sig/definition.rbs
CHANGED
@@ -21,13 +21,13 @@ module RBS
|
|
21
21
|
attr_reader defined_in: TypeName
|
22
22
|
attr_reader implemented_in: TypeName?
|
23
23
|
|
24
|
-
def initialize: (type: MethodType, member: method_member, defined_in: TypeName
|
24
|
+
def initialize: (type: MethodType, member: method_member, defined_in: TypeName, implemented_in: TypeName?) -> void
|
25
25
|
|
26
26
|
def comment: () -> AST::Comment?
|
27
27
|
|
28
28
|
def annotations: () -> Array[AST::Annotation]
|
29
29
|
|
30
|
-
def update: (?type: MethodType, ?member: method_member, ?defined_in: TypeName
|
30
|
+
def update: (?type: MethodType, ?member: method_member, ?defined_in: TypeName, ?implemented_in: TypeName?) -> TypeDef
|
31
31
|
|
32
32
|
def overload?: () -> bool
|
33
33
|
end
|
@@ -42,8 +42,13 @@ module RBS
|
|
42
42
|
attr_reader comments: Array[AST::Comment]
|
43
43
|
attr_reader annotations: Array[AST::Annotation]
|
44
44
|
attr_reader members: Array[method_member]
|
45
|
+
attr_reader alias_of: Method?
|
45
46
|
|
46
|
-
def initialize: (super_method: Method?,
|
47
|
+
def initialize: (super_method: Method?,
|
48
|
+
defs: Array[TypeDef],
|
49
|
+
accessibility: accessibility,
|
50
|
+
alias_of: Method?,
|
51
|
+
?annotations: Array[AST::Annotation]) -> void
|
47
52
|
|
48
53
|
def public?: () -> bool
|
49
54
|
|
data/sig/definition_builder.rbs
CHANGED
@@ -61,6 +61,8 @@ module RBS
|
|
61
61
|
|
62
62
|
def ensure_namespace!: (Namespace, location: Location?) -> void
|
63
63
|
|
64
|
+
def build_singleton: (TypeName) -> Definition
|
65
|
+
|
64
66
|
def build_instance: (TypeName) -> Definition
|
65
67
|
|
66
68
|
def build_interface: (TypeName) -> Definition
|
@@ -69,11 +71,12 @@ module RBS
|
|
69
71
|
|
70
72
|
def build_one_singleton: (TypeName) -> Definition
|
71
73
|
|
74
|
+
type ancestors = Definition::InstanceAncestors | Definition::SingletonAncestors | nil
|
72
75
|
def merge_definitions: (TypeName,
|
73
76
|
Array[[Definition::Ancestor::t, Definition]],
|
74
77
|
entry: Environment::ModuleEntry | Environment::ClassEntry,
|
75
78
|
self_type: Definition::self_type,
|
76
|
-
ancestors:
|
79
|
+
ancestors: ancestors) -> Definition
|
77
80
|
|
78
81
|
type method_kind = :instance | :singleton
|
79
82
|
def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, kind: method_kind) -> void
|
data/sig/environment_loader.rbs
CHANGED
@@ -1,58 +1,104 @@
|
|
1
1
|
module RBS
|
2
|
+
# EnvironmentLoader is an object to load RBS files from filesystem.
|
3
|
+
#
|
4
|
+
# Set up your configuration through repository and `#add` method.
|
5
|
+
#
|
6
|
+
# # Set up the repository to load library RBSs from.
|
7
|
+
# repo = RBS::Repository.default
|
8
|
+
# repo.add(Pathname("vendor/rbs/gem-rbs"))
|
9
|
+
# repo.add(Pathname("vendor/rbs/internal-rbs"))
|
10
|
+
#
|
11
|
+
# loader = RBS::EnvironmentLoader.new(repository: repo)
|
12
|
+
#
|
13
|
+
# # Add libraries to load RBS files.
|
14
|
+
# loader.add(library: "minitest")
|
15
|
+
# loader.add(library: "rbs", version: "1.0.0")
|
16
|
+
#
|
17
|
+
# # Add dirs to load RBS files from.
|
18
|
+
# loader.add(path: Pathname("sig"))
|
19
|
+
#
|
20
|
+
# # Load RBSs into an environment.
|
21
|
+
# environment = RBS::Environment.new()
|
22
|
+
# loader.load(env: environment)
|
23
|
+
#
|
2
24
|
class EnvironmentLoader
|
3
|
-
class
|
4
|
-
attr_reader
|
5
|
-
|
6
|
-
def initialize: (name: String) -> void
|
7
|
-
end
|
8
|
-
|
9
|
-
class LibraryPath
|
10
|
-
attr_reader name: String
|
11
|
-
attr_reader path: Pathname
|
25
|
+
class UnknownLibraryError < StandardError
|
26
|
+
attr_reader library: Library
|
12
27
|
|
13
|
-
def initialize: (
|
28
|
+
def initialize: (lib: Library) -> void
|
14
29
|
end
|
15
30
|
|
16
|
-
class
|
31
|
+
class Library < Struct[String | String?]
|
17
32
|
attr_reader name: String
|
18
33
|
attr_reader version: String?
|
19
|
-
attr_reader path: Pathname
|
20
34
|
|
21
|
-
def initialize: (name: String, version: String
|
35
|
+
def initialize: (name: String, version: String?) -> void
|
22
36
|
end
|
23
37
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
attr_reader
|
30
|
-
attr_reader
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
38
|
+
DEFAULT_CORE_ROOT: Pathname
|
39
|
+
|
40
|
+
attr_reader core_root: Pathname?
|
41
|
+
attr_reader repository: Repository
|
42
|
+
|
43
|
+
attr_reader libs: Array[Library]
|
44
|
+
attr_reader dirs: Array[Pathname]
|
45
|
+
|
46
|
+
# The source where the RBS comes from.
|
47
|
+
#
|
48
|
+
# `:core` means it is part of core library.
|
49
|
+
# `Library` means it is from library.
|
50
|
+
# `Pathname` means it is loaded from a directory.
|
51
|
+
#
|
52
|
+
type source = :core
|
53
|
+
| Library
|
54
|
+
| Pathname
|
55
|
+
|
56
|
+
# Accepts two optional keyword arguments.
|
57
|
+
#
|
58
|
+
# `core_root` is the path to the directory with RBSs for core classes.
|
59
|
+
# The default value is the core library included in RBS gem. (EnvironmentLoader::DEFAULT_CORE_ROOT)
|
60
|
+
# Passing `nil` means it skips loading core class definitions.
|
61
|
+
#
|
62
|
+
# `repository` is the repository for library classes.
|
63
|
+
# The default value is repository only with stdlib classes. (Repository.new)
|
64
|
+
#
|
65
|
+
def initialize: (?core_root: Pathname?, ?repository: Repository) -> void
|
66
|
+
|
67
|
+
# Add a path or library to load RBSs from.
|
68
|
+
#
|
69
|
+
# `path` can be a file or a directory.
|
70
|
+
# All `.rbs` files from the given directory will be loaded.
|
71
|
+
# Specifying a file will load the file regardless the extension of the file is.
|
72
|
+
#
|
73
|
+
# `library` can be a name of a gem.
|
74
|
+
# Specifying `nil` to `version` will load any version available.
|
75
|
+
# It first tries to load RBS files from gem with specified version.
|
76
|
+
# If RBS files cannot be found in the gem, it tries to load RBSs from repository.
|
77
|
+
#
|
78
|
+
def add: (path: Pathname) -> void
|
79
|
+
| (library: String, version: String?) -> void
|
80
|
+
|
81
|
+
# This is helper function to test if RBS for a library is available or not.
|
82
|
+
#
|
83
|
+
def has_library?: (library: String, version: String?) -> bool
|
84
|
+
|
85
|
+
# Add all declarations to environment.
|
86
|
+
#
|
87
|
+
# Raises `UnknownLibraryError` if RBS cannot be loaded from a library.
|
88
|
+
#
|
89
|
+
# Returns an array of tuples of the declaration, path to the file, and the source.
|
90
|
+
#
|
91
|
+
def load: (env: Environment) -> Array[[AST::Declarations::t, Pathname, source]]
|
92
|
+
|
93
|
+
# Returns a pair of spec and path for a gem with RBS.
|
94
|
+
# Returns nil if the gem is not installed, or the gem doesn't provide RBS.
|
95
|
+
#
|
96
|
+
def self.gem_sig_path: (String name, String? version) -> [Gem::Specification, Pathname]?
|
97
|
+
|
98
|
+
def each_decl: () { (AST::Declarations::t, Buffer, source, Pathname) -> void } -> void
|
99
|
+
|
100
|
+
def each_dir: { (source, Pathname) -> void } -> void
|
101
|
+
|
102
|
+
def each_file: (Pathname path, immediate: boolish, skip_hidden: boolish) { (Pathname) -> void } -> void
|
57
103
|
end
|
58
104
|
end
|