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,534 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module Ruby
|
4
|
+
module Signature
|
5
|
+
class CLI
|
6
|
+
class LibraryOptions
|
7
|
+
attr_reader :libs
|
8
|
+
attr_reader :dirs
|
9
|
+
attr_accessor :no_stdlib
|
10
|
+
|
11
|
+
def initialize()
|
12
|
+
@libs = []
|
13
|
+
@dirs = []
|
14
|
+
@no_stdlib = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup(loader)
|
18
|
+
libs.each do |lib|
|
19
|
+
loader.add(library: lib)
|
20
|
+
end
|
21
|
+
|
22
|
+
dirs.each do |dir|
|
23
|
+
loader.add(path: Pathname(dir))
|
24
|
+
end
|
25
|
+
|
26
|
+
loader.no_builtin! nil if no_stdlib
|
27
|
+
|
28
|
+
loader
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :stdout
|
33
|
+
attr_reader :stderr
|
34
|
+
|
35
|
+
def initialize(stdout:, stderr:)
|
36
|
+
@stdout = stdout
|
37
|
+
@stderr = stderr
|
38
|
+
end
|
39
|
+
|
40
|
+
COMMANDS = [:ast, :list, :ancestors, :methods, :method, :validate, :constant, :paths, :prototype, :vendor, :version]
|
41
|
+
|
42
|
+
def library_parse(opts, options:)
|
43
|
+
opts.on("-r LIBRARY") do |lib|
|
44
|
+
options.libs << lib
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-I DIR") do |dir|
|
48
|
+
options.dirs << dir
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("--no-stdlib") do
|
52
|
+
options.no_stdlib = true
|
53
|
+
end
|
54
|
+
|
55
|
+
opts
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_logging_options(opts)
|
59
|
+
opts.on("--log-level=LEVEL", "Specify log level (defaults to `warn`)") do |level|
|
60
|
+
Ruby::Signature.logger_level = level
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on("--log-output=OUTPUT", "Specify the file to output log (defaults to stderr)") do |output|
|
64
|
+
Ruby::Signature.logger_output = File.open(output, "a")
|
65
|
+
end
|
66
|
+
|
67
|
+
opts
|
68
|
+
end
|
69
|
+
|
70
|
+
def run(args)
|
71
|
+
options = LibraryOptions.new
|
72
|
+
|
73
|
+
opts = OptionParser.new
|
74
|
+
opts.banner = <<~USAGE
|
75
|
+
Usage: rbs [options] COMMAND
|
76
|
+
Available commands: #{COMMANDS.join(", ")}
|
77
|
+
USAGE
|
78
|
+
library_parse(opts, options: options)
|
79
|
+
parse_logging_options(opts)
|
80
|
+
|
81
|
+
opts.order!(args)
|
82
|
+
|
83
|
+
command = args.shift&.to_sym
|
84
|
+
|
85
|
+
if COMMANDS.include?(command)
|
86
|
+
__send__ :"run_#{command}", args, options
|
87
|
+
else
|
88
|
+
stdout.puts opts.help
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def run_ast(args, options)
|
93
|
+
loader = EnvironmentLoader.new()
|
94
|
+
|
95
|
+
options.setup(loader)
|
96
|
+
|
97
|
+
env = Environment.new()
|
98
|
+
loader.load(env: env)
|
99
|
+
|
100
|
+
stdout.print JSON.generate(env.declarations)
|
101
|
+
stdout.flush
|
102
|
+
end
|
103
|
+
|
104
|
+
def run_list(args, options)
|
105
|
+
list = []
|
106
|
+
|
107
|
+
OptionParser.new do |opts|
|
108
|
+
opts.on("--class") { list << :class }
|
109
|
+
opts.on("--module") { list << :module }
|
110
|
+
opts.on("--interface") { list << :interface }
|
111
|
+
end.order!(args)
|
112
|
+
|
113
|
+
list.push(:class, :module, :interface) if list.empty?
|
114
|
+
|
115
|
+
loader = EnvironmentLoader.new()
|
116
|
+
|
117
|
+
options.setup(loader)
|
118
|
+
|
119
|
+
env = Environment.new()
|
120
|
+
loader.load(env: env)
|
121
|
+
|
122
|
+
env.each_decl.sort_by {|name,| name.to_s }.each do |type_name, decl|
|
123
|
+
case decl
|
124
|
+
when AST::Declarations::Class
|
125
|
+
if list.include?(:class)
|
126
|
+
stdout.puts "#{type_name} (class)"
|
127
|
+
end
|
128
|
+
when AST::Declarations::Module
|
129
|
+
if list.include?(:module)
|
130
|
+
stdout.puts "#{type_name} (module)"
|
131
|
+
end
|
132
|
+
when AST::Declarations::Interface
|
133
|
+
if list.include?(:interface)
|
134
|
+
stdout.puts "#{type_name} (interface)"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def run_ancestors(args, options)
|
141
|
+
kind = :instance
|
142
|
+
|
143
|
+
OptionParser.new do |opts|
|
144
|
+
opts.on("--instance") { kind = :instance }
|
145
|
+
opts.on("--singleton") { kind = :singleton }
|
146
|
+
end.order!(args)
|
147
|
+
|
148
|
+
loader = EnvironmentLoader.new()
|
149
|
+
|
150
|
+
options.setup(loader)
|
151
|
+
|
152
|
+
env = Environment.new()
|
153
|
+
loader.load(env: env)
|
154
|
+
|
155
|
+
builder = DefinitionBuilder.new(env: env)
|
156
|
+
type_name = parse_type_name(args[0]).absolute!
|
157
|
+
|
158
|
+
if env.class?(type_name)
|
159
|
+
ancestor = case kind
|
160
|
+
when :instance
|
161
|
+
decl = env.find_class(type_name)
|
162
|
+
Definition::Ancestor::Instance.new(name: type_name,
|
163
|
+
args: Types::Variable.build(decl.type_params.each.map(&:name)))
|
164
|
+
when :singleton
|
165
|
+
Definition::Ancestor::Singleton.new(name: type_name)
|
166
|
+
end
|
167
|
+
|
168
|
+
ancestors = builder.build_ancestors(ancestor)
|
169
|
+
|
170
|
+
ancestors.each do |ancestor|
|
171
|
+
case ancestor
|
172
|
+
when Definition::Ancestor::Singleton
|
173
|
+
stdout.puts "singleton(#{ancestor.name})"
|
174
|
+
when Definition::Ancestor::ExtensionSingleton
|
175
|
+
stdout.puts "singleton(#{ancestor.name} (#{ancestor.extension_name}))"
|
176
|
+
when Definition::Ancestor::Instance
|
177
|
+
if ancestor.args.empty?
|
178
|
+
stdout.puts ancestor.name.to_s
|
179
|
+
else
|
180
|
+
stdout.puts "#{ancestor.name}[#{ancestor.args.join(", ")}]"
|
181
|
+
end
|
182
|
+
when Definition::Ancestor::ExtensionInstance
|
183
|
+
if ancestor.args.empty?
|
184
|
+
stdout.puts "#{ancestor.name} (#{ancestor.extension_name})"
|
185
|
+
else
|
186
|
+
stdout.puts "#{ancestor.name}[#{ancestor.args.join(", ")}] (#{ancestor.extension_name})"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
else
|
191
|
+
stdout.puts "Cannot find class: #{type_name}"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def run_methods(args, options)
|
196
|
+
kind = :instance
|
197
|
+
inherit = true
|
198
|
+
|
199
|
+
OptionParser.new do |opts|
|
200
|
+
opts.on("--instance") { kind = :instance }
|
201
|
+
opts.on("--singleton") { kind = :singleton }
|
202
|
+
opts.on("--inherit") { inherit = true }
|
203
|
+
opts.on("--no-inherit") { inherit = false }
|
204
|
+
end.order!(args)
|
205
|
+
|
206
|
+
unless args.size == 1
|
207
|
+
stdout.puts "Expected one argument."
|
208
|
+
return
|
209
|
+
end
|
210
|
+
|
211
|
+
loader = EnvironmentLoader.new()
|
212
|
+
|
213
|
+
options.setup(loader)
|
214
|
+
|
215
|
+
env = Environment.new()
|
216
|
+
loader.load(env: env)
|
217
|
+
|
218
|
+
builder = DefinitionBuilder.new(env: env)
|
219
|
+
type_name = parse_type_name(args[0]).absolute!
|
220
|
+
|
221
|
+
if env.class?(type_name)
|
222
|
+
definition = case kind
|
223
|
+
when :instance
|
224
|
+
builder.build_instance(type_name)
|
225
|
+
when :singleton
|
226
|
+
builder.build_singleton(type_name)
|
227
|
+
end
|
228
|
+
|
229
|
+
definition.methods.keys.sort.each do |name|
|
230
|
+
method = definition.methods[name]
|
231
|
+
if inherit || method.implemented_in == definition.declaration
|
232
|
+
stdout.puts "#{name} (#{method.accessibility})"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
else
|
236
|
+
stdout.puts "Cannot find class: #{type_name}"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def run_method(args, options)
|
241
|
+
kind = :instance
|
242
|
+
|
243
|
+
OptionParser.new do |opts|
|
244
|
+
opts.on("--instance") { kind = :instance }
|
245
|
+
opts.on("--singleton") { kind = :singleton }
|
246
|
+
end.order!(args)
|
247
|
+
|
248
|
+
unless args.size == 2
|
249
|
+
stdout.puts "Expected two arguments, but given #{args.size}."
|
250
|
+
return
|
251
|
+
end
|
252
|
+
|
253
|
+
loader = EnvironmentLoader.new()
|
254
|
+
|
255
|
+
options.setup(loader)
|
256
|
+
|
257
|
+
env = Environment.new()
|
258
|
+
loader.load(env: env)
|
259
|
+
|
260
|
+
builder = DefinitionBuilder.new(env: env)
|
261
|
+
type_name = parse_type_name(args[0]).absolute!
|
262
|
+
method_name = args[1].to_sym
|
263
|
+
|
264
|
+
unless env.class?(type_name)
|
265
|
+
stdout.puts "Cannot find class: #{type_name}"
|
266
|
+
return
|
267
|
+
end
|
268
|
+
|
269
|
+
definition = case kind
|
270
|
+
when :instance
|
271
|
+
builder.build_instance(type_name)
|
272
|
+
when :singleton
|
273
|
+
builder.build_singleton(type_name)
|
274
|
+
end
|
275
|
+
|
276
|
+
method = definition.methods[method_name]
|
277
|
+
|
278
|
+
unless method
|
279
|
+
stdout.puts "Cannot find method: #{method_name}"
|
280
|
+
return
|
281
|
+
end
|
282
|
+
|
283
|
+
stdout.puts "#{type_name}#{kind == :instance ? "#" : "."}#{method_name}"
|
284
|
+
stdout.puts " defined_in: #{method.defined_in&.name&.absolute!}"
|
285
|
+
stdout.puts " implementation: #{method.implemented_in.name.absolute!}"
|
286
|
+
stdout.puts " accessibility: #{method.accessibility}"
|
287
|
+
stdout.puts " types:"
|
288
|
+
separator = " "
|
289
|
+
for type in method.method_types
|
290
|
+
stdout.puts " #{separator} #{type}"
|
291
|
+
separator = "|"
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
def run_validate(args, options)
|
296
|
+
loader = EnvironmentLoader.new()
|
297
|
+
|
298
|
+
options.setup(loader)
|
299
|
+
|
300
|
+
env = Environment.new()
|
301
|
+
loader.load(env: env)
|
302
|
+
|
303
|
+
builder = DefinitionBuilder.new(env: env)
|
304
|
+
|
305
|
+
env.each_decl do |name, decl|
|
306
|
+
case decl
|
307
|
+
when AST::Declarations::Class, AST::Declarations::Module
|
308
|
+
stdout.puts "#{Location.to_string decl.location}:\tValidating class/module definition: `#{name}`..."
|
309
|
+
builder.build_instance(decl.name.absolute!).each_type do |type|
|
310
|
+
env.validate type, namespace: Namespace.root
|
311
|
+
end
|
312
|
+
builder.build_singleton(decl.name.absolute!).each_type do |type|
|
313
|
+
env.validate type, namespace: Namespace.root
|
314
|
+
end
|
315
|
+
when AST::Declarations::Interface
|
316
|
+
stdout.puts "#{Location.to_string decl.location}:\tValidating interface: `#{name}`..."
|
317
|
+
builder.build_interface(decl.name.absolute!, decl).each_type do |type|
|
318
|
+
env.validate type, namespace: Namespace.root
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
env.each_constant do |name, const|
|
324
|
+
stdout.puts "#{Location.to_string const.location}:\tValidating constant: `#{name}`..."
|
325
|
+
env.validate const.type, namespace: name.namespace
|
326
|
+
end
|
327
|
+
|
328
|
+
env.each_global do |name, global|
|
329
|
+
stdout.puts "#{Location.to_string global.location}:\tValidating global: `#{name}`..."
|
330
|
+
env.validate global.type, namespace: Namespace.root
|
331
|
+
end
|
332
|
+
|
333
|
+
env.each_alias do |name, decl|
|
334
|
+
stdout.puts "#{Location.to_string decl.location}:\tValidating alias: `#{name}`..."
|
335
|
+
env.validate decl.type, namespace: name.namespace
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
def run_constant(args, options)
|
340
|
+
context = nil
|
341
|
+
|
342
|
+
OptionParser.new do |opts|
|
343
|
+
opts.on("--context CONTEXT") {|c| context = c }
|
344
|
+
end.order!(args)
|
345
|
+
|
346
|
+
unless args.size == 1
|
347
|
+
stdout.puts "Expected one argument."
|
348
|
+
return
|
349
|
+
end
|
350
|
+
|
351
|
+
loader = EnvironmentLoader.new()
|
352
|
+
|
353
|
+
options.setup(loader)
|
354
|
+
|
355
|
+
env = Environment.new()
|
356
|
+
loader.load(env: env)
|
357
|
+
|
358
|
+
builder = DefinitionBuilder.new(env: env)
|
359
|
+
table = ConstantTable.new(builder: builder)
|
360
|
+
|
361
|
+
namespace = context ? Namespace.parse(context).absolute! : Namespace.root
|
362
|
+
stdout.puts "Context: #{namespace}"
|
363
|
+
name = Namespace.parse(args[0]).to_type_name
|
364
|
+
stdout.puts "Constant name: #{name}"
|
365
|
+
|
366
|
+
constant = table.resolve_constant_reference(name, context: namespace)
|
367
|
+
|
368
|
+
if constant
|
369
|
+
stdout.puts " => #{constant.name}: #{constant.type}"
|
370
|
+
else
|
371
|
+
stdout.puts " => [no constant]"
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
def run_version(args, options)
|
376
|
+
stdout.puts "ruby-signature #{VERSION}"
|
377
|
+
end
|
378
|
+
|
379
|
+
def run_paths(args, options)
|
380
|
+
loader = EnvironmentLoader.new()
|
381
|
+
|
382
|
+
options.setup(loader)
|
383
|
+
|
384
|
+
kind_of = -> (path) {
|
385
|
+
case
|
386
|
+
when path.file?
|
387
|
+
"file"
|
388
|
+
when path.directory?
|
389
|
+
"dir"
|
390
|
+
when !path.exist?
|
391
|
+
"absent"
|
392
|
+
else
|
393
|
+
"unknown"
|
394
|
+
end
|
395
|
+
}
|
396
|
+
|
397
|
+
if loader.stdlib_root
|
398
|
+
path = loader.stdlib_root
|
399
|
+
stdout.puts "#{path}/builtin (#{kind_of[path]}, stdlib)"
|
400
|
+
end
|
401
|
+
|
402
|
+
loader.paths.each do |path|
|
403
|
+
case path
|
404
|
+
when Pathname
|
405
|
+
stdout.puts "#{path} (#{kind_of[path]})"
|
406
|
+
when EnvironmentLoader::GemPath
|
407
|
+
stdout.puts "#{path.path} (#{kind_of[path.path]}, gem, name=#{path.name}, version=#{path.version})"
|
408
|
+
when EnvironmentLoader::LibraryPath
|
409
|
+
stdout.puts "#{path.path} (#{kind_of[path.path]}, library, name=#{path.name})"
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def run_prototype(args, options)
|
415
|
+
format = args.shift
|
416
|
+
|
417
|
+
case format
|
418
|
+
when "rbi", "rb"
|
419
|
+
decls = run_prototype_file(format, args)
|
420
|
+
when "runtime"
|
421
|
+
require_libs = []
|
422
|
+
relative_libs = []
|
423
|
+
merge = false
|
424
|
+
owners_included = []
|
425
|
+
|
426
|
+
OptionParser.new do |opts|
|
427
|
+
opts.on("--require=[LIB]") do |lib|
|
428
|
+
require_libs << lib
|
429
|
+
end
|
430
|
+
opts.on("--require-relative=[LIB]") do |lib|
|
431
|
+
relative_libs << lib
|
432
|
+
end
|
433
|
+
opts.on("--merge") do
|
434
|
+
merge = true
|
435
|
+
end
|
436
|
+
opts.on("--method-owner=[CLASS]") do |klass|
|
437
|
+
owners_included << klass
|
438
|
+
end
|
439
|
+
end.parse!(args)
|
440
|
+
|
441
|
+
loader = EnvironmentLoader.new()
|
442
|
+
|
443
|
+
options.setup(loader)
|
444
|
+
|
445
|
+
env = Environment.new()
|
446
|
+
loader.load(env: env)
|
447
|
+
|
448
|
+
require(*require_libs) unless require_libs.empty?
|
449
|
+
require_relative(*relative_libs) unless relative_libs.empty?
|
450
|
+
|
451
|
+
decls = Prototype::Runtime.new(patterns: args, env: env, merge: merge, owners_included: owners_included).decls
|
452
|
+
else
|
453
|
+
stdout.puts "Supported formats: rbi, rb, runtime"
|
454
|
+
exit 1
|
455
|
+
end
|
456
|
+
|
457
|
+
writer = Writer.new(out: stdout)
|
458
|
+
writer.write decls
|
459
|
+
end
|
460
|
+
|
461
|
+
def run_prototype_file(format, args)
|
462
|
+
parser = case format
|
463
|
+
when "rbi"
|
464
|
+
Prototype::RBI.new()
|
465
|
+
when "rb"
|
466
|
+
Prototype::RB.new()
|
467
|
+
end
|
468
|
+
|
469
|
+
args.each do |file|
|
470
|
+
parser.parse Pathname(file).read
|
471
|
+
end
|
472
|
+
|
473
|
+
parser.decls
|
474
|
+
end
|
475
|
+
|
476
|
+
def run_vendor(args, options)
|
477
|
+
clean = false
|
478
|
+
vendor_stdlib = false
|
479
|
+
vendor_dir = Pathname("vendor/sigs")
|
480
|
+
|
481
|
+
OptionParser.new do |opts|
|
482
|
+
opts.banner = <<~EOB
|
483
|
+
Usage: rbs vendor [options] GEMS...
|
484
|
+
Vendor signatures in the project directory.
|
485
|
+
EOB
|
486
|
+
|
487
|
+
opts.on("--[no-]clean", "Clean vendor directory (default: no)") do |v|
|
488
|
+
clean = v
|
489
|
+
end
|
490
|
+
|
491
|
+
opts.on("--[no-]stdlib", "Vendor stdlib signatures or not (default: no)") do |v|
|
492
|
+
vendor_stdlib = v
|
493
|
+
end
|
494
|
+
|
495
|
+
opts.on("--vendor-dir [DIR]", "Specify the directory for vendored signatures (default: vendor/sigs)") do |path|
|
496
|
+
vendor_dir = Pathname(path)
|
497
|
+
end
|
498
|
+
end.parse!(args)
|
499
|
+
|
500
|
+
stdout.puts "Vendoring signatures to #{vendor_dir}..."
|
501
|
+
|
502
|
+
vendorer = Vendorer.new(vendor_dir: vendor_dir)
|
503
|
+
|
504
|
+
if clean
|
505
|
+
stdout.puts " Deleting #{vendor_dir}..."
|
506
|
+
vendorer.clean!
|
507
|
+
end
|
508
|
+
|
509
|
+
if vendor_stdlib
|
510
|
+
stdout.puts " Vendoring standard libraries..."
|
511
|
+
vendorer.stdlib!
|
512
|
+
end
|
513
|
+
|
514
|
+
args.each do |gem|
|
515
|
+
name, version = EnvironmentLoader.parse_library(gem)
|
516
|
+
|
517
|
+
unless EnvironmentLoader.gem_sig_path(name, version)
|
518
|
+
stdout.puts " ⚠️ Cannot find rubygem: name=#{name}, version=#{version} 🚨"
|
519
|
+
else
|
520
|
+
stdout.puts " Vendoring gem: name=#{name}, version=#{version}..."
|
521
|
+
vendorer.gem!(name, version)
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
def parse_type_name(string)
|
527
|
+
Namespace.parse(string).yield_self do |namespace|
|
528
|
+
last = namespace.path.last
|
529
|
+
TypeName.new(name: last, namespace: namespace.parent)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
533
|
+
end
|
534
|
+
end
|