rbs 3.9.2 → 4.0.0.dev.1

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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.github/workflows/windows.yml +1 -1
  4. data/CHANGELOG.md +0 -13
  5. data/Rakefile +28 -21
  6. data/Steepfile +1 -0
  7. data/config.yml +232 -62
  8. data/ext/rbs_extension/ast_translation.c +1149 -0
  9. data/ext/rbs_extension/ast_translation.h +30 -0
  10. data/{src/constants.c → ext/rbs_extension/class_constants.c} +15 -1
  11. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +10 -1
  12. data/ext/rbs_extension/extconf.rb +3 -1
  13. data/ext/rbs_extension/{location.c → legacy_location.c} +25 -34
  14. data/ext/rbs_extension/legacy_location.h +40 -0
  15. data/ext/rbs_extension/main.c +402 -8
  16. data/ext/rbs_extension/rbs_extension.h +3 -21
  17. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  18. data/ext/rbs_extension/rbs_string_bridging.h +20 -0
  19. data/include/rbs/ast.h +748 -0
  20. data/include/rbs/defines.h +60 -0
  21. data/{ext/rbs_extension → include/rbs}/lexer.h +40 -32
  22. data/include/rbs/location.h +59 -0
  23. data/include/rbs/parser.h +151 -0
  24. data/include/rbs/string.h +49 -0
  25. data/include/rbs/util/rbs_allocator.h +38 -0
  26. data/include/rbs/util/rbs_assert.h +9 -0
  27. data/include/rbs/util/rbs_buffer.h +83 -0
  28. data/include/rbs/util/rbs_constant_pool.h +3 -64
  29. data/include/rbs/util/rbs_encoding.h +280 -0
  30. data/include/rbs/util/rbs_unescape.h +23 -0
  31. data/include/rbs.h +1 -2
  32. data/lib/rbs/annotate/formatter.rb +3 -13
  33. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  34. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  35. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  36. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  37. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  38. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  39. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  40. data/lib/rbs/ast/ruby/members.rb +213 -0
  41. data/lib/rbs/buffer.rb +104 -24
  42. data/lib/rbs/cli/validate.rb +39 -34
  43. data/lib/rbs/cli.rb +4 -5
  44. data/lib/rbs/definition.rb +6 -1
  45. data/lib/rbs/definition_builder/ancestor_builder.rb +63 -60
  46. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  47. data/lib/rbs/definition_builder.rb +44 -9
  48. data/lib/rbs/environment/class_entry.rb +69 -0
  49. data/lib/rbs/environment/module_entry.rb +66 -0
  50. data/lib/rbs/environment.rb +185 -154
  51. data/lib/rbs/environment_loader.rb +2 -2
  52. data/lib/rbs/errors.rb +4 -3
  53. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  54. data/lib/rbs/inline_parser.rb +206 -0
  55. data/lib/rbs/location_aux.rb +35 -3
  56. data/lib/rbs/parser_aux.rb +11 -1
  57. data/lib/rbs/prototype/runtime.rb +2 -2
  58. data/lib/rbs/source.rb +99 -0
  59. data/lib/rbs/subtractor.rb +4 -3
  60. data/lib/rbs/version.rb +1 -1
  61. data/lib/rbs.rb +12 -0
  62. data/lib/rdoc/discover.rb +1 -1
  63. data/lib/rdoc_plugin/parser.rb +2 -2
  64. data/rbs.gemspec +1 -0
  65. data/sig/ancestor_builder.rbs +1 -1
  66. data/sig/annotate/formatter.rbs +2 -2
  67. data/sig/annotate/rdoc_annotater.rbs +1 -1
  68. data/sig/ast/ruby/annotations.rbs +110 -0
  69. data/sig/ast/ruby/comment_block.rbs +119 -0
  70. data/sig/ast/ruby/declarations.rbs +60 -0
  71. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  72. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  73. data/sig/ast/ruby/members.rbs +72 -0
  74. data/sig/buffer.rbs +63 -5
  75. data/sig/definition.rbs +1 -0
  76. data/sig/definition_builder.rbs +1 -1
  77. data/sig/environment/class_entry.rbs +50 -0
  78. data/sig/environment/module_entry.rbs +50 -0
  79. data/sig/environment.rbs +22 -76
  80. data/sig/errors.rbs +13 -6
  81. data/sig/inline_parser/comment_association.rbs +71 -0
  82. data/sig/inline_parser.rbs +87 -0
  83. data/sig/location.rbs +32 -7
  84. data/sig/method_builder.rbs +7 -4
  85. data/sig/parser.rbs +16 -0
  86. data/sig/source.rbs +48 -0
  87. data/src/ast.c +1345 -0
  88. data/src/lexer.c +2867 -0
  89. data/src/lexer.re +151 -0
  90. data/{ext/rbs_extension → src}/lexstate.c +58 -42
  91. data/src/location.c +71 -0
  92. data/src/parser.c +3739 -0
  93. data/src/string.c +89 -0
  94. data/src/util/rbs_allocator.c +149 -0
  95. data/src/util/rbs_assert.c +19 -0
  96. data/src/util/rbs_buffer.c +54 -0
  97. data/src/util/rbs_constant_pool.c +13 -81
  98. data/src/util/rbs_encoding.c +5273 -0
  99. data/src/util/rbs_unescape.c +130 -0
  100. data/stdlib/rdoc/0/code_object.rbs +2 -2
  101. data/stdlib/rdoc/0/comment.rbs +2 -0
  102. data/stdlib/rdoc/0/options.rbs +76 -0
  103. data/stdlib/rdoc/0/rdoc.rbs +6 -4
  104. data/stdlib/rdoc/0/store.rbs +1 -1
  105. metadata +70 -17
  106. data/ext/rbs_extension/lexer.c +0 -2728
  107. data/ext/rbs_extension/lexer.re +0 -147
  108. data/ext/rbs_extension/location.h +0 -85
  109. data/ext/rbs_extension/parser.c +0 -2982
  110. data/ext/rbs_extension/parser.h +0 -18
  111. data/ext/rbs_extension/parserstate.c +0 -411
  112. data/ext/rbs_extension/parserstate.h +0 -163
  113. data/ext/rbs_extension/unescape.c +0 -32
  114. data/include/rbs/ruby_objs.h +0 -72
  115. data/src/ruby_objs.c +0 -799
