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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/CHANGELOG.md +0 -13
- data/Rakefile +28 -21
- data/Steepfile +1 -0
- data/config.yml +232 -62
- data/ext/rbs_extension/ast_translation.c +1149 -0
- data/ext/rbs_extension/ast_translation.h +30 -0
- data/{src/constants.c → ext/rbs_extension/class_constants.c} +15 -1
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +10 -1
- data/ext/rbs_extension/extconf.rb +3 -1
- data/ext/rbs_extension/{location.c → legacy_location.c} +25 -34
- data/ext/rbs_extension/legacy_location.h +40 -0
- data/ext/rbs_extension/main.c +402 -8
- data/ext/rbs_extension/rbs_extension.h +3 -21
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +20 -0
- data/include/rbs/ast.h +748 -0
- data/include/rbs/defines.h +60 -0
- data/{ext/rbs_extension → include/rbs}/lexer.h +40 -32
- data/include/rbs/location.h +59 -0
- data/include/rbs/parser.h +151 -0
- data/include/rbs/string.h +49 -0
- data/include/rbs/util/rbs_allocator.h +38 -0
- data/include/rbs/util/rbs_assert.h +9 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +3 -64
- data/include/rbs/util/rbs_encoding.h +280 -0
- data/include/rbs/util/rbs_unescape.h +23 -0
- data/include/rbs.h +1 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/ast/ruby/annotations.rb +119 -0
- data/lib/rbs/ast/ruby/comment_block.rb +221 -0
- data/lib/rbs/ast/ruby/declarations.rb +86 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +213 -0
- data/lib/rbs/buffer.rb +104 -24
- data/lib/rbs/cli/validate.rb +39 -34
- data/lib/rbs/cli.rb +4 -5
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +63 -60
- data/lib/rbs/definition_builder/method_builder.rb +45 -30
- data/lib/rbs/definition_builder.rb +44 -9
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +185 -154
- data/lib/rbs/environment_loader.rb +2 -2
- data/lib/rbs/errors.rb +4 -3
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +206 -0
- data/lib/rbs/location_aux.rb +35 -3
- data/lib/rbs/parser_aux.rb +11 -1
- data/lib/rbs/prototype/runtime.rb +2 -2
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +12 -0
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +1 -0
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +110 -0
- data/sig/ast/ruby/comment_block.rbs +119 -0
- data/sig/ast/ruby/declarations.rbs +60 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +72 -0
- data/sig/buffer.rbs +63 -5
- data/sig/definition.rbs +1 -0
- data/sig/definition_builder.rbs +1 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +22 -76
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +87 -0
- data/sig/location.rbs +32 -7
- data/sig/method_builder.rbs +7 -4
- data/sig/parser.rbs +16 -0
- data/sig/source.rbs +48 -0
- data/src/ast.c +1345 -0
- data/src/lexer.c +2867 -0
- data/src/lexer.re +151 -0
- data/{ext/rbs_extension → src}/lexstate.c +58 -42
- data/src/location.c +71 -0
- data/src/parser.c +3739 -0
- data/src/string.c +89 -0
- data/src/util/rbs_allocator.c +149 -0
- data/src/util/rbs_assert.c +19 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +13 -81
- data/src/util/rbs_encoding.c +5273 -0
- data/src/util/rbs_unescape.c +130 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -2
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/rdoc.rbs +6 -4
- data/stdlib/rdoc/0/store.rbs +1 -1
- metadata +70 -17
- data/ext/rbs_extension/lexer.c +0 -2728
- data/ext/rbs_extension/lexer.re +0 -147
- data/ext/rbs_extension/location.h +0 -85
- data/ext/rbs_extension/parser.c +0 -2982
- data/ext/rbs_extension/parser.h +0 -18
- data/ext/rbs_extension/parserstate.c +0 -411
- data/ext/rbs_extension/parserstate.h +0 -163
- data/ext/rbs_extension/unescape.c +0 -32
- data/include/rbs/ruby_objs.h +0 -72
- data/src/ruby_objs.c +0 -799
@@ -0,0 +1,206 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
class InlineParser
|
5
|
+
class Result
|
6
|
+
attr_reader :buffer, :prism_result, :declarations, :diagnostics
|
7
|
+
|
8
|
+
def initialize(buffer, prism)
|
9
|
+
@buffer = buffer
|
10
|
+
@prism_result = prism
|
11
|
+
@declarations = []
|
12
|
+
@diagnostics = []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Diagnostic
|
17
|
+
class Base
|
18
|
+
attr_reader :message, :location
|
19
|
+
|
20
|
+
def initialize(location, message)
|
21
|
+
@location = location
|
22
|
+
@message = message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
NotImplementedYet = _ = Class.new(Base)
|
27
|
+
NonConstantClassName = _ = Class.new(Base)
|
28
|
+
NonConstantModuleName = _ = Class.new(Base)
|
29
|
+
TopLevelMethodDefinition = _ = Class.new(Base)
|
30
|
+
UnusedInlineAnnotation = _ = Class.new(Base)
|
31
|
+
AnnotationSyntaxError = _ = Class.new(Base)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse(buffer, prism)
|
35
|
+
result = Result.new(buffer, prism)
|
36
|
+
|
37
|
+
Parser.new(result).visit(prism.value)
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
class Parser < Prism::Visitor
|
43
|
+
attr_reader :module_nesting, :result, :comments
|
44
|
+
|
45
|
+
include AST::Ruby::Helpers::ConstantHelper
|
46
|
+
include AST::Ruby::Helpers::LocationHelper
|
47
|
+
|
48
|
+
def initialize(result)
|
49
|
+
@result = result
|
50
|
+
@module_nesting = []
|
51
|
+
@comments = CommentAssociation.build(result.buffer, result.prism_result)
|
52
|
+
end
|
53
|
+
|
54
|
+
def buffer
|
55
|
+
result.buffer
|
56
|
+
end
|
57
|
+
|
58
|
+
def current_module
|
59
|
+
module_nesting.last
|
60
|
+
end
|
61
|
+
|
62
|
+
def current_module!
|
63
|
+
current_module || raise("#current_module is nil")
|
64
|
+
end
|
65
|
+
|
66
|
+
def diagnostics
|
67
|
+
result.diagnostics
|
68
|
+
end
|
69
|
+
|
70
|
+
def push_module_nesting(mod)
|
71
|
+
module_nesting.push(mod)
|
72
|
+
yield
|
73
|
+
ensure
|
74
|
+
module_nesting.pop()
|
75
|
+
end
|
76
|
+
|
77
|
+
def skip_node?(node)
|
78
|
+
if ref = comments.leading_block(node)
|
79
|
+
if ref.block.each_paragraph([]).any? { _1.is_a?(AST::Ruby::Annotations::SkipAnnotation) }
|
80
|
+
ref.associate!
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
def visit_class_node(node)
|
89
|
+
return if skip_node?(node)
|
90
|
+
|
91
|
+
unless class_name = constant_as_type_name(node.constant_path)
|
92
|
+
diagnostics << Diagnostic::NonConstantClassName.new(
|
93
|
+
rbs_location(node.constant_path.location),
|
94
|
+
"Class name must be a constant"
|
95
|
+
)
|
96
|
+
return
|
97
|
+
end
|
98
|
+
|
99
|
+
class_decl = AST::Ruby::Declarations::ClassDecl.new(buffer, class_name, node)
|
100
|
+
insert_declaration(class_decl)
|
101
|
+
push_module_nesting(class_decl) do
|
102
|
+
visit_child_nodes(node)
|
103
|
+
end
|
104
|
+
|
105
|
+
comments.each_enclosed_block(node) do |block|
|
106
|
+
report_unused_block(block)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def visit_module_node(node)
|
111
|
+
return if skip_node?(node)
|
112
|
+
|
113
|
+
unless module_name = constant_as_type_name(node.constant_path)
|
114
|
+
diagnostics << Diagnostic::NonConstantModuleName.new(
|
115
|
+
rbs_location(node.constant_path.location),
|
116
|
+
"Module name must be a constant"
|
117
|
+
)
|
118
|
+
return
|
119
|
+
end
|
120
|
+
|
121
|
+
module_decl = AST::Ruby::Declarations::ModuleDecl.new(buffer, module_name, node)
|
122
|
+
insert_declaration(module_decl)
|
123
|
+
push_module_nesting(module_decl) do
|
124
|
+
visit_child_nodes(node)
|
125
|
+
end
|
126
|
+
|
127
|
+
comments.each_enclosed_block(node) do |block|
|
128
|
+
report_unused_block(block)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def visit_def_node(node)
|
133
|
+
return if skip_node?(node)
|
134
|
+
|
135
|
+
if node.receiver
|
136
|
+
diagnostics << Diagnostic::NotImplementedYet.new(
|
137
|
+
rbs_location(node.receiver.location),
|
138
|
+
"Singleton method definition is not supported yet"
|
139
|
+
)
|
140
|
+
return
|
141
|
+
end
|
142
|
+
|
143
|
+
case current = current_module
|
144
|
+
when AST::Ruby::Declarations::ClassDecl, AST::Ruby::Declarations::ModuleDecl
|
145
|
+
leading_block = comments.leading_block!(node)
|
146
|
+
|
147
|
+
if node.end_keyword_loc
|
148
|
+
# Not an end-less def
|
149
|
+
end_loc = node.rparen_loc || node.parameters&.location || node.name_loc
|
150
|
+
trailing_block = comments.trailing_block!(end_loc)
|
151
|
+
end
|
152
|
+
|
153
|
+
method_type, leading_unuseds, trailing_unused = AST::Ruby::Members::MethodTypeAnnotation.build(leading_block, trailing_block, [])
|
154
|
+
report_unused_annotation(trailing_unused, *leading_unuseds)
|
155
|
+
|
156
|
+
defn = AST::Ruby::Members::DefMember.new(buffer, node.name, node, method_type)
|
157
|
+
current.members << defn
|
158
|
+
|
159
|
+
# Skip other comments in `def` node
|
160
|
+
comments.each_enclosed_block(node) do |block|
|
161
|
+
comments.associated_blocks << block
|
162
|
+
end
|
163
|
+
else
|
164
|
+
diagnostics << Diagnostic::TopLevelMethodDefinition.new(
|
165
|
+
rbs_location(node.name_loc),
|
166
|
+
"Top-level method definition is not supported"
|
167
|
+
)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def insert_declaration(decl)
|
172
|
+
if current_module
|
173
|
+
current_module.members << decl
|
174
|
+
else
|
175
|
+
result.declarations << decl
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def report_unused_annotation(*annotations)
|
180
|
+
annotations.each do |annotation|
|
181
|
+
case annotation
|
182
|
+
when AST::Ruby::CommentBlock::AnnotationSyntaxError
|
183
|
+
diagnostics << Diagnostic::AnnotationSyntaxError.new(
|
184
|
+
annotation.location, "Syntax error: " + annotation.error.error_message
|
185
|
+
)
|
186
|
+
when AST::Ruby::Annotations::Base
|
187
|
+
diagnostics << Diagnostic::UnusedInlineAnnotation.new(
|
188
|
+
annotation.location, "Unused inline rbs annotation"
|
189
|
+
)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def report_unused_block(block)
|
195
|
+
block.each_paragraph([]) do |paragraph|
|
196
|
+
case paragraph
|
197
|
+
when Location
|
198
|
+
# noop
|
199
|
+
else
|
200
|
+
report_unused_annotation(paragraph)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
data/lib/rbs/location_aux.rb
CHANGED
@@ -28,6 +28,14 @@ module RBS
|
|
28
28
|
|
29
29
|
WithChildren = self
|
30
30
|
|
31
|
+
def start_pos
|
32
|
+
buffer.absolute_position(_start_pos) || raise
|
33
|
+
end
|
34
|
+
|
35
|
+
def end_pos
|
36
|
+
buffer.absolute_position(_end_pos) || raise
|
37
|
+
end
|
38
|
+
|
31
39
|
def name
|
32
40
|
buffer.name
|
33
41
|
end
|
@@ -49,11 +57,11 @@ module RBS
|
|
49
57
|
end
|
50
58
|
|
51
59
|
def start_loc
|
52
|
-
@start_loc ||= buffer.pos_to_loc(start_pos)
|
60
|
+
@start_loc ||= buffer.top_buffer.pos_to_loc(start_pos)
|
53
61
|
end
|
54
62
|
|
55
63
|
def end_loc
|
56
|
-
@end_loc ||= buffer.pos_to_loc(end_pos)
|
64
|
+
@end_loc ||= buffer.top_buffer.pos_to_loc(end_pos)
|
57
65
|
end
|
58
66
|
|
59
67
|
def range
|
@@ -61,7 +69,7 @@ module RBS
|
|
61
69
|
end
|
62
70
|
|
63
71
|
def source
|
64
|
-
@source ||= (buffer.content[range] || raise)
|
72
|
+
@source ||= (buffer.top_buffer.content[range] || raise)
|
65
73
|
end
|
66
74
|
|
67
75
|
def to_s
|
@@ -134,5 +142,29 @@ module RBS
|
|
134
142
|
def required_key?(name)
|
135
143
|
_required_keys.include?(name)
|
136
144
|
end
|
145
|
+
|
146
|
+
def local_location
|
147
|
+
loc = Location.new(buffer.detach, _start_pos, _end_pos)
|
148
|
+
|
149
|
+
each_optional_key do |key|
|
150
|
+
value = self[key]
|
151
|
+
if value
|
152
|
+
loc.add_optional_child(key, value._start_pos...value._end_pos)
|
153
|
+
else
|
154
|
+
loc.add_optional_child(key, nil)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
each_required_key do |key|
|
159
|
+
value = self[key] or raise
|
160
|
+
loc.add_required_child(key, value._start_pos...value._end_pos)
|
161
|
+
end
|
162
|
+
|
163
|
+
loc #: self
|
164
|
+
end
|
165
|
+
|
166
|
+
def local_source
|
167
|
+
local_location.source
|
168
|
+
end
|
137
169
|
end
|
138
170
|
end
|
data/lib/rbs/parser_aux.rb
CHANGED
@@ -71,7 +71,7 @@ module RBS
|
|
71
71
|
def self.buffer(source)
|
72
72
|
case source
|
73
73
|
when String
|
74
|
-
Buffer.new(content: source, name: "a.rbs")
|
74
|
+
Buffer.new(content: source, name: Pathname("a.rbs"))
|
75
75
|
when Buffer
|
76
76
|
source
|
77
77
|
end
|
@@ -110,5 +110,15 @@ module RBS
|
|
110
110
|
).each_with_object({}) do |keyword, hash| #$ Hash[String, bot]
|
111
111
|
hash[keyword] = _ = nil
|
112
112
|
end
|
113
|
+
|
114
|
+
def self.parse_inline_leading_annotation(source, range, variables: [])
|
115
|
+
buf = buffer(source)
|
116
|
+
_parse_inline_leading_annotation(buf, range.begin || 0, range.end || buf.last_position, variables)
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.parse_inline_trailing_annotation(source, range, variables: [])
|
120
|
+
buf = buffer(source)
|
121
|
+
_parse_inline_trailing_annotation(buf, range.begin || 0, range.end || buf.last_position, variables)
|
122
|
+
end
|
113
123
|
end
|
114
124
|
end
|
@@ -50,8 +50,8 @@ module RBS
|
|
50
50
|
type_name_absolute = type_name.absolute!
|
51
51
|
@mixin_decls_cache ||= {} #: Hash[TypeName, Array[AST::Members::Mixin]]
|
52
52
|
@mixin_decls_cache.fetch(type_name_absolute) do
|
53
|
-
@mixin_decls_cache[type_name_absolute] = @builder.env.class_decls[type_name_absolute].
|
54
|
-
|
53
|
+
@mixin_decls_cache[type_name_absolute] = @builder.env.class_decls[type_name_absolute].each_decl.flat_map do |decl|
|
54
|
+
decl.members.select { |m| m.kind_of?(AST::Members::Mixin) }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/lib/rbs/source.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Source
|
5
|
+
class RBS
|
6
|
+
attr_reader :buffer, :directives, :declarations
|
7
|
+
|
8
|
+
def initialize(buffer, directives, decls)
|
9
|
+
@buffer = buffer
|
10
|
+
@directives = directives
|
11
|
+
@declarations = decls
|
12
|
+
end
|
13
|
+
|
14
|
+
def each_type_name(&block)
|
15
|
+
if block
|
16
|
+
set = Set[] #: Set[TypeName]
|
17
|
+
declarations.each do |decl|
|
18
|
+
each_declaration_type_name(set, decl, &block)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
enum_for :each_type_name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_declaration_type_name(names, decl, &block)
|
26
|
+
case decl
|
27
|
+
when AST::Declarations::Class
|
28
|
+
decl.each_decl { each_declaration_type_name(names, _1, &block) }
|
29
|
+
type_name = decl.name
|
30
|
+
when AST::Declarations::Module
|
31
|
+
decl.each_decl { each_declaration_type_name(names, _1, &block) }
|
32
|
+
type_name = decl.name
|
33
|
+
when AST::Declarations::Interface
|
34
|
+
type_name = decl.name
|
35
|
+
when AST::Declarations::TypeAlias
|
36
|
+
type_name = decl.name
|
37
|
+
when AST::Declarations::ModuleAlias
|
38
|
+
type_name = decl.new_name
|
39
|
+
when AST::Declarations::ClassAlias
|
40
|
+
type_name = decl.new_name
|
41
|
+
end
|
42
|
+
|
43
|
+
if type_name
|
44
|
+
unless names.include?(type_name)
|
45
|
+
yield type_name
|
46
|
+
names << type_name
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Ruby
|
53
|
+
attr_reader :buffer
|
54
|
+
attr_reader :prism_result
|
55
|
+
attr_reader :declarations
|
56
|
+
attr_reader :diagnostics
|
57
|
+
|
58
|
+
def initialize(buffer, prism, declarations, diagnostics)
|
59
|
+
@buffer = buffer
|
60
|
+
@prism_result = prism
|
61
|
+
@declarations = declarations
|
62
|
+
@diagnostics = diagnostics
|
63
|
+
end
|
64
|
+
|
65
|
+
def each_type_name(&block)
|
66
|
+
if block
|
67
|
+
names = Set[] #: Set[TypeName]
|
68
|
+
declarations.each do |decl|
|
69
|
+
each_declaration_type_name(names, decl, &block)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
enum_for :each_type_name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def each_declaration_type_name(names, decl, &block)
|
77
|
+
case decl
|
78
|
+
when AST::Ruby::Declarations::ClassDecl
|
79
|
+
decl.each_decl do |d|
|
80
|
+
each_declaration_type_name(names, d, &block)
|
81
|
+
end
|
82
|
+
type_name = decl.class_name
|
83
|
+
when AST::Ruby::Declarations::ModuleDecl
|
84
|
+
decl.each_decl do |d|
|
85
|
+
each_declaration_type_name(names, d, &block)
|
86
|
+
end
|
87
|
+
type_name = decl.module_name
|
88
|
+
end
|
89
|
+
|
90
|
+
if type_name
|
91
|
+
unless names.include?(type_name)
|
92
|
+
yield type_name
|
93
|
+
names << type_name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/rbs/subtractor.rb
CHANGED
@@ -129,9 +129,10 @@ module RBS
|
|
129
129
|
|
130
130
|
entry = @subtrahend.class_decls[owner]
|
131
131
|
return unless entry
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
entry.each_decl do |d|
|
133
|
+
next unless d.is_a?(AST::Declarations::Base)
|
134
|
+
d.members.each { |m| block.call(m) }
|
135
|
+
end
|
135
136
|
end
|
136
137
|
|
137
138
|
private def mixin_exist?(owner, mixin, context:)
|
data/lib/rbs/version.rb
CHANGED
data/lib/rbs.rb
CHANGED
@@ -10,6 +10,7 @@ require "ripper"
|
|
10
10
|
require "logger"
|
11
11
|
require "tsort"
|
12
12
|
require "strscan"
|
13
|
+
require "prism"
|
13
14
|
|
14
15
|
require "rbs/errors"
|
15
16
|
require "rbs/buffer"
|
@@ -24,8 +25,19 @@ require "rbs/ast/declarations"
|
|
24
25
|
require "rbs/ast/members"
|
25
26
|
require "rbs/ast/annotation"
|
26
27
|
require "rbs/ast/visitor"
|
28
|
+
require "rbs/ast/ruby/comment_block"
|
29
|
+
require "rbs/ast/ruby/helpers/constant_helper"
|
30
|
+
require "rbs/ast/ruby/helpers/location_helper"
|
31
|
+
require "rbs/ast/ruby/annotations"
|
32
|
+
require "rbs/ast/ruby/declarations"
|
33
|
+
require "rbs/ast/ruby/members"
|
34
|
+
require "rbs/source"
|
35
|
+
require "rbs/inline_parser"
|
36
|
+
require "rbs/inline_parser/comment_association"
|
27
37
|
require "rbs/environment"
|
28
38
|
require "rbs/environment/use_map"
|
39
|
+
require "rbs/environment/class_entry"
|
40
|
+
require "rbs/environment/module_entry"
|
29
41
|
require "rbs/environment_loader"
|
30
42
|
require "rbs/builtin_names"
|
31
43
|
require "rbs/definition"
|
data/lib/rdoc/discover.rb
CHANGED
data/lib/rdoc_plugin/parser.rb
CHANGED
@@ -86,7 +86,7 @@ module RBS
|
|
86
86
|
end
|
87
87
|
|
88
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)
|
89
|
+
alias_def = RDoc::Alias.new(nil, decl.old_name.to_s, decl.new_name.to_s, nil, singleton: decl.kind == :singleton)
|
90
90
|
alias_def.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
|
91
91
|
context.add_alias(alias_def)
|
92
92
|
end
|
@@ -100,7 +100,7 @@ module RBS
|
|
100
100
|
when ::RBS::AST::Members::AttrAccessor
|
101
101
|
'RW'
|
102
102
|
end
|
103
|
-
attribute = RDoc::Attr.new(nil, decl.name.to_s, rw, nil, decl.kind == :singleton)
|
103
|
+
attribute = RDoc::Attr.new(nil, decl.name.to_s, rw, nil, singleton: decl.kind == :singleton)
|
104
104
|
attribute.visibility = decl.visibility
|
105
105
|
attribute.comment = construct_comment(context: context, comment: comment_string(decl)) if decl.comment
|
106
106
|
context.add_attribute(attribute)
|
data/rbs.gemspec
CHANGED
data/sig/ancestor_builder.rbs
CHANGED
@@ -146,7 +146,7 @@ module RBS
|
|
146
146
|
extended_modules: Array[Definition::Ancestor::Instance]?,
|
147
147
|
extended_interfaces: Array[Definition::Ancestor::Instance]?) -> void
|
148
148
|
|
149
|
-
def mixin_ancestors0: (AST::Declarations::Class | AST::Declarations::Module | AST::Declarations::Interface,
|
149
|
+
def mixin_ancestors0: (AST::Declarations::Class | AST::Declarations::Module | AST::Declarations::Interface | AST::Ruby::Declarations::ClassDecl | AST::Ruby::Declarations::ModuleDecl,
|
150
150
|
TypeName,
|
151
151
|
align_params: Substitution?,
|
152
152
|
included_modules: Array[Definition::Ancestor::Instance]?,
|
data/sig/annotate/formatter.rbs
CHANGED
@@ -17,8 +17,8 @@ module RBS
|
|
17
17
|
|
18
18
|
def self.translate: (RDoc::Markup::Document) -> String?
|
19
19
|
|
20
|
-
def self.each_part: (RDoc::Markup::Document
|
21
|
-
| (RDoc::Markup::Document
|
20
|
+
def self.each_part: (RDoc::Markup::Document) { (RDoc::Markup::Document) -> void } -> void
|
21
|
+
| (RDoc::Markup::Document) -> Enumerator[RDoc::Markup::Document, void]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -17,7 +17,7 @@ module RBS
|
|
17
17
|
end
|
18
18
|
|
19
19
|
interface _WithRDocComment
|
20
|
-
def comment: () -> (RDoc::
|
20
|
+
def comment: () -> (RDoc::Comment | String)
|
21
21
|
end
|
22
22
|
|
23
23
|
def each_part: (Array[Object & _WithRDocComment], tester: _PathTester) { ([RDoc::Markup::Document, Object & _WithRDocComment]) -> void } -> void
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module RBS
|
2
|
+
module AST
|
3
|
+
module Ruby
|
4
|
+
module Annotations
|
5
|
+
type leading_annotation = ColonMethodTypeAnnotation
|
6
|
+
| MethodTypesAnnotation
|
7
|
+
| SkipAnnotation
|
8
|
+
| ReturnTypeAnnotation
|
9
|
+
|
10
|
+
type trailing_annotation = NodeTypeAssertion
|
11
|
+
|
12
|
+
type t = leading_annotation | trailing_annotation
|
13
|
+
|
14
|
+
class Base
|
15
|
+
# Location that covers all of the annotation
|
16
|
+
#
|
17
|
+
attr_reader location: Location
|
18
|
+
|
19
|
+
# Location of `@rbs`, `@rbs!`, or `:` prefix
|
20
|
+
#
|
21
|
+
attr_reader prefix_location: Location
|
22
|
+
|
23
|
+
def initialize: (Location location, Location prefix_location) -> void
|
24
|
+
|
25
|
+
def buffer: () -> Buffer
|
26
|
+
end
|
27
|
+
|
28
|
+
# `: TYPE` annotation attached to nodes
|
29
|
+
#
|
30
|
+
class NodeTypeAssertion < Base
|
31
|
+
attr_reader type: Types::t
|
32
|
+
|
33
|
+
def initialize: (location: Location, prefix_location: Location, type: Types::t) -> void
|
34
|
+
|
35
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
36
|
+
end
|
37
|
+
|
38
|
+
# `: METHOD-TYPE` annotation in leading comments
|
39
|
+
#
|
40
|
+
class ColonMethodTypeAnnotation < Base
|
41
|
+
attr_reader annotations: Array[AST::Annotation]
|
42
|
+
|
43
|
+
attr_reader method_type: MethodType
|
44
|
+
|
45
|
+
def initialize: (location: Location, prefix_location: Location, annotations: Array[AST::Annotation], method_type: MethodType) -> void
|
46
|
+
|
47
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
48
|
+
end
|
49
|
+
|
50
|
+
# `@rbs METHOD-TYPEs` annotation in leading comments
|
51
|
+
#
|
52
|
+
# ```
|
53
|
+
# @rbs () -> void | %a{foo} () -> String
|
54
|
+
# ^^^^ -- prefix_location
|
55
|
+
# ^ -- vertical_bar_locations[0]
|
56
|
+
# ```
|
57
|
+
class MethodTypesAnnotation < Base
|
58
|
+
class Overload = AST::Members::MethodDefinition::Overload
|
59
|
+
|
60
|
+
attr_reader overloads: Array[Overload]
|
61
|
+
|
62
|
+
attr_reader vertical_bar_locations: Array[Location]
|
63
|
+
|
64
|
+
def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location]) -> void
|
65
|
+
|
66
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
67
|
+
end
|
68
|
+
|
69
|
+
# `@rbs skip -- comment` annotation in leading comments
|
70
|
+
#
|
71
|
+
class SkipAnnotation < Base
|
72
|
+
attr_reader skip_location: Location
|
73
|
+
attr_reader comment_location: Location?
|
74
|
+
|
75
|
+
def initialize: (location: Location, prefix_location: Location, skip_location: Location, comment_location: Location?) -> void
|
76
|
+
end
|
77
|
+
|
78
|
+
# `@rbs return: T -- comment` annotation in leading comments
|
79
|
+
#
|
80
|
+
# ```
|
81
|
+
# @rbs return: String -- Returns a string
|
82
|
+
# ^^^ -- prefix_location
|
83
|
+
# ^^^^^^ -- return_location
|
84
|
+
# ^ -- colon_location
|
85
|
+
# ^^^^^^^^^^^^^^^^^^^ -- comment
|
86
|
+
# ```
|
87
|
+
class ReturnTypeAnnotation < Base
|
88
|
+
attr_reader return_location: Location
|
89
|
+
|
90
|
+
attr_reader colon_location: Location
|
91
|
+
|
92
|
+
attr_reader return_type: Types::t
|
93
|
+
|
94
|
+
attr_reader comment_location: Location?
|
95
|
+
|
96
|
+
def initialize: (
|
97
|
+
location: Location,
|
98
|
+
prefix_location: Location,
|
99
|
+
return_location: Location,
|
100
|
+
colon_location: Location,
|
101
|
+
return_type: Types::t,
|
102
|
+
comment_location: Location?,
|
103
|
+
) -> void
|
104
|
+
|
105
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|