rbi 0.0.12 → 0.0.15
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/Gemfile +2 -2
- data/Rakefile +1 -1
- data/lib/rbi/loc.rb +15 -0
- data/lib/rbi/parser.rb +93 -17
- data/lib/rbi/version.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a98dd77d2fde6771b24b8ab87d585b94b944beea38a2d60a2ba38f7738deb67b
|
4
|
+
data.tar.gz: 56eb299a37b8755b57ebd72ffc4dcf6179a739e4146f6903c3d63450a586307b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e2a8e48b3210f41a3b38bf2844d895a0d232c8296b7122ecb64705ec9b77d56dd88ca0e1dd3b2fa15755ce90e63ee3ef17ccbc1174b3034b4d825bb4444c357
|
7
|
+
data.tar.gz: df19f77e6e4dd24e9309b03d4a1cd3008386bc3a48fe6998782008459fac78f9f97c52f603db2f65b1c68d42c3fe49f1145a7d40fcc845473c667ec4287127af
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
source "https://rubygems.org"
|
@@ -14,5 +14,5 @@ group(:development, :test) do
|
|
14
14
|
gem("rubocop-shopify", require: false)
|
15
15
|
gem("rubocop-sorbet", require: false)
|
16
16
|
gem("sorbet", ">= 0.5.9204", require: false)
|
17
|
-
gem("tapioca",
|
17
|
+
gem("tapioca", require: false)
|
18
18
|
end
|
data/Rakefile
CHANGED
data/lib/rbi/loc.rb
CHANGED
@@ -32,5 +32,20 @@ module RBI
|
|
32
32
|
def to_s
|
33
33
|
"#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
|
34
34
|
end
|
35
|
+
|
36
|
+
sig { returns(T.nilable(String)) }
|
37
|
+
def source
|
38
|
+
file = self.file
|
39
|
+
return nil unless file
|
40
|
+
return nil unless ::File.file?(file)
|
41
|
+
|
42
|
+
return ::File.read(file) unless begin_line && end_line
|
43
|
+
|
44
|
+
string = String.new
|
45
|
+
::File.foreach(file).with_index do |line, line_number|
|
46
|
+
string << line if line_number + 1 >= begin_line && line_number + 1 <= end_line
|
47
|
+
end
|
48
|
+
string
|
49
|
+
end
|
35
50
|
end
|
36
51
|
end
|
data/lib/rbi/parser.rb
CHANGED
@@ -17,6 +17,39 @@ module RBI
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
class UnexpectedParserError < StandardError
|
21
|
+
extend T::Sig
|
22
|
+
|
23
|
+
sig { returns(Loc) }
|
24
|
+
attr_reader :last_location
|
25
|
+
|
26
|
+
sig { params(parent_exception: Exception, last_location: Loc).void }
|
27
|
+
def initialize(parent_exception, last_location)
|
28
|
+
super(parent_exception)
|
29
|
+
set_backtrace(parent_exception.backtrace)
|
30
|
+
@last_location = last_location
|
31
|
+
end
|
32
|
+
|
33
|
+
sig { params(io: T.any(IO, StringIO)).void }
|
34
|
+
def print_debug(io: $stderr)
|
35
|
+
io.puts ""
|
36
|
+
io.puts "##################################"
|
37
|
+
io.puts "### RBI::Parser internal error ###"
|
38
|
+
io.puts "##################################"
|
39
|
+
io.puts ""
|
40
|
+
io.puts "There was an internal parser error while processing this source."
|
41
|
+
io.puts ""
|
42
|
+
io.puts "Error: #{message} while parsing #{last_location}:"
|
43
|
+
io.puts ""
|
44
|
+
io.puts last_location.source || "<no source>"
|
45
|
+
io.puts ""
|
46
|
+
io.puts "Please open an issue at https://github.com/Shopify/rbi/issues/new."
|
47
|
+
io.puts ""
|
48
|
+
io.puts "##################################"
|
49
|
+
io.puts ""
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
20
53
|
class Parser
|
21
54
|
extend T::Sig
|
22
55
|
|
@@ -77,6 +110,19 @@ module RBI
|
|
77
110
|
builder.tree
|
78
111
|
rescue ::Parser::SyntaxError => e
|
79
112
|
raise ParseError.new(e.message, Loc.from_ast_loc(file, e.diagnostic.location))
|
113
|
+
rescue ParseError => e
|
114
|
+
raise e
|
115
|
+
rescue => e
|
116
|
+
last_node = builder&.last_node
|
117
|
+
last_location = if last_node
|
118
|
+
Loc.from_ast_loc(file, last_node.location)
|
119
|
+
else
|
120
|
+
Loc.new(file: file)
|
121
|
+
end
|
122
|
+
|
123
|
+
exception = UnexpectedParserError.new(e, last_location)
|
124
|
+
exception.print_debug
|
125
|
+
raise exception
|
80
126
|
end
|
81
127
|
end
|
82
128
|
|
@@ -113,6 +159,9 @@ module RBI
|
|
113
159
|
sig { returns(Tree) }
|
114
160
|
attr_reader :tree
|
115
161
|
|
162
|
+
sig { returns(T.nilable(::AST::Node)) }
|
163
|
+
attr_reader :last_node
|
164
|
+
|
116
165
|
sig do
|
117
166
|
params(
|
118
167
|
file: String,
|
@@ -127,7 +176,9 @@ module RBI
|
|
127
176
|
@nodes_comments_assoc = nodes_comments_assoc
|
128
177
|
@tree = T.let(Tree.new, Tree)
|
129
178
|
@scopes_stack = T.let([@tree], T::Array[Tree])
|
179
|
+
@last_node = T.let(nil, T.nilable(::AST::Node))
|
130
180
|
@last_sigs = T.let([], T::Array[RBI::Sig])
|
181
|
+
@last_sigs_comments = T.let([], T::Array[Comment])
|
131
182
|
|
132
183
|
separate_header_comments
|
133
184
|
end
|
@@ -141,6 +192,8 @@ module RBI
|
|
141
192
|
sig { override.params(node: T.nilable(Object)).void }
|
142
193
|
def visit(node)
|
143
194
|
return unless node.is_a?(AST::Node)
|
195
|
+
@last_node = node
|
196
|
+
|
144
197
|
case node.type
|
145
198
|
when :module, :class, :sclass
|
146
199
|
scope = parse_scope(node)
|
@@ -156,15 +209,18 @@ module RBI
|
|
156
209
|
node = parse_send(node)
|
157
210
|
current_scope << node if node
|
158
211
|
when :block
|
159
|
-
|
160
|
-
if
|
161
|
-
@last_sigs <<
|
162
|
-
|
163
|
-
|
212
|
+
rbi_node = parse_block(node)
|
213
|
+
if rbi_node.is_a?(Sig)
|
214
|
+
@last_sigs << rbi_node
|
215
|
+
@last_sigs_comments.concat(node_comments(node))
|
216
|
+
elsif rbi_node
|
217
|
+
current_scope << rbi_node
|
164
218
|
end
|
165
219
|
else
|
166
220
|
visit_all(node.children)
|
167
221
|
end
|
222
|
+
|
223
|
+
@last_node = nil
|
168
224
|
end
|
169
225
|
|
170
226
|
private
|
@@ -214,7 +270,7 @@ module RBI
|
|
214
270
|
params: node.children[1].children.map { |child| parse_param(child) },
|
215
271
|
sigs: current_sigs,
|
216
272
|
loc: loc,
|
217
|
-
comments: node_comments(node)
|
273
|
+
comments: current_sigs_comments + node_comments(node)
|
218
274
|
)
|
219
275
|
when :defs
|
220
276
|
Method.new(
|
@@ -223,7 +279,7 @@ module RBI
|
|
223
279
|
is_singleton: true,
|
224
280
|
sigs: current_sigs,
|
225
281
|
loc: loc,
|
226
|
-
comments: node_comments(node)
|
282
|
+
comments: current_sigs_comments + node_comments(node)
|
227
283
|
)
|
228
284
|
else
|
229
285
|
raise ParseError.new("Unsupported def node type `#{node.type}`", loc)
|
@@ -270,13 +326,13 @@ module RBI
|
|
270
326
|
case method_name
|
271
327
|
when :attr_reader
|
272
328
|
symbols = node.children[2..-1].map { |child| child.children[0] }
|
273
|
-
AttrReader.new(*symbols, sigs: current_sigs, loc: loc, comments: comments)
|
329
|
+
AttrReader.new(*symbols, sigs: current_sigs, loc: loc, comments: current_sigs_comments + comments)
|
274
330
|
when :attr_writer
|
275
331
|
symbols = node.children[2..-1].map { |child| child.children[0] }
|
276
|
-
AttrWriter.new(*symbols, sigs: current_sigs, loc: loc, comments: comments)
|
332
|
+
AttrWriter.new(*symbols, sigs: current_sigs, loc: loc, comments: current_sigs_comments + comments)
|
277
333
|
when :attr_accessor
|
278
334
|
symbols = node.children[2..-1].map { |child| child.children[0] }
|
279
|
-
AttrAccessor.new(*symbols, sigs: current_sigs, loc: loc, comments: comments)
|
335
|
+
AttrAccessor.new(*symbols, sigs: current_sigs, loc: loc, comments: current_sigs_comments + comments)
|
280
336
|
when :include
|
281
337
|
names = node.children[2..-1].map { |child| parse_expr(child) }
|
282
338
|
Include.new(*names, loc: loc, comments: comments)
|
@@ -429,7 +485,14 @@ module RBI
|
|
429
485
|
sig { params(node: AST::Node).returns(TEnumBlock) }
|
430
486
|
def parse_enum(node)
|
431
487
|
enum = TEnumBlock.new
|
432
|
-
|
488
|
+
|
489
|
+
body = if node.children[2].type == :begin
|
490
|
+
node.children[2].children
|
491
|
+
else
|
492
|
+
[node.children[2]]
|
493
|
+
end
|
494
|
+
|
495
|
+
body.each do |child|
|
433
496
|
enum << parse_name(child)
|
434
497
|
end
|
435
498
|
enum.loc = node_loc(node)
|
@@ -472,6 +535,13 @@ module RBI
|
|
472
535
|
sigs
|
473
536
|
end
|
474
537
|
|
538
|
+
sig { returns(T::Array[Comment]) }
|
539
|
+
def current_sigs_comments
|
540
|
+
comments = @last_sigs_comments.dup
|
541
|
+
@last_sigs_comments.clear
|
542
|
+
comments
|
543
|
+
end
|
544
|
+
|
475
545
|
sig { void }
|
476
546
|
def assoc_dangling_comments
|
477
547
|
last_line = T.let(nil, T.nilable(Integer))
|
@@ -605,19 +675,25 @@ module RBI
|
|
605
675
|
when :overridable
|
606
676
|
@current.is_overridable = true
|
607
677
|
when :checked
|
608
|
-
|
678
|
+
if node.children.length >= 3
|
679
|
+
@current.checked = node.children[2].children[0]
|
680
|
+
end
|
609
681
|
when :type_parameters
|
610
682
|
node.children[2..-1].each do |child|
|
611
683
|
@current.type_params << child.children[0].to_s
|
612
684
|
end
|
613
685
|
when :params
|
614
|
-
node.children
|
615
|
-
|
616
|
-
|
617
|
-
|
686
|
+
if node.children.length >= 3
|
687
|
+
node.children[2].children.each do |child|
|
688
|
+
name = child.children[0].children[0].to_s
|
689
|
+
type = parse_expr(child.children[1])
|
690
|
+
@current << SigParam.new(name, type)
|
691
|
+
end
|
618
692
|
end
|
619
693
|
when :returns
|
620
|
-
|
694
|
+
if node.children.length >= 3
|
695
|
+
@current.return_type = parse_expr(node.children[2])
|
696
|
+
end
|
621
697
|
when :void
|
622
698
|
@current.return_type = nil
|
623
699
|
else
|
data/lib/rbi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.6.4.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.6.4.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sorbet-runtime
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.
|
110
|
+
version: 2.7.0
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
113
|
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.3.3
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: RBI generation framework
|