rbs 1.2.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -1
- data/.gitignore +2 -0
- data/CHANGELOG.md +53 -0
- data/README.md +1 -1
- data/Rakefile +9 -0
- data/Steepfile +1 -0
- data/core/array.rbs +1 -1
- data/core/basic_object.rbs +1 -1
- data/core/io.rbs +1 -1
- data/core/kernel.rbs +2 -2
- data/core/marshal.rbs +4 -3
- data/docs/rbs_by_example.md +328 -0
- data/docs/sigs.md +3 -1
- data/docs/stdlib.md +1 -1
- data/docs/syntax.md +0 -3
- data/lib/rbs/definition_builder.rb +2 -18
- data/lib/rbs/definition_builder/ancestor_builder.rb +9 -2
- data/lib/rbs/errors.rb +36 -0
- data/lib/rbs/parser.rb +913 -892
- data/lib/rbs/parser.y +10 -6
- data/lib/rbs/prototype/rb.rb +7 -3
- data/lib/rbs/prototype/runtime.rb +118 -42
- data/lib/rbs/version.rb +1 -1
- data/rbs.gemspec +1 -1
- data/sig/ancestor_builder.rbs +2 -0
- data/sig/errors.rbs +15 -0
- data/sig/namespace.rbs +1 -1
- data/sig/polyfill.rbs +0 -18
- data/stdlib/dbm/0/dbm.rbs +43 -30
- data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
- data/stdlib/net-http/0/net-http.rbs +1846 -0
- data/stdlib/optparse/0/optparse.rbs +1214 -0
- data/stdlib/resolv/0/resolv.rbs +1504 -0
- data/stdlib/socket/0/addrinfo.rbs +469 -0
- data/stdlib/socket/0/basic_socket.rbs +503 -0
- data/stdlib/socket/0/ip_socket.rbs +72 -0
- data/stdlib/socket/0/socket.rbs +2687 -0
- data/stdlib/socket/0/tcp_server.rbs +177 -0
- data/stdlib/socket/0/tcp_socket.rbs +35 -0
- data/stdlib/socket/0/udp_socket.rbs +111 -0
- data/stdlib/socket/0/unix_server.rbs +154 -0
- data/stdlib/socket/0/unix_socket.rbs +132 -0
- data/stdlib/timeout/0/timeout.rbs +5 -0
- data/steep/Gemfile.lock +12 -12
- metadata +16 -12
- data/bin/annotate-with-rdoc +0 -153
- data/bin/console +0 -14
- data/bin/query-rdoc +0 -103
- data/bin/rbs-prof +0 -9
- data/bin/run_in_md.rb +0 -49
- data/bin/setup +0 -8
- data/bin/sort +0 -89
- data/bin/steep +0 -4
- data/bin/test_runner.rb +0 -29
data/bin/query-rdoc
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "rdoc"
|
4
|
-
|
5
|
-
def store_for_class(name, stores:)
|
6
|
-
stores.find do |store|
|
7
|
-
store.find_class_named(name) || store.find_module_named(name)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def format_comment(comment)
|
12
|
-
out = RDoc::Markup::Document.new
|
13
|
-
out << comment
|
14
|
-
formatter = RDoc::Markup::ToMarkdown.new
|
15
|
-
out.accept(formatter)
|
16
|
-
end
|
17
|
-
|
18
|
-
def comment_for_constant(name, stores:)
|
19
|
-
*class_components, const_name = name.split(/::/)
|
20
|
-
class_name = class_components.join("::")
|
21
|
-
|
22
|
-
klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
|
23
|
-
store.find_class_named(class_name) || store.find_module_named(class_name)
|
24
|
-
}
|
25
|
-
|
26
|
-
constant = klass.constants.find do |const|
|
27
|
-
const.name == const_name
|
28
|
-
end
|
29
|
-
|
30
|
-
if constant&.documented?
|
31
|
-
format_comment(constant.comment)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def comment_for_class(class_name, stores:)
|
36
|
-
klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
|
37
|
-
store.find_class_named(class_name) || store.find_module_named(class_name)
|
38
|
-
}
|
39
|
-
|
40
|
-
if klass&.documented?
|
41
|
-
format_comment(klass.comment)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def comment_for_method(klass, method, stores:)
|
46
|
-
method = store_for_class(klass, stores: stores)&.load_method(klass, method)
|
47
|
-
|
48
|
-
if method&.documented?
|
49
|
-
out = RDoc::Markup::Document.new
|
50
|
-
|
51
|
-
out << method.comment
|
52
|
-
|
53
|
-
if method.arglists
|
54
|
-
out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
|
55
|
-
arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
|
56
|
-
out << RDoc::Markup::Verbatim.new(*arglists)
|
57
|
-
end
|
58
|
-
|
59
|
-
out.accept(RDoc::Markup::ToMarkdown.new)
|
60
|
-
end
|
61
|
-
rescue RDoc::Store::MissingFileError
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
|
65
|
-
if ARGV.empty?
|
66
|
-
puts 'query-rdoc [subject]'
|
67
|
-
puts " subject ::= ClassName (class, module, or constant)"
|
68
|
-
puts " | ClassName.method (singleton method)"
|
69
|
-
puts " | ClassName#method (instance method)"
|
70
|
-
exit
|
71
|
-
end
|
72
|
-
|
73
|
-
stores = []
|
74
|
-
RDoc::RI::Paths.each true, true, false, false do |path, type|
|
75
|
-
STDERR.puts "Loading store from #{path}..."
|
76
|
-
store = RDoc::RI::Store.new(path, type)
|
77
|
-
store.load_all
|
78
|
-
stores << store
|
79
|
-
end
|
80
|
-
|
81
|
-
subject = ARGV[0]
|
82
|
-
|
83
|
-
case
|
84
|
-
when match = subject.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
|
85
|
-
STDERR.puts "Finding instance method #{match[:constant_name]} # #{match[:method_name]} ..."
|
86
|
-
comment = comment_for_method(match[:constant_name], "##{match[:method_name]}", stores: stores)
|
87
|
-
when match = subject.match(/(?<constant_name>[^.]+)\.(?<method_name>.+)/)
|
88
|
-
STDERR.puts "Finding singleton method #{match[:constant_name]} . #{match[:method_name]} ..."
|
89
|
-
comment = comment_for_method(match[:constant_name], "::#{match[:method_name]}", stores: stores)
|
90
|
-
else
|
91
|
-
STDERR.puts "Finding class/module/constant #{subject} ..."
|
92
|
-
comment = comment_for_class(subject, stores: stores) || comment_for_constant(subject, stores: stores)
|
93
|
-
end
|
94
|
-
|
95
|
-
if comment
|
96
|
-
STDERR.puts "Printing document..."
|
97
|
-
comment.each_line do |line|
|
98
|
-
puts "# #{line}"
|
99
|
-
end
|
100
|
-
else
|
101
|
-
STDERR.puts "Nothing to print; failed to query the document..."
|
102
|
-
exit 1
|
103
|
-
end
|
data/bin/rbs-prof
DELETED
data/bin/run_in_md.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require "tmpdir"
|
2
|
-
require "shellwords"
|
3
|
-
|
4
|
-
ARGV.each do |path|
|
5
|
-
puts "~~~~~~~ Checking #{path} ~~~~~~"
|
6
|
-
content = File.read(path)
|
7
|
-
|
8
|
-
snippets = []
|
9
|
-
lines = []
|
10
|
-
content.lines.each.with_index do |line, index|
|
11
|
-
case line
|
12
|
-
when /run-start:/
|
13
|
-
lines = [[line, index+1]]
|
14
|
-
when /run-end/
|
15
|
-
lines << [line, index+1]
|
16
|
-
snippets << lines
|
17
|
-
lines = []
|
18
|
-
else
|
19
|
-
lines << [line, index+1]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
snippets.each do |lines|
|
24
|
-
puts ">>> Code detected: "
|
25
|
-
hd, _, *code_lines, _, _ = lines
|
26
|
-
|
27
|
-
head = hd[0]
|
28
|
-
head.gsub!(/^<!-- +/, "").gsub!(/ +-->$/, "")
|
29
|
-
_,name,command = head.split(/:/)
|
30
|
-
|
31
|
-
puts "# command=#{Shellwords.split(command).inspect}"
|
32
|
-
puts "# name=#{name}"
|
33
|
-
puts code_lines.map {|line, i| "#{"%4d" % i} #{line}" }.join
|
34
|
-
|
35
|
-
code = code_lines.map(&:first).join
|
36
|
-
|
37
|
-
puts ">>> Running..."
|
38
|
-
Dir.mktmpdir do |dir|
|
39
|
-
File.write(File.join(dir, name), code)
|
40
|
-
pid = spawn({ "BUNDLE_GEMFILE" => File.join(__dir__, "../Gemfile") },
|
41
|
-
*Shellwords.split(command),
|
42
|
-
chdir: dir)
|
43
|
-
|
44
|
-
_, status = Process.waitpid2(pid)
|
45
|
-
|
46
|
-
status.success? or raise "Failed to execute code: #{code_lines.join}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/bin/setup
DELETED
data/bin/sort
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "rbs"
|
5
|
-
|
6
|
-
Members = RBS::AST::Members
|
7
|
-
|
8
|
-
def group(member)
|
9
|
-
case member
|
10
|
-
when Members::Include, Members::Extend, Members::Prepend
|
11
|
-
0
|
12
|
-
when Members::ClassVariable
|
13
|
-
-3
|
14
|
-
when Members::ClassInstanceVariable
|
15
|
-
-2
|
16
|
-
when Members::InstanceVariable
|
17
|
-
-1
|
18
|
-
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
19
|
-
2
|
20
|
-
when Members::MethodDefinition
|
21
|
-
if member.singleton?
|
22
|
-
if member.name == :new
|
23
|
-
0.4
|
24
|
-
else
|
25
|
-
1
|
26
|
-
end
|
27
|
-
else
|
28
|
-
if member.name == :initialize
|
29
|
-
0.5
|
30
|
-
else
|
31
|
-
3
|
32
|
-
end
|
33
|
-
end
|
34
|
-
when Members::Alias
|
35
|
-
if member.singleton?
|
36
|
-
1
|
37
|
-
else
|
38
|
-
3
|
39
|
-
end
|
40
|
-
when Members::Private, Members::Public
|
41
|
-
-4
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def key(member)
|
46
|
-
case member
|
47
|
-
when Members::Include, Members::Extend, Members::Prepend
|
48
|
-
member.name.to_s
|
49
|
-
when Members::ClassVariable, Members::ClassInstanceVariable, Members::InstanceVariable
|
50
|
-
member.name.to_s
|
51
|
-
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
52
|
-
member.name.to_s
|
53
|
-
when Members::MethodDefinition
|
54
|
-
member.name.to_s
|
55
|
-
when Members::Alias
|
56
|
-
member.new_name.to_s
|
57
|
-
else
|
58
|
-
1
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
ARGV.map {|f| Pathname(f) }.each do |path|
|
63
|
-
puts "Opening #{path}..."
|
64
|
-
|
65
|
-
buffer = RBS::Buffer.new(name: path, content: path.read)
|
66
|
-
sigs = RBS::Parser.parse_signature(buffer)
|
67
|
-
|
68
|
-
sigs.each do |sig|
|
69
|
-
case sig
|
70
|
-
when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module, RBS::AST::Declarations::Interface
|
71
|
-
sig.members.sort! do |m1, m2|
|
72
|
-
group1 = group(m1)
|
73
|
-
group2 = group(m2)
|
74
|
-
|
75
|
-
if group1 == group2
|
76
|
-
key(m1) <=> key(m2)
|
77
|
-
else
|
78
|
-
group1 <=> group2
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
puts "Writing #{path}..."
|
85
|
-
path.open('w') do |out|
|
86
|
-
writer = RBS::Writer.new(out: out)
|
87
|
-
writer.write sigs
|
88
|
-
end
|
89
|
-
end
|
data/bin/steep
DELETED
data/bin/test_runner.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH << File.join(__dir__, "../lib")
|
4
|
-
|
5
|
-
require "set"
|
6
|
-
|
7
|
-
IS_LATEST_RUBY = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
|
8
|
-
Gem::Version.new('3.0.0') <= ruby_version && ruby_version < Gem::Version.new('3.1.0')
|
9
|
-
end
|
10
|
-
|
11
|
-
unless IS_LATEST_RUBY
|
12
|
-
STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.0 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
|
13
|
-
end
|
14
|
-
|
15
|
-
KNOWN_FAILS = %w(dbm).map do |lib|
|
16
|
-
/cannot load such file -- #{lib}/
|
17
|
-
end
|
18
|
-
|
19
|
-
ARGV.each do |arg|
|
20
|
-
begin
|
21
|
-
load arg
|
22
|
-
rescue LoadError => exn
|
23
|
-
if KNOWN_FAILS.any? {|pat| pat =~ exn.message }
|
24
|
-
STDERR.puts "Loading #{arg} failed, ignoring it: #{exn.inspect}"
|
25
|
-
else
|
26
|
-
raise
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|