rbs 3.0.0.dev.1 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Gemfile.lock +2 -2
  5. data/README.md +1 -0
  6. data/Rakefile +75 -1
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +16 -2
  12. data/ext/rbs_extension/constants.h +8 -1
  13. data/ext/rbs_extension/extconf.rb +1 -1
  14. data/ext/rbs_extension/lexer.c +834 -777
  15. data/ext/rbs_extension/lexer.h +3 -1
  16. data/ext/rbs_extension/lexer.re +3 -1
  17. data/ext/rbs_extension/lexstate.c +4 -2
  18. data/ext/rbs_extension/parser.c +264 -44
  19. data/ext/rbs_extension/ruby_objs.c +56 -2
  20. data/ext/rbs_extension/ruby_objs.h +7 -1
  21. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  22. data/lib/rbs/ast/declarations.rb +49 -2
  23. data/lib/rbs/ast/directives.rb +39 -0
  24. data/lib/rbs/cli.rb +32 -18
  25. data/lib/rbs/collection/config/lockfile_generator.rb +25 -20
  26. data/lib/rbs/collection/config.rb +2 -2
  27. data/lib/rbs/collection/sources/git.rb +1 -1
  28. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  29. data/lib/rbs/definition_builder.rb +8 -8
  30. data/lib/rbs/environment/use_map.rb +77 -0
  31. data/lib/rbs/environment.rb +352 -83
  32. data/lib/rbs/environment_loader.rb +9 -7
  33. data/lib/rbs/environment_walker.rb +1 -1
  34. data/lib/rbs/errors.rb +34 -37
  35. data/lib/rbs/locator.rb +1 -1
  36. data/lib/rbs/parser_aux.rb +8 -6
  37. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  38. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  39. data/lib/rbs/sorter.rb +3 -3
  40. data/lib/rbs/test/setup.rb +1 -1
  41. data/lib/rbs/type_alias_dependency.rb +1 -1
  42. data/lib/rbs/type_alias_regularity.rb +3 -3
  43. data/lib/rbs/validator.rb +23 -2
  44. data/lib/rbs/variance_calculator.rb +2 -2
  45. data/lib/rbs/version.rb +1 -1
  46. data/lib/rbs/writer.rb +28 -2
  47. data/lib/rbs.rb +2 -2
  48. data/lib/rdoc_plugin/parser.rb +2 -2
  49. data/rbs.gemspec +1 -1
  50. data/sig/ancestor_graph.rbs +22 -2
  51. data/sig/collection/config/lockfile_generator.rbs +8 -10
  52. data/sig/collection/config.rbs +1 -1
  53. data/sig/collection/sources.rbs +12 -6
  54. data/sig/constant.rbs +1 -1
  55. data/sig/declarations.rbs +36 -3
  56. data/sig/definition.rbs +1 -1
  57. data/sig/definition_builder.rbs +0 -1
  58. data/sig/directives.rbs +61 -0
  59. data/sig/environment.rbs +150 -28
  60. data/sig/environment_loader.rbs +1 -1
  61. data/sig/errors.rbs +22 -1
  62. data/sig/parser.rbs +8 -15
  63. data/sig/resolver/constant_resolver.rbs +1 -2
  64. data/sig/shims/bundler.rbs +18 -0
  65. data/sig/shims/rubygems.rbs +6 -0
  66. data/sig/use_map.rbs +35 -0
  67. data/sig/validator.rbs +12 -5
  68. data/sig/writer.rbs +4 -2
  69. metadata +7 -9
  70. data/lib/rbs/constant_table.rb +0 -167
  71. data/lib/rbs/type_name_resolver.rb +0 -67
  72. data/sig/constant_table.rbs +0 -30
  73. data/sig/type_name_resolver.rbs +0 -26
  74. data/steep/Gemfile +0 -3
  75. data/steep/Gemfile.lock +0 -61
data/sig/constant.rbs CHANGED
@@ -2,7 +2,7 @@ module RBS
2
2
  class Constant
3
3
  type constant_entry = Environment::ClassEntry
4
4
  | Environment::ModuleEntry
5
- | Environment::SingleEntry[TypeName, AST::Declarations::Constant]
5
+ | Environment::ConstantEntry
6
6
 
7
7
  attr_reader name: TypeName
8
8
 
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 | Alias
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 Alias < Base
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::SingleEntry[TypeName, AST::Declarations::Interface]
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
@@ -5,7 +5,6 @@ module RBS
5
5
  #
