rbs 0.12.2 → 0.16.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/.gitignore +0 -1
- data/CHANGELOG.md +32 -0
- data/Gemfile +4 -0
- data/README.md +8 -2
- data/Rakefile +9 -2
- data/Steepfile +1 -1
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/bin/test_runner.rb +15 -1
- data/{stdlib/builtin → core}/array.rbs +124 -120
- data/{stdlib/builtin → core}/basic_object.rbs +54 -54
- data/{stdlib/builtin → core}/binding.rbs +42 -42
- data/core/builtin.rbs +70 -0
- data/{stdlib/builtin → core}/class.rbs +33 -33
- data/{stdlib/builtin → core}/comparable.rbs +0 -0
- data/{stdlib/builtin → core}/complex.rbs +90 -90
- 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 +0 -0
- data/{stdlib/builtin → core}/encoding.rbs +33 -33
- data/{stdlib/builtin → core}/enumerable.rbs +58 -52
- data/{stdlib/builtin → core}/enumerator.rbs +35 -35
- data/{stdlib/builtin → core}/errno.rbs +0 -0
- data/{stdlib/builtin → core}/errors.rbs +2 -2
- data/{stdlib/builtin → core}/exception.rbs +50 -50
- data/{stdlib/builtin → core}/false_class.rbs +6 -6
- data/{stdlib/builtin → core}/fiber.rbs +14 -14
- data/{stdlib/builtin → core}/fiber_error.rbs +1 -1
- data/{stdlib/builtin → core}/file.rbs +0 -0
- data/{stdlib/builtin → core}/file_test.rbs +0 -0
- data/{stdlib/builtin → core}/float.rbs +161 -161
- data/{stdlib/builtin → core}/gc.rbs +3 -3
- data/{stdlib/builtin → core}/hash.rbs +7 -7
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +88 -88
- data/{stdlib/builtin → core}/kernel.rbs +71 -153
- data/{stdlib/builtin → core}/marshal.rbs +0 -0
- data/{stdlib/builtin → core}/match_data.rbs +1 -1
- data/{stdlib/builtin → core}/math.rbs +0 -0
- data/{stdlib/builtin → core}/method.rbs +19 -19
- data/{stdlib/builtin → core}/module.rbs +13 -13
- data/{stdlib/builtin → core}/nil_class.rbs +20 -20
- data/{stdlib/builtin → core}/numeric.rbs +101 -101
- data/{stdlib/builtin → core}/object.rbs +173 -173
- data/{stdlib/builtin → core}/proc.rbs +91 -91
- data/{stdlib/builtin → core}/process.rbs +0 -0
- data/{stdlib/builtin → core}/random.rbs +1 -1
- data/{stdlib/builtin → core}/range.rbs +3 -5
- data/{stdlib/builtin → core}/rational.rbs +83 -83
- 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 +7 -7
- data/{stdlib/builtin → core}/string.rbs +10 -10
- data/{stdlib/builtin → core}/string_io.rbs +8 -8
- data/{stdlib/builtin → core}/struct.rbs +1 -1
- data/{stdlib/builtin → core}/symbol.rbs +1 -1
- data/{stdlib/builtin → core}/thread.rbs +189 -189
- data/{stdlib/builtin → core}/thread_group.rbs +2 -2
- data/{stdlib/builtin → core}/time.rbs +0 -0
- data/{stdlib/builtin → core}/trace_point.rbs +0 -0
- data/{stdlib/builtin → core}/true_class.rbs +10 -10
- data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
- data/{stdlib/builtin → core}/warning.rbs +1 -1
- data/docs/CONTRIBUTING.md +1 -0
- data/docs/repo.md +125 -0
- data/docs/syntax.md +50 -6
- data/goodcheck.yml +22 -5
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/cli.rb +117 -107
- data/lib/rbs/constant.rb +1 -1
- data/lib/rbs/constant_table.rb +9 -8
- data/lib/rbs/definition_builder.rb +6 -7
- data/lib/rbs/environment.rb +5 -1
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3148 -0
- data/lib/rbs/parser.y +10 -3
- data/lib/rbs/prototype/rb.rb +38 -6
- data/lib/rbs/prototype/runtime.rb +17 -7
- data/lib/rbs/repository.rb +121 -0
- data/lib/rbs/test/hook.rb +2 -0
- data/lib/rbs/test/setup.rb +5 -3
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/tester.rb +4 -1
- data/lib/rbs/test/type_check.rb +12 -6
- data/lib/rbs/type_name.rb +3 -2
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +25 -15
- data/sig/cli.rbs +58 -0
- data/sig/constant.rbs +21 -0
- data/sig/constant_table.rbs +30 -0
- data/sig/declarations.rbs +2 -2
- data/sig/definition.rbs +2 -2
- data/sig/definition_builder.rbs +6 -5
- data/sig/environment_loader.rbs +100 -0
- data/sig/members.rbs +2 -2
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +4 -4
- data/sig/parser.rbs +25 -0
- data/sig/polyfill.rbs +42 -0
- data/sig/rbs.rbs +8 -0
- data/sig/repository.rbs +79 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/vendorer.rbs +44 -0
- data/sig/version.rbs +3 -0
- data/sig/writer.rbs +40 -0
- data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
- data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
- data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +2 -2
- 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} +2 -2
- data/stdlib/csv/{csv.rbs → 0/csv.rbs} +1 -1
- data/stdlib/date/{date.rbs → 0/date.rbs} +4 -4
- data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
- 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} +12 -12
- 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} +1 -1
- data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
- data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
- data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
- data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
- data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +41 -39
- data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
- data/stdlib/prime/{prime.rbs → 0/prime.rbs} +0 -0
- data/stdlib/pstore/0/pstore.rbs +287 -0
- data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
- data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
- data/stdlib/set/{set.rbs → 0/set.rbs} +0 -0
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +12 -12
- data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
- data/stdlib/uri/{generic.rbs → 0/generic.rbs} +2 -2
- data/stdlib/uri/0/http.rbs +158 -0
- data/stdlib/uri/0/https.rbs +108 -0
- data/stdlib/uri/0/ldap.rbs +224 -0
- data/stdlib/uri/0/ldaps.rbs +108 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +13 -17
- metadata +105 -89
- data/stdlib/builtin/builtin.rbs +0 -42
data/lib/rbs/type_name.rb
CHANGED
@@ -16,14 +16,15 @@ module RBS
|
|
16
16
|
when "_"
|
17
17
|
:interface
|
18
18
|
else
|
19
|
-
|
19
|
+
# Defaults to :class
|
20
|
+
:class
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
def ==(other)
|
24
25
|
other.is_a?(self.class) && other.namespace == namespace && other.name == name
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
alias eql? ==
|
28
29
|
|
29
30
|
def hash
|
@@ -120,7 +120,7 @@ module RBS
|
|
120
120
|
|
121
121
|
type.args.each.with_index do |ty, i|
|
122
122
|
var = type_params.params[i]
|
123
|
-
case var
|
123
|
+
case var&.variance
|
124
124
|
when :invariant
|
125
125
|
type(ty, result: result, context: :invariant)
|
126
126
|
when :covariant
|
@@ -135,7 +135,7 @@ module RBS
|
|
135
135
|
when :contravariant
|
136
136
|
:covariant
|
137
137
|
else
|
138
|
-
raise
|
138
|
+
raise
|
139
139
|
end
|
140
140
|
type(ty, result: result, context: con)
|
141
141
|
end
|
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/lib/rbs/writer.rb
CHANGED
@@ -60,6 +60,8 @@ module RBS
|
|
60
60
|
|
61
61
|
def write(decls)
|
62
62
|
[nil, *decls].each_cons(2) do |prev, decl|
|
63
|
+
raise unless decl
|
64
|
+
|
63
65
|
preserve_empty_line(prev, decl)
|
64
66
|
write_decl decl
|
65
67
|
end
|
@@ -68,8 +70,8 @@ module RBS
|
|
68
70
|
def write_decl(decl)
|
69
71
|
case decl
|
70
72
|
when AST::Declarations::Class
|
71
|
-
super_class = if decl.super_class
|
72
|
-
" < #{name_and_args(
|
73
|
+
super_class = if super_class = decl.super_class
|
74
|
+
" < #{name_and_args(super_class.name, super_class.args)}"
|
73
75
|
end
|
74
76
|
write_comment decl.comment
|
75
77
|
write_annotation decl.annotations
|
@@ -77,6 +79,8 @@ module RBS
|
|
77
79
|
|
78
80
|
indent do
|
79
81
|
[nil, *decl.members].each_cons(2) do |prev, member|
|
82
|
+
raise unless member
|
83
|
+
|
80
84
|
preserve_empty_line prev, member
|
81
85
|
write_member member
|
82
86
|
end
|
@@ -134,9 +138,6 @@ module RBS
|
|
134
138
|
|
135
139
|
puts "end"
|
136
140
|
|
137
|
-
when AST::Declarations::Extension
|
138
|
-
RBS.logger.warn "Extension is ignored: #{decl.name}"
|
139
|
-
|
140
141
|
end
|
141
142
|
end
|
142
143
|
|
@@ -288,20 +289,29 @@ module RBS
|
|
288
289
|
end
|
289
290
|
|
290
291
|
def preserve_empty_line(prev, decl)
|
291
|
-
|
292
|
+
# @type var decl: _Located
|
292
293
|
|
293
|
-
|
294
|
+
return unless prev
|
294
295
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
return
|
296
|
+
if (_ = decl).respond_to?(:comment)
|
297
|
+
if comment = (_ = decl).comment
|
298
|
+
decl = comment
|
299
|
+
end
|
300
300
|
end
|
301
301
|
|
302
|
-
|
303
|
-
|
304
|
-
|
302
|
+
prev_loc = prev.location
|
303
|
+
decl_loc = decl.location
|
304
|
+
|
305
|
+
if prev_loc && decl_loc
|
306
|
+
prev_end_line = prev_loc.end_line
|
307
|
+
start_line = decl_loc.start_line
|
308
|
+
|
309
|
+
if start_line - prev_end_line > 1
|
310
|
+
puts
|
311
|
+
end
|
312
|
+
else
|
313
|
+
# When the signature is not constructed by the parser,
|
314
|
+
# it always inserts an empty line.
|
305
315
|
puts
|
306
316
|
end
|
307
317
|
end
|
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/constant.rbs
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module RBS
|
2
|
+
class Constant
|
3
|
+
type constant_entry = Environment::ClassEntry
|
4
|
+
| Environment::ModuleEntry
|
5
|
+
| Environment::SingleEntry[TypeName, AST::Declarations::Constant]
|
6
|
+
|
7
|
+
attr_reader name: TypeName
|
8
|
+
|
9
|
+
attr_reader type: Types::t
|
10
|
+
|
11
|
+
attr_reader entry: constant_entry
|
12
|
+
|
13
|
+
def initialize: (name: TypeName, type: Types::t, entry: constant_entry) -> void
|
14
|
+
|
15
|
+
def ==: (untyped other) -> bool
|
16
|
+
|
17
|
+
alias eql? ==
|
18
|
+
|
19
|
+
def hash: () -> Integer
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RBS
|
2
|
+
class ConstantTable
|
3
|
+
attr_reader definition_builder: DefinitionBuilder
|
4
|
+
attr_reader constant_scopes_cache: Hash[TypeName, Array[Namespace]]
|
5
|
+
attr_reader resolver: TypeNameResolver
|
6
|
+
attr_reader env(): Environment
|
7
|
+
|
8
|
+
def initialize: (builder: DefinitionBuilder) -> void
|
9
|
+
|
10
|
+
def absolute_type: (Types::t, context: Array[Namespace]) -> Types::t
|
11
|
+
|
12
|
+
def absolute_type_name: (TypeName, context: Array[Namespace], location: Location?) -> TypeName
|
13
|
+
|
14
|
+
def name_to_constant: (TypeName) -> Constant?
|
15
|
+
|
16
|
+
def split_name: (TypeName) -> Array[Symbol]
|
17
|
+
|
18
|
+
def resolve_constant_reference: (TypeName name, context: Array[Namespace]) -> Constant?
|
19
|
+
|
20
|
+
def resolve_constant_reference_context: (Symbol, context: Array[Namespace]) -> Constant?
|
21
|
+
|
22
|
+
def resolve_constant_reference_inherit: (Symbol, scopes: Array[Namespace], ?no_object: boolish) -> Constant?
|
23
|
+
|
24
|
+
def constant_scopes: (TypeName) -> Array[Namespace]
|
25
|
+
|
26
|
+
def constant_scopes_module: (TypeName, scopes: Array[Namespace]) -> Array[Namespace]
|
27
|
+
|
28
|
+
def constant_scopes0: (TypeName, ?scopes: Array[Namespace]) -> Array[Namespace]
|
29
|
+
end
|
30
|
+
end
|
data/sig/declarations.rbs
CHANGED
@@ -2,7 +2,7 @@ module RBS
|
|
2
2
|
module AST
|
3
3
|
module Declarations
|
4
4
|
type t = Class | Module | Interface | Constant | Global | Alias
|
5
|
-
|
5
|
+
|
6
6
|
class Base
|
7
7
|
end
|
8
8
|
|
@@ -14,7 +14,7 @@ module RBS
|
|
14
14
|
attr_reader variance: variance
|
15
15
|
attr_reader skip_validation: bool
|
16
16
|
|
17
|
-
def initialize: (name: Symbol, variance: variance, skip_validation:
|
17
|
+
def initialize: (name: Symbol, variance: variance, skip_validation: boolish) -> void
|
18
18
|
|
19
19
|
include _ToJson
|
20
20
|
end
|
data/sig/definition.rbs
CHANGED
@@ -18,7 +18,7 @@ module RBS
|
|
18
18
|
class TypeDef
|
19
19
|
attr_reader type: MethodType
|
20
20
|
attr_reader member: method_member
|
21
|
-
attr_reader defined_in: TypeName
|
21
|
+
attr_reader defined_in: TypeName
|
22
22
|
attr_reader implemented_in: TypeName?
|
23
23
|
|
24
24
|
def initialize: (type: MethodType, member: method_member, defined_in: TypeName?, implemented_in: TypeName?) -> void
|
@@ -28,7 +28,7 @@ module RBS
|
|
28
28
|
def annotations: () -> Array[AST::Annotation]
|
29
29
|
|
30
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
|
34
34
|
|
data/sig/definition_builder.rbs
CHANGED
@@ -29,14 +29,14 @@ module RBS
|
|
29
29
|
|
30
30
|
attr_reader env: Environment
|
31
31
|
attr_reader type_name_resolver: TypeNameResolver
|
32
|
-
|
32
|
+
|
33
33
|
attr_reader instance_cache: Hash[TypeName, Definition | false | nil]
|
34
34
|
attr_reader singleton_cache: Hash[TypeName, Definition | false | nil]
|
35
35
|
attr_reader interface_cache: Hash[TypeName, Definition | false | nil]
|
36
36
|
|
37
37
|
attr_reader one_instance_cache: Hash[TypeName, Definition]
|
38
38
|
attr_reader one_singleton_cache: Hash[TypeName, Definition]
|
39
|
-
|
39
|
+
|
40
40
|
attr_reader instance_ancestors_cache: Hash[TypeName, Definition::InstanceAncestors]
|
41
41
|
attr_reader singleton_ancestor_cache: Hash[TypeName, Definition::SingletonAncestors]
|
42
42
|
|
@@ -48,7 +48,7 @@ module RBS
|
|
48
48
|
def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
|
49
49
|
|
50
50
|
def one_instance_ancestors: (TypeName) -> OneAncestors
|
51
|
-
|
51
|
+
|
52
52
|
def one_singleton_ancestors: (TypeName) -> OneAncestors
|
53
53
|
|
54
54
|
def instance_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
|
@@ -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,7 +71,7 @@ module RBS
|
|
69
71
|
|
70
72
|
def build_one_singleton: (TypeName) -> Definition
|
71
73
|
|
72
|
-
def merge_definitions: (TypeName,
|
74
|
+
def merge_definitions: (TypeName,
|
73
75
|
Array[[Definition::Ancestor::t, Definition]],
|
74
76
|
entry: Environment::ModuleEntry | Environment::ClassEntry,
|
75
77
|
self_type: Definition::self_type,
|
@@ -92,4 +94,3 @@ module RBS
|
|
92
94
|
def expand_alias: (TypeName) -> Types::t
|
93
95
|
end
|
94
96
|
end
|
95
|
-
|
data/sig/environment_loader.rbs
CHANGED
@@ -1,4 +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
|
25
|
+
class UnknownLibraryError < StandardError
|
26
|
+
attr_reader library: Library
|
27
|
+
|
28
|
+
def initialize: (lib: Library) -> void
|
29
|
+
end
|
30
|
+
|
31
|
+
class Library < Struct[String | String?]
|
32
|
+
attr_reader name: String
|
33
|
+
attr_reader version: String?
|
34
|
+
|
35
|
+
def initialize: (name: String, version: String?) -> void
|
36
|
+
end
|
37
|
+
|
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
|
3
103
|
end
|
4
104
|
end
|