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,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module AST
|
5
|
+
module Ruby
|
6
|
+
module Declarations
|
7
|
+
class Base
|
8
|
+
attr_reader :buffer
|
9
|
+
|
10
|
+
include Helpers::ConstantHelper
|
11
|
+
include Helpers::LocationHelper
|
12
|
+
|
13
|
+
def initialize(buffer)
|
14
|
+
@buffer = buffer
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ClassDecl < Base
|
19
|
+
attr_reader :class_name
|
20
|
+
|
21
|
+
attr_reader :members
|
22
|
+
|
23
|
+
attr_reader :node
|
24
|
+
|
25
|
+
def initialize(buffer, name, node)
|
26
|
+
super(buffer)
|
27
|
+
@class_name = name
|
28
|
+
@node = node
|
29
|
+
@members = []
|
30
|
+
end
|
31
|
+
|
32
|
+
def each_decl(&block)
|
33
|
+
return enum_for(:each_decl) unless block
|
34
|
+
|
35
|
+
@members.each do |member|
|
36
|
+
if member.is_a?(Base)
|
37
|
+
yield member
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def super_class = nil
|
43
|
+
|
44
|
+
def type_params = []
|
45
|
+
|
46
|
+
def location
|
47
|
+
rbs_location(node.location)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class ModuleDecl < Base
|
52
|
+
attr_reader :module_name
|
53
|
+
|
54
|
+
attr_reader :members
|
55
|
+
|
56
|
+
attr_reader :node
|
57
|
+
|
58
|
+
def initialize(buffer, name, node)
|
59
|
+
super(buffer)
|
60
|
+
@module_name = name
|
61
|
+
@node = node
|
62
|
+
@members = []
|
63
|
+
end
|
64
|
+
|
65
|
+
def each_decl(&block)
|
66
|
+
return enum_for(:each_decl) unless block
|
67
|
+
|
68
|
+
@members.each do |member|
|
69
|
+
if member.is_a?(Base)
|
70
|
+
yield member
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def type_params = []
|
76
|
+
|
77
|
+
def self_types = []
|
78
|
+
|
79
|
+
def location
|
80
|
+
rbs_location(node.location)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module AST
|
5
|
+
module Ruby
|
6
|
+
module Helpers
|
7
|
+
module ConstantHelper
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def constant_as_type_name(node)
|
11
|
+
case node
|
12
|
+
when Prism::ConstantPathNode, Prism::ConstantReadNode
|
13
|
+
begin
|
14
|
+
TypeName.parse(node.full_name)
|
15
|
+
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module AST
|
5
|
+
module Ruby
|
6
|
+
module Helpers
|
7
|
+
module LocationHelper
|
8
|
+
def rbs_location(location)
|
9
|
+
Location.new(buffer, location.start_character_offset, location.end_character_offset)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module AST
|
5
|
+
module Ruby
|
6
|
+
module Members
|
7
|
+
class Base
|
8
|
+
attr_reader :buffer
|
9
|
+
|
10
|
+
def initialize(buffer)
|
11
|
+
@buffer = buffer
|
12
|
+
end
|
13
|
+
|
14
|
+
include Helpers::LocationHelper
|
15
|
+
end
|
16
|
+
|
17
|
+
class MethodTypeAnnotation
|
18
|
+
class DocStyle
|
19
|
+
attr_accessor :return_type_annotation
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@return_type_annotation = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def map_type_name(&block)
|
26
|
+
DocStyle.new.tap do |new|
|
27
|
+
new.return_type_annotation = return_type_annotation&.map_type_name(&block)
|
28
|
+
end #: self
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_type
|
32
|
+
return_type =
|
33
|
+
case return_type_annotation
|
34
|
+
when Annotations::NodeTypeAssertion
|
35
|
+
return_type_annotation.type
|
36
|
+
when Annotations::ReturnTypeAnnotation
|
37
|
+
return_type_annotation.return_type
|
38
|
+
else
|
39
|
+
Types::Bases::Any.new(location: nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
type = Types::Function.new(
|
43
|
+
required_positionals: [],
|
44
|
+
optional_positionals: [],
|
45
|
+
rest_positionals: nil,
|
46
|
+
trailing_positionals: [],
|
47
|
+
required_keywords: {},
|
48
|
+
optional_keywords: {},
|
49
|
+
rest_keywords: nil,
|
50
|
+
return_type: return_type
|
51
|
+
)
|
52
|
+
|
53
|
+
MethodType.new(
|
54
|
+
type_params: [],
|
55
|
+
type: type,
|
56
|
+
block: nil,
|
57
|
+
location: nil
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_reader :type_annotations
|
63
|
+
|
64
|
+
def initialize(type_annotations:)
|
65
|
+
@type_annotations = type_annotations
|
66
|
+
end
|
67
|
+
|
68
|
+
def map_type_name(&block)
|
69
|
+
case type_annotations
|
70
|
+
when Array
|
71
|
+
updated_annots = type_annotations.map do |annotation|
|
72
|
+
annotation.map_type_name(&block)
|
73
|
+
end
|
74
|
+
when DocStyle
|
75
|
+
updated_annots = type_annotations.map_type_name(&block)
|
76
|
+
end
|
77
|
+
|
78
|
+
MethodTypeAnnotation.new(type_annotations: updated_annots) #: self
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.build(leading_block, trailing_block, variables)
|
82
|
+
unused_annotations = [] #: Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError]
|
83
|
+
unused_trailing_annotation = nil #: Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
|
84
|
+
|
85
|
+
type_annotations = nil #: type_annotations
|
86
|
+
|
87
|
+
if trailing_block
|
88
|
+
case annotation = trailing_block.trailing_annotation(variables)
|
89
|
+
when Annotations::NodeTypeAssertion
|
90
|
+
type_annotations = DocStyle.new()
|
91
|
+
type_annotations.return_type_annotation = annotation
|
92
|
+
else
|
93
|
+
unused_trailing_annotation = annotation
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
if leading_block
|
98
|
+
leading_block.each_paragraph(variables) do |paragraph|
|
99
|
+
next if paragraph.is_a?(Location)
|
100
|
+
|
101
|
+
if paragraph.is_a?(CommentBlock::AnnotationSyntaxError)
|
102
|
+
unused_annotations << paragraph
|
103
|
+
next
|
104
|
+
end
|
105
|
+
|
106
|
+
case paragraph
|
107
|
+
when Annotations::MethodTypesAnnotation, Annotations::ColonMethodTypeAnnotation
|
108
|
+
type_annotations = [] unless type_annotations
|
109
|
+
if type_annotations.is_a?(Array)
|
110
|
+
type_annotations << paragraph
|
111
|
+
next
|
112
|
+
end
|
113
|
+
when Annotations::ReturnTypeAnnotation
|
114
|
+
unless type_annotations
|
115
|
+
type_annotations = DocStyle.new()
|
116
|
+
end
|
117
|
+
|
118
|
+
if type_annotations.is_a?(DocStyle)
|
119
|
+
unless type_annotations.return_type_annotation
|
120
|
+
type_annotations.return_type_annotation = paragraph
|
121
|
+
next
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
unused_annotations << paragraph
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
[
|
131
|
+
MethodTypeAnnotation.new(
|
132
|
+
type_annotations: type_annotations
|
133
|
+
),
|
134
|
+
unused_annotations,
|
135
|
+
unused_trailing_annotation
|
136
|
+
]
|
137
|
+
end
|
138
|
+
|
139
|
+
def empty?
|
140
|
+
type_annotations.nil?
|
141
|
+
end
|
142
|
+
|
143
|
+
def overloads
|
144
|
+
case type_annotations
|
145
|
+
when DocStyle
|
146
|
+
method_type = type_annotations.method_type
|
147
|
+
|
148
|
+
[
|
149
|
+
AST::Members::MethodDefinition::Overload.new(annotations: [], method_type: method_type)
|
150
|
+
]
|
151
|
+
when Array
|
152
|
+
type_annotations.flat_map do |annotation|
|
153
|
+
case annotation
|
154
|
+
when Annotations::ColonMethodTypeAnnotation
|
155
|
+
[
|
156
|
+
AST::Members::MethodDefinition::Overload.new(
|
157
|
+
annotations: annotation.annotations,
|
158
|
+
method_type: annotation.method_type
|
159
|
+
)
|
160
|
+
]
|
161
|
+
when Annotations::MethodTypesAnnotation
|
162
|
+
annotation.overloads
|
163
|
+
end
|
164
|
+
end
|
165
|
+
when nil
|
166
|
+
method_type = MethodType.new(
|
167
|
+
type_params: [],
|
168
|
+
type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)),
|
169
|
+
block: nil,
|
170
|
+
location: nil
|
171
|
+
)
|
172
|
+
|
173
|
+
[
|
174
|
+
AST::Members::MethodDefinition::Overload.new(method_type: method_type, annotations: [])
|
175
|
+
]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
class DefMember < Base
|
181
|
+
Overload = AST::Members::MethodDefinition::Overload
|
182
|
+
|
183
|
+
attr_reader :name
|
184
|
+
attr_reader :node
|
185
|
+
attr_reader :method_type
|
186
|
+
|
187
|
+
def initialize(buffer, name, node, method_type)
|
188
|
+
super(buffer)
|
189
|
+
@name = name
|
190
|
+
@node = node
|
191
|
+
@method_type = method_type
|
192
|
+
end
|
193
|
+
|
194
|
+
def location
|
195
|
+
rbs_location(node.location)
|
196
|
+
end
|
197
|
+
|
198
|
+
def overloads
|
199
|
+
method_type.overloads
|
200
|
+
end
|
201
|
+
|
202
|
+
def overloading?
|
203
|
+
false
|
204
|
+
end
|
205
|
+
|
206
|
+
def annotations
|
207
|
+
[]
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
data/lib/rbs/buffer.rb
CHANGED
@@ -4,39 +4,53 @@ module RBS
|
|
4
4
|
class Buffer
|
5
5
|
attr_reader :name
|
6
6
|
attr_reader :content
|
7
|
+
attr_reader :parent
|
7
8
|
|
8
|
-
def initialize(name:,
|
9
|
-
|
10
|
-
|
9
|
+
def initialize(name: nil, content:, parent: nil)
|
10
|
+
case
|
11
|
+
when name && content
|
12
|
+
@name = name
|
13
|
+
@content = content
|
14
|
+
@parent = nil
|
15
|
+
when parent && content
|
16
|
+
@name = parent[0].name
|
17
|
+
@content = content
|
18
|
+
@parent = parent
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
def lines
|
14
|
-
|
23
|
+
ranges.map { self.content[_1] || raise } #$ String
|
24
|
+
end
|
25
|
+
|
26
|
+
def line_count
|
27
|
+
ranges.size
|
15
28
|
end
|
16
29
|
|
17
30
|
def ranges
|
18
|
-
@ranges ||=
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@ranges
|
31
|
+
@ranges ||= begin
|
32
|
+
lines = content.lines
|
33
|
+
lines << "" if content.end_with?("\n")
|
34
|
+
|
35
|
+
ranges = [] #: Array[Range[Integer]]
|
36
|
+
offset = 0
|
37
|
+
|
38
|
+
lines.each do |line|
|
39
|
+
size0 = line.size
|
40
|
+
line = line.chomp
|
41
|
+
range = offset...(offset+line.size)
|
42
|
+
ranges << range
|
43
|
+
|
44
|
+
offset += size0
|
34
45
|
end
|
46
|
+
|
47
|
+
ranges
|
48
|
+
end
|
35
49
|
end
|
36
50
|
|
37
51
|
def pos_to_loc(pos)
|
38
52
|
index = ranges.bsearch_index do |range|
|
39
|
-
pos
|
53
|
+
pos <= range.end ? true : false
|
40
54
|
end
|
41
55
|
|
42
56
|
if index
|
@@ -49,7 +63,7 @@ module RBS
|
|
49
63
|
def loc_to_pos(loc)
|
50
64
|
line, column = loc
|
51
65
|
|
52
|
-
if range = ranges
|
66
|
+
if range = ranges.fetch(line - 1, nil)
|
53
67
|
range.begin + column
|
54
68
|
else
|
55
69
|
last_position
|
@@ -57,11 +71,77 @@ module RBS
|
|
57
71
|
end
|
58
72
|
|
59
73
|
def last_position
|
60
|
-
|
74
|
+
if ranges.empty?
|
75
|
+
0
|
76
|
+
else
|
77
|
+
ranges[-1].end
|
78
|
+
end
|
61
79
|
end
|
62
80
|
|
63
81
|
def inspect
|
64
|
-
"#<RBS::Buffer:#{__id__} @name=#{name}, @content=#{content.bytesize} bytes, @lines=#{
|
82
|
+
"#<RBS::Buffer:#{__id__} @name=#{name}, @content=#{content.bytesize} bytes, @lines=#{ranges.size} lines,>"
|
83
|
+
end
|
84
|
+
|
85
|
+
def rbs_location(location, loc2=nil)
|
86
|
+
if loc2
|
87
|
+
Location.new(self, location.start_character_offset, loc2.end_character_offset)
|
88
|
+
else
|
89
|
+
Location.new(self, location.start_character_offset, location.end_character_offset)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def sub_buffer(lines:)
|
94
|
+
buf = +""
|
95
|
+
lines.each_with_index do |range, index|
|
96
|
+
start_pos = range.begin
|
97
|
+
end_pos = range.end
|
98
|
+
slice = content[start_pos...end_pos] or raise
|
99
|
+
if slice.include?("\n")
|
100
|
+
raise "Line #{index + 1} cannot contain newline character."
|
101
|
+
end
|
102
|
+
buf << slice
|
103
|
+
buf << "\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
buf.chomp!
|
107
|
+
|
108
|
+
Buffer.new(content: buf, parent: [self, lines])
|
109
|
+
end
|
110
|
+
|
111
|
+
def parent_buffer
|
112
|
+
if parent
|
113
|
+
parent[0]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def parent_position(position)
|
118
|
+
parent or raise "#parent_position is unavailable with buffer without parent"
|
119
|
+
return nil unless position <= last_position
|
120
|
+
|
121
|
+
line, column = pos_to_loc(position)
|
122
|
+
parent_range = parent[1][line - 1]
|
123
|
+
parent_range.begin + column
|
124
|
+
end
|
125
|
+
|
126
|
+
def absolute_position(position)
|
127
|
+
if parent_buffer
|
128
|
+
pos = parent_position(position) or return
|
129
|
+
parent_buffer.absolute_position(pos)
|
130
|
+
else
|
131
|
+
position
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def top_buffer
|
136
|
+
if parent_buffer
|
137
|
+
parent_buffer.top_buffer
|
138
|
+
else
|
139
|
+
self
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def detach
|
144
|
+
Buffer.new(name: name, content: content)
|
65
145
|
end
|
66
146
|
end
|
67
147
|
end
|
data/lib/rbs/cli/validate.rb
CHANGED
@@ -109,8 +109,8 @@ EOU
|
|
109
109
|
|
110
110
|
case entry
|
111
111
|
when Environment::ClassEntry
|
112
|
-
entry.
|
113
|
-
if super_class = decl.
|
112
|
+
entry.each_decl do |decl|
|
113
|
+
if super_class = decl.super_class
|
114
114
|
super_class.args.each do |arg|
|
115
115
|
void_type_context_validator(arg, true)
|
116
116
|
no_self_type_validator(arg)
|
@@ -120,8 +120,8 @@ EOU
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
when Environment::ModuleEntry
|
123
|
-
entry.
|
124
|
-
decl.
|
123
|
+
entry.each_decl do |decl|
|
124
|
+
decl.self_types.each do |self_type|
|
125
125
|
self_type.args.each do |arg|
|
126
126
|
void_type_context_validator(arg, true)
|
127
127
|
no_self_type_validator(arg)
|
@@ -143,7 +143,7 @@ EOU
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
d = entry.
|
146
|
+
d = entry.primary_decl
|
147
147
|
|
148
148
|
@validator.validate_type_params(
|
149
149
|
d.type_params,
|
@@ -169,39 +169,44 @@ EOU
|
|
169
169
|
|
170
170
|
TypeParamDefaultReferenceError.check!(d.type_params)
|
171
171
|
|
172
|
-
entry.
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
void_type_context_validator(member.type)
|
182
|
-
when AST::Members::Mixin
|
183
|
-
member.args.each do |arg|
|
184
|
-
no_self_type_validator(arg)
|
185
|
-
unless arg.is_a?(Types::Bases::Void)
|
186
|
-
void_type_context_validator(arg, true)
|
172
|
+
entry.each_decl do |decl|
|
173
|
+
case decl
|
174
|
+
when AST::Declarations::Base
|
175
|
+
decl.each_member do |member|
|
176
|
+
case member
|
177
|
+
when AST::Members::MethodDefinition
|
178
|
+
@validator.validate_method_definition(member, type_name: name)
|
179
|
+
member.overloads.each do |ov|
|
180
|
+
void_type_context_validator(ov.method_type)
|
187
181
|
end
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
182
|
+
when AST::Members::Attribute
|
183
|
+
void_type_context_validator(member.type)
|
184
|
+
when AST::Members::Mixin
|
185
|
+
member.args.each do |arg|
|
186
|
+
no_self_type_validator(arg)
|
187
|
+
unless arg.is_a?(Types::Bases::Void)
|
188
|
+
void_type_context_validator(arg, true)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
params =
|
192
|
+
if member.name.class?
|
193
|
+
module_decl = @env.normalized_module_entry(member.name) or raise
|
194
|
+
module_decl.type_params
|
195
|
+
else
|
196
|
+
interface_decl = @env.interface_decls.fetch(member.name)
|
197
|
+
interface_decl.decl.type_params
|
198
|
+
end
|
199
|
+
InvalidTypeApplicationError.check!(type_name: member.name, params: params, args: member.args, location: member.location)
|
200
|
+
when AST::Members::Var
|
201
|
+
@validator.validate_variable(member)
|
202
|
+
void_type_context_validator(member.type)
|
203
|
+
if member.is_a?(AST::Members::ClassVariable)
|
204
|
+
no_self_type_validator(member.type)
|
196
205
|
end
|
197
|
-
InvalidTypeApplicationError.check!(type_name: member.name, params: params, args: member.args, location: member.location)
|
198
|
-
when AST::Members::Var
|
199
|
-
@validator.validate_variable(member)
|
200
|
-
void_type_context_validator(member.type)
|
201
|
-
if member.is_a?(AST::Members::ClassVariable)
|
202
|
-
no_self_type_validator(member.type)
|
203
206
|
end
|
204
207
|
end
|
208
|
+
else
|
209
|
+
raise "Unknown declaration: #{decl.class}"
|
205
210
|
end
|
206
211
|
end
|
207
212
|
rescue BaseError => error
|
data/lib/rbs/cli.rb
CHANGED
@@ -175,10 +175,9 @@ EOB
|
|
175
175
|
|
176
176
|
env = Environment.from_loader(loader).resolve_type_names
|
177
177
|
|
178
|
-
decls = env.
|
179
|
-
loc = decl.location or raise
|
178
|
+
decls = env.sources.select do |source|
|
180
179
|
# @type var name: String
|
181
|
-
name =
|
180
|
+
name = source.buffer.name.to_s
|
182
181
|
|
183
182
|
patterns.empty? || patterns.any? do |pat|
|
184
183
|
case pat
|
@@ -188,7 +187,7 @@ EOB
|
|
188
187
|
name.end_with?(pat) || File.fnmatch(pat, name, File::FNM_EXTGLOB)
|
189
188
|
end
|
190
189
|
end
|
191
|
-
end
|
190
|
+
end.flat_map { _1.declarations }
|
192
191
|
|
193
192
|
stdout.print JSON.generate(decls)
|
194
193
|
stdout.flush
|
@@ -913,7 +912,7 @@ Options:
|
|
913
912
|
Buffer.new(content: file_path.read, name: file_path)
|
914
913
|
end
|
915
914
|
end
|
916
|
-
bufs << Buffer.new(content: e_code, name: '-e') if e_code
|
915
|
+
bufs << Buffer.new(content: e_code, name: Pathname('-e')) if e_code
|
917
916
|
|
918
917
|
bufs.each do |buf|
|
919
918
|
RBS.logger.info "Parsing #{buf.name}..."
|
data/lib/rbs/definition.rb
CHANGED
@@ -62,7 +62,12 @@ module RBS
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def comment
|
65
|
-
member
|
65
|
+
case member
|
66
|
+
when AST::Members::Base
|
67
|
+
member.comment
|
68
|
+
when AST::Ruby::Members::Base
|
69
|
+
nil
|
70
|
+
end
|
66
71
|
end
|
67
72
|
|
68
73
|
def update(type: self.type, member: self.member, defined_in: self.defined_in, implemented_in: self.implemented_in)
|