6
6
  class DefinitionBuilder
7
7
  attr_reader env: Environment
8
- attr_reader type_name_resolver: TypeNameResolver
9
8
  attr_reader ancestor_builder: AncestorBuilder
10
9
  attr_reader method_builder: MethodBuilder
11
10
 
@@ -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]) -> Array[Namespace]
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: Array[Namespace]
30
+ @context: Resolver::context
29
31
 
30
- def context: () -> Array[Namespace]
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: Array[Namespace]
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
- def context: () -> Array[Namespace]
88
+ class ConstantEntry < SingleEntry[TypeName, AST::Declarations::Constant]
70
89
  end
71
90
 
72
- # Top level declarations.
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
- attr_reader interface_decls: Hash[TypeName, SingleEntry[TypeName, AST::Declarations::Interface]]
77
- attr_reader alias_decls: Hash[TypeName, SingleEntry[TypeName, AST::Declarations::Alias]]
78
- attr_reader constant_decls: Hash[TypeName, SingleEntry[TypeName, AST::Declarations::Constant]]
79
- attr_reader global_decls: Hash[Symbol, SingleEntry[Symbol, AST::Declarations::Global]]
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 cache_name: [N, D] (Hash[N, SingleEntry[N, D]] cache, name: N, decl: D, outer: Array[module_decl]) -> SingleEntry[N, D]
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 env.
126
+ # Insert a toplevel declaration into the environment
92
127
  #
93
128
  def <<: (AST::Declarations::t decl) -> self
94
129
 
95
- # Runs generics type params validation over each class definitions.
96
- def validate_type_params: () -> void
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
@@ -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 each_decl: () { (AST::Declarations::t, Buffer, source, Pathname) -> void } -> void
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/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
- # `line` and `column` is deprecated and are ignored.
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
- # `line` and `column` is deprecated and are ignored.
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
- # `line` and `column` is deprecated and are ignored.
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, boolish eof) -> Types::t?
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, boolish eof) -> MethodType?
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
@@ -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::SingleEntry[TypeName, AST::Declarations::Constant]) -> Constant
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.
@@ -1,13 +1,31 @@
1
1
  module Bundler
2
2
  class LockfileParser
3
3
  def initialize: (String) -> void
4
+
4
5
  def specs: () -> Array[LazySpecification]
5
6
  end
6
7
 
7
8
  class LazySpecification
8
9
  def name: () -> String
10
+
9
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]
10
26
  end
11
27
 
12
28
  def self.default_lockfile: () -> Pathname
29
+
30
+ def self.definition: () -> Definition
13
31
  end
@@ -5,5 +5,11 @@ module Gem
5
5
  attr_reader gem_dir (): String
6
6
 
7
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
8
14
  end
9
15
  end
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: TypeNameResolver::context) -> void
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::SingleEntry[TypeName, AST::Declarations::Alias]) ?{ (Types::t rhs_type) -> void } -> void
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: TypeNameResolver::context) { (Types::t) -> TypeName } -> Types::t
57
+ def absolute_type: (Types::t, context: Resolver::context) { (Types::t) -> TypeName } -> Types::t
51
58
  end
52
59
  end
data/sig/writer.rbs CHANGED
@@ -21,7 +21,7 @@ module RBS
21
21
  # Output the array of declarations.
22
22
  # It automatically inserts empty lines between the declarations.
23
23
  #
24
- def write: (Array[AST::Declarations::t]) -> void
24
+ def write: (Array[AST::Declarations::t | AST::Directives::t]) -> void
25
25
 
26
26
  def preserve?: () -> bool
27
27
 
@@ -96,6 +96,8 @@ module RBS
96
96
 
97
97
  def format_annotation: (AST::Annotation) -> String
98
98
 
99
+ def write_directive: (AST::Directives::t) -> void
100
+
99
101
  def write_annotation: (Array[AST::Annotation]) -> void
100
102
 
101
103
  def write_comment: (AST::Comment?) -> void
@@ -108,7 +110,7 @@ module RBS
108
110
 
109
111
  def name_and_args: (TypeName, Array[Types::t]) -> String?
110
112
 
111
- def write_alias: (AST::Declarations::Alias) -> void
113
+ def write_alias: (AST::Declarations::TypeAlias) -> void
112
114
 
113
115
  def method_name: (Symbol) -> String
114
116