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,56 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class PrintProject
|
4
|
+
attr_reader :stdout
|
5
|
+
attr_reader :stderr
|
6
|
+
|
7
|
+
include Utils::DriverHelper
|
8
|
+
|
9
|
+
def initialize(stdout:, stderr:)
|
10
|
+
@stdout = stdout
|
11
|
+
@stderr = stderr
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
project = load_config()
|
16
|
+
|
17
|
+
loader = Project::FileLoader.new(project: project)
|
18
|
+
loader.load_sources([])
|
19
|
+
loader.load_signatures()
|
20
|
+
|
21
|
+
project.targets.each do |target|
|
22
|
+
stdout.puts "Target:"
|
23
|
+
stdout.puts " #{target.name}:"
|
24
|
+
stdout.puts " sources:"
|
25
|
+
stdout.puts " patterns:"
|
26
|
+
target.source_patterns.each do |pattern|
|
27
|
+
stdout.puts " - #{pattern}"
|
28
|
+
end
|
29
|
+
stdout.puts " ignores:"
|
30
|
+
target.ignore_patterns.each do |pattern|
|
31
|
+
stdout.puts " - #{pattern}"
|
32
|
+
end
|
33
|
+
stdout.puts " files:"
|
34
|
+
target.source_files.each_key do |path|
|
35
|
+
stdout.puts " - #{path}"
|
36
|
+
end
|
37
|
+
stdout.puts " signatures:"
|
38
|
+
stdout.puts " patterns:"
|
39
|
+
target.signature_patterns.each do |pattern|
|
40
|
+
stdout.puts " - #{pattern}"
|
41
|
+
end
|
42
|
+
stdout.puts " files:"
|
43
|
+
target.signature_files.each_key do |path|
|
44
|
+
stdout.puts " - #{path}"
|
45
|
+
end
|
46
|
+
stdout.puts " libraries:"
|
47
|
+
target.options.libraries.each do |lib|
|
48
|
+
stdout.puts " - #{lib}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
0
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class SignatureErrorPrinter
|
4
|
+
attr_reader :stdout
|
5
|
+
attr_reader :stderr
|
6
|
+
|
7
|
+
def initialize(stdout:, stderr:)
|
8
|
+
@stdout = stdout
|
9
|
+
@stderr = stderr
|
10
|
+
end
|
11
|
+
|
12
|
+
def print_syntax_errors(errors)
|
13
|
+
errors.each do |error|
|
14
|
+
stderr.puts error.message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def print_semantic_errors(errors)
|
19
|
+
errors.each do |error|
|
20
|
+
error.puts stderr
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class TracePrinter
|
4
|
+
attr_reader :io
|
5
|
+
|
6
|
+
def initialize(io)
|
7
|
+
@io = io
|
8
|
+
end
|
9
|
+
|
10
|
+
def print(trace, level: 0)
|
11
|
+
trace.each.with_index do |t, i|
|
12
|
+
prefix = " " * (i + level)
|
13
|
+
case t[0]
|
14
|
+
when :type
|
15
|
+
io.puts "#{prefix}#{t[1]} <: #{t[2]}"
|
16
|
+
when :method
|
17
|
+
io.puts "#{prefix}(#{t[3]}) #{t[1]} <: #{t[2]}"
|
18
|
+
when :method_type
|
19
|
+
io.puts "#{prefix}#{t[1]} <: #{t[2]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
module Utils
|
4
|
+
module DriverHelper
|
5
|
+
attr_accessor :steepfile
|
6
|
+
|
7
|
+
def load_config(path: steepfile || Pathname("Steepfile"))
|
8
|
+
raise "Cannot find a configuration at #{path}: `steep init` to scaffold" unless path.file?
|
9
|
+
|
10
|
+
steep_file_path = path.absolute? ? path : Pathname.pwd + path
|
11
|
+
Project.new(base_dir: steep_file_path.parent).tap do |project|
|
12
|
+
Project::DSL.parse(project, path.read, filename: path.to_s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def type_check(project)
|
17
|
+
project.targets.each do |target|
|
18
|
+
Steep.logger.tagged "target=#{target.name}" do
|
19
|
+
target.type_check
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,58 +1,38 @@
|
|
1
1
|
module Steep
|
2
2
|
module Drivers
|
3
3
|
class Validate
|
4
|
-
attr_reader :signature_dirs
|
5
4
|
attr_reader :stdout
|
6
5
|
attr_reader :stderr
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
include Utils::DriverHelper
|
8
|
+
|
9
|
+
def initialize(stdout:, stderr:)
|
10
10
|
@stdout = stdout
|
11
11
|
@stderr = stderr
|
12
12
|
end
|
13
13
|
|
14
|
-
include Utils::EachSignature
|
15
|
-
|
16
14
|
def run
|
17
|
-
project =
|
15
|
+
project = load_config()
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
file = Project::SignatureFile.new(path: file_path)
|
22
|
-
file.content = file_path.read
|
23
|
-
project.signature_files[file_path] = file
|
24
|
-
end
|
25
|
-
end
|
17
|
+
loader = Project::FileLoader.new(project: project)
|
18
|
+
loader.load_signatures()
|
26
19
|
|
27
|
-
project
|
20
|
+
type_check(project)
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
stdout.puts " #{s.name}(#{s.type_name}) <: #{t.name}(#{t.type_name})"
|
39
|
-
when Interface::MethodType
|
40
|
-
stdout.puts " #{s} <: #{t} (#{s.location&.name||"?"}:#{s.location&.start_line||"?"})"
|
41
|
-
else
|
42
|
-
stdout.puts " #{s} <: #{t}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
stdout.puts " 🚨 #{error.result.error.message}"
|
46
|
-
when Interface::Instantiated::InvalidIvarOverrideError
|
47
|
-
stdout.puts "😱 #{error.message}"
|
48
|
-
else
|
49
|
-
stdout.puts "😱 #{error.inspect}"
|
22
|
+
project.targets.each do |target|
|
23
|
+
Steep.logger.tagged "target=#{target.name}" do
|
24
|
+
case (status = target.status)
|
25
|
+
when Project::Target::SignatureSyntaxErrorStatus
|
26
|
+
printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
|
27
|
+
printer.print_syntax_errors(status.errors)
|
28
|
+
when Project::Target::SignatureValidationErrorStatus
|
29
|
+
printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
|
30
|
+
printer.print_semantic_errors(status.errors)
|
50
31
|
end
|
51
32
|
end
|
52
|
-
1
|
53
|
-
else
|
54
|
-
0
|
55
33
|
end
|
34
|
+
|
35
|
+
project.targets.all? {|target| target.status.is_a?(Project::Target::TypeCheckStatus) } ? 0 : 1
|
56
36
|
end
|
57
37
|
end
|
58
38
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class Vendor
|
4
|
+
attr_reader :stdout
|
5
|
+
attr_reader :stderr
|
6
|
+
attr_reader :stdin
|
7
|
+
|
8
|
+
attr_accessor :vendor_dir
|
9
|
+
attr_accessor :clean_before
|
10
|
+
|
11
|
+
def initialize(stdout:, stderr:, stdin:)
|
12
|
+
@stdout = stdout
|
13
|
+
@stderr = stderr
|
14
|
+
@stdin = stdin
|
15
|
+
|
16
|
+
@clean_before = false
|
17
|
+
@vendor_dir = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
stdout.puts "Vendoring into #{vendor_dir}..."
|
22
|
+
|
23
|
+
vendorer = Ruby::Signature::Vendorer.new(vendor_dir: vendor_dir)
|
24
|
+
|
25
|
+
if clean_before
|
26
|
+
stdout.puts " Cleaning directory..."
|
27
|
+
vendorer.clean!
|
28
|
+
end
|
29
|
+
|
30
|
+
stdout.puts " Vendoring standard libraries..."
|
31
|
+
vendorer.stdlib!
|
32
|
+
|
33
|
+
if defined?(Bundler)
|
34
|
+
Bundler.locked_gems.specs.each do |spec|
|
35
|
+
if Ruby::Signature::EnvironmentLoader.gem_sig_path(spec.name, spec.version.to_s).directory?
|
36
|
+
stdout.puts " Vendoring rubygem: #{spec.full_name}..."
|
37
|
+
vendorer.gem! spec.name, spec.version.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/steep/drivers/watch.rb
CHANGED
@@ -1,187 +1,125 @@
|
|
1
1
|
module Steep
|
2
2
|
module Drivers
|
3
3
|
class Watch
|
4
|
-
|
5
|
-
attr_accessor :fallback_any_is_error
|
6
|
-
attr_accessor :allow_missing_definitions
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
self.fallback_any_is_error = false
|
10
|
-
self.allow_missing_definitions = true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :source_dirs
|
15
|
-
attr_reader :signature_dirs
|
4
|
+
attr_reader :dirs
|
16
5
|
attr_reader :stdout
|
17
6
|
attr_reader :stderr
|
18
|
-
attr_reader :options
|
19
7
|
attr_reader :queue
|
20
8
|
|
21
|
-
include Utils::
|
9
|
+
include Utils::DriverHelper
|
22
10
|
|
23
|
-
def initialize(
|
24
|
-
@
|
25
|
-
@signature_dirs = signature_dirs
|
11
|
+
def initialize(stdout:, stderr:)
|
12
|
+
@dirs = []
|
26
13
|
@stdout = stdout
|
27
14
|
@stderr = stderr
|
28
|
-
@options = Options.new
|
29
15
|
@queue = Thread::Queue.new
|
30
16
|
end
|
31
17
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@source_listener ||= yield_self do
|
41
|
-
Listen.to(*source_dirs.map(&:to_s), only: /\.rb$/) do |modified, added, removed|
|
42
|
-
queue << [:source, modified, added, removed]
|
18
|
+
def listener
|
19
|
+
@listener ||= begin
|
20
|
+
Steep.logger.info "Watching #{dirs.join(", ")}..."
|
21
|
+
Listen.to(*dirs.map(&:to_s)) do |modified, added, removed|
|
22
|
+
Steep.logger.tagged "watch" do
|
23
|
+
Steep.logger.info "Received file system updates: modified=[#{modified.join(",")}], added=[#{added.join(",")}], removed=[#{removed.join(",")}]"
|
24
|
+
end
|
25
|
+
queue << [modified, added, removed]
|
43
26
|
end
|
44
27
|
end
|
45
28
|
end
|
46
29
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
queue << [:signature, modified, added, removed]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
30
|
+
def type_check_loop(project)
|
31
|
+
until queue.closed?
|
32
|
+
stdout.puts "🚥 Waiting for updates..."
|
54
33
|
|
55
|
-
|
56
|
-
|
57
|
-
until queue.
|
58
|
-
|
59
|
-
|
60
|
-
events << queue.deq
|
61
|
-
until queue.empty?
|
62
|
-
events << queue.deq(nonblock: true)
|
63
|
-
end
|
34
|
+
events = []
|
35
|
+
events << queue.deq
|
36
|
+
until queue.empty?
|
37
|
+
events << queue.deq(nonblock: true)
|
38
|
+
end
|
64
39
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
(modified + added).each do |name|
|
69
|
-
path = Pathname(name).relative_path_from(Pathname.pwd)
|
70
|
-
file = project.source_files[path] || Project::SourceFile.new(path: path, options: project_options)
|
71
|
-
file.content = path.read
|
72
|
-
project.source_files[path] = file
|
73
|
-
end
|
74
|
-
|
75
|
-
removed.each do |name|
|
76
|
-
path = Pathname(name).relative_path_from(Pathname.pwd)
|
77
|
-
project.source_files.delete(path)
|
78
|
-
end
|
79
|
-
|
80
|
-
when :signature
|
81
|
-
(modified + added).each do |name|
|
82
|
-
path = Pathname(name).relative_path_from(Pathname.pwd)
|
83
|
-
file = project.signature_files[path] || Project::SignatureFile.new(path: path)
|
84
|
-
file.content = path.read
|
85
|
-
project.signature_files[path] = file
|
86
|
-
end
|
87
|
-
|
88
|
-
removed.each do |name|
|
89
|
-
path = Pathname(name).relative_path_from(Pathname.pwd)
|
90
|
-
project.signature_files.delete(path)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
40
|
+
events.compact.each do |modified, added, removed|
|
41
|
+
modified.each do |name|
|
42
|
+
path = Pathname(name).relative_path_from(Pathname.pwd)
|
94
43
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
stderr.puts exn.message
|
99
|
-
project.clear
|
44
|
+
project.targets.each do |target|
|
45
|
+
target.update_source path, path.read if target.source_file?(path)
|
46
|
+
target.update_signature path, path.read if target.signature_file?(path)
|
100
47
|
end
|
101
48
|
end
|
102
|
-
end
|
103
|
-
rescue ClosedQueueError
|
104
|
-
# nop
|
105
|
-
end
|
106
|
-
end
|
107
49
|
|
108
|
-
|
109
|
-
|
110
|
-
attr_reader :stderr
|
111
|
-
|
112
|
-
def initialize(stdout:, stderr:, verbose:)
|
113
|
-
@stdout = stdout
|
114
|
-
@stderr = stderr
|
115
|
-
end
|
50
|
+
added.each do |name|
|
51
|
+
path = Pathname(name).relative_path_from(Pathname.pwd)
|
116
52
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
if project.has_type_error?
|
121
|
-
stdout.puts "Detected #{project.errors.size} errors... 🔥"
|
122
|
-
else
|
123
|
-
stdout.puts "No error detected. 🎉"
|
53
|
+
project.targets.each do |target|
|
54
|
+
target.add_source path, path.read if target.possible_source_file?(path)
|
55
|
+
target.add_signature path, path.read if target.possible_signature_file?(path)
|
124
56
|
end
|
125
|
-
else
|
126
|
-
stdout.puts "Type checking failed... 🔥"
|
127
57
|
end
|
128
|
-
end
|
129
|
-
end
|
130
58
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
59
|
+
removed.each do |name|
|
60
|
+
path = Pathname(name).relative_path_from(Pathname.pwd)
|
61
|
+
|
62
|
+
project.targets.each do |target|
|
63
|
+
target.remove_source path if target.source_file?(path)
|
64
|
+
target.remove_signature path if target.signature_file?(path)
|
137
65
|
end
|
138
66
|
end
|
139
67
|
end
|
68
|
+
|
69
|
+
stdout.puts "🔬 Type checking..."
|
70
|
+
type_check project
|
71
|
+
print_project_result project
|
140
72
|
end
|
73
|
+
rescue ClosedQueueError
|
74
|
+
# nop
|
75
|
+
end
|
141
76
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
case
|
146
|
-
when Project::
|
147
|
-
|
148
|
-
|
149
|
-
|
77
|
+
def print_project_result(project)
|
78
|
+
project.targets.each do |target|
|
79
|
+
Steep.logger.tagged "target=#{target.name}" do
|
80
|
+
case (status = target.status)
|
81
|
+
when Project::Target::SignatureSyntaxErrorStatus
|
82
|
+
printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
|
83
|
+
printer.print_syntax_errors(status.errors)
|
84
|
+
when Project::Target::SignatureValidationErrorStatus
|
85
|
+
printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
|
86
|
+
printer.print_semantic_errors(status.errors)
|
87
|
+
when Project::Target::TypeCheckStatus
|
88
|
+
status.type_check_sources.each do |source_file|
|
89
|
+
source_file.errors.each do |error|
|
90
|
+
error.print_to stdout
|
91
|
+
end
|
150
92
|
end
|
151
93
|
end
|
152
94
|
end
|
153
95
|
end
|
154
96
|
end
|
155
97
|
|
156
|
-
def run(
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
each_file_in_path(".rb", path) do |file_path|
|
161
|
-
file = Project::SourceFile.new(path: file_path, options: options)
|
162
|
-
file.content = file_path.read
|
163
|
-
project.source_files[file_path] = file
|
164
|
-
end
|
98
|
+
def run()
|
99
|
+
if dirs.empty?
|
100
|
+
stdout.puts "Specify directories to watch"
|
101
|
+
return 1
|
165
102
|
end
|
166
103
|
|
167
|
-
|
168
|
-
each_file_in_path(".rbi", path) do |file_path|
|
169
|
-
file = Project::SignatureFile.new(path: file_path)
|
170
|
-
file.content = file_path.read
|
171
|
-
project.signature_files[file_path] = file
|
172
|
-
end
|
173
|
-
end
|
104
|
+
project = load_config()
|
174
105
|
|
175
|
-
project
|
106
|
+
loader = Project::FileLoader.new(project: project)
|
107
|
+
loader.load_sources([])
|
108
|
+
loader.load_signatures()
|
176
109
|
|
177
|
-
|
178
|
-
|
179
|
-
t = type_check_thread(project)
|
110
|
+
type_check project
|
111
|
+
print_project_result project
|
180
112
|
|
181
|
-
|
113
|
+
listener.start
|
114
|
+
|
115
|
+
stdout.puts "👀 Watching directories, Ctrl-C to stop."
|
116
|
+
begin
|
117
|
+
type_check_loop project
|
118
|
+
rescue Interrupt
|
119
|
+
# bye
|
120
|
+
end
|
182
121
|
|
183
|
-
|
184
|
-
t.join
|
122
|
+
0
|
185
123
|
end
|
186
124
|
end
|
187
125
|
end
|