rbs 2.6.0 → 2.7.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +5 -0
  4. data/CHANGELOG.md +48 -1
  5. data/Gemfile.lock +10 -9
  6. data/Rakefile +0 -5
  7. data/Steepfile +1 -0
  8. data/core/basic_object.rbs +2 -2
  9. data/core/fiber.rbs +304 -14
  10. data/core/float.rbs +2 -0
  11. data/core/io.rbs +95 -1
  12. data/core/kernel.rbs +1 -1
  13. data/core/module.rbs +1 -1
  14. data/core/regexp.rbs +1 -1
  15. data/core/string_io.rbs +1 -1
  16. data/core/warning.rbs +1 -1
  17. data/ext/rbs_extension/parser.c +36 -10
  18. data/ext/rbs_extension/ruby_objs.c +4 -2
  19. data/ext/rbs_extension/ruby_objs.h +2 -2
  20. data/lib/rbs/ancestor_graph.rb +2 -0
  21. data/lib/rbs/annotate/annotations.rb +2 -0
  22. data/lib/rbs/annotate/formatter.rb +4 -2
  23. data/lib/rbs/annotate/rdoc_annotator.rb +2 -0
  24. data/lib/rbs/annotate/rdoc_source.rb +2 -0
  25. data/lib/rbs/annotate.rb +2 -0
  26. data/lib/rbs/ast/annotation.rb +2 -0
  27. data/lib/rbs/ast/comment.rb +2 -0
  28. data/lib/rbs/ast/declarations.rb +2 -0
  29. data/lib/rbs/ast/members.rb +2 -0
  30. data/lib/rbs/ast/type_param.rb +3 -1
  31. data/lib/rbs/buffer.rb +2 -0
  32. data/lib/rbs/builtin_names.rb +2 -0
  33. data/lib/rbs/cli.rb +39 -2
  34. data/lib/rbs/collection/cleaner.rb +2 -0
  35. data/lib/rbs/collection/config/lockfile_generator.rb +8 -3
  36. data/lib/rbs/collection/config.rb +2 -0
  37. data/lib/rbs/collection/installer.rb +2 -0
  38. data/lib/rbs/collection/sources/base.rb +14 -0
  39. data/lib/rbs/collection/sources/git.rb +3 -0
  40. data/lib/rbs/collection/sources/rubygems.rb +3 -0
  41. data/lib/rbs/collection/sources/stdlib.rb +12 -7
  42. data/lib/rbs/collection/sources.rb +3 -0
  43. data/lib/rbs/collection.rb +2 -0
  44. data/lib/rbs/constant.rb +2 -0
  45. data/lib/rbs/constant_table.rb +5 -3
  46. data/lib/rbs/definition.rb +13 -1
  47. data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
  48. data/lib/rbs/definition_builder/method_builder.rb +2 -0
  49. data/lib/rbs/definition_builder.rb +75 -13
  50. data/lib/rbs/environment.rb +2 -0
  51. data/lib/rbs/environment_loader.rb +25 -5
  52. data/lib/rbs/environment_walker.rb +2 -0
  53. data/lib/rbs/errors.rb +3 -1
  54. data/lib/rbs/factory.rb +2 -0
  55. data/lib/rbs/location_aux.rb +3 -1
  56. data/lib/rbs/locator.rb +2 -0
  57. data/lib/rbs/method_type.rb +7 -5
  58. data/lib/rbs/namespace.rb +9 -5
  59. data/lib/rbs/parser_aux.rb +2 -0
  60. data/lib/rbs/parser_compat/lexer_error.rb +2 -0
  61. data/lib/rbs/parser_compat/located_value.rb +2 -0
  62. data/lib/rbs/parser_compat/semantics_error.rb +2 -0
  63. data/lib/rbs/parser_compat/syntax_error.rb +2 -0
  64. data/lib/rbs/prototype/helpers.rb +13 -8
  65. data/lib/rbs/prototype/rb.rb +2 -0
  66. data/lib/rbs/prototype/rbi.rb +11 -6
  67. data/lib/rbs/prototype/runtime.rb +13 -4
  68. data/lib/rbs/repository.rb +4 -4
  69. data/lib/rbs/resolver/constant_resolver.rb +2 -0
  70. data/lib/rbs/resolver/type_name_resolver.rb +2 -0
  71. data/lib/rbs/sorter.rb +168 -0
  72. data/lib/rbs/substitution.rb +2 -0
  73. data/lib/rbs/test/errors.rb +2 -0
  74. data/lib/rbs/test/hook.rb +2 -0
  75. data/lib/rbs/test/observer.rb +2 -0
  76. data/lib/rbs/test/setup.rb +2 -0
  77. data/lib/rbs/test/setup_helper.rb +2 -0
  78. data/lib/rbs/test/spy.rb +2 -0
  79. data/lib/rbs/test/tester.rb +2 -0
  80. data/lib/rbs/test/type_check.rb +2 -0
  81. data/lib/rbs/test.rb +2 -0
  82. data/lib/rbs/type_alias_dependency.rb +2 -0
  83. data/lib/rbs/type_alias_regularity.rb +2 -0
  84. data/lib/rbs/type_name.rb +2 -0
  85. data/lib/rbs/type_name_resolver.rb +4 -2
  86. data/lib/rbs/types.rb +68 -18
  87. data/lib/rbs/validator.rb +2 -0
  88. data/lib/rbs/variance_calculator.rb +2 -0
  89. data/lib/rbs/vendorer.rb +2 -0
  90. data/lib/rbs/version.rb +3 -1
  91. data/lib/rbs/writer.rb +3 -1
  92. data/lib/rbs.rb +4 -2
  93. data/lib/rdoc/discover.rb +20 -0
  94. data/lib/rdoc_plugin/parser.rb +163 -0
  95. data/schema/methodType.json +7 -1
  96. data/schema/types.json +13 -1
  97. data/sig/ancestor_builder.rbs +66 -7
  98. data/sig/annotation.rbs +7 -6
  99. data/sig/builtin_names.rbs +2 -0
  100. data/sig/cli.rbs +8 -0
  101. data/sig/collection/config.rbs +13 -4
  102. data/sig/collection/installer.rbs +2 -0
  103. data/sig/collection/sources.rbs +23 -4
  104. data/sig/definition.rbs +8 -0
  105. data/sig/definition_builder.rbs +64 -7
  106. data/sig/environment.rbs +4 -0
  107. data/sig/environment_loader.rbs +4 -2
  108. data/sig/location.rbs +8 -4
  109. data/sig/manifest.yaml +1 -0
  110. data/sig/members.rbs +1 -1
  111. data/sig/method_builder.rbs +10 -0
  112. data/sig/namespace.rbs +54 -31
  113. data/sig/prototype/rb.rbs +4 -0
  114. data/sig/rbs.rbs +8 -6
  115. data/sig/rdoc/rbs.rbs +63 -0
  116. data/sig/{polyfill.rbs → shims.rbs} +1 -31
  117. data/sig/sorter.rbs +23 -0
  118. data/sig/types.rbs +14 -2
  119. data/sig/vendorer.rbs +32 -25
  120. data/stdlib/bigdecimal/0/big_decimal.rbs +250 -0
  121. data/stdlib/erb/0/erb.rbs +107 -0
  122. data/stdlib/logger/0/logger.rbs +2 -2
  123. data/stdlib/rdoc/0/rdoc.rbs +758 -0
  124. data/steep/Gemfile.lock +8 -8
  125. metadata +12 -6
  126. data/stdlib/fiber/0/fiber.rbs +0 -99
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rbs'
4
+
5
+ module RBS
6
+ module RDocPlugin
7
+ class Parser
8
+
9
+ attr_accessor :top_level, :content
10
+
11
+ def initialize(top_level, content)
12
+ @top_level = top_level
13
+ @content = content
14
+ end
15
+
16
+ def scan
17
+ ast = ::RBS::Parser.parse_signature(@content)
18
+ ast.each do |decl|
19
+ parse_member(decl: decl, context: @top_level)
20
+ end
21
+ @top_level
22
+ end
23
+
24
+ def parse_member(decl:, context:, outer_name: nil)
25
+ case decl
26
+ when ::RBS::AST::Declarations::Class
27
+ parse_class_decl(decl: decl, context: context, outer_name: outer_name)
28
+ when ::RBS::AST::Declarations::Module
29
+ parse_module_decl(decl: decl, context: context, outer_name: outer_name)
30
+ when ::RBS::AST::Declarations::Constant
31
+ context = @top_level.find_class_or_module outer_name.to_s if outer_name
32
+ parse_constant_decl(decl: decl, context: context, outer_name: outer_name)
33
+ when ::RBS::AST::Declarations::Interface
34
+ parse_module_decl(decl: decl, context: context, outer_name: outer_name)
35
+ when ::RBS::AST::Members::MethodDefinition
36
+ context = @top_level.find_class_or_module outer_name.to_s if outer_name
37
+ parse_method_decl(decl: decl, context: context, outer_name: outer_name)
38
+ when ::RBS::AST::Members::Alias
39
+ context = @top_level.find_class_or_module outer_name.to_s if outer_name
40
+ parse_method_alias_decl(decl: decl, context: context, outer_name: outer_name)
41
+ when ::RBS::AST::Members::AttrReader, ::RBS::AST::Members::AttrWriter, ::RBS::AST::Members::AttrAccessor
42
+ context = @top_level.find_class_or_module outer_name.to_s if outer_name
43
+ parse_attr_decl(decl: decl, context: context, outer_name: outer_name)
44
+ when ::RBS::AST::Members::Include
45
+ context = @top_level.find_class_or_module outer_name.to_s if outer_name
46
+ parse_include_decl(decl: decl, context: context, outer_name: outer_name)
47
+ when ::RBS::AST::Members::Extend
48
+ context = @top_level.find_class_or_module outer_name.to_s if outer_name
49
+ parse_extend_decl(decl: decl, context: context, outer_name: outer_name)
50
+ end
51
+ end
52
+
53
+ def parse_class_decl(decl:, context:, outer_name: nil)
54
+ full_name = fully_qualified_name(outer_name: outer_name, decl: decl)
55
+ klass = context.add_class(RDoc::NormalClass, full_name.to_s, decl.super_class&.name&.to_s || "::Object")
56
+ klass.add_comment(construct_comment(context: context, comment: comment_string(decl)), context) if decl.comment
57
+ decl.members.each { |member| parse_member(decl: member, context: context, outer_name: full_name) }
58
+ end
59
+
60
+ def parse_module_decl(decl:, context:, outer_name: nil)
61
+ full_name = fully_qualified_name(outer_name: outer_name, decl: _ = decl)
62
+ kmodule = context.add_module(RDoc::NormalModule, full_name.to_s)
63
+ kmodule.add_comment(construct_comment(context: context, comment: comment_string(decl)), context) if decl.comment
64
+ decl.members.each { |member| parse_member(decl: member, context: context, outer_name: full_name) }
65
+ end
66
+
67
+ def parse_constant_decl(decl:, context:, outer_name: nil)
68
+ comment = decl.comment ? construct_comment(context: context, comment: comment_string(decl)) : nil
69
+ constant = RDoc::Constant.new(decl.name.to_s, decl.type.to_s, comment)
70
+ context.add_constant(constant)
71
+ end
72
+
73
+ def parse_method_decl(decl:, context:, outer_name: nil)
74
+ method = RDoc::AnyMethod.new(nil, decl.name.to_s)
75
+ method.singleton = decl.singleton?
76
+ method.visibility = decl.visibility
77
+ method.call_seq = decl.types.map { |type| "#{decl.name.to_s}#{type.to_s}" }.join("\n")
78
+ if loc = decl.location
79
+ method.start_collecting_tokens
80
+ method.add_token({ line_no: 1, char_no: 1, kind: :on_comment, text: "# File #{@top_level.relative_name}, line(s) #{loc.start_line}:#{loc.end_line}\n" })
81
+ method.add_token({ line_no: 1, char_no: 1, text: loc.source })
82
+ method.line = loc.start_line
83
+ end
84
+ method.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
85
+ context.add_method(method)
86
+ end
87
+
88
+ def parse_method_alias_decl(decl:, context:, outer_name: nil)
89
+ alias_def = RDoc::Alias.new(nil, decl.old_name.to_s, decl.new_name.to_s, nil, decl.kind == :singleton)
90
+ alias_def.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
91
+ context.add_alias(alias_def)
92
+ end
93
+
94
+ def parse_attr_decl(decl:, context:, outer_name: nil)
95
+ rw = case decl
96
+ when ::RBS::AST::Members::AttrReader
97
+ 'R'
98
+ when ::RBS::AST::Members::AttrWriter
99
+ 'W'
100
+ when ::RBS::AST::Members::AttrAccessor
101
+ 'RW'
102
+ end
103
+ attribute = RDoc::Attr.new(nil, decl.name.to_s, rw, nil, decl.kind == :singleton)
104
+ attribute.visibility = decl.visibility
105
+ attribute.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
106
+ context.add_attribute(attribute)
107
+ end
108
+
109
+ def parse_include_decl(decl:, context:, outer_name: nil)
110
+ name = decl.name.to_s
111
+ outer_names = outer_name ? outer_name.to_s.split("::") : []
112
+ qualified_name = ''
113
+ outer_names.each do |namespace|
114
+ qualified_name += namespace
115
+ if (module_name = @top_level.find_module_named((qualified_name += "::") + name))
116
+ name = module_name.full_name
117
+ break
118
+ end
119
+ end
120
+ include_decl = RDoc::Include.new(name, nil)
121
+ include_decl.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
122
+ context.add_include(include_decl)
123
+ end
124
+
125
+ def parse_extend_decl(decl:, context:, outer_name: nil)
126
+ name = decl.name.to_s
127
+ outer_names = outer_name ? outer_name.to_s.split("::") : []
128
+ qualified_name = ''
129
+ outer_names.each do |namespace|
130
+ qualified_name += namespace
131
+ if (module_name = @top_level.find_module_named((qualified_name += "::") + name))
132
+ name = module_name.full_name
133
+ break
134
+ end
135
+ end
136
+ extend_decl = RDoc::Extend.new(name, nil)
137
+ extend_decl.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
138
+ context.add_extend(extend_decl)
139
+ end
140
+
141
+ private
142
+
143
+ def construct_comment(context:, comment:)
144
+ comment = RDoc::Comment.new(comment, context)
145
+ comment.format = "markdown"
146
+ comment
147
+ end
148
+
149
+ def comment_string(with_comment)
150
+ comment = with_comment.comment or raise "Object with `#comment` returning a object is expected"
151
+ comment.string
152
+ end
153
+
154
+ def fully_qualified_name(outer_name:, decl:)
155
+ if outer_name
156
+ (outer_name + decl.name)
157
+ else
158
+ decl.name
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -9,9 +9,15 @@
9
9
  },