@@ -0,0 +1,119 @@
1
+ use Prism::Comment
2
+
3
+ module RBS
4
+ module AST
5
+ module Ruby
6
+ # CommentBlock is a collection of comments
7
+ #
8
+ # ```ruby
9
+ # # Comment1 < block1
10
+ # # Comment2 <
11
+ #
12
+ # # Comment3 < block2
13
+ # ```
14
+ #
15
+ # A comment block is a *leading* block or *trailing* block.
16
+ #
17
+ # ```ruby
18
+ # # This is leading block.
19
+ # # This is the second line of the leading block.
20
+ #
21
+ # foo # This is trailing block.
22
+ # # This is second line of the trailing block.
23
+ # ```
24
+ #
25
+ # A leading block is a comment block where all of the comments are at the start of the line content.
26
+ # A trailing block is a comment block where the first comment of the block has something at the line before the comment.
27
+ #
28
+ class CommentBlock
29
+ attr_reader name: Pathname
30
+
31
+ # Sub buffer of the contents of the comments
32
+ #
33
+ attr_reader comment_buffer: Buffer
34
+
35
+ attr_reader offsets: Array[
36
+ [
37
+ Comment,
38
+ Integer, # -- prefix size
39
+ ]
40
+ ]
41
+
42
+ def initialize: (Buffer source_buffer, Array[Comment]) -> void
43
+
44
+ # Build comment block instances
45
+ def self.build: (Buffer, Array[Comment]) -> Array[instance]
46
+
47
+ # Returns true if the comment block is a *leading* comment, which is attached to the successor node
48
+ def leading?: () -> bool
49
+
50
+ # Returns true if the comment block is a *trailing* comment, which is attached to the predecessor node
51
+ def trailing?: () -> bool
52
+
53
+ # The line number of the first comment in the block
54
+ def start_line: () -> Integer
55
+
56
+ # The line number of the last comment in the block
57
+ def end_line: () -> Integer
58
+
59
+ # The character index of `#comment_buffer` at the start of the lines
60
+ #
61
+ def line_starts: () -> Array[Integer]
62
+
63
+ # Returns the text content of the comment
64
+ def text: (Integer index) -> String
65
+
66
+ # Yields paragraph and annotation
67
+ #
68
+ # A paragraph is a sequence of lines that are separated by annotations.
69
+ # An annotation starts with a line starting with `@rbs` or `:`, and may continue with lines that has more leading spaces.
70
+ #
71
+ # ```
72
+ # # Line 1 ^ Paragraph 1
73
+ # # Line 2 |
74
+ # # |
75
+ # # Line 3 v
76
+ # # @rbs ... < Annotation 1
77
+ # # @rbs ... ^ Annotation 2
78
+ # # ... |
79
+ # # |
80
+ # # ... v
81
+ # # ^ Paragraph 2
82
+ # # Line 4 |
83
+ # # Line 5 v
84
+ # ```
85
+ #
86
+ def each_paragraph: (Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
87
+ | (Array[Symbol] variables) -> Enumerator[Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError]
88
+
89
+ # Returns a trailing annotation if it exists
90
+ #
91
+ # * Returns `nil` if the block is not a type annotation
92
+ # * Returns an annotation if the block has a type annotation
93
+ # * Returns AnnotationSyntaxError if the annotation has a syntax error
94
+ #
95
+ def trailing_annotation: (Array[Symbol] variables) -> (AST::Ruby::Annotations::trailing_annotation | AnnotationSyntaxError | nil)
96
+
97
+ class AnnotationSyntaxError
98
+ attr_reader location: Location
99
+
100
+ attr_reader error: ParsingError
101
+
102
+ def initialize: (Location, ParsingError) -> void
103
+ end
104
+
105
+ private def yield_paragraph: (Integer start_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
106
+
107
+ private def yield_annotation: (Integer start_line, Integer end_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
108
+
109
+ private def parse_annotation_lines: (Integer start_line, Integer end_line, Array[Symbol] variables) -> (AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError)
110
+
111
+ def comments: () -> Array[Comment]
112
+
113
+ def line_location: (Integer start_line, Integer end_line) -> Location
114
+
115
+ private def leading_annotation?: (Integer index) -> bool
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,60 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Declarations
5
+ type t = ClassDecl | ModuleDecl
6
+
7
+ class Base
8
+ attr_reader buffer: Buffer
9
+
10
+ include Helpers::ConstantHelper
11
+ include Helpers::LocationHelper
12
+
13
+ def initialize: (Buffer) -> void
14
+ end
15
+
16
+ class ClassDecl < Base
17
+ type member = t | Members::t
18
+
19
+ attr_reader class_name: TypeName
20
+
21
+ attr_reader node: Prism::ClassNode
22
+
23
+ attr_reader members: Array[member]
24
+
25
+ def initialize: (Buffer, TypeName, Prism::ClassNode) -> void
26
+
27
+ def each_decl: () { (t) -> void } -> void
28
+ | () -> Enumerator[t]
29
+
30
+ def super_class: () -> nil
31
+
32
+ def type_params: () -> Array[AST::TypeParam]
33
+
34
+ def location: () -> Location
35
+ end
36
+
37
+ class ModuleDecl < Base
38
+ type member = t | Members::t
39
+
40
+ attr_reader module_name: TypeName
41
+
42
+ attr_reader node: Prism::ModuleNode
43
+
44
+ attr_reader members: Array[member]
45
+
46
+ def initialize: (Buffer, TypeName, Prism::ModuleNode) -> void
47
+
48
+ def each_decl: () { (t) -> void } -> void
49
+ | () -> Enumerator[t]
50
+
51
+ def type_params: () -> Array[AST::TypeParam]
52
+
53
+ def location: () -> Location
54
+
55
+ def self_types: () -> Array[AST::Declarations::Module::Self]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Helpers
5
+ module ConstantHelper
6
+ def self?.constant_as_type_name: (Prism::node?) -> TypeName?
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Helpers
5
+ module LocationHelper : _WithBuffer
6
+ interface _WithBuffer
7
+ def buffer: () -> Buffer
8
+ end
9
+
10
+ def rbs_location: (Prism::Location) -> Location
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,72 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Members
5
+ class Base
6
+ attr_reader buffer: Buffer
7
+
8
+ def initialize: (Buffer) -> void
9
+
10
+ include Helpers::LocationHelper
11
+ end
12
+
13
+ type t = DefMember
14
+
15
+ class MethodTypeAnnotation
16
+ class DocStyle
17
+ attr_accessor return_type_annotation: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil
18
+
19
+ def initialize: () -> void
20
+
21
+ def map_type_name: () { (TypeName) -> TypeName } -> self
22
+
23
+ def method_type: () -> MethodType
24
+ end
25
+
26
+ type type_annotations = DocStyle | Array[Annotations::ColonMethodTypeAnnotation | Annotations::MethodTypesAnnotation] | nil
27
+
28
+ attr_reader type_annotations: type_annotations
29
+
30
+ def initialize: (type_annotations: type_annotations) -> void
31
+
32
+ def map_type_name: { (TypeName) -> TypeName } -> self
33
+
34
+ # Returns the method type annotations from the comment block
35
+ #
36
+ # Returns a tuple of `DefAnnotations` object, array of unused leading annotations, and unused trailing annotation.
37
+ #
38
+ def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol]) -> [
39
+ MethodTypeAnnotation,
40
+ Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError],
41
+ Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
42
+ ]
43
+
44
+ # Returns `true` if it doesn't have any annotation
45
+ def empty?: () -> bool
46
+
47
+ # Returns the method type overloads
48
+ #
49
+ def overloads: () -> Array[AST::Members::MethodDefinition::Overload]
50
+ end
51
+
52
+ class DefMember < Base
53
+ class Overload = AST::Members::MethodDefinition::Overload
54
+
55
+ attr_reader name: Symbol
56
+ attr_reader node: Prism::DefNode
57
+ attr_reader method_type: MethodTypeAnnotation
58
+
59
+ def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation) -> void
60
+
61
+ def location: () -> Location
62
+
63
+ def overloads: () -> Array[Overload]
64
+
65
+ def overloading?: () -> bool
66
+
67
+ def annotations: () -> Array[AST::Annotation]
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
data/sig/buffer.rbs CHANGED
@@ -6,21 +6,45 @@ module RBS
6
6
  type loc = [Integer, Integer]
