rbs 3.0.0.dev.1 → 3.0.0.dev.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -3
- data/CHANGELOG.md +28 -0
- data/Gemfile.lock +12 -12
- data/README.md +1 -0
- data/Rakefile +77 -3
- data/Steepfile +1 -1
- data/core/array.rbs +574 -424
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +9 -1
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +114 -176
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +111 -18
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/constants.c +16 -2
- data/ext/rbs_extension/constants.h +8 -1
- data/ext/rbs_extension/extconf.rb +1 -1
- data/ext/rbs_extension/lexer.c +834 -777
- data/ext/rbs_extension/lexer.h +3 -1
- data/ext/rbs_extension/lexer.re +3 -1
- data/ext/rbs_extension/lexstate.c +4 -2
- data/ext/rbs_extension/parser.c +262 -43
- data/ext/rbs_extension/ruby_objs.c +56 -2
- data/ext/rbs_extension/ruby_objs.h +7 -1
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/ast/declarations.rb +49 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +37 -30
- data/lib/rbs/collection/config.rb +3 -3
- data/lib/rbs/collection/sources/git.rb +10 -3
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder.rb +8 -8
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +358 -88
- data/lib/rbs/environment_loader.rb +12 -9
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +52 -37
- data/lib/rbs/locator.rb +27 -8
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +5 -5
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/type_alias_dependency.rb +1 -1
- data/lib/rbs/type_alias_regularity.rb +3 -3
- data/lib/rbs/validator.rb +23 -2
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +28 -2
- data/lib/rbs.rb +2 -2
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +1 -1
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile_generator.rbs +8 -10
- data/sig/collection/config.rbs +1 -1
- data/sig/collection/sources.rbs +44 -9
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +0 -1
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -29
- data/sig/environment_loader.rbs +1 -1
- data/sig/errors.rbs +22 -1
- data/sig/locator.rbs +14 -2
- data/sig/parser.rbs +8 -15
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/sig/shims/bundler.rbs +18 -0
- data/sig/shims/rubygems.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +4 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +13 -13
- data/core/deprecated.rbs +0 -9
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- data/sig/shims/ripper.rbs +0 -8
- data/sig/type_name_resolver.rbs +0 -26
- data/steep/Gemfile +0 -3
- data/steep/Gemfile.lock +0 -61
@@ -13,18 +13,18 @@ module RBS
|
|
13
13
|
end
|
14
14
|
|
15
15
|
attr_reader config: Config
|
16
|
-
attr_reader gemfile_lock: Bundler::LockfileParser
|
17
16
|
|
18
17
|
attr_reader lockfile: Lockfile
|
19
18
|
attr_reader existing_lockfile: Lockfile?
|
20
19
|
|
21
|
-
|
20
|
+
attr_reader definition: Bundler::Definition
|
22
21
|
|
23
|
-
|
22
|
+
# A hash table to look up a spec from name of the gem
|
23
|
+
attr_reader gem_hash: Hash[String, Bundler::LazySpecification]
|
24
24
|
|
25
|
-
def self.generate: (config: Config,
|
25
|
+
def self.generate: (config: Config, definition: Bundler::Definition, ?with_lockfile: boolish) -> Lockfile
|
26
26
|
|
27
|
-
def initialize: (config: Config,
|
27
|
+
def initialize: (config: Config, definition: Bundler::Definition, with_lockfile: boolish) -> void
|
28
28
|
|
29
29
|
def generate: () -> void
|
30
30
|
|
@@ -34,14 +34,12 @@ module RBS
|
|
34
34
|
#
|
35
35
|
def validate_gemfile_lock_path!: (lock: Lockfile?, gemfile_lock_path: Pathname) -> void
|
36
36
|
|
37
|
-
|
37
|
+
# Inserts a entry to lockfile of a gem and its dependencies, if not included in `ignored_gems:`
|
38
|
+
#
|
39
|
+
def assign_gem: (name: String, version: String?, src_data: Sources::source_entry?, ignored_gems: Set[String]) -> void
|
38
40
|
|
39
41
|
def assign_stdlib: (name: String, from_gem: String?) -> void
|
40
42
|
|
41
|
-
def gemfile_lock_gems: () { (untyped) -> void } -> void
|
42
|
-
|
43
|
-
def remove_ignored_gems!: () -> void
|
44
|
-
|
45
43
|
# Find a source of a gem from ones registered in `config.sources`
|
46
44
|
#
|
47
45
|
# Returns `nil` if no source contains the definition of the gem.
|
data/sig/collection/config.rbs
CHANGED
@@ -23,7 +23,7 @@ module RBS
|
|
23
23
|
|
24
24
|
def self.find_config_path: () -> Pathname?
|
25
25
|
|
26
|
-
def self.generate_lockfile: (config_path: Pathname,
|
26
|
+
def self.generate_lockfile: (config_path: Pathname, definition: Bundler::Definition, ?with_lockfile: boolish) -> [Config, Lockfile]
|
27
27
|
|
28
28
|
def self.from_path: (Pathname path) -> Config
|
29
29
|
|
data/sig/collection/sources.rbs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module RBS
|
2
2
|
module Collection
|
3
3
|
module Sources
|
4
|
-
def self.from_config_entry: (Git::source_entry) -> Git
|
5
|
-
| (source_entry) -> t
|
4
|
+
def self.from_config_entry: (Git::source_entry, base_directory: Pathname) -> Git
|
5
|
+
| (source_entry, base_directory: Pathname) -> t
|
6
6
|
|
7
7
|
interface _Source
|
8
8
|
def has?: (String name, String? version) -> boolish
|
@@ -13,11 +13,12 @@ module RBS
|
|
13
13
|
def dependencies_of: (String name, String version) -> Array[manifest_dependency]?
|
14
14
|
end
|
15
15
|
|
16
|
-
type t = Git | Stdlib | Rubygems
|
16
|
+
type t = Git | Stdlib | Rubygems | Local
|
17
17
|
|
18
18
|
type source_entry = Git::source_entry
|
19
19
|
| Stdlib::source_entry
|
20
20
|
| Rubygems::source_entry
|
21
|
+
| Local::source_entry
|
21
22
|
|
22
23
|
type manifest_entry = {
|
23
24
|
"dependencies" => Array[manifest_dependency]?,
|
@@ -78,28 +79,34 @@ module RBS
|
|
78
79
|
|
79
80
|
def cp_r: (Pathname, Pathname) -> void
|
80
81
|
|
81
|
-
# Ensure the git repository
|
82
|
+
# Ensure the git repository exists, and
|
82
83
|
#
|
83
|
-
# *
|
84
|
-
# *
|
84
|
+
# * When `revision` is a commit hash, the commit exists in the local repository, or
|
85
|
+
# * When `revision` is a branch name, the latest version is fetched from `origin`
|
86
|
+
#
|
87
|
+
# It may require a network connection to fetch or clone the repository from remote.
|
88
|
+
#
|
89
|
+
# * If `revision` is a commit hash and the commit doesn't exists in the local repository, it runs `git fetch`
|
90
|
+
# * If `revision` is a branch name, it runs `git fetch` once per instance
|
85
91
|
#
|
86
92
|
def setup!: [T] () { () -> T } -> T
|
87
93
|
| () -> void
|
88
94
|
|
89
95
|
def need_to_fetch?: (String revision) -> bool
|
90
96
|
|
97
|
+
# The full path of local git repository
|
91
98
|
def git_dir: () -> Pathname
|
92
99
|
|
100
|
+
# The full path of `repo_dir` in the local git repository
|
93
101
|
def gem_repo_dir: () -> Pathname
|
94
102
|
|
95
|
-
def with_revision: [T] () { () -> T } -> T
|
96
|
-
|
97
103
|
# Returns `true` if `revision` looks like a commit hash
|
98
|
-
#
|
99
104
|
def commit_hash?: () -> bool
|
100
105
|
|
106
|
+
# Executes a git command, raises an error if failed
|
101
107
|
def git: (*String cmd, **untyped opt) -> String
|
102
108
|
|
109
|
+
# Executes a git command, returns `nil` if failed
|
103
110
|
def git?: (*String cmd, **untyped opt) -> String?
|
104
111
|
|
105
112
|
def sh!: (*String cmd, **untyped opt) -> String
|
@@ -120,6 +127,34 @@ module RBS
|
|
120
127
|
def gems_versions: () -> Hash[String, Set[String]]
|
121
128
|
end
|
122
129
|
|
130
|
+
class Local
|
131
|
+
include Base
|
132
|
+
|
133
|
+
type source_entry = {
|
134
|
+
'type' => 'local',
|
135
|
+
'path' => String,
|
136
|
+
}
|
137
|
+
|
138
|
+
attr_reader path: Pathname
|
139
|
+
attr_reader full_path: Pathname
|
140
|
+
|
141
|
+
def initialize: (path: String, base_directory: Pathname) -> void
|
142
|
+
|
143
|
+
def has?: (String name, String? version) -> boolish
|
144
|
+
|
145
|
+
def versions: (String name) -> Array[String]
|
146
|
+
|
147
|
+
def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
|
148
|
+
|
149
|
+
def to_lockfile: () -> source_entry
|
150
|
+
|
151
|
+
def manifest_of: (String name, String version) -> manifest_entry?
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
def _install: (Pathname src, Pathname dest) -> void
|
156
|
+
end
|
157
|
+
|
123
158
|
# signatures that are bundled in rbs gem under the stdlib/ directory
|
124
159
|
class Stdlib
|
125
160
|
|
data/sig/constant.rbs
CHANGED
data/sig/declarations.rbs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module RBS
|
2
2
|
module AST
|
3
3
|
module Declarations
|
4
|
-
type t = Class | Module | Interface | Constant | Global |
|
4
|
+
type t = Class | Module | Interface | Constant | Global | TypeAlias | ClassAlias | ModuleAlias
|
5
5
|
|
6
6
|
class Base
|
7
7
|
end
|
@@ -135,7 +135,7 @@ module RBS
|
|
135
135
|
include _ToJson
|
136
136
|
end
|
137
137
|
|
138
|
-
class Interface
|
138
|
+
class Interface < Base
|
139
139
|
type member = Members::t
|
140
140
|
|
141
141
|
# interface _Foo end
|
@@ -166,7 +166,7 @@ module RBS
|
|
166
166
|
include _ToJson
|
167
167
|
end
|
168
168
|
|
169
|
-
class
|
169
|
+
class TypeAlias < Base
|
170
170
|
# type loc[T] = Location[T, bot]
|
171
171
|
# ^^^^ keyword
|
172
172
|
# ^^^ name
|
@@ -223,6 +223,39 @@ module RBS
|
|
223
223
|
include _HashEqual
|
224
224
|
include _ToJson
|
225
225
|
end
|
226
|
+
|
227
|
+
class AliasDecl < Base
|
228
|
+
# module Foo = Bar
|
229
|
+
# ^^^^^^ keyword
|
230
|
+
# ^^^ new_name
|
231
|
+
# ^ eq
|
232
|
+
# ^^^ old_name
|
233
|
+
#
|
234
|
+
# class Foo = Bar
|
235
|
+
# ^^^^^ keyword
|
236
|
+
#
|
237
|
+
type loc = Location[:keyword | :new_name | :eq | :old_name, bot]
|
238
|
+
|
239
|
+
attr_reader new_name: TypeName
|
240
|
+
|
241
|
+
attr_reader old_name: TypeName
|
242
|
+
|
243
|
+
attr_reader location: loc?
|
244
|
+
|
245
|
+
attr_reader comment: Comment?
|
246
|
+
|
247
|
+
def initialize: (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?) -> void
|
248
|
+
|
249
|
+
include _HashEqual
|
250
|
+
end
|
251
|
+
|
252
|
+
class ClassAlias < AliasDecl
|
253
|
+
include _ToJson
|
254
|
+
end
|
255
|
+
|
256
|
+
class ModuleAlias < AliasDecl
|
257
|
+
include _ToJson
|
258
|
+
end
|
226
259
|
end
|
227
260
|
end
|
228
261
|
end
|
data/sig/definition.rbs
CHANGED
@@ -119,7 +119,7 @@ module RBS
|
|
119
119
|
end
|
120
120
|
|
121
121
|
type self_type = Types::ClassSingleton | Types::ClassInstance | Types::Interface
|
122
|
-
type definition_entry = Environment::ModuleEntry | Environment::ClassEntry | Environment::
|
122
|
+
type definition_entry = Environment::ModuleEntry | Environment::ClassEntry | Environment::InterfaceEntry
|
123
123
|
|
124
124
|
attr_reader type_name: TypeName
|
125
125
|
attr_reader entry: definition_entry
|
data/sig/definition_builder.rbs
CHANGED
data/sig/directives.rbs
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module RBS
|
2
|
+
module AST
|
3
|
+
module Directives
|
4
|
+
type t = Use
|
5
|
+
|
6
|
+
class Base
|
7
|
+
end
|
8
|
+
|
9
|
+
# ```
|
10
|
+
# use Foo, Foo::Bar as FBar, Foo:Baz::*
|
11
|
+
# ```
|
12
|
+
#
|
13
|
+
class Use < Base
|
14
|
+
type clause = SingleClause | WildcardClause
|
15
|
+
|
16
|
+
class SingleClause
|
17
|
+
# Foo::Bar
|
18
|
+
# ^^^^^^^^ type_name
|
19
|
+
#
|
20
|
+
# Foo::Bar as X
|
21
|
+
# ^^ keyword
|
22
|
+
# ^ new_name
|
23
|
+
#
|
24
|
+
type loc = Location[:type_name, :keyword | :new_name]
|
25
|
+
|
26
|
+
attr_reader type_name: TypeName
|
27
|
+
|
28
|
+
attr_reader new_name: Symbol?
|
29
|
+
|
30
|
+
attr_reader location: loc?
|
31
|
+
|
32
|
+
def initialize: (type_name: TypeName, new_name: Symbol?, location: loc?) -> void
|
33
|
+
end
|
34
|
+
|
35
|
+
class WildcardClause
|
36
|
+
# Foo::Bar::*
|
37
|
+
# ^^^^^^^^^^ namespace
|
38
|
+
# ^ star
|
39
|
+
#
|
40
|
+
type loc = Location[:namespace | :star, bot]
|
41
|
+
|
42
|
+
attr_reader namespace: Namespace
|
43
|
+
|
44
|
+
attr_reader location: loc?
|
45
|
+
|
46
|
+
def initialize: (namespace: Namespace, location: loc?) -> void
|
47
|
+
end
|
48
|
+
|
49
|
+
# use Foo
|
50
|
+
# ^^^ keyword
|
51
|
+
type loc = Location[:keyword, bot]
|
52
|
+
|
53
|
+
attr_reader clauses: Array[clause]
|
54
|
+
|
55
|
+
attr_reader location: loc?
|
56
|
+
|
57
|
+
def initialize: (clauses: Array[clause], location: loc?) -> void
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/sig/environment.rbs
CHANGED
@@ -13,9 +13,11 @@ module RBS
|
|
13
13
|
end
|
14
14
|
|
15
15
|
module ContextUtil
|
16
|
-
def calculate_context: (Array[_NamedDecl]) ->
|
16
|
+
def calculate_context: (Array[_NamedDecl]) -> Resolver::context
|
17
17
|
end
|
18
18
|
|
19
|
+
# Name of object, it's (multiple) declarations with the outer module declarations
|
20
|
+
#
|
19
21
|
class MultiEntry[M < _ModuleOrClass]
|
20
22
|
class D[M < _ModuleOrClass]
|
21
23
|
attr_reader decl: M
|
@@ -25,9 +27,9 @@ module RBS
|
|
25
27
|
|
26
28
|
include ContextUtil
|
27
29
|
|
28
|
-
@context:
|
30
|
+
@context: Resolver::context
|
29
31
|
|
30
|
-
def context: () ->
|
32
|
+
def context: () -> Resolver::context
|
31
33
|
end
|
32
34
|
|
33
35
|
attr_reader name: TypeName
|
@@ -55,6 +57,8 @@ module RBS
|
|
55
57
|
class ClassEntry < MultiEntry[AST::Declarations::Class]
|
56
58
|
end
|
57
59
|
|
60
|
+
# Name of object, it's (single) declaration, and the outer module declarations
|
61
|
+
#
|
58
62
|
class SingleEntry[N, D]
|
59
63
|
attr_reader name: N
|
60
64
|
attr_reader decl: D
|
@@ -64,36 +68,68 @@ module RBS
|
|
64
68
|
|
65
69
|
include ContextUtil
|
66
70
|
|
67
|
-
@context:
|
71
|
+
@context: Resolver::context
|
72
|
+
|
73
|
+
def context: () -> Resolver::context
|
74
|
+
end
|
75
|
+
|
76
|
+
class ModuleAliasEntry < SingleEntry[TypeName, AST::Declarations::ModuleAlias]
|
77
|
+
end
|
78
|
+
|
79
|
+
class ClassAliasEntry < SingleEntry[TypeName, AST::Declarations::ClassAlias]
|
80
|
+
end
|
81
|
+
|
82
|
+
class InterfaceEntry < SingleEntry[TypeName, AST::Declarations::Interface]
|
83
|
+
end
|
68
84
|
|
69
|
-
|
85
|
+
class TypeAliasEntry < SingleEntry[TypeName, AST::Declarations::TypeAlias]
|
70
86
|
end
|
71
87
|
|
72
|
-
|
88
|
+
class ConstantEntry < SingleEntry[TypeName, AST::Declarations::Constant]
|
89
|
+
end
|
90
|
+
|
91
|
+
class GlobalEntry < SingleEntry[Symbol, AST::Declarations::Global]
|
92
|
+
end
|
93
|
+
|
94
|
+
# Top level declarations
|
73
95
|
attr_reader declarations: Array[AST::Declarations::t]
|
74
96
|
|
97
|
+
# Class declarations
|
75
98
|
attr_reader class_decls: Hash[TypeName, ModuleEntry | ClassEntry]
|
76
|
-
|
77
|
-
attr_reader
|
78
|
-
|
79
|
-
|
99
|
+
|
100
|
+
attr_reader class_alias_decls: Hash[TypeName, ModuleAliasEntry | ClassAliasEntry]
|
101
|
+
|
102
|
+
# Interface declarations
|
103
|
+
attr_reader interface_decls: Hash[TypeName, InterfaceEntry]
|
104
|
+
|
105
|
+
# Type alias declarations
|
106
|
+
attr_reader type_alias_decls: Hash[TypeName, TypeAliasEntry]
|
107
|
+
|
108
|
+
# Constant declarations
|
109
|
+
attr_reader constant_decls: Hash[TypeName, ConstantEntry]
|
110
|
+
|
111
|
+
# Global declarations
|
112
|
+
attr_reader global_decls: Hash[Symbol, GlobalEntry]
|
113
|
+
|
114
|
+
attr_reader buffer_directives: Hash[Buffer, Array[AST::Directives::t]]
|
80
115
|
|
81
116
|
def initialize: () -> void
|
82
117
|
|
83
118
|
def initialize_copy: (Environment) -> void
|
84
119
|
|
120
|
+
# Construct an environment from EnvironmentLoader
|
121
|
+
#
|
85
122
|
def self.from_loader: (EnvironmentLoader) -> Environment
|
86
123
|
|
87
|
-
def
|
88
|
-
|
89
|
-
def insert_decl: (AST::Declarations::t, outer: Array[module_decl], namespace: Namespace) -> void
|
124
|
+
def add_signature: (buffer: Buffer, directives: Array[AST::Directives::t], decls: Array[AST::Declarations::t]) -> void
|
90
125
|
|
91
|
-
# Insert a toplevel declaration into the
|
126
|
+
# Insert a toplevel declaration into the environment
|
92
127
|
#
|
93
128
|
def <<: (AST::Declarations::t decl) -> self
|
94
129
|
|
95
|
-
#
|
96
|
-
|
130
|
+
# Insert a declaration into the environment
|
131
|
+
#
|
132
|
+
private def insert_decl: (AST::Declarations::t, outer: Array[module_decl], namespace: Namespace) -> void
|
97
133
|
|
98
134
|
# Resolve all type names in the environment to absolute type names.
|
99
135
|
# Relative type name will be left if absolute type name cannot be found.
|
@@ -103,29 +139,114 @@ module RBS
|
|
103
139
|
#
|
104
140
|
def resolve_type_names: (?only: Set[AST::Declarations::t]?) -> Environment
|
105
141
|
|
106
|
-
def
|
142
|
+
def inspect: () -> String
|
107
143
|
|
108
|
-
|
144
|
+
@buffers: Array[Buffer]
|
109
145
|
|
110
|
-
def
|
146
|
+
def buffers: () -> Array[Buffer]
|
111
147
|
|
112
|
-
def
|
148
|
+
def buffers_decls: () -> Hash[Buffer, Array[AST::Declarations::t]]
|
113
149
|
|
114
|
-
|
150
|
+
# Remove declarations and directives that are loaded from `buffers`
|
151
|
+
#
|
152
|
+
def unload: (Set[Buffer] buffers) -> Environment
|
115
153
|
|
116
|
-
|
154
|
+
# Returns true if an interface with the type name is defined
|
155
|
+
#
|
156
|
+
def interface_name?: (TypeName) -> bool
|
117
157
|
|
118
|
-
|
158
|
+
# Returns true if a type alias with the type name is defined
|
159
|
+
#
|
160
|
+
def type_alias_name?: (TypeName) -> bool
|
119
161
|
|
120
|
-
|
162
|
+
# Returns true if a module or class with the type name is defined
|
163
|
+
#
|
164
|
+
def module_name?: (TypeName) -> bool
|
121
165
|
|
122
|
-
|
166
|
+
# Returns true if the type name is defined
|
167
|
+
#
|
168
|
+
def type_name?: (TypeName) -> bool
|
123
169
|
|
124
|
-
|
170
|
+
# Returns if a constant of the name is defined
|
171
|
+
#
|
172
|
+
def constant_name?: (TypeName) -> bool
|
173
|
+
|
174
|
+
# Returns true if the type name is defined by constant declaration
|
175
|
+
#
|
176
|
+
def constant_decl?: (TypeName) -> bool
|
177
|
+
|
178
|
+
# Returns true if the type name is defined by class declaration
|
179
|
+
#
|
180
|
+
def class_decl?: (TypeName) -> bool
|
181
|
+
|
182
|
+
# Returns true if the type name is defined by module declaration
|
183
|
+
#
|
184
|
+
def module_decl?: (TypeName) -> bool
|
185
|
+
|
186
|
+
# Returns true if the type name is a module alias
|
187
|
+
#
|
188
|
+
def module_alias?: (TypeName) -> bool
|
189
|
+
|
190
|
+
# Returns true if the type name is a class alias
|
191
|
+
def class_alias?: (TypeName) -> bool
|
192
|
+
|
193
|
+
def class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | nil)
|
194
|
+
|
195
|
+
# Returns ClassEntry if the class definition is found, normalized in case of alias
|
196
|
+
#
|
197
|
+
def normalized_class_entry: (TypeName) -> ClassEntry?
|
198
|
+
|
199
|
+
def module_entry: (TypeName) -> (ModuleEntry | ModuleAliasEntry | nil)
|
200
|
+
|
201
|
+
# Returns ModuleEntry if the module definition is found, normalized in case of alias
|
202
|
+
#
|
203
|
+
def normalized_module_entry: (TypeName) -> ModuleEntry?
|
204
|
+
|
205
|
+
def constant_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
|
206
|
+
|
207
|
+
def module_class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
|
125
208
|
|
126
|
-
|
127
|
-
|
209
|
+
def normalized_module_class_entry: (TypeName) -> (ClassEntry | ModuleEntry | nil)
|
210
|
+
|
211
|
+
@normalize_module_name_cache: Hash[TypeName, TypeName | false | nil]
|
212
|
+
|
213
|
+
# Returns the original module name that is defined with `module` declaration
|
214
|
+
#
|
215
|
+
# * Calls `#absolute!` for relative module names
|
216
|
+
# * Returns `nil` if the rhs name cannot be found
|
217
|
+
# * Returns `false` if the name is cyclic
|
218
|
+
#
|
219
|
+
def normalize_module_name?: (TypeName) -> (TypeName | nil | false)
|
220
|
+
|
221
|
+
# Returns the original module name that is defined with `module` declaration
|
222
|
+
#
|
223
|
+
# * Raises an error if given type name is not module
|
224
|
+
# * Calls `#absolute!` for relative module names
|
225
|
+
# * Returns the name itself if the name cannot be normalized to a class/module
|
226
|
+
#
|
227
|
+
def normalize_module_name: (TypeName) -> TypeName
|
228
|
+
|
229
|
+
# Runs generics type params validation over each class definitions
|
230
|
+
def validate_type_params: () -> void
|
231
|
+
|
232
|
+
private
|
233
|
+
|
234
|
+
# Returns a context for inside given decls
|
128
235
|
#
|
129
|
-
def
|
236
|
+
def resolver_context: (*module_decl) -> Resolver::context
|
237
|
+
|
238
|
+
def append_context: (Resolver::context, module_decl) -> Resolver::context
|
239
|
+
|
240
|
+
def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, outer: Array[module_decl], prefix: Namespace) -> AST::Declarations::t
|
241
|
+
|
242
|
+
def resolve_member: (Resolver::TypeNameResolver, UseMap map, AST::Members::t, context: Resolver::context) -> AST::Members::t
|
243
|
+
|
244
|
+
def resolve_method_type: (Resolver::TypeNameResolver, UseMap map, RBS::MethodType, context: Resolver::context) -> RBS::MethodType
|
245
|
+
|
246
|
+
def resolve_type_params: (Resolver::TypeNameResolver resolver, UseMap map, Array[AST::TypeParam], context: Resolver::context) -> Array[AST::TypeParam]
|
247
|
+
|
248
|
+
def absolute_type: (Resolver::TypeNameResolver, UseMap map, Types::t, context: Resolver::context) -> Types::t
|
249
|
+
|
250
|
+
def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName
|
130
251
|
end
|
131
252
|
end
|
data/sig/environment_loader.rbs
CHANGED
@@ -100,7 +100,7 @@ module RBS
|
|
100
100
|
#
|
101
101
|
def self.gem_sig_path: (String name, String? version) -> [Gem::Specification, Pathname]?
|
102
102
|
|
103
|
-
def
|
103
|
+
def each_signature: () { (source, Pathname, Buffer, Array[AST::Declarations::t], Array[AST::Directives::t]) -> void } -> void
|
104
104
|
|
105
105
|
def each_dir: { (source, Pathname) -> void } -> void
|
106
106
|
|
data/sig/errors.rbs
CHANGED
@@ -174,7 +174,7 @@ module RBS
|
|
174
174
|
end
|
175
175
|
|
176
176
|
# The *overloading* method definition cannot find *non-overloading* method definition
|
177
|
-
#
|
177
|
+
#
|
178
178
|
class InvalidOverloadMethodError < DefinitionError
|
179
179
|
attr_reader type_name: TypeName
|
180
180
|
attr_reader method_name: Symbol
|
@@ -280,4 +280,25 @@ module RBS
|
|
280
280
|
|
281
281
|
def initialize: (type_name: TypeName, method_name: Symbol?, params: Array[AST::TypeParam], location: Location[untyped, untyped]?) -> void
|
282
282
|
end
|
283
|
+
|
284
|
+
# A module/class alias declaration has inconsistent right-hand-side
|
285
|
+
#
|
286
|
+
# ```rbs
|
287
|
+
# module Foo = Object # Error
|
288
|
+
# class Bar = Kernel # Error
|
289
|
+
# ```
|
290
|
+
#
|
291
|
+
class InconsistentClassModuleAliasError < BaseError
|
292
|
+
attr_reader alias_entry: Environment::ModuleAliasEntry | Environment::ClassAliasEntry
|
293
|
+
|
294
|
+
def initialize: (Environment::ModuleAliasEntry | Environment::ClassAliasEntry) -> void
|
295
|
+
end
|
296
|
+
|
297
|
+
# A module/class alias declaration is cyclic
|
298
|
+
#
|
299
|
+
class CyclicClassAliasDefinitionError < BaseError
|
300
|
+
attr_reader alias_entry: Environment::ModuleAliasEntry | Environment::ClassAliasEntry
|
301
|
+
|
302
|
+
def initialize: (Environment::ModuleAliasEntry | Environment::ClassAliasEntry) -> void
|
303
|
+
end
|
283
304
|
end
|
data/sig/locator.rbs
CHANGED
@@ -10,14 +10,22 @@ module RBS
|
|
10
10
|
| AST::TypeParam
|
11
11
|
| AST::Declarations::Class::Super
|
12
12
|
| AST::Declarations::Module::Self
|
13
|
+
| AST::Directives::t
|
14
|
+
| AST::Directives::Use::clause
|
15
|
+
|
16
|
+
# The buffer the location points to
|
17
|
+
#
|
18
|
+
attr_reader buffer: Buffer
|
13
19
|
|
14
20
|
# Array of _top-level_ declarations.
|
15
21
|
#
|
16
22
|
attr_reader decls: Array[AST::Declarations::t]
|
17
23
|
|
18
|
-
|
24
|
+
# Array of directives.
|
25
|
+
#
|
26
|
+
attr_reader dirs: Array[AST::Directives::t]
|
19
27
|
|
20
|
-
def buffer:
|
28
|
+
def initialize: (buffer: Buffer, decls: Array[AST::Declarations::t], dirs: Array[AST::Directives::t]) -> void
|
21
29
|
|
22
30
|
# Returns list of components.
|
23
31
|
# Inner component comes first.
|
@@ -29,6 +37,10 @@ module RBS
|
|
29
37
|
#
|
30
38
|
def find2: (line: Integer, column: Integer) -> [Symbol?, Array[component]]?
|
31
39
|
|
40
|
+
private
|
41
|
+
|
42
|
+
def find_in_directive: (Integer pos, AST::Directives::t, Array[component]) -> bool
|
43
|
+
|
32
44
|
def find_in_decl: (Integer pos, decl: AST::Declarations::t, array: Array[component]) -> bool
|
33
45
|
|
34
46
|
def find_in_member: (Integer pos, member: AST::Members::t, array: Array[component]) -> bool
|