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
data/lib/steep/drivers/check.rb
CHANGED
@@ -1,124 +1,88 @@
|
|
1
1
|
module Steep
|
2
2
|
module Drivers
|
3
3
|
class Check
|
4
|
-
attr_reader :source_paths
|
5
|
-
attr_reader :signature_dirs
|
6
4
|
attr_reader :stdout
|
7
5
|
attr_reader :stderr
|
6
|
+
attr_reader :command_line_patterns
|
8
7
|
|
9
|
-
attr_accessor :accept_implicit_any
|
10
8
|
attr_accessor :dump_all_types
|
11
|
-
attr_accessor :fallback_any_is_error
|
12
|
-
attr_accessor :allow_missing_definitions
|
13
9
|
|
14
|
-
|
10
|
+
include Utils::DriverHelper
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
def initialize(source_paths:, signature_dirs:, stdout:, stderr:)
|
19
|
-
@source_paths = source_paths
|
20
|
-
@signature_dirs = signature_dirs
|
12
|
+
def initialize(stdout:, stderr:)
|
21
13
|
@stdout = stdout
|
22
14
|
@stderr = stderr
|
15
|
+
@command_line_patterns = []
|
23
16
|
|
24
|
-
self.accept_implicit_any = false
|
25
17
|
self.dump_all_types = false
|
26
|
-
self.fallback_any_is_error = false
|
27
|
-
self.allow_missing_definitions = true
|
28
|
-
end
|
29
|
-
|
30
|
-
def options
|
31
|
-
Project::Options.new.tap do |opt|
|
32
|
-
opt.allow_missing_definitions = allow_missing_definitions
|
33
|
-
opt.fallback_any_is_error = fallback_any_is_error
|
34
|
-
end
|
35
18
|
end
|
36
19
|
|
37
20
|
def run
|
38
|
-
project =
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
21
|
+
project = load_config()
|
22
|
+
|
23
|
+
loader = Project::FileLoader.new(project: project)
|
24
|
+
loader.load_sources(command_line_patterns)
|
25
|
+
loader.load_signatures()
|
26
|
+
|
27
|
+
type_check(project)
|
28
|
+
|
29
|
+
if self.dump_all_types
|
30
|
+
project.targets.each do |target|
|
31
|
+
case (status = target.status)
|
32
|
+
when Project::Target::TypeCheckStatus
|
33
|
+
target.source_files.each_value do |file|
|
34
|
+
case (file_status = file.status)
|
35
|
+
when Project::SourceFile::TypeCheckStatus
|
36
|
+
output_types(file_status.typing)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
53
40
|
end
|
54
41
|
end
|
55
42
|
|
56
|
-
project.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# @type var project: Project
|
70
|
-
|
71
|
-
if dump_all_types
|
72
|
-
project.source_files.each_value do |file|
|
73
|
-
lines = []
|
74
|
-
|
75
|
-
if typing = file.typing
|
76
|
-
typing.nodes.each_value do |node|
|
77
|
-
begin
|
78
|
-
type = typing.type_of(node: node)
|
79
|
-
lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, type]
|
80
|
-
rescue
|
81
|
-
lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, nil]
|
43
|
+
project.targets.each do |target|
|
44
|
+
Steep.logger.tagged "target=#{target.name}" do
|
45
|
+
case (status = target.status)
|
46
|
+
when Project::Target::SignatureSyntaxErrorStatus
|
47
|
+
printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
|
48
|
+
printer.print_syntax_errors(status.errors)
|
49
|
+
when Project::Target::SignatureValidationErrorStatus
|
50
|
+
printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
|
51
|
+
printer.print_semantic_errors(status.errors)
|
52
|
+
when Project::Target::TypeCheckStatus
|
53
|
+
status.type_check_sources.each do |source_file|
|
54
|
+
source_file.errors.each do |error|
|
55
|
+
error.print_to stdout
|
82
56
|
end
|
83
57
|
end
|
84
|
-
|
85
|
-
lines.sort {|x,y| y <=> x }.reverse_each do |line|
|
86
|
-
source = line[3].loc.expression.source
|
87
|
-
stdout.puts "#{line[0]}:(#{line[2].join(",")}):(#{line[1].join(",")}):\t#{line[3].type}:\t#{line[4]}\t(#{source.split(/\n/).first})"
|
88
|
-
end
|
89
58
|
end
|
90
59
|
end
|
91
60
|
end
|
92
61
|
|
93
|
-
project.
|
94
|
-
|
95
|
-
|
96
|
-
end
|
62
|
+
if project.targets.all? {|target| target.status.is_a?(Project::Target::TypeCheckStatus) && target.errors.empty? }
|
63
|
+
Steep.logger.info "No type error found"
|
64
|
+
return 0
|
97
65
|
end
|
66
|
+
|
67
|
+
1
|
98
68
|
end
|
99
69
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
when Interface::MethodType
|
110
|
-
stdout.puts " #{s} <: #{t} (#{s.location&.name||"?"}:#{s.location&.start_line||"?"})"
|
111
|
-
else
|
112
|
-
stdout.puts " #{s} <: #{t}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
stdout.puts " 🚨 #{error.result.error.message}"
|
116
|
-
when Interface::Instantiated::InvalidIvarOverrideError
|
117
|
-
stdout.puts "😱 #{error.message}"
|
118
|
-
else
|
119
|
-
stdout.puts "😱 #{error.inspect}"
|
70
|
+
def output_types(typing)
|
71
|
+
lines = []
|
72
|
+
|
73
|
+
typing.nodes.each_value do |node|
|
74
|
+
begin
|
75
|
+
type = typing.type_of(node: node)
|
76
|
+
lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, type]
|
77
|
+
rescue
|
78
|
+
lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, nil]
|
120
79
|
end
|
121
80
|
end
|
81
|
+
|
82
|
+
lines.sort {|x,y| y <=> x }.reverse_each do |line|
|
83
|
+
source = line[3].loc.expression.source
|
84
|
+
stdout.puts "#{line[0]}:(#{line[2].join(",")}):(#{line[1].join(",")}):\t#{line[3].type}:\t#{line[4]}\t(#{source.split(/\n/).first})"
|
85
|
+
end
|
122
86
|
end
|
123
87
|
end
|
124
88
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class Init
|
4
|
+
attr_reader :stdout
|
5
|
+
attr_reader :stderr
|
6
|
+
attr_accessor :force_write
|
7
|
+
|
8
|
+
include Utils::DriverHelper
|
9
|
+
|
10
|
+
TEMPLATE = <<~EOF
|
11
|
+
# target :lib do
|
12
|
+
# signature "sig"
|
13
|
+
#
|
14
|
+
# check "lib" # Directory name
|
15
|
+
# check "Gemfile" # File name
|
16
|
+
# check "app/models/**/*.rb" # Glob
|
17
|
+
# # ignore "lib/templates/*.rb"
|
18
|
+
#
|
19
|
+
# # library "pathname", "set" # Standard libraries
|
20
|
+
# # library "strong_json" # Gems
|
21
|
+
# end
|
22
|
+
|
23
|
+
# target :spec do
|
24
|
+
# signature "sig", "sig-private"
|
25
|
+
#
|
26
|
+
# check "spec"
|
27
|
+
#
|
28
|
+
# # library "pathname", "set" # Standard libraries
|
29
|
+
# # library "rspec"
|
30
|
+
# end
|
31
|
+
EOF
|
32
|
+
|
33
|
+
def initialize(stdout:, stderr:)
|
34
|
+
@stdout = stdout
|
35
|
+
@stderr = stderr
|
36
|
+
@force_write = false
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
path = steepfile || Pathname("Steepfile")
|
41
|
+
|
42
|
+
if path.file? && !force_write
|
43
|
+
stdout.puts "#{path} already exists, --force to overwrite"
|
44
|
+
return 1
|
45
|
+
end
|
46
|
+
|
47
|
+
stdout.puts "Writing #{path}..."
|
48
|
+
path.write(TEMPLATE)
|
49
|
+
|
50
|
+
0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,192 +1,283 @@
|
|
1
1
|
module Steep
|
2
2
|
module Drivers
|
3
3
|
class Langserver
|
4
|
-
attr_reader :
|
5
|
-
attr_reader :
|
6
|
-
attr_reader :
|
7
|
-
attr_reader :
|
8
|
-
attr_reader :
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(source_dirs:, signature_dirs:)
|
13
|
-
@source_dirs = source_dirs
|
14
|
-
@signature_dirs = signature_dirs
|
15
|
-
@options = Project::Options.new
|
16
|
-
@subscribers = {}
|
17
|
-
@open_paths = Set.new
|
18
|
-
|
19
|
-
subscribe :initialize do |request:, notifier:|
|
20
|
-
LanguageServer::Protocol::Interface::InitializeResult.new(
|
21
|
-
capabilities: LanguageServer::Protocol::Interface::ServerCapabilities.new(
|
22
|
-
text_document_sync: LanguageServer::Protocol::Interface::TextDocumentSyncOptions.new(
|
23
|
-
open_close: true,
|
24
|
-
change: LanguageServer::Protocol::Constant::TextDocumentSyncKind::FULL,
|
25
|
-
),
|
26
|
-
hover_provider: true
|
27
|
-
),
|
28
|
-
)
|
29
|
-
end
|
4
|
+
attr_reader :stdout
|
5
|
+
attr_reader :stderr
|
6
|
+
attr_reader :stdin
|
7
|
+
attr_reader :latest_update_version
|
8
|
+
attr_reader :write_mutex
|
9
|
+
attr_reader :type_check_queue
|
10
|
+
attr_reader :type_check_thread
|
30
11
|
|
31
|
-
|
32
|
-
Steep.logger.warn "Shutting down the server..."
|
33
|
-
exit
|
34
|
-
end
|
12
|
+
include Utils::DriverHelper
|
35
13
|
|
36
|
-
|
37
|
-
uri = URI.parse(request[:params][:textDocument][:uri])
|
38
|
-
open_path uri
|
39
|
-
text = request[:params][:textDocument][:text]
|
40
|
-
synchronize_project(uri: uri, text: text, notifier: notifier)
|
41
|
-
end
|
14
|
+
TypeCheckRequest = Struct.new(:version, keyword_init: true)
|
42
15
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
16
|
+
def initialize(stdout:, stderr:, stdin:)
|
17
|
+
@stdout = stdout
|
18
|
+
@stderr = stderr
|
19
|
+
@stdin = stdin
|
20
|
+
@write_mutex = Mutex.new
|
21
|
+
@type_check_queue = Queue.new
|
22
|
+
end
|
47
23
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
synchronize_project(uri: uri, text: text, notifier: notifier)
|
52
|
-
end
|
24
|
+
def writer
|
25
|
+
@writer ||= LanguageServer::Protocol::Transport::Io::Writer.new(stdout)
|
26
|
+
end
|
53
27
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
28
|
+
def reader
|
29
|
+
@reader ||= LanguageServer::Protocol::Transport::Io::Reader.new(stdin)
|
30
|
+
end
|
31
|
+
|
32
|
+
def project
|
33
|
+
@project or raise "Empty #project"
|
61
34
|
end
|
62
35
|
|
63
|
-
def
|
64
|
-
|
36
|
+
def enqueue_type_check(version)
|
37
|
+
@latest_update_version = version
|
38
|
+
type_check_queue << TypeCheckRequest.new(version: version)
|
39
|
+
end
|
65
40
|
|
66
|
-
|
67
|
-
|
68
|
-
project.type_of(path: path, line: line + 1, column: column) do |type, node|
|
69
|
-
Steep.logger.warn "type = #{type.to_s}"
|
41
|
+
def run
|
42
|
+
@project = load_config()
|
70
43
|
|
71
|
-
|
72
|
-
|
73
|
-
|
44
|
+
loader = Project::FileLoader.new(project: project)
|
45
|
+
loader.load_sources([])
|
46
|
+
loader.load_signatures()
|
74
47
|
|
75
|
-
|
76
|
-
Steep.logger.warn "range = #{range.inspect}"
|
48
|
+
start_type_check()
|
77
49
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
)
|
50
|
+
reader.read do |request|
|
51
|
+
Steep.logger.tagged "lsp" do
|
52
|
+
Steep.logger.debug { "Received a request: request=#{request.to_json}" }
|
53
|
+
handle_request(request) do |id, result|
|
54
|
+
if id
|
55
|
+
write_mutex.synchronize do
|
56
|
+
Steep.logger.debug { "Writing response to #{id}: #{result.to_json}" }
|
57
|
+
writer.write(id: id, result: result)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
82
61
|
end
|
83
62
|
end
|
63
|
+
|
64
|
+
0
|
84
65
|
end
|
85
66
|
|
86
|
-
def
|
87
|
-
|
67
|
+
def write(method:, params:)
|
68
|
+
write_mutex.synchronize do
|
69
|
+
Steep.logger.debug { "Sending request: method=#{method}, params=#{params.to_json}"}
|
70
|
+
writer.write(method: method, params: params)
|
71
|
+
end
|
88
72
|
end
|
89
73
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
74
|
+
def handle_request(request)
|
75
|
+
id = request[:id]
|
76
|
+
method = request[:method].to_sym
|
77
|
+
|
78
|
+
Steep.logger.tagged "id=#{id}, method=#{method}" do
|
79
|
+
case method
|
80
|
+
when :initialize
|
81
|
+
yield id, LanguageServer::Protocol::Interface::InitializeResult.new(
|
82
|
+
capabilities: LanguageServer::Protocol::Interface::ServerCapabilities.new(
|
83
|
+
text_document_sync: LanguageServer::Protocol::Interface::TextDocumentSyncOptions.new(
|
84
|
+
change: LanguageServer::Protocol::Constant::TextDocumentSyncKind::FULL
|
85
|
+
),
|
86
|
+
hover_provider: true,
|
87
|
+
)
|
88
|
+
)
|
89
|
+
|
90
|
+
enqueue_type_check nil
|
91
|
+
when :"textDocument/didChange"
|
92
|
+
uri = URI.parse(request[:params][:textDocument][:uri])
|
93
|
+
path = project.relative_path(Pathname(uri.path))
|
94
|
+
text = request[:params][:contentChanges][0][:text]
|
95
|
+
|
96
|
+
Steep.logger.debug { "path=#{path}, content=#{text.lines.first&.chomp}..." }
|
97
|
+
|
98
|
+
project.targets.each do |target|
|
99
|
+
Steep.logger.tagged "target=#{target.name}" do
|
100
|
+
case
|
101
|
+
when target.source_file?(path)
|
102
|
+
if text.empty? && !path.file?
|
103
|
+
Steep.logger.info { "Deleting source file: #{path}..." }
|
104
|
+
target.remove_source(path)
|
105
|
+
report_diagnostics path, []
|
106
|
+
else
|
107
|
+
Steep.logger.info { "Updating source file: #{path}..." }
|
108
|
+
target.update_source(path, text)
|
109
|
+
end
|
110
|
+
when target.possible_source_file?(path)
|
111
|
+
Steep.logger.info { "Adding source file: #{path}..." }
|
112
|
+
target.add_source(path, text)
|
113
|
+
when target.signature_file?(path)
|
114
|
+
if text.empty? && !path.file?
|
115
|
+
Steep.logger.info { "Deleting signature file: #{path}..." }
|
116
|
+
target.remove_signature(path)
|
117
|
+
report_diagnostics path, []
|
118
|
+
else
|
119
|
+
Steep.logger.info { "Updating signature file: #{path}..." }
|
120
|
+
target.update_signature(path, text)
|
121
|
+
end
|
122
|
+
when target.possible_signature_file?(path)
|
123
|
+
Steep.logger.info { "Adding signature file: #{path}..." }
|
124
|
+
target.add_signature(path, text)
|
125
|
+
end
|
126
|
+
end
|
97
127
|
end
|
128
|
+
|
129
|
+
version = request[:params][:textDocument][:version]
|
130
|
+
enqueue_type_check version
|
131
|
+
when :"textDocument/hover"
|
132
|
+
uri = URI.parse(request[:params][:textDocument][:uri])
|
133
|
+
path = project.relative_path(Pathname(uri.path))
|
134
|
+
line = request[:params][:position][:line]
|
135
|
+
column = request[:params][:position][:character]
|
136
|
+
|
137
|
+
yield id, response_to_hover(path: path, line: line, column: column)
|
138
|
+
|
139
|
+
when :shutdown
|
140
|
+
yield id, nil
|
141
|
+
|
142
|
+
when :exit
|
143
|
+
type_check_queue << nil
|
144
|
+
type_check_thread.join
|
145
|
+
exit
|
98
146
|
end
|
147
|
+
end
|
148
|
+
end
|
99
149
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
150
|
+
def start_type_check
|
151
|
+
@type_check_thread = Thread.start do
|
152
|
+
while request = type_check_queue.deq
|
153
|
+
if @latest_update_version == nil || @latest_update_version == request.version
|
154
|
+
run_type_check()
|
105
155
|
end
|
106
156
|
end
|
107
157
|
end
|
108
158
|
end
|
109
159
|
|
110
|
-
def
|
111
|
-
|
160
|
+
def run_type_check()
|
161
|
+
Steep.logger.tagged "#run_type_check" do
|
162
|
+
Steep.logger.info { "Running type check..." }
|
163
|
+
type_check project
|
164
|
+
|
165
|
+
Steep.logger.info { "Sending diagnostics..." }
|
166
|
+
project.targets.each do |target|
|
167
|
+
Steep.logger.tagged "target=#{target.name}, status=#{target.status.class}" do
|
168
|
+
Steep.logger.info { "Clearing signature diagnostics..." }
|
169
|
+
target.signature_files.each_value do |file|
|
170
|
+
report_diagnostics file.path, []
|
171
|
+
end
|
172
|
+
|
173
|
+
case (status = target.status)
|
174
|
+
when Project::Target::SignatureValidationErrorStatus
|
175
|
+
Steep.logger.info { "Signature validation error" }
|
176
|
+
status.errors.group_by(&:path).each do |path, errors|
|
177
|
+
diagnostics = errors.map {|error| diagnostic_for_validation_error(error) }
|
178
|
+
report_diagnostics path, diagnostics
|
179
|
+
end
|
180
|
+
when Project::Target::TypeCheckStatus
|
181
|
+
Steep.logger.info { "Type check" }
|
182
|
+
status.type_check_sources.each do |source|
|
183
|
+
diagnostics = case source.status
|
184
|
+
when Project::SourceFile::TypeCheckStatus
|
185
|
+
source.errors.map {|error| diagnostic_for_type_error(error) }
|
186
|
+
when Project::SourceFile::AnnotationSyntaxErrorStatus
|
187
|
+
[diagnostics_raw(source.status.error.message, source.status.location)]
|
188
|
+
when Project::SourceFile::ParseErrorStatus
|
189
|
+
[]
|
190
|
+
end
|
191
|
+
|
192
|
+
report_diagnostics source.path, diagnostics
|
193
|
+
end
|
194
|
+
when Project::Target::SignatureSyntaxErrorStatus
|
195
|
+
Steep.logger.info { "Signature syntax error" }
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
112
200
|
end
|
113
201
|
|
114
|
-
def
|
115
|
-
|
202
|
+
def report_diagnostics(path, diagnostics)
|
203
|
+
Steep.logger.info { "Reporting #{diagnostics.size} diagnostics for #{path}..." }
|
204
|
+
write(
|
205
|
+
method: :"textDocument/publishDiagnostics",
|
206
|
+
params: LanguageServer::Protocol::Interface::PublishDiagnosticsParams.new(
|
207
|
+
uri: URI.parse(project.absolute_path(path).to_s).tap {|uri| uri.scheme = "file"},
|
208
|
+
diagnostics: diagnostics,
|
209
|
+
)
|
210
|
+
)
|
116
211
|
end
|
117
212
|
|
118
|
-
def
|
119
|
-
|
213
|
+
def diagnostic_for_validation_error(error)
|
214
|
+
LanguageServer::Protocol::Interface::Diagnostic.new(
|
215
|
+
message: StringIO.new("").tap {|io| error.puts(io) }.string,
|
216
|
+
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
217
|
+
range: LanguageServer::Protocol::Interface::Range.new(
|
218
|
+
start: LanguageServer::Protocol::Interface::Position.new(
|
219
|
+
line: error.location.start_line - 1,
|
220
|
+
character: error.location.start_column,
|
221
|
+
),
|
222
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
223
|
+
line: error.location.end_line - 1,
|
224
|
+
character: error.location.end_column,
|
225
|
+
),
|
226
|
+
)
|
227
|
+
)
|
120
228
|
end
|
121
229
|
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
|
230
|
+
def diagnostics_raw(message, loc)
|
231
|
+
LanguageServer::Protocol::Interface::Diagnostic.new(
|
232
|
+
message: message,
|
233
|
+
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
234
|
+
range: LanguageServer::Protocol::Interface::Range.new(
|
235
|
+
start: LanguageServer::Protocol::Interface::Position.new(
|
236
|
+
line: loc.start_line - 1,
|
237
|
+
character: loc.start_column,
|
238
|
+
),
|
239
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
240
|
+
line: loc.end_line - 1,
|
241
|
+
character: loc.end_column,
|
242
|
+
),
|
243
|
+
)
|
244
|
+
)
|
245
|
+
end
|
126
246
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
247
|
+
def diagnostic_for_type_error(error)
|
248
|
+
LanguageServer::Protocol::Interface::Diagnostic.new(
|
249
|
+
message: error.to_s,
|
250
|
+
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
251
|
+
range: LanguageServer::Protocol::Interface::Range.new(
|
252
|
+
start: LanguageServer::Protocol::Interface::Position.new(
|
253
|
+
line: error.node.loc.line - 1,
|
254
|
+
character: error.node.loc.column,
|
255
|
+
),
|
256
|
+
end: LanguageServer::Protocol::Interface::Position.new(
|
257
|
+
line: error.node.loc.last_line - 1,
|
258
|
+
character: error.node.loc.last_column,
|
259
|
+
),
|
260
|
+
)
|
261
|
+
)
|
141
262
|
end
|
142
263
|
|
143
|
-
def
|
144
|
-
path
|
145
|
-
|
146
|
-
case path.extname
|
147
|
-
when ".rb"
|
148
|
-
file = project.source_files[path] || Project::SourceFile.new(path: path, options: options)
|
149
|
-
file.content = text
|
150
|
-
project.source_files[path] = file
|
151
|
-
when ".rbi"
|
152
|
-
file = project.signature_files[path] || Project::SignatureFile.new(path: path)
|
153
|
-
file.content = text
|
154
|
-
project.signature_files[path] = file
|
155
|
-
end
|
264
|
+
def response_to_hover(path:, line:, column:)
|
265
|
+
Steep.logger.info { "path=#{path}, line=#{line}, column=#{column}" }
|
156
266
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
Pathname(uri.path).relative_path_from(Pathname.pwd).yield_self do |path|
|
161
|
-
case path.extname
|
162
|
-
when ".rb"
|
163
|
-
file = project.source_files[path] || Project::SourceFile.new(path: path, options: options)
|
164
|
-
diags = (file.errors || []).map do |error|
|
165
|
-
LanguageServer::Protocol::Interface::Diagnostic.new(
|
166
|
-
message: error.to_s,
|
167
|
-
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
168
|
-
range: LanguageServer::Protocol::Interface::Range.new(
|
169
|
-
start: LanguageServer::Protocol::Interface::Position.new(
|
170
|
-
line: error.node.loc.line - 1,
|
171
|
-
character: error.node.loc.column,
|
172
|
-
),
|
173
|
-
end: LanguageServer::Protocol::Interface::Position.new(
|
174
|
-
line: error.node.loc.last_line - 1,
|
175
|
-
character: error.node.loc.last_column,
|
176
|
-
),
|
177
|
-
)
|
178
|
-
)
|
179
|
-
end
|
267
|
+
# line in LSP is zero-origin
|
268
|
+
project.type_of_node(path: path, line: line + 1, column: column) do |type, node|
|
269
|
+
Steep.logger.warn { "node = #{node.type}, type = #{type.to_s}" }
|
180
270
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
271
|
+
start_position = { line: node.location.line - 1, character: node.location.column }
|
272
|
+
end_position = { line: node.location.last_line - 1, character: node.location.last_column }
|
273
|
+
range = { start: start_position, end: end_position }
|
274
|
+
|
275
|
+
Steep.logger.warn { "range = #{range.inspect}" }
|
276
|
+
|
277
|
+
LanguageServer::Protocol::Interface::Hover.new(
|
278
|
+
contents: { kind: "markdown", value: "`#{type}`" },
|
279
|
+
range: range
|
280
|
+
)
|
190
281
|
end
|
191
282
|
end
|
192
283
|
end
|