7
7
 
8
8
  # Name to identify Buffer.
9
- attr_reader name: untyped
9
+ attr_reader name: Pathname
10
10
 
11
11
  # The content of the buffer.
12
12
  attr_reader content: String
13
13
 
14
- @lines: Array[String]
14
+ attr_reader parent: [Buffer, Array[Range[Integer]]]?
15
15
 
16
- @ranges: Array[Range[Integer]]
17
-
18
- def initialize: (name: untyped name, content: String content) -> void
16
+ def initialize: (name: Pathname name, content: String content) -> void
17
+ | (content: String content, parent: [Buffer, Array[Range[Integer]]] parent) -> void
19
18
 
19
+ # Array of lines of the content, without the EOL
20
+ #
21
+ # ```rb
22
+ # buffer = Buffer.new(name: name, content: "123\nabc")
23
+ # buffer.lines # => ["123", "abc"]
24
+ # ```
25
+ #
26
+ # If the input has EOL at the end of the file, the `lines` has an empty string at the end.
27
+ #
28
+ # ```rb
29
+ # buffer = Buffer.new(name: name, content: "123\nabc\n")
30
+ # buffer.lines # => ["123", "abc", ""]
31
+ # ```
32
+ #
20
33
  def lines: () -> Array[String]
21
34
 
