steep 0.13.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +28 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +33 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +124 -89
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +13 -287
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +298 -0
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +54 -47
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +1004 -727
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +91 -23
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/alias/a.rb +1 -1
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regexp/b.rb +4 -4
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +8 -8
- metadata +38 -138
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -66
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,534 +0,0 @@
|
|
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
|