steep 0.11.1 → 0.12.0
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 +27 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +48 -90
- data/Rakefile +10 -6
- data/Steepfile +1 -0
- data/bin/setup +1 -0
- data/bin/smoke_runner.rb +9 -14
- data/exe/rbs +3 -0
- data/exe/ruby-signature +3 -0
- data/exe/steep +1 -0
- data/lib/steep.rb +32 -26
- data/lib/steep/annotation_parser.rb +167 -0
- data/lib/steep/ast/annotation/collection.rb +7 -7
- data/lib/steep/ast/types.rb +60 -0
- data/lib/steep/ast/types/any.rb +1 -1
- data/lib/steep/ast/types/factory.rb +535 -0
- data/lib/steep/ast/types/name.rb +3 -3
- data/lib/steep/ast/types/var.rb +1 -1
- data/lib/steep/cli.rb +56 -240
- data/lib/steep/drivers/annotations.rb +36 -19
- data/lib/steep/drivers/check.rb +55 -91
- data/lib/steep/drivers/init.rb +54 -0
- data/lib/steep/drivers/langserver.rb +241 -150
- data/lib/steep/drivers/print_project.rb +56 -0
- data/lib/steep/drivers/signature_error_printer.rb +25 -0
- data/lib/steep/drivers/trace_printer.rb +25 -0
- data/lib/steep/drivers/utils/driver_helper.rb +26 -0
- data/lib/steep/drivers/validate.rb +18 -38
- data/lib/steep/drivers/vendor.rb +46 -0
- data/lib/steep/drivers/watch.rb +78 -140
- data/lib/steep/errors.rb +22 -13
- data/lib/steep/interface/interface.rb +91 -0
- data/lib/steep/interface/method.rb +0 -4
- data/lib/steep/interface/method_type.rb +362 -2
- data/lib/steep/interface/substitution.rb +22 -0
- data/lib/steep/project.rb +25 -233
- data/lib/steep/project/dsl.rb +132 -0
- data/lib/steep/project/file.rb +93 -76
- data/lib/steep/project/file_loader.rb +63 -0
- data/lib/steep/project/options.rb +7 -0
- data/lib/steep/project/target.rb +190 -0
- data/lib/steep/signature/errors.rb +25 -77
- data/lib/steep/signature/validator.rb +122 -0
- data/lib/steep/source.rb +12 -7
- data/lib/steep/subtyping/check.rb +357 -633
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/subtyping/trace.rb +23 -0
- data/lib/steep/type_construction.rb +509 -455
- data/lib/steep/type_inference/constant_env.rb +16 -24
- data/lib/steep/type_inference/type_env.rb +26 -18
- data/lib/steep/version.rb +1 -1
- data/sample/Steepfile +6 -0
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +6 -0
- data/smoke/alias/Steepfile +4 -0
- data/smoke/alias/a.rb +2 -2
- data/smoke/alias/{a.rbi → a.rbs} +1 -1
- data/smoke/and/Steepfile +4 -0
- data/smoke/array/Steepfile +4 -0
- data/smoke/array/a.rb +2 -2
- data/smoke/array/b.rb +4 -4
- data/smoke/array/c.rb +2 -2
- data/smoke/block/Steepfile +5 -0
- data/smoke/block/{a.rbi → a.rbs} +1 -1
- data/smoke/block/{c.rbi → c.rbs} +0 -0
- data/smoke/block/d.rb +6 -6
- data/smoke/case/Steepfile +4 -0
- data/smoke/case/a.rb +4 -3
- data/smoke/class/Steepfile +4 -0
- data/smoke/class/a.rb +1 -4
- data/smoke/class/a.rbs +24 -0
- data/smoke/class/h.rb +6 -2
- data/smoke/class/{h.rbi → h.rbs} +1 -2
- data/smoke/class/i.rb +1 -2
- data/smoke/class/i.rbs +9 -0
- data/smoke/const/Steepfile +4 -0
- data/smoke/dstr/Steepfile +4 -0
- data/smoke/ensure/Steepfile +4 -0
- data/smoke/ensure/a.rb +1 -1
- data/smoke/enumerator/Steepfile +4 -0
- data/smoke/enumerator/a.rb +7 -7
- data/smoke/enumerator/b.rb +6 -6
- data/smoke/extension/Steepfile +4 -0
- data/smoke/extension/{a.rbi → a.rbs} +2 -2
- data/smoke/extension/{e.rbi → e.rbs} +2 -2
- data/smoke/hash/Steepfile +4 -0
- data/smoke/hash/{a.rbi → a.rbs} +0 -0
- data/smoke/hash/b.rb +2 -2
- data/smoke/hash/c.rb +1 -1
- data/smoke/hash/e.rbs +3 -0
- data/smoke/hash/f.rb +1 -1
- data/smoke/hello/Steepfile +4 -0
- data/smoke/hello/hello.rbs +7 -0
- data/smoke/if/Steepfile +4 -0
- data/smoke/implements/Steepfile +4 -0
- data/smoke/implements/a.rbs +6 -0
- data/smoke/initialize/Steepfile +4 -0
- data/smoke/initialize/a.rbs +3 -0
- data/smoke/integer/Steepfile +4 -0
- data/smoke/integer/a.rb +5 -3
- data/smoke/interface/Steepfile +4 -0
- data/smoke/interface/{a.rbi → a.rbs} +0 -0
- data/smoke/kwbegin/Steepfile +4 -0
- data/smoke/lambda/Steepfile +4 -0
- data/smoke/lambda/a.rb +9 -2
- data/smoke/literal/Steepfile +4 -0
- data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
- data/smoke/map/Steepfile +4 -0
- data/smoke/map/a.rb +1 -1
- data/smoke/method/Steepfile +4 -0
- data/smoke/method/{a.rbi → a.rbs} +0 -0
- data/smoke/method/b.rb +1 -4
- data/smoke/method/d.rb +1 -0
- data/smoke/method/d.rbs +3 -0
- data/smoke/module/Steepfile +4 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbs +16 -0
- data/smoke/module/c.rb +1 -1
- data/smoke/regexp/Steepfile +4 -0
- data/smoke/regexp/a.rb +2 -2
- data/smoke/regexp/b.rb +16 -16
- data/smoke/regression/Steepfile +5 -0
- data/smoke/regression/array.rb +2 -2
- data/smoke/regression/hash.rb +2 -2
- data/smoke/regression/poly_new.rb +2 -0
- data/smoke/regression/poly_new.rbs +4 -0
- data/smoke/regression/set_divide.rb +2 -2
- data/smoke/rescue/Steepfile +4 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +4 -0
- data/smoke/self/a.rbs +4 -0
- data/smoke/skip/Steepfile +4 -0
- data/smoke/stdout/Steepfile +4 -0
- data/smoke/stdout/{a.rbi → a.rbs} +1 -1
- data/smoke/super/Steepfile +4 -0
- data/smoke/super/a.rbs +10 -0
- data/smoke/type_case/Steepfile +4 -0
- data/smoke/type_case/a.rb +1 -1
- data/smoke/yield/Steepfile +4 -0
- data/smoke/yield/a.rb +2 -2
- data/steep.gemspec +14 -7
- data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
- data/vendor/ruby-signature/.gitignore +12 -0
- data/vendor/ruby-signature/.rubocop.yml +15 -0
- data/vendor/ruby-signature/BSDL +22 -0
- data/vendor/ruby-signature/COPYING +56 -0
- data/vendor/ruby-signature/Gemfile +6 -0
- data/vendor/ruby-signature/README.md +93 -0
- data/vendor/ruby-signature/Rakefile +66 -0
- data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
- data/vendor/ruby-signature/bin/console +14 -0
- data/vendor/ruby-signature/bin/query-rdoc +103 -0
- data/vendor/ruby-signature/bin/setup +10 -0
- data/vendor/ruby-signature/bin/sort +88 -0
- data/vendor/ruby-signature/bin/test_runner.rb +17 -0
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
- data/vendor/ruby-signature/docs/sigs.md +148 -0
- data/vendor/ruby-signature/docs/stdlib.md +152 -0
- data/vendor/ruby-signature/docs/syntax.md +528 -0
- data/vendor/ruby-signature/exe/rbs +3 -0
- data/vendor/ruby-signature/exe/ruby-signature +7 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
- data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
- data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
- data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +244 -54
- data/.travis.yml +0 -7
- data/lib/steep/ast/signature/alias.rb +0 -19
- data/lib/steep/ast/signature/class.rb +0 -33
- data/lib/steep/ast/signature/const.rb +0 -17
- data/lib/steep/ast/signature/env.rb +0 -138
- data/lib/steep/ast/signature/extension.rb +0 -21
- data/lib/steep/ast/signature/gvar.rb +0 -17
- data/lib/steep/ast/signature/interface.rb +0 -31
- data/lib/steep/ast/signature/members.rb +0 -115
- data/lib/steep/ast/signature/module.rb +0 -21
- data/lib/steep/drivers/print_interface.rb +0 -94
- data/lib/steep/drivers/scaffold.rb +0 -321
- data/lib/steep/drivers/utils/each_signature.rb +0 -31
- data/lib/steep/interface/abstract.rb +0 -68
- data/lib/steep/interface/builder.rb +0 -637
- data/lib/steep/interface/instantiated.rb +0 -163
- data/lib/steep/interface/ivar_chain.rb +0 -26
- data/lib/steep/parser.y +0 -1278
- data/lib/steep/project/listener.rb +0 -53
- data/smoke/class/a.rbi +0 -24
- data/smoke/class/d.rb +0 -9
- data/smoke/class/e.rb +0 -12
- data/smoke/class/i.rbi +0 -9
- data/smoke/hash/e.rbi +0 -3
- data/smoke/hello/hello.rbi +0 -7
- data/smoke/implements/a.rbi +0 -6
- data/smoke/initialize/a.rbi +0 -3
- data/smoke/module/a.rbi +0 -16
- data/smoke/self/a.rbi +0 -4
- data/smoke/super/a.rbi +0 -10
- data/stdlib/builtin.rbi +0 -787
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "ruby/signature"
|
4
|
+
require "rdoc"
|
5
|
+
|
6
|
+
def store_for_class(name, stores:)
|
7
|
+
stores.find do |store|
|
8
|
+
store.find_class_named(name) || store.find_module_named(name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_comment(comment)
|
13
|
+
out = RDoc::Markup::Document.new
|
14
|
+
out << comment
|
15
|
+
formatter = RDoc::Markup::ToMarkdown.new
|
16
|
+
out.accept(formatter)
|
17
|
+
end
|
18
|
+
|
19
|
+
def comment_for_constant(decl, stores:)
|
20
|
+
class_name = decl.name.namespace.to_type_name.to_s
|
21
|
+
klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
|
22
|
+
store.find_class_named(class_name) || store.find_module_named(class_name)
|
23
|
+
}
|
24
|
+
|
25
|
+
if klass
|
26
|
+
constant = klass.constants.find do |const|
|
27
|
+
const.name == decl.name.name.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
if constant&.documented?
|
31
|
+
string = format_comment(constant.comment)
|
32
|
+
Ruby::Signature::AST::Comment.new(location: nil, string: string)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def comment_for_class(decl, stores:)
|
38
|
+
name = decl.name.to_s
|
39
|
+
klass = store_for_class(name, stores: stores)&.yield_self {|store|
|
40
|
+
store.find_class_named(name) || store.find_module_named(name)
|
41
|
+
}
|
42
|
+
|
43
|
+
if klass&.documented?
|
44
|
+
string = format_comment(klass.comment)
|
45
|
+
Ruby::Signature::AST::Comment.new(location: nil, string: string)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def comment_for_method(klass, method, stores:)
|
50
|
+
method = store_for_class(klass, stores: stores)&.load_method(klass, method)
|
51
|
+
|
52
|
+
if method&.documented?
|
53
|
+
out = RDoc::Markup::Document.new
|
54
|
+
|
55
|
+
out << method.comment
|
56
|
+
|
57
|
+
if method.arglists
|
58
|
+
out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
|
59
|
+
arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
|
60
|
+
out << RDoc::Markup::Verbatim.new(*arglists)
|
61
|
+
end
|
62
|
+
|
63
|
+
string = out.accept(RDoc::Markup::ToMarkdown.new)
|
64
|
+
Ruby::Signature::AST::Comment.new(location: nil, string: string)
|
65
|
+
end
|
66
|
+
|
67
|
+
rescue RDoc::Store::MissingFileError
|
68
|
+
puts " 👺 No document found for #{klass}#{method}"
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
if ARGV.empty?
|
73
|
+
puts 'annotate-with-rdoc [RBS files...]'
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
|
77
|
+
def print_members(stores, klass_name, members)
|
78
|
+
members.each do |member|
|
79
|
+
case member
|
80
|
+
when Ruby::Signature::AST::Members::MethodDefinition
|
81
|
+
puts " Processing #{member.name}..."
|
82
|
+
|
83
|
+
method_name = case
|
84
|
+
when member.instance?
|
85
|
+
"##{member.name}"
|
86
|
+
when member.singleton?
|
87
|
+
"::#{member.name}"
|
88
|
+
end
|
89
|
+
|
90
|
+
comment = comment_for_method(klass_name, method_name, stores: stores)
|
91
|
+
|
92
|
+
unless comment
|
93
|
+
if member.instance? && member.name == :initialize
|
94
|
+
comment = comment_for_method(klass_name, '::new', stores: stores)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
member.instance_variable_set(:@comment, comment)
|
99
|
+
when Ruby::Signature::AST::Members::AttrReader, Ruby::Signature::AST::Members::AttrAccessor, Ruby::Signature::AST::Members::AttrWriter
|
100
|
+
puts " 👻 Attributes not supported (#{klass_name})"
|
101
|
+
when Ruby::Signature::AST::Members::Alias
|
102
|
+
puts " Processing #{member.new_name}(alias)..."
|
103
|
+
prefix = case
|
104
|
+
when member.instance?
|
105
|
+
"#"
|
106
|
+
when member.singleton?
|
107
|
+
"."
|
108
|
+
end
|
109
|
+
name = "#{prefix}#{member.new_name}"
|
110
|
+
|
111
|
+
comment = comment_for_method(klass_name, name, stores: stores)
|
112
|
+
member.instance_variable_set(:@comment, comment)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
stores = []
|
118
|
+
RDoc::RI::Paths.each true, true, false, false do |path, type|
|
119
|
+
puts "Loading store from #{path}..."
|
120
|
+
store = RDoc::RI::Store.new(path, type)
|
121
|
+
store.load_all
|
122
|
+
stores << store
|
123
|
+
end
|
124
|
+
|
125
|
+
ARGV.map {|f| Pathname(f) }.each do |path|
|
126
|
+
puts "Opening #{path}..."
|
127
|
+
|
128
|
+
buffer = Ruby::Signature::Buffer.new(name: path, content: path.read)
|
129
|
+
sigs = Ruby::Signature::Parser.parse_signature(buffer)
|
130
|
+
|
131
|
+
sigs.each do |decl|
|
132
|
+
case decl
|
133
|
+
when Ruby::Signature::AST::Declarations::Constant
|
134
|
+
puts " Importing documentation for #{decl.name}..."
|
135
|
+
comment = comment_for_constant(decl, stores: stores)
|
136
|
+
decl.instance_variable_set(:@comment, comment)
|
137
|
+
when Ruby::Signature::AST::Declarations::Class, Ruby::Signature::AST::Declarations::Module
|
138
|
+
puts " Importing documentation for #{decl.name}..."
|
139
|
+
comment = comment_for_class(decl, stores: stores)
|
140
|
+
decl.instance_variable_set(:@comment, comment)
|
141
|
+
|
142
|
+
print_members stores, decl.name.to_s, decl.members
|
143
|
+
when Ruby::Signature::AST::Declarations::Extension
|
144
|
+
puts " Importing documentation for #{decl.name} (#{decl.extension_name})"
|
145
|
+
|
146
|
+
print_members stores, decl.name.to_s, decl.members
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
puts "Writing #{path}..."
|
151
|
+
path.open('w') do |out|
|
152
|
+
writer = Ruby::Signature::Writer.new(out: out)
|
153
|
+
writer.write sigs
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby/signature"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,103 @@
|
|
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
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "ruby/signature"
|
4
|
+
|
5
|
+
Members = Ruby::Signature::AST::Members
|
6
|
+
|
7
|
+
def group(member)
|
8
|
+
case member
|
9
|
+
when Members::Include, Members::Extend, Members::Prepend
|
10
|
+
0
|
11
|
+
when Members::ClassVariable
|
12
|
+
-3
|
13
|
+
when Members::ClassInstanceVariable
|
14
|
+
-2
|
15
|
+
when Members::InstanceVariable
|
16
|
+
-1
|
17
|
+
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
18
|
+
2
|
19
|
+
when Members::MethodDefinition
|
20
|
+
if member.singleton?
|
21
|
+
if member.name == :new
|
22
|
+
0.4
|
23
|
+
else
|
24
|
+
1
|
25
|
+
end
|
26
|
+
else
|
27
|
+
if member.name == :initialize
|
28
|
+
0.5
|
29
|
+
else
|
30
|
+
3
|
31
|
+
end
|
32
|
+
end
|
33
|
+
when Members::Alias
|
34
|
+
if member.singleton?
|
35
|
+
1
|
36
|
+
else
|
37
|
+
3
|
38
|
+
end
|
39
|
+
when Members::Private, Members::Public
|
40
|
+
-4
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def key(member)
|
45
|
+
case member
|
46
|
+
when Members::Include, Members::Extend, Members::Prepend
|
47
|
+
member.name.to_s
|
48
|
+
when Members::ClassVariable, Members::ClassInstanceVariable, Members::InstanceVariable
|
49
|
+
member.name.to_s
|
50
|
+
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
51
|
+
member.name.to_s
|
52
|
+
when Members::MethodDefinition
|
53
|
+
member.name.to_s
|
54
|
+
when Members::Alias
|
55
|
+
member.new_name.to_s
|
56
|
+
else
|
57
|
+
1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
ARGV.map {|f| Pathname(f) }.each do |path|
|
62
|
+
puts "Opening #{path}..."
|
63
|
+
|
64
|
+
buffer = Ruby::Signature::Buffer.new(name: path, content: path.read)
|
65
|
+
sigs = Ruby::Signature::Parser.parse_signature(buffer)
|
66
|
+
|
67
|
+
sigs.each do |sig|
|
68
|
+
case sig
|
69
|
+
when Ruby::Signature::AST::Declarations::Class, Ruby::Signature::AST::Declarations::Module, Ruby::Signature::AST::Declarations::Interface
|
70
|
+
sig.members.sort! do |m1, m2|
|
71
|
+
group1 = group(m1)
|
72
|
+
group2 = group(m2)
|
73
|
+
|
74
|
+
if group1 == group2
|
75
|
+
key(m1) <=> key(m2)
|
76
|
+
else
|
77
|
+
group1 <=> group2
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
puts "Writing #{path}..."
|
84
|
+
path.open('w') do |out|
|
85
|
+
writer = Ruby::Signature::Writer.new(out: out)
|
86
|
+
writer.write sigs
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
RUBY_27_OR_LATER = Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION)
|
4
|
+
RUBY_27 = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
|
5
|
+
Gem::Version.new('2.7.0') <= ruby_version && ruby_version < Gem::Version.new("2.8.0")
|
6
|
+
end
|
7
|
+
|
8
|
+
unless RUBY_27
|
9
|
+
STDERR.puts "🚨🚨🚨 stdlib test requires Ruby 2.7 but RUBY_VERSION==#{RUBY_VERSION}, exiting... 🚨🚨🚨"
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
require "pathname"
|
14
|
+
|
15
|
+
ARGV.each do |arg|
|
16
|
+
load arg
|
17
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Standard Library Signatures Contribution Guide
|
2
|
+
|
3
|
+
## Guides
|
4
|
+
|
5
|
+
* [Stdlib Signatures Guide](stdlib.md)
|
6
|
+
* [Syntax](syntax.md)
|
7
|
+
* [Writing Signature Guide](sigs.md)
|
8
|
+
|
9
|
+
## Steps for Contribution
|
10
|
+
|
11
|
+
1. Pick the class/library you will work for.
|
12
|
+
2. Assign yourself on the [work spreadsheet](https://docs.google.com/spreadsheets/d/199rRB93I16H0k4TGZS3EGojns2R0W1oCsN8UPJzOpyU/edit#gid=1383307992) (optional but recommended to avoid duplication).
|
13
|
+
3. Sort RBS members (if there is RBS files for the classes).
|
14
|
+
- Use `bin/sort stdlib/path/to/signature.rbs` command and confirm it does not break definitions.
|
15
|
+
- Committing the sorted RBSs is recommended.
|
16
|
+
4. Add method prototypes.
|
17
|
+
- Use `rbs prototype runtime --merge CLASS_NAME` command to generate the missing method definitions.
|
18
|
+
- Committing the auto generated signatures is recommended.
|
19
|
+
5. Annotate with RDoc.
|
20
|
+
- Use `bin/annotate-with-rdoc stdlib/path/to/signature.rbs` to annotate the RBS files.
|
21
|
+
- Committing the generated annotations is recommended.
|
22
|
+
6. Fix method types and comments.
|
23
|
+
- The auto generated RDoc comments include `argslist` section, which we don't expect to be included the RBS files.
|
24
|
+
- Delete the `argslist` sections.
|
25
|
+
- Give methods correct types.
|
26
|
+
- Write tests, if possible. (If it is too difficult to write test, skip it.)
|
27
|
+
|
28
|
+
## The Target Version
|
29
|
+
|
30
|
+
* The standard library signatures targets Ruby 2.7 for now.
|
31
|
+
* The library code targets Ruby 2.6, 2.7, and 3.0.
|
32
|
+
|
33
|
+
## Stdlib Worksheet
|
34
|
+
|
35
|
+
You can find the list of classes/libraries:
|
36
|
+
|
37
|
+
* https://docs.google.com/spreadsheets/d/199rRB93I16H0k4TGZS3EGojns2R0W1oCsN8UPJzOpyU/edit#gid=1383307992
|
38
|
+
|
39
|
+
Assign yourself when you start working for a class or library.
|
40
|
+
After reviewing and merging your pull request, I will update the status of the library.
|
41
|
+
|
42
|
+
You may find the *Good for first contributor* column where you can find some classes are recommended for new contributors (👍), and some classes are not-recommended (👎).
|
43
|
+
|
44
|
+
## Useful Tools
|
45
|
+
|
46
|
+
* `rbs prototype runtime --merge String`
|
47
|
+
* Generate a prototype using runtime API.
|
48
|
+
* `--merge` tells to use the method types in RBS if exists.
|
49
|
+
* `rbs prototype runtime --merge --method-owner=Numeric Integer`
|
50
|
+
* You can use --method-owner if you want to print method of other classes too, for documentation purpose.
|
51
|
+
* `bin/annotate-with-rdoc stdlib/builtin/string.rbs`
|
52
|
+
* Write comments using RDoc.
|
53
|
+
* It contains argslist section, but I don't think we should have it in RBS files.
|
54
|
+
* `bin/query-rdoc String#initialize`
|
55
|
+
* Print RDoc documents in the format you can copy-and-paste to RBS.
|
56
|
+
* `bin/sort stdlib/builtin/string.rbs`
|
57
|
+
* Sort declarations members in RBS files.
|
58
|
+
* `rbs validate -r LIB`
|
59
|
+
Validate the syntax and some of the semantics.
|
60
|
+
* `rake generate::stdlib_test[String]`
|
61
|
+
Scaffold the stdlib test.
|
62
|
+
|
63
|
+
## Standard STDLIB Members Order
|
64
|
+
|
65
|
+
We define the standard members order so that ordering doesn't bother reading diffs or git-annotate outputs.
|
66
|
+
|
67
|
+
1. `def self.new` or `def initialize`
|
68
|
+
2. Mixins
|
69
|
+
3. Attributes
|
70
|
+
4. Singleton methods
|
71
|
+
5. `public` & public instance methods
|
72
|
+
6. `private` & private instance methods
|
73
|
+
|
74
|
+
```
|
75
|
+
class HelloWorld[X]
|
76
|
+
def self.new: [A] () { (void) -> A } -> HelloWorld[A] # new or initialize comes first
|
77
|
+
def initialize: () -> void
|
78
|
+
|
79
|
+
include Enumerable[X, void] # Mixin comes next
|
80
|
+
|
81
|
+
attr_reader language: (:ja | :en) # Attributes
|
82
|
+
|
83
|
+
def self.all_languages: () -> Array[Symbol] # Singleton methods
|
84
|
+
|
85
|
+
public # Public instance methods
|
86
|
+
|
87
|
+
def each: () { (A) -> void } -> void # Members are sorted dicionary order
|
88
|
+
|
89
|
+
def to_s: (?Locale) -> String
|
90
|
+
|
91
|
+
private # Private instance methods
|
92
|
+
|
93
|
+
alias validate validate_locale
|
94
|
+
|
95
|
+
def validate_locale: () -> void
|
96
|
+
end
|
97
|
+
```
|