35
+ @ranges: Array[Range[Integer]]?
36
+ # Array of ranges that stores the ranges of the each line, without the EOL
37
+ #
38
+ # ```rb
39
+ # buffer = Buffer.new(name: name, content: "123\nabc\n")
40
+ # buffer.ranges # => [0...3, 4...7, 8...8]
41
+ # ```
42
+ #
22
43
  def ranges: () -> Array[Range[Integer]]
23
44
 
45
+ # Returns the number of the lines
46
+ def line_count: () -> Integer
47
+
24
48
  # Translate position to location.
25
49
  def pos_to_loc: (Integer pos) -> loc
26
50
 
@@ -28,5 +52,39 @@ module RBS
28
52
  def loc_to_pos: (loc loc) -> Integer
29
53
 
30
54
  def last_position: () -> Integer
55
+
56
+ # Translate `Prism::Location` to `RBS::Location` attached to this buffer
57
+ #
58
+ # It assumes the `Prism::Location` has a source which is equivalent to `self`.
59
+ #
60
+ def rbs_location: (Prism::Location) -> Location
61
+ | (Prism::Location, Prism::Location) -> Location
62
+
63
+ # Construct a buffer from substrings of this buffer.
64
+ #
65
+ # The returned buffer contains lines from given ranges.
66
+ #
67
+ # ```rb
68
+ # buffer = Buffer.new(name: name, content: <<TEXT)
69
+ # 12345
70
+ # abcde
71
+ # ABCDE
72
+ # TEXT
73
+ #
74
+ # buffer.sub_buffer(lines: [0...1, 2...3]) # => Buffer with content = 1\n34
75
+ # buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline
76
+ # ```
77
+ #
78
+ %a{pure} def sub_buffer: (lines: Array[Range[Integer]]) -> Buffer
79
+
80
+ %a{pure} def parent_buffer: () -> Buffer?
81
+
82
+ %a{pure} def parent_position: (Integer) -> Integer?
83
+
84
+ %a{pure} def absolute_position: (Integer) -> Integer?
85
+
86
+ %a{pure} def top_buffer: () -> Buffer
87
+
88
+ %a{pure} def detach: () -> Buffer
31
89
  end