10
10
  "required": {
11
11
  "type": "boolean"
12
+ },
13
+ "self_type": {
14
+ "oneOf": [
15
+ { "$ref": "#" },
16
+ { "type": "null" }
17
+ ]
12
18
  }
13
19
  },
14
- "required": ["type", "required"]
20
+ "required": ["type", "required", "self_type"]
15
21
  }
16
22
  },
17
23
  "title": "Method type: `() -> void`, `[X] (::Integer) { (::String) -> X } -> Array[X]`, ...",
data/schema/types.json CHANGED
@@ -238,9 +238,21 @@
238
238
  },
239
239
  "location": {
240
240
  "$ref": "location.json"
241
+ },
242
+ "block": {
243
+ "oneOf": [
244
+ { "$ref": "methodType.json#/definitions/block" },
245
+ { "type": "null" }
246
+ ]
247
+ },
248
+ "self_type": {
249
+ "oneOf": [
250
+ { "$ref": "#" },
251
+ { "type": "null" }
252
+ ]
241
253
  }
242
254
  },
243
- "required": ["class", "type", "location"]
255
+ "required": ["class", "type", "location", "block", "self_type"]
244
256
  },
245
257
  "literal": {
246
258
  "title": "Literal types: `1`, `:foo`, `\"foo\"`, ...",
@@ -1,15 +1,68 @@
1
1
  module RBS
2
2
  class DefinitionBuilder
3
+ # AncestorBuilder calculates the ancestors of a class or module.
4
+ #
3
5
  class AncestorBuilder
6
+ # OneAncestors represents a list of _direct_ ancestors of a type name
7
+ #
8
+ # _Direct_ ancestors is defined as follows:
9
+ #
10
+ # * Super class is a direct ancestor
11
+ # * Self type constraints are direct ancestors
12
+ # * Mixin modules are direct ancestors
13
+ # * Mixin interfaces are direct ancestors
14
+ #
15
+ # The optional attributes are defined by the type of the ancestors object, one of the following five groups:
16
+ #
17
+ # 1. Instance of a class -- with super_class, included_modules, included_interfaces, and prepended_modules
18
+ # 2. Instance of a module -- with self_types, included_modules, included_interfaces, and prepended_modules
19
+ # 3. Singleton of a class or module -- with super_class, extended_modules, and extended_interfaces
20
+ # 4. Interface -- with included_interfaces
21
+ #
4
22
  class OneAncestors
5
23
  attr_reader type_name: TypeName
6
24
  attr_reader params: Array[Symbol]?
25
+
26
+ # Returns super_class ancestor if specified
27
+ #
28
+ # * Always `nil` if this is not a class.
29
+ #
7
30
  attr_reader super_class: Definition::Ancestor::t?
31
+
32
+ # Returns list of _self type constraints_ of a module
33
+ #
34
+ # * Returns `nil` if it is not a module instance.
35
+ #
8
36
  attr_reader self_types: Array[Definition::Ancestor::Instance]?
37
+
38
+ # Returns the list of included modules
39
+ #
40
+ # * Returns `nil` if it is an interface or it is a singleton.
41
+ #
9
42
  attr_reader included_modules: Array[Definition::Ancestor::Instance]?
43
+
44
+ # Returns the list of included interfaces
45
+ #
46
+ # * Returns `nil` it it is a singleton.
47
+ #
10
48
  attr_reader included_interfaces: Array[Definition::Ancestor::Instance]?
49
+
50
+ # Returns the list of prepended modules
51
+ #
52
+ # * Returns `nil` if it is an interface or it is a singleton.
53
+ #
11
54
  attr_reader prepended_modules: Array[Definition::Ancestor::Instance]?
55
+
56
+ # Returns the list of extended modules
57
+ #
58
+ # * Returns `nil` if it is an interface or it is an instance.
59
+ #
12
60
  attr_reader extended_modules: Array[Definition::Ancestor::Instance]?
61
+
62
+ # Returns the list of extended interfaces
63
+ #
64
+ # * Returns `nil` if it is an interface or it is an instance.
65
+ #
13
66
  attr_reader extended_interfaces: Array[Definition::Ancestor::Instance]?
14
67
 
15
68
  def initialize: (type_name: TypeName,
@@ -25,12 +78,16 @@ module RBS
25
78
  def each_ancestor: { (Definition::Ancestor::t) -> void } -> void
26
79
  | -> Enumerator[Definition::Ancestor::t, void]
27
80
 
81
+ # Returns a OneAncestors object for class instance
28
82
  def self.class_instance: (type_name: TypeName, params: Array[Symbol], super_class: Definition::Ancestor::t?) -> instance
29
83
 
30
- def self.singleton: (type_name: TypeName, super_class: Definition::Ancestor::t?) -> instance
31
-
84
+ # Returns a OneAncestors object for module instance
32
85
  def self.module_instance: (type_name: TypeName, params: Array[Symbol]) -> instance
33
86
 
87
+ # Returns a OneAncestors object for class/module singleton
88
+ def self.singleton: (type_name: TypeName, super_class: Definition::Ancestor::t) -> instance
89
+
90
+ # Returns a OneAncestors object for interface
34
91
  def self.interface: (type_name: TypeName, params: Array[Symbol]) -> instance
35
92
 
36
93
  def each_included_module: () { (Definition::Ancestor::Instance) -> void } -> void
@@ -65,7 +122,11 @@ module RBS
65
122
 
66
123
  def initialize: (env: Environment) -> void
67
124
 
68
- def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
125
+ def instance_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
126
+
127
+ def singleton_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::SingletonAncestors
128
+
129
+ def interface_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
69
130
 
70
131
  def one_instance_ancestors: (TypeName) -> OneAncestors
71
132
 
@@ -73,11 +134,9 @@ module RBS
73
134
 
74
135
  def one_interface_ancestors: (TypeName) -> OneAncestors
75
136
 
76
- def instance_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
77
-
78
- def singleton_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::SingletonAncestors
137
+ private
79
138
 
80
- def interface_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
139
+ def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
81
140
 
82
141
  def mixin_ancestors: (Environment::ClassEntry | Environment::ModuleEntry,
83
142
  TypeName,
data/sig/annotation.rbs CHANGED
@@ -2,12 +2,13 @@ module RBS
2
2
  module AST
3
3
  # RBS allows writing annotations of declarations and members.
4
4
  #
5
- # %a{annotation_here}
6
- # class Hello
7
- # %a{rbs:test:skip}
8
- # def foo: () -> void
9
- # end
10
- #
5
+ # ```rbs
6
+ # %a{annotation_here}
7
+ # class Hello
8
+ # %a{rbs:test:skip}
9
+ # def foo: () -> void
10
+ # end
11
+ # ```
11
12
  class Annotation
12
13
  attr_reader string: String
13
14
  attr_reader location: Location[untyped, untyped]?
@@ -3,6 +3,8 @@ module RBS
3
3
  class Name
4
4
  attr_reader name: TypeName
5
5
 
6
+ @singleton_type: Types::t?
7
+
6
8
  def initialize: (name: TypeName) -> void
7
9
 
8
10
  def to_s: () -> String
data/sig/cli.rbs CHANGED
@@ -26,6 +26,14 @@ module RBS
26
26
  attr_reader stdout: _IO
27
27
  attr_reader stderr: _IO
28
28
 
29
+ # The copy of `args` passed to `run`.
30
+ #
31
+ # `OptionParser#order!` mutates given `arg`, the `run_***` actions should read `original_args` to get the original commandline arguments.
32
+ #
33
+ # Returns `nil` if called before `#run` call.
34
+ #
35
+ attr_reader original_args: Array[String]
36
+
29
37
  def initialize: (stdout: IO, stderr: IO) -> void
30
38
 
31
39
  COMMANDS: Array[Symbol]
@@ -3,6 +3,7 @@ module RBS
3
3
  # This class represent the configration file.
4
4
  class Config
5
5
  class CollectionNotAvailable < StandardError
6
+ def initialize: () -> void
6
7
  end
7
8
 
8
9
  class LockfileGenerator
@@ -11,6 +12,10 @@ module RBS
11
12
  attr_reader lock_path: Pathname
12
13
  attr_reader gemfile_lock: Bundler::LockfileParser
13
14
 
15
+ type gem_queue_entry = { name: String, version: String? }
16
+
17
+ @gem_queue: Array[gem_queue_entry]
18
+
14
19
  def self.generate: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
15
20
 
16
21
  def initialize: (config_path: Pathname, gemfile_lock_path: Pathname, with_lockfile: boolish) -> void
@@ -27,7 +32,7 @@ module RBS
27
32
 
28
33
  def remove_ignored_gems!: () -> void
29
34
 
30
- def find_source: (name: String) -> untyped
35
+ def find_source: (name: String) -> Sources::_Source?
31
36
 
32
37
  def find_best_version: (version: String?, versions: Array[String]) -> Gem::Version
33
38
  end
@@ -43,6 +48,10 @@ module RBS
43
48
 
44
49
  @config_path: Pathname
45
50
 
51
+ @data: untyped
52
+
53
+ @sources: Array[Sources::_Source]
54
+
46
55
  def self.generate_lockfile: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
47
56
 
48
57
  def self.from_path: (Pathname path) -> Config
@@ -54,9 +63,9 @@ module RBS
54
63
  # config_path is necessary to resolve relative repo_path
55
64
  def initialize: (untyped data, config_path: Pathname) -> void
56
65
 
57
- def add_gem: (untyped gem) -> untyped
66
+ def add_gem: (gem_entry gem) -> void
58
67
 
59
- def gem: (String gem_name) -> untyped
68
+ def gem: (String gem_name) -> gem_entry?
60
69
 
61
70
  def repo_path: () -> Pathname
62
71
 
@@ -64,7 +73,7 @@ module RBS
64
73
 
65
74
  def dump_to: (Pathname) -> void
66
75
 
67
- def gems: () -> Array[untyped]
76
+ def gems: () -> Array[gem_entry]
68
77
 
69
78
  def check_rbs_availability!: () -> void
70
79
  end
@@ -9,6 +9,8 @@ module RBS
9
9
 
10
10
  private
11
11
 
12
+ @source_for: Hash[Sources::source_entry, Sources::_Source]
13
+
12
14
  def source_for: (Config::gem_entry) -> Sources::_Source
13
15
  end
14
16
  end
@@ -9,16 +9,24 @@ module RBS
9
9
  def install: (dest: Pathname, config_entry: Config::gem_entry, stdout: CLI::_IO) -> void
10
10
  def to_lockfile: () -> source_entry
11
11
  def manifest_of: (Config::gem_entry) -> manifest_entry?
12
+ def dependencies_of: (Config::gem_entry) -> Array[{"name" => String}]?
12
13
  end
13
14
 
14
15
  type source_entry = Git::source_entry
15
- | Stdlib::source_entry
16
- | Rubygems::source_entry
16
+ | Stdlib::source_entry
17
+ | Rubygems::source_entry
18
+
17
19
  type manifest_entry = {
18
20
  "dependencies" => Array[{"name" => String}]?,
19
21
  }
20
22
 
23
+ module Base : _Source
24
+ def dependencies_of: (Config::gem_entry config_entry) -> Array[{"name" => String}]?
25
+ end
26
+
21
27
  class Git
28
+ include Base
29
+
22
30
  METADATA_FILENAME: String
23
31
 
24
32
  type source_entry = {
@@ -50,6 +58,10 @@ module RBS
50
58
 
51
59
  private
52
60
 
61
+ @git_dir: Pathname?
62
+
63
+ @resolved_revision: String?
64
+
53
65
  def _install: (dest: Pathname , config_entry: Config::gem_entry) -> void
54
66
 
55
67
  def cp_r: (Pathname, Pathname) -> void
@@ -77,6 +89,11 @@ module RBS
77
89
 
78
90
  # signatures that are bundled in rbs gem under the stdlib/ directory
79
91
  class Stdlib
92
+
93
+ REPO: Repository
94
+
95
+ include Base
96
+
80
97
  type source_entry = {
81
98
  'type' => 'stdlib',
82
99
  }
@@ -84,7 +101,7 @@ module RBS
84
101
  # polyfill of singleton module
85
102
  def self.instance: () -> instance
86
103
 
87
- def has?: (Config::gem_entry) -> bool
104
+ def has?: (Config::gem_entry) -> boolish
88
105
 
89
106
  def versions: (Config::gem_entry) -> Array[String]
90
107
 
@@ -96,11 +113,13 @@ module RBS
96
113
 
97
114
  private
98
115
 
99
- def gem_dir: (Config::gem_entry) -> Pathname
116
+ def lookup: (Config::gem_entry) -> Pathname?
100
117
  end
101
118
 
102
119
  # sig/ directory
103
120
  class Rubygems
121
+ include Base
122
+
104
123
  type source_entry = {
105
124
  'type' => 'rubygems',
106
125
  }
data/sig/definition.rbs CHANGED
@@ -69,6 +69,14 @@ module RBS
69
69
  def map_type_bound: () { (AST::TypeParam::bound) -> AST::TypeParam::bound } -> Method
70
70
 
71
71
  def map_method_type: () { (MethodType) -> MethodType } -> Method
72
+
73
+ def update: (
74
+ ?super_method: Method?,
75
+ ?defs: Array[TypeDef],
76
+ ?accessibility: accessibility,
77
+ ?alias_of: Method?,
78
+ ?annotations: Array[AST::Annotation]
79
+ ) -> Method
72
80
  end
73
81
 
74
82
  module Ancestor
@@ -1,4 +1,15 @@
1
1
  module RBS
2
+ # DefinitionBuilder translates TypeName to Definition of the type
3
+ #
4
+ # The translation goes three steps:
5
+ #
6
+ # 1. Calculate _ancestors_ of the type with AncestorBuilder
7
+ # 2. Calculate _partial_ definitions of each ancestor
8
+ # 3. Merge _partial_ definitions
9
+ #
10
+ # A _partial_ definition is a definition of one type name, in terms of it doesn't have methods of super classes nor included modules.
11
+ #
12
+ #
2
13
  class DefinitionBuilder
3
14
  attr_reader env: Environment
4
15
  attr_reader type_name_resolver: TypeNameResolver
@@ -12,18 +23,23 @@ module RBS
12
23
 
13
24
  def initialize: (env: Environment, ?ancestor_builder: AncestorBuilder?, ?method_builder: MethodBuilder?) -> void
14
25
 
15
- def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
16
-
17
- def ensure_namespace!: (Namespace, location: Location[untyped, untyped]?) -> void
18
-
19
26
  def build_interface: (TypeName) -> Definition
20
27
 
28
+ # Returns a Definition of a instance of given type name.
29
+ #
30
+ # If TypeName is a module and `no_self_types` is `true`, it won't have methods of _self type constraints_.
31
+ # This typically happens when definition is being calculated for mixin.
32
+ #
21
33
  def build_instance: (TypeName, ?no_self_types: bool) -> Definition
22
34
 
23
- def build_singleton0: (TypeName) -> Definition
24
-
25
35
  def build_singleton: (TypeName) -> Definition
26
36
 
37
+ def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
38
+
39
+ def ensure_namespace!: (Namespace, location: Location[untyped, untyped]?) -> void
40
+
41
+ def build_singleton0: (TypeName) -> Definition
42
+
27
43
  def merge_definition: (src: Definition, dest: Definition, subst: Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
28
44
 
29
45
  def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
@@ -41,7 +57,48 @@ module RBS
41
57
 
42
58
  def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
43
59
 
44
- def define_methods: (Definition, interface_methods: Hash[Symbol, Definition::Method], methods: MethodBuilder::Methods, super_interface_method: bool) -> void
60
+ # Add methods from `methods` to Definition
61
+ #
62
+ # * `methods`:
63
+ # * `interface_methods`: Methods of interfaces mixed into the type
64
+ # * `self_constraints_methods`: Methods of the self constraints methods
65
+ # * `super_interface_method`: `true` to have super method of existing method (`true` is the Definition is the target module)
66
+ #
67
+ def define_methods: (
68
+ Definition,
69
+ methods: MethodBuilder::Methods,
70
+ interface_methods: Hash[Symbol, Definition::Method],
71
+ methods_with_self: Hash[Symbol, Definition::Method]?,
72
+ super_interface_method: bool
73
+ ) -> void
74
+
75
+ # Define methods on singleton type
76
+ #
77
+ def define_methods_singleton: (
78
+ Definition,
79
+ methods: MethodBuilder::Methods,
80
+ interface_methods: Hash[Symbol, Definition::Method]
81
+ ) -> void
82
+
83
+ # Define methods on instance type
84
+ #
85
+ def define_methods_instance: (
86
+ Definition,
87
+ methods: MethodBuilder::Methods,
88
+ interface_methods: Hash[Symbol, Definition::Method]
89
+ ) -> void
90
+
91
+ # Define methods on module instance type
92
+ #
93
+ # * Pass `nil` to `module_self_methods:` to build a module instance type that will be mixed in to other modules/classes
94
+ # * Pass methods from self-type-constraints to build a module instance type alone (to type check itself)
95
+ #
96
+ def define_methods_module_instance: (
97
+ Definition,
98
+ methods: MethodBuilder::Methods,
99
+ interface_methods: Hash[Symbol, Definition::Method],
100
+ module_self_methods: Hash[Symbol, Definition::Method]?
101
+ ) -> void
45
102
 
46
103
  # Validates presence of type names recursively.
47
104
  # Assumes the type names are already resolved.
data/sig/environment.rbs CHANGED
@@ -33,6 +33,8 @@ module RBS
33
33
  attr_reader name: TypeName
34
34
  attr_reader decls: Array[D[M]]
35
35
 
36
+ @primary: D[M]?
37
+
36
38
  def initialize: (name: TypeName) -> void
37
39
 
38
40
  def insert: (decl: M, outer: Array[module_decl]) -> void
@@ -115,6 +117,8 @@ module RBS
115
117
 
116
118
  def inspect: () -> String
117
119
 
120
+ @buffers: Array[Buffer]
121
+
118
122
  def buffers: () -> Array[Buffer]
119
123
 
120
124
  def buffers_decls: () -> Hash[Buffer, Array[AST::Declarations::t]]
@@ -40,7 +40,7 @@ module RBS
40
40
  attr_reader core_root: Pathname?
41
41
  attr_reader repository: Repository
42
42
 
43
- attr_reader libs: Array[Library]
43
+ attr_reader libs: Set[Library]
44
44
  attr_reader dirs: Array[Pathname]
45
45
 
46
46
  # The source where the RBS comes from.
@@ -76,7 +76,9 @@ module RBS
76
76
  # If RBS files cannot be found in the gem, it tries to load RBSs from repository.
77
77
  #
78
78
  def add: (path: Pathname) -> void
79
- | (library: String, version: String?) -> void
79
+ | (library: String, version: String?, ?resolve_dependencies: boolish) -> void
80
+
81
+ def resolve_dependencies: (library: String, version: String?) -> void
80
82
 
81
83
  # Add repository path and libraries via rbs_collection.lock.yaml.
82
84
  def add_collection: (Collection::Config collection_config) -> void