rbs 2.8.4 → 3.0.0.dev.2
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 +4 -4
- data/.github/workflows/ruby.yml +0 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -0
- data/Rakefile +66 -0
- data/core/array.rbs +1 -1
- data/core/builtin.rbs +1 -1
- data/core/hash.rbs +1 -1
- data/core/module.rbs +1 -1
- data/ext/rbs_extension/constants.c +18 -2
- data/ext/rbs_extension/constants.h +9 -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 +287 -57
- data/ext/rbs_extension/ruby_objs.c +71 -5
- data/ext/rbs_extension/ruby_objs.h +9 -2
- 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/ast/members.rb +49 -15
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/config/lockfile.rb +115 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
- data/lib/rbs/collection/config.rb +12 -40
- data/lib/rbs/collection/installer.rb +9 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +135 -62
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +10 -13
- data/lib/rbs/collection/sources.rb +7 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder/method_builder.rb +3 -3
- data/lib/rbs/definition_builder.rb +456 -579
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +356 -85
- data/lib/rbs/environment_loader.rb +20 -17
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +34 -37
- data/lib/rbs/locator.rb +3 -3
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/prototype/helpers.rb +29 -13
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +3 -2
- data/lib/rbs/prototype/rbi.rb +6 -4
- data/lib/rbs/prototype/runtime.rb +25 -12
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +3 -3
- data/lib/rbs/substitution.rb +19 -0
- 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/types.rb +1 -5
- data/lib/rbs/validator.rb +25 -3
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -19
- data/lib/rbs.rb +3 -2
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/schema/members.json +15 -10
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile.rbs +80 -0
- data/sig/collection/config/lockfile_generator.rbs +53 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +76 -33
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +94 -82
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -28
- data/sig/environment_loader.rbs +2 -2
- data/sig/errors.rbs +42 -0
- data/sig/members.rbs +31 -7
- data/sig/parser.rbs +8 -15
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/bundler.rbs +31 -0
- data/sig/shims/rubygems.rbs +15 -0
- data/sig/shims.rbs +0 -22
- data/sig/substitution.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +6 -2
- metadata +16 -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/type_name_resolver.rbs +0 -26
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
|
84
|
+
|
85
|
+
class TypeAliasEntry < SingleEntry[TypeName, AST::Declarations::TypeAlias]
|
86
|
+
end
|
68
87
|
|
69
|
-
|
88
|
+
class ConstantEntry < SingleEntry[TypeName, AST::Declarations::Constant]
|
70
89
|
end
|
71
90
|
|
72
|
-
|
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,18 +139,6 @@ module RBS
|
|
103
139
|
#
|
104
140
|
def resolve_type_names: (?only: Set[AST::Declarations::t]?) -> Environment
|
105
141
|
|
106
|
-
def resolve_declaration: (TypeNameResolver resolver, AST::Declarations::t decl, outer: Array[module_decl], prefix: Namespace) -> AST::Declarations::t
|
107
|
-
|
108
|
-
def resolve_member: (TypeNameResolver, AST::Members::t, context: Array[Namespace]) -> AST::Members::t
|
109
|
-
|
110
|
-
def resolve_method_type: (TypeNameResolver, RBS::MethodType, context: Array[Namespace]) -> RBS::MethodType
|
111
|
-
|
112
|
-
def resolve_type_params: (TypeNameResolver resolver, Array[AST::TypeParam], context: Array[Namespace]) -> Array[AST::TypeParam]
|
113
|
-
|
114
|
-
def absolute_type: (TypeNameResolver, Types::t, context: Array[Namespace]) -> Types::t
|
115
|
-
|
116
|
-
def absolute_type_name: (TypeNameResolver, TypeName, context: Array[Namespace]) -> TypeName
|
117
|
-
|
118
142
|
def inspect: () -> String
|
119
143
|
|
120
144
|
@buffers: Array[Buffer]
|
@@ -127,5 +151,103 @@ module RBS
|
|
127
151
|
# Construction of new environment is done with `<<` so that nested declarations will work well.
|
128
152
|
#
|
129
153
|
def reject: () { (AST::Declarations::t) -> boolish } -> Environment
|
154
|
+
|
155
|
+
# Returns true if an interface with the type name is defined
|
156
|
+
#
|
157
|
+
def interface_name?: (TypeName) -> bool
|
158
|
+
|
159
|
+
# Returns true if a type alias with the type name is defined
|
160
|
+
#
|
161
|
+
def type_alias_name?: (TypeName) -> bool
|
162
|
+
|
163
|
+
# Returns true if a module or class with the type name is defined
|
164
|
+
#
|
165
|
+
def module_name?: (TypeName) -> bool
|
166
|
+
|
167
|
+
# Returns true if the type name is defined
|
168
|
+
#
|
169
|
+
def type_name?: (TypeName) -> bool
|
170
|
+
|
171
|
+
# Returns if a constant of the name is defined
|
172
|
+
#
|
173
|
+
def constant_name?: (TypeName) -> bool
|
174
|
+
|
175
|
+
# Returns true if the type name is defined by constant declaration
|
176
|
+
#
|
177
|
+
def constant_decl?: (TypeName) -> bool
|
178
|
+
|
179
|
+
# Returns true if the type name is defined by class declaration
|
180
|
+
#
|
181
|
+
def class_decl?: (TypeName) -> bool
|
182
|
+
|
183
|
+
# Returns true if the type name is defined by module declaration
|
184
|
+
#
|
185
|
+
def module_decl?: (TypeName) -> bool
|
186
|
+
|
187
|
+
# Returns true if the type name is a module alias
|
188
|
+
#
|
189
|
+
def module_alias?: (TypeName) -> bool
|
190
|
+
|
191
|
+
# Returns true if the type name is a class alias
|
192
|
+
def class_alias?: (TypeName) -> bool
|
193
|
+
|
194
|
+
def class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | nil)
|
195
|
+
|
196
|
+
# Returns ClassEntry if the class definition is found, normalized in case of alias
|
197
|
+
#
|
198
|
+
def normalized_class_entry: (TypeName) -> ClassEntry?
|
199
|
+
|
200
|
+
def module_entry: (TypeName) -> (ModuleEntry | ModuleAliasEntry | nil)
|
201
|
+
|
202
|
+
# Returns ModuleEntry if the module definition is found, normalized in case of alias
|
203
|
+
#
|
204
|
+
def normalized_module_entry: (TypeName) -> ModuleEntry?
|
205
|
+
|
206
|
+
def constant_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
|
207
|
+
|
208
|
+
def module_class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
|
209
|
+
|
210
|
+
def normalized_module_class_entry: (TypeName) -> (ClassEntry | ModuleEntry | nil)
|
211
|
+
|
212
|
+
@normalize_module_name_cache: Hash[TypeName, TypeName | false | nil]
|
213
|
+
|
214
|
+
# Returns the original module name that is defined with `module` declaration
|
215
|
+
#
|
216
|
+
# * Calls `#absolute!` for relative module names
|
217
|
+
# * Returns `nil` if the rhs name cannot be found
|
218
|
+
# * Returns `false` if the name is cyclic
|
219
|
+
#
|
220
|
+
def normalize_module_name?: (TypeName) -> (TypeName | nil | false)
|
221
|
+
|
222
|
+
# Returns the original module name that is defined with `module` declaration
|
223
|
+
#
|
224
|
+
# * Raises an error if given type name is not module
|
225
|
+
# * Calls `#absolute!` for relative module names
|
226
|
+
# * Returns the name itself if the name cannot be normalized to a class/module
|
227
|
+
#
|
228
|
+
def normalize_module_name: (TypeName) -> TypeName
|
229
|
+
|
230
|
+
# Runs generics type params validation over each class definitions
|
231
|
+
def validate_type_params: () -> void
|
232
|
+
|
233
|
+
private
|
234
|
+
|
235
|
+
# Returns a context for inside given decls
|
236
|
+
#
|
237
|
+
def resolver_context: (*module_decl) -> Resolver::context
|
238
|
+
|
239
|
+
def append_context: (Resolver::context, module_decl) -> Resolver::context
|
240
|
+
|
241
|
+
def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, outer: Array[module_decl], prefix: Namespace) -> AST::Declarations::t
|
242
|
+
|
243
|
+
def resolve_member: (Resolver::TypeNameResolver, UseMap map, AST::Members::t, context: Resolver::context) -> AST::Members::t
|
244
|
+
|
245
|
+
def resolve_method_type: (Resolver::TypeNameResolver, UseMap map, RBS::MethodType, context: Resolver::context) -> RBS::MethodType
|
246
|
+
|
247
|
+
def resolve_type_params: (Resolver::TypeNameResolver resolver, UseMap map, Array[AST::TypeParam], context: Resolver::context) -> Array[AST::TypeParam]
|
248
|
+
|
249
|
+
def absolute_type: (Resolver::TypeNameResolver, UseMap map, Types::t, context: Resolver::context) -> Types::t
|
250
|
+
|
251
|
+
def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName
|
130
252
|
end
|
131
253
|
end
|
data/sig/environment_loader.rbs
CHANGED
@@ -81,7 +81,7 @@ module RBS
|
|
81
81
|
def resolve_dependencies: (library: String, version: String?) -> void
|
82
82
|
|
83
83
|
# Add repository path and libraries via rbs_collection.lock.yaml.
|
84
|
-
def add_collection: (Collection::Config
|
84
|
+
def add_collection: (Collection::Config::Lockfile lockfile) -> void
|
85
85
|
|
86
86
|
# This is helper function to test if RBS for a library is available or not.
|
87
87
|
#
|
@@ -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
@@ -123,6 +123,23 @@ module RBS
|
|
123
123
|
def other_locations: () -> Array[Location[untyped, untyped]?]
|
124
124
|
end
|
125
125
|
|
126
|
+
# An interface mixin causes a duplication of a method definition
|
127
|
+
#
|
128
|
+
# ```rbs
|
129
|
+
# interface _Foo1
|
130
|
+
# def foo: () -> void
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# interface _Foo2
|
134
|
+
# def foo: () -> void
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# class Foo
|
138
|
+
# include _Foo1
|
139
|
+
# include _Foo2 # <= The error will be reported here (or the line of _Foo1)
|
140
|
+
# end
|
141
|
+
# ```
|
142
|
+
#
|
126
143
|
class DuplicatedInterfaceMethodDefinitionError < DefinitionError
|
127
144
|
type ty = Types::ClassSingleton | Types::ClassInstance | Types::Interface
|
128
145
|
type mixin_member = AST::Members::Include | AST::Members::Extend
|
@@ -138,6 +155,8 @@ module RBS
|
|
138
155
|
def qualified_method_name: () -> String
|
139
156
|
end
|
140
157
|
|
158
|
+
# The `alias` member declares an alias from unknown method
|
159
|
+
#
|
141
160
|
class UnknownMethodAliasError < DefinitionError
|
142
161
|
attr_reader type_name: TypeName
|
143
162
|
attr_reader original_name: Symbol
|
@@ -154,6 +173,8 @@ module RBS
|
|
154
173
|
def initialize: (name: TypeName, entry: Environment::ClassEntry) -> void
|
155
174
|
end
|
156
175
|
|
176
|
+
# The *overloading* method definition cannot find *non-overloading* method definition
|
177
|
+
#
|
157
178
|
class InvalidOverloadMethodError < DefinitionError
|
158
179
|
attr_reader type_name: TypeName
|
159
180
|
attr_reader method_name: Symbol
|
@@ -259,4 +280,25 @@ module RBS
|
|
259
280
|
|
260
281
|
def initialize: (type_name: TypeName, method_name: Symbol?, params: Array[AST::TypeParam], location: Location[untyped, untyped]?) -> void
|
261
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
|
262
304
|
end
|
data/sig/members.rbs
CHANGED
@@ -15,6 +15,26 @@ module RBS
|
|
15
15
|
type visibility = :public | :private
|
16
16
|
|
17
17
|
class MethodDefinition < Base
|
18
|
+
class Overload
|
19
|
+
attr_reader method_type: MethodType
|
20
|
+
|
21
|
+
attr_reader annotations: Array[Annotation]
|
22
|
+
|
23
|
+
def initialize: (method_type: MethodType, annotations: Array[Annotation]) -> void
|
24
|
+
|
25
|
+
def ==: (untyped) -> bool
|
26
|
+
|
27
|
+
def hash: () -> Integer
|
28
|
+
|
29
|
+
alias eql? ==
|
30
|
+
|
31
|
+
def update: (?annotations: Array[Annotation], ?method_type: MethodType) -> Overload
|
32
|
+
|
33
|
+
def sub: (Substitution) -> Overload
|
34
|
+
|
35
|
+
include _ToJson
|
36
|
+
end
|
37
|
+
|
18
38
|
type kind = :instance | :singleton | :singleton_instance
|
19
39
|
|
20
40
|
# def foo: () -> void
|
@@ -26,31 +46,35 @@ module RBS
|
|
26
46
|
# ^^^ keyword
|
27
47
|
# ^^^^^ kind
|
28
48
|
# ^^^ name
|
29
|
-
# ^^^
|
49
|
+
# ^^^ overloading
|
30
50
|
#
|
31
|
-
type loc = Location[:keyword | :name, :kind | :
|
51
|
+
type loc = Location[:keyword | :name, :kind | :overloading | :visibility]
|
32
52
|
|
33
53
|
attr_reader name: Symbol
|
34
54
|
attr_reader kind: kind
|
35
|
-
attr_reader
|
55
|
+
attr_reader overloads: Array[Overload]
|
36
56
|
attr_reader annotations: Array[Annotation]
|
37
57
|
attr_reader location: loc?
|
38
58
|
attr_reader comment: Comment?
|
39
|
-
attr_reader
|
59
|
+
attr_reader overloading: bool
|
40
60
|
attr_reader visibility: visibility?
|
41
61
|
|
42
|
-
def initialize: (name: Symbol, kind: kind,
|
62
|
+
def initialize: (name: Symbol, kind: kind, overloads: Array[Overload], annotations: Array[Annotation], location: loc?, comment: Comment?, overloading: bool, visibility: visibility?) -> void
|
43
63
|
|
44
64
|
include _HashEqual
|
45
65
|
include _ToJson
|
46
66
|
|
67
|
+
# Returns true if the `def` is to define instance method
|
47
68
|
def instance?: () -> bool
|
48
69
|
|
70
|
+
# Returns true if the `def` is to define singleton method
|
49
71
|
def singleton?: () -> bool
|
50
72
|
|
51
|
-
def
|
73
|
+
# Returns true if the `def` is overloading (== with `...`)
|
74
|
+
#
|
75
|
+
def overloading?: () -> bool
|
52
76
|
|
53
|
-
def update: (?name: Symbol, ?kind: kind, ?
|
77
|
+
def update: (?name: Symbol, ?kind: kind, ?overloads: Array[Overload], ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?overloading: bool, ?visibility: visibility?) -> MethodDefinition
|
54
78
|
end
|
55
79
|
|
56
80
|
module Var
|
data/sig/parser.rbs
CHANGED
@@ -6,15 +6,13 @@ module RBS
|
|
6
6
|
# If no token is left in the input, it returns `nil`.
|
7
7
|
#
|
8
8
|
# ```ruby
|
9
|
+
# RBS::Parser.parse_method_type("() -> void") # => `() -> void`
|
9
10
|
# RBS::Parser.parse_method_type("() -> void", range: 0...) # => `() -> void`
|
10
11
|
# RBS::Parser.parse_method_type("() -> void () -> String", range: 11...) # => `() -> String`
|
11
12
|
# RBS::Parser.parse_method_type("() -> void () -> String", range: 23...) # => nil
|
12
13
|
# ```
|
13
14
|
#
|
14
|
-
|
15
|
-
#
|
16
|
-
def self.parse_method_type: (Buffer | String, range: Range[Integer?], ?variables: Array[Symbol]) -> MethodType?
|
17
|
-
| (Buffer | String, ?line: top, ?column: top, ?variables: Array[Symbol]) -> MethodType
|
15
|
+
def self.parse_method_type: (Buffer | String, ?range: Range[Integer?], ?variables: Array[Symbol]) -> MethodType?
|
18
16
|
|
19
17
|
# Parse a type and return it
|
20
18
|
#
|
@@ -22,22 +20,17 @@ module RBS
|
|
22
20
|
# If no token is left in the input, it returns `nil`.
|
23
21
|
#
|
24
22
|
# ```ruby
|
23
|
+
# RBS::Parser.parse_type("String") # => `String`
|
25
24
|
# RBS::Parser.parse_type("String", range: 0...) # => `String`
|
26
25
|
# RBS::Parser.parse_type("String Integer", pos: 7...) # => `Integer`
|
27
26
|
# RBS::Parser.parse_type("String Integer", pos: 14...) # => nil
|
28
27
|
# ```
|
29
28
|
#
|
30
|
-
|
31
|
-
#
|
32
|
-
def self.parse_type: (Buffer | String, range: Range[Integer?], ?variables: Array[Symbol]) -> Types::t?
|
33
|
-
| (Buffer | String, ?line: top, ?column: top, ?variables: Array[Symbol]) -> Types::t
|
29
|
+
def self.parse_type: (Buffer | String, ?range: Range[Integer?], ?variables: Array[Symbol]) -> Types::t?
|
34
30
|
|
35
31
|
# Parse whole RBS file and return an array of declarations
|
36
32
|
#
|
37
|
-
|
38
|
-
#
|
39
|
-
def self.parse_signature: (Buffer | String) -> Array[AST::Declarations::t]
|
40
|
-
| (Buffer | String, ?line: top, ?column: top) -> Array[AST::Declarations::t]
|
33
|
+
def self.parse_signature: (Buffer | String) -> [Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]]
|
41
34
|
|
42
35
|
KEYWORDS: Hash[String, bot]
|
43
36
|
|
@@ -45,11 +38,11 @@ module RBS
|
|
45
38
|
|
46
39
|
def self.buffer: (String | Buffer source) -> Buffer
|
47
40
|
|
48
|
-
def self._parse_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables
|
41
|
+
def self._parse_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> Types::t?
|
49
42
|
|
50
|
-
def self._parse_method_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables
|
43
|
+
def self._parse_method_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> MethodType?
|
51
44
|
|
52
|
-
def self._parse_signature: (Buffer, Integer end_pos) -> Array[AST::Declarations::t]
|
45
|
+
def self._parse_signature: (Buffer, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
|
53
46
|
|
54
47
|
class LocatedValue
|
55
48
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RBS
|
2
|
+
module Prototype
|
3
|
+
class NodeUsage
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
type node = RubyVM::AbstractSyntaxTree::Node
|
7
|
+
|
8
|
+
attr_reader node: node
|
9
|
+
|
10
|
+
attr_reader conditional_nodes: Set[node]
|
11
|
+
|
12
|
+
def initialize: (node) -> void
|
13
|
+
|
14
|
+
def calculate: (node, conditional: bool) -> void
|
15
|
+
|
16
|
+
def each_conditional_node: () { (node) -> void } -> void
|
17
|
+
| () -> Enumerator[node, void]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -37,7 +37,7 @@ module RBS
|
|
37
37
|
|
38
38
|
def constant_of_module: (TypeName name, Environment::ClassEntry | Environment::ModuleEntry) -> Constant
|
39
39
|
|
40
|
-
def constant_of_constant: (TypeName name, Environment::
|
40
|
+
def constant_of_constant: (TypeName name, Environment::ConstantEntry) -> Constant
|
41
41
|
end
|
42
42
|
|
43
43
|
attr_reader builder: DefinitionBuilder
|
@@ -65,7 +65,6 @@ module RBS
|
|
65
65
|
# ^ <- constant_name
|
66
66
|
# ```
|
67
67
|
#
|
68
|
-
# Find the
|
69
68
|
def resolve_child: (TypeName module_name, Symbol constant_name) -> Constant?
|
70
69
|
|
71
70
|
# Returns the table of all constants accessible with `::` (colon2) operator.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Bundler
|
2
|
+
class LockfileParser
|
3
|
+
def initialize: (String) -> void
|
4
|
+
|
5
|
+
def specs: () -> Array[LazySpecification]
|
6
|
+
end
|
7
|
+
|
8
|
+
class LazySpecification
|
9
|
+
def name: () -> String
|
10
|
+
|
11
|
+
def version: () -> String
|
12
|
+
|
13
|
+
def dependencies: () -> Array[Gem::Dependency]
|
14
|
+
end
|
15
|
+
|
16
|
+
class Dependency < Gem::Dependency
|
17
|
+
attr_reader autorequire: Array[String]?
|
18
|
+
end
|
19
|
+
|
20
|
+
class Definition
|
21
|
+
def lockfile: () -> Pathname
|
22
|
+
|
23
|
+
def locked_gems: () -> LockfileParser
|
24
|
+
|
25
|
+
def dependencies: () -> Array[Dependency]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.default_lockfile: () -> Pathname
|
29
|
+
|
30
|
+
def self.definition: () -> Definition
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Gem
|
2
|
+
class Specification
|
3
|
+
attr_reader version (): Version
|
4
|
+
|
5
|
+
attr_reader gem_dir (): String
|
6
|
+
|
7
|
+
def self.find_by_name: (String name, *String requirements) -> instance
|
8
|
+
|
9
|
+
def dependencies: () -> Array[Dependency]
|
10
|
+
end
|
11
|
+
|
12
|
+
class Dependency
|
13
|
+
def name: () -> String
|
14
|
+
end
|
15
|
+
end
|
data/sig/shims.rbs
CHANGED
@@ -1,25 +1,3 @@
|
|
1
|
-
module Gem
|
2
|
-
class Specification
|
3
|
-
attr_reader version (): Version
|
4
|
-
|
5
|
-
attr_reader gem_dir (): String
|
6
|
-
|
7
|
-
def self.find_by_name: (String name, *String requirements) -> instance
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module Bundler
|
12
|
-
class LockfileParser
|
13
|
-
def initialize: (String) -> void
|
14
|
-
def specs: () -> Array[LazySpecification]
|
15
|
-
end
|
16
|
-
|
17
|
-
class LazySpecification
|
18
|
-
def name: () -> String
|
19
|
-
def version: () -> String
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
1
|
module RDoc
|
24
2
|
class Store
|
25
3
|
def initialize: (?String? path, ?Symbol? type) -> void
|
data/sig/substitution.rbs
CHANGED
data/sig/use_map.rbs
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module RBS
|
2
|
+
class Environment
|
3
|
+
# ```rb
|
4
|
+
# map = UseMap.build(environment)
|
5
|
+
#
|
6
|
+
# map.resolve?(TypeName("TN")) # => nil or resolved type name
|
7
|
+
# ```
|
8
|
+
#
|
9
|
+
class UseMap
|
10
|
+
class Table
|
11
|
+
attr_reader known_types: Set[TypeName]
|
12
|
+
|
13
|
+
attr_reader children: Hash[Namespace, Set[TypeName]]
|
14
|
+
|
15
|
+
def initialize: () -> void
|
16
|
+
|
17
|
+
def compute_children: () -> self
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader use_dirs: Array[AST::Directives::Use]
|
21
|
+
|
22
|
+
@map: Hash[Symbol, TypeName]
|
23
|
+
|
24
|
+
@table: Table
|
25
|
+
|
26
|
+
def initialize: (table: Table) -> void
|
27
|
+
|
28
|
+
def resolve?: (TypeName) -> TypeName?
|
29
|
+
|
30
|
+
def resolve: (TypeName) -> TypeName
|
31
|
+
|
32
|
+
def build_map: (AST::Directives::Use::clause) -> self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/sig/validator.rbs
CHANGED
@@ -2,7 +2,7 @@ module RBS
|
|
2
2
|
class Validator
|
3
3
|
attr_reader env: Environment
|
4
4
|
|
5
|
-
attr_reader resolver: TypeNameResolver
|
5
|
+
attr_reader resolver: Resolver::TypeNameResolver
|
6
6
|
|
7
7
|
attr_reader definition_builder: DefinitionBuilder
|
8
8
|
|
@@ -10,11 +10,11 @@ module RBS
|
|
10
10
|
|
11
11
|
attr_reader type_alias_regularity: TypeAliasRegularity
|
12
12
|
|
13
|
-
def initialize: (env: Environment, resolver: TypeNameResolver) -> void
|
13
|
+
def initialize: (env: Environment, resolver: Resolver::TypeNameResolver) -> void
|
14
14
|
|
15
15
|
# Validates the presence of type names and type application arity match.
|
16
16
|
#
|
17
|
-
def validate_type: (Types::t, context:
|
17
|
+
def validate_type: (Types::t, context: Resolver::context) -> void
|
18
18
|
|
19
19
|
# Validates type alias definition:
|
20
20
|
#
|
@@ -25,7 +25,7 @@ module RBS
|
|
25
25
|
#
|
26
26
|
# It yields the rhs type if block is given, so that you can validate the rhs type.
|
27
27
|
#
|
28
|
-
def validate_type_alias: (entry: Environment::
|
28
|
+
def validate_type_alias: (entry: Environment::TypeAliasEntry) ?{ (Types::t rhs_type) -> void } -> void
|
29
29
|
|
30
30
|
# Validates the type parameters in generic methods.
|
31
31
|
#
|
@@ -42,11 +42,18 @@ module RBS
|
|
42
42
|
#
|
43
43
|
def validate_type_params: (Array[AST::TypeParam] params, type_name: TypeName, ?method_name: Symbol?, location: Location[untyped, untyped]?) -> void
|
44
44
|
|
45
|
+
# Validates class alias declaration
|
46
|
+
#
|
47
|
+
# - The right hand side can be normalized
|
48
|
+
# - No mixing alias declaration between class and modules
|
49
|
+
#
|
50
|
+
def validate_class_alias: (entry: Environment::ClassAliasEntry | Environment::ModuleAliasEntry) -> void
|
51
|
+
|
45
52
|
private
|
46
53
|
|
47
54
|
# Resolves relative type names to absolute type names in given context.
|
48
55
|
# Yields the type when the type name resolution using `#resolver` fails.
|
49
56
|
#
|
50
|
-
def absolute_type: (Types::t, context:
|
57
|
+
def absolute_type: (Types::t, context: Resolver::context) { (Types::t) -> TypeName } -> Types::t
|
51
58
|
end
|
52
59
|
end
|