32
90
  end
data/sig/definition.rbs CHANGED
@@ -21,6 +21,7 @@ module RBS
21
21
 
22
22
  class Method
23
23
  type method_member = AST::Members::MethodDefinition | AST::Members::AttrReader | AST::Members::AttrAccessor | AST::Members::AttrWriter
24
+ | AST::Ruby::Members::DefMember
24
25
 
25
26
  class TypeDef
26
27
  attr_reader type: MethodType
@@ -103,7 +103,7 @@ module RBS
103
103
 
104
104
  def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
105
105
 
106
- def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
106
+ def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t | AST::Ruby::Declarations::t) -> Location[untyped, untyped]?
107
107
 
108
108
  def validate_variable: (Definition::Variable) -> void
109
109
 
@@ -0,0 +1,50 @@
1
+ module RBS
2
+ class Environment
3
+ # Represents a class entry in the environment
4
+ #
5
+ # ```rb
6
+ # entry = ClassEntry.new(TypeName.parse("::String"))
7
+ # entry << [nil, declaration]
8
+ # entry << [[nil, TypeName.parse("::Kernel")], declaration]
9
+ # ```
10
+ class ClassEntry
11
+ attr_reader name: TypeName
12
+
13
+ type declaration = AST::Declarations::Class | AST::Ruby::Declarations::ClassDecl
14
+
15
+ type context_decl = [Resolver::context, declaration]
16
+
17
+ attr_reader context_decls: Array[context_decl]
18
+
19
+ @primary_decl: declaration?
20
+
21
+ def initialize: (TypeName) -> void
22
+
23
+ def <<: (context_decl) -> self
24
+
25
+ def each_decl: { (declaration) -> void } -> void
26
+ | () -> Enumerator[declaration]
27
+
28
+ # Returns true if the entry doesn't have any declaration
29
+ #
30
+ def empty?: () -> bool
31
+
32
+ # Find the *primary* declaration of the class
33
+ #
34
+ # * Returns the first declaration with super class
35
+ # * Returns the first declaration if the declaration doesn't have super class
36
+ #
37
+ %a{pure} def primary_decl: () -> declaration
38
+
39
+ # Returns the generics declaration
40
+ #
41
+ def type_params: () -> Array[AST::TypeParam]
42
+
43
+ # Confirms if the type parameters in the declaration are compatible
44
+ #
45
+ # * Raises `GenericParameterMismatchError` if incompatible declaration is detected.
46
+ #
47
+ def validate_type_params: () -> void
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ module RBS
2
+ class Environment
3
+ # Represents a class entry in the environment
4
+ #
5
+ # ```rb
6
+ # entry = ModuleEntry.new(TypeName.parse("::Kernel"))
7
+ # entry << [nil, declaration]
8
+ # entry << [[nil, TypeName.parse("::Object")], declaration]
9
+ # ```
10
+ #
11
+ class ModuleEntry
12
+ attr_reader name: TypeName
13
+
14
+ type declaration = AST::Declarations::Module | AST::Ruby::Declarations::ModuleDecl
15
+
16
+ type context_decl = [Resolver::context, declaration]
17
+
18
+ attr_reader context_decls: Array[context_decl]
19
+
20
+ def initialize: (TypeName) -> void
21
+
22
+ def <<: (context_decl) -> self
23
+
24
+ def each_decl: { (declaration) -> void } -> void
25
+ | () -> Enumerator[declaration]
26
+
27
+ # Returns true if the entry doesn't have any declaration
28
+ #
29
+ def empty?: () -> bool
30
+
31
+ # Returns the first declaration
32
+ #
33
+ # This method helps using the class with `ClassEntry` objects.
34
+ #
35
+ def primary_decl: () -> declaration
36
+
37
+ # Returns the generics declaration
38
+ #
39
+ def type_params: () -> Array[AST::TypeParam]
40
+
41
+ # Confirms if the type parameters in the declaration are compatible
42
+ #
43
+ # * Raises `GenericParameterMismatchError` if incompatible declaration is detected.
44
+ #
45
+ def validate_type_params: () -> void
46
+
47
+ def self_types: () -> Array[AST::Declarations::Module::Self]
48
+ end
49
+ end
50
+ end
data/sig/environment.rbs CHANGED
@@ -2,75 +2,14 @@ module RBS
2
2
  class Environment
3
3
  type module_decl = AST::Declarations::Class | AST::Declarations::Module
4
4
 
5
- interface _ModuleOrClass
6
- def name: () -> TypeName
7
-
8
- def type_params: () -> Array[AST::TypeParam]
9
- end
10
-
11
- interface _NamedDecl
12
- def name: () -> TypeName
13
- end
14
-
15
- module ContextUtil
16
- def calculate_context: (Array[_NamedDecl]) -> Resolver::context
17
- end
18
-
19
- # Name of object, it's (multiple) declarations with the outer module declarations
20
- #
21
- class MultiEntry[M < _ModuleOrClass]
22
- class D[M < _ModuleOrClass]
23
- attr_reader decl: M
24
- attr_reader outer: Array[module_decl]
25
-
26
- def initialize: (decl: M, outer: Array[module_decl]) -> void
27
-
28
- include ContextUtil
29
-
30
- @context: Resolver::context
31
-
32
- def context: () -> Resolver::context
33
- end
34
-
35
- attr_reader name: TypeName
36
- attr_reader decls: Array[D[M]]
37
-
38
- @primary: D[M]?
39
-
40
- def initialize: (name: TypeName) -> void
41
-
42
- def insert: (decl: M, outer: Array[module_decl]) -> void
43
-
44
- def validate_type_params: () -> void
45
-
46
- def compatible_params?: (Array[AST::TypeParam], Array[AST::TypeParam]) -> boolish
47
-
48
- def type_params: () -> Array[AST::TypeParam]
49
-
50
- def primary: () -> D[M]
51
- end
52
-
53
- class ModuleEntry < MultiEntry[AST::Declarations::Module]
54
- def self_types: () -> Array[AST::Declarations::Module::Self]
55
- end
56
-
57
- class ClassEntry < MultiEntry[AST::Declarations::Class]
58
- end
59
-
60
5
  # Name of object, it's (single) declaration, and the outer module declarations
61
6
  #
62
7
  class SingleEntry[N, D]
63
8
  attr_reader name: N
64
9
  attr_reader decl: D
65
- attr_reader outer: Array[module_decl]
66
-
67
- def initialize: (name: N, decl: D, outer: Array[module_decl]) -> void
68
-
69
- include ContextUtil
10
+ attr_reader context: Resolver::context
70
11
 
71
- @context: Resolver::context
72
-
73
- def context: () -> Resolver::context
12
+ def initialize: (name: N, decl: D, context: Resolver::context) -> void
74
13
  end
75
14
 
76
15
  class ModuleAliasEntry < SingleEntry[TypeName, AST::Declarations::ModuleAlias]
@@ -91,8 +30,9 @@ module RBS
91
30
  class GlobalEntry < SingleEntry[Symbol, AST::Declarations::Global]
92
31
  end
93
32
 
94
- # Top level declarations
95
- attr_reader declarations: Array[AST::Declarations::t]
33
+ # Array of source objects loaded in the environment
34
+ #
35
+ attr_reader sources: Array[Source::t]
96
36
 
97
37
  # Class declarations
98
38
  attr_reader class_decls: Hash[TypeName, ModuleEntry | ClassEntry]
@@ -111,10 +51,6 @@ module RBS
111
51
  # Global declarations
112
52
  attr_reader global_decls: Hash[Symbol, GlobalEntry]
113
53
 
114
- # A hash from Buffer to it's contents
115
- #
116
- attr_reader signatures: Hash[Buffer, [Array[AST::Directives::t], Array[AST::Declarations::t]]]
117
-
118
54
  def initialize: () -> void
119
55
 
120
56
  def initialize_copy: (Environment) -> void
@@ -123,15 +59,21 @@ module RBS
123
59
  #
124
60
  def self.from_loader: (EnvironmentLoader) -> Environment
125
61
 
126
- def add_signature: (buffer: Buffer, directives: Array[AST::Directives::t], decls: Array[AST::Declarations::t]) -> void
62
+ def add_source: (Source::t) -> void
63
+
64
+ def each_rbs_source: () { (Source::RBS) -> void } -> void
65
+ | () -> Enumerator[Source::RBS]
127
66
 
128
- # Insert a toplevel declaration into the environment
67
+ def each_ruby_source: () { (Source::Ruby) -> void } -> void
68
+ | () -> Enumerator[Source::Ruby]
69
+
70
+ # Insert a declaration into the environment
129
71
  #
130
- def <<: (AST::Declarations::t decl) -> self
72
+ private def insert_rbs_decl: (AST::Declarations::t, context: Resolver::context, namespace: Namespace) -> void
131
73
 
132
74
  # Insert a declaration into the environment
133
75
  #
134
- private def insert_decl: (AST::Declarations::t, outer: Array[module_decl], namespace: Namespace) -> void
76
+ private def insert_ruby_decl: (AST::Ruby::Declarations::t, context: Resolver::context, namespace: Namespace) -> void
135
77
 
136
78
  # Resolve all type names in the environment to absolute type names.
137
79
  # Relative type name will be left if absolute type name cannot be found.
@@ -264,7 +206,7 @@ module RBS
264
206
 
265
207
  def append_context: (Resolver::context, module_decl) -> Resolver::context
266
208
 
267
- def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, outer: Array[module_decl], prefix: Namespace) -> AST::Declarations::t
209
+ def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, context: Resolver::context, prefix: Namespace) -> AST::Declarations::t
268
210
 
269
211
  def resolve_member: (Resolver::TypeNameResolver, UseMap map, AST::Members::t, context: Resolver::context) -> AST::Members::t
270
212
 
@@ -272,8 +214,12 @@ module RBS
272
214
 
273
215
  def resolve_type_params: (Resolver::TypeNameResolver resolver, UseMap map, Array[AST::TypeParam], context: Resolver::context) -> Array[AST::TypeParam]
274
216
 
275
- def absolute_type: (Resolver::TypeNameResolver, UseMap map, Types::t, context: Resolver::context) -> Types::t
217
+ def resolve_ruby_decl: (Resolver::TypeNameResolver, AST::Ruby::Declarations::t, context: Resolver::context, prefix: Namespace) -> AST::Ruby::Declarations::t
218
+
219
+ def resolve_ruby_member: (Resolver::TypeNameResolver, AST::Ruby::Members::t, context: Resolver::context) -> AST::Ruby::Members::t
220
+
221
+ def absolute_type: (Resolver::TypeNameResolver, UseMap? map, Types::t, context: Resolver::context) -> Types::t
276
222
 
277
- def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName
223
+ def absolute_type_name: (Resolver::TypeNameResolver, UseMap? map, TypeName, context: Resolver::context) -> TypeName
278
224
  end
279
225
  end
data/sig/errors.rbs CHANGED
@@ -226,28 +226,35 @@ module RBS
226
226
  class InvalidOverloadMethodError < DefinitionError
227
227
  include DetailedMessageable
228
228
 
229
+ type member = AST::Members::MethodDefinition | AST::Ruby::Members::DefMember
230
+
229
231
  attr_reader type_name: TypeName
230
232
  attr_reader method_name: Symbol
231
233
  attr_reader kind: :instance | :singleton
232
- attr_reader members: Array[AST::Members::MethodDefinition]
234
+ attr_reader members: Array[member]
233
235
 
234
- def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[AST::Members::MethodDefinition]) -> void
236
+ def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[member]) -> void
235
237
 
236
238
  def location: () -> AST::Members::MethodDefinition::loc?
237
239
  end
238
240
 
239
241
  class GenericParameterMismatchError < LoadingError
242
+ type decl = AST::Declarations::Class | AST::Declarations::Module
243
+ | AST::Ruby::Declarations::ClassDecl | AST::Ruby::Declarations::ModuleDecl
244
+
240
245
  attr_reader name: TypeName
241
- attr_reader decl: AST::Declarations::Class | AST::Declarations::Module
246
+ attr_reader decl: decl
242
247
 
243
- def initialize: (name: TypeName, decl: AST::Declarations::Class | AST::Declarations::Module) -> void
248
+ def initialize: (name: TypeName, decl: decl, ?location: Location) -> void
244
249
  end
245
250
 
246
251
  class DuplicatedDeclarationError < LoadingError
252
+ type declaration = AST::Declarations::t | AST::Ruby::Declarations::t
253
+
247
254
  attr_reader name: TypeName | Symbol
248
- attr_reader decls: Array[AST::Declarations::t]
255
+ attr_reader decls: Array[declaration]
249
256
 
250
- def initialize: (TypeName | Symbol, *AST::Declarations::t) -> void
257
+ def initialize: (TypeName | Symbol, *declaration) -> void
251
258
  end
252
259
 
253
260
  class InvalidVarianceAnnotationError < DefinitionError