steep 0.37.0 → 0.42.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 +1 -1
- data/CHANGELOG.md +34 -0
- data/Rakefile +5 -2
- data/bin/output_rebaseline.rb +34 -0
- data/bin/output_test.rb +53 -0
- data/lib/steep.rb +95 -14
- data/lib/steep/ast/types/bot.rb +1 -1
- data/lib/steep/ast/types/class.rb +4 -0
- data/lib/steep/ast/types/factory.rb +10 -0
- data/lib/steep/ast/types/logic.rb +16 -3
- data/lib/steep/ast/types/top.rb +1 -1
- data/lib/steep/cli.rb +31 -7
- data/lib/steep/diagnostic/helper.rb +17 -0
- data/lib/steep/diagnostic/lsp_formatter.rb +16 -0
- data/lib/steep/diagnostic/ruby.rb +619 -0
- data/lib/steep/diagnostic/signature.rb +357 -0
- data/lib/steep/drivers/annotations.rb +19 -28
- data/lib/steep/drivers/check.rb +182 -60
- data/lib/steep/drivers/diagnostic_printer.rb +99 -0
- data/lib/steep/drivers/langserver.rb +3 -8
- data/lib/steep/drivers/print_project.rb +10 -9
- data/lib/steep/drivers/stats.rb +124 -32
- data/lib/steep/drivers/trace_printer.rb +5 -1
- data/lib/steep/drivers/utils/jobs_count.rb +9 -0
- data/lib/steep/drivers/validate.rb +31 -13
- data/lib/steep/drivers/watch.rb +69 -48
- data/lib/steep/drivers/worker.rb +16 -8
- data/lib/steep/expectations.rb +159 -0
- data/lib/steep/index/rbs_index.rb +334 -0
- data/lib/steep/index/signature_symbol_provider.rb +162 -0
- data/lib/steep/index/source_index.rb +100 -0
- data/lib/steep/project.rb +0 -30
- data/lib/steep/project/dsl.rb +5 -3
- data/lib/steep/project/options.rb +4 -4
- data/lib/steep/project/pattern.rb +56 -0
- data/lib/steep/project/target.rb +9 -214
- data/lib/steep/range_extension.rb +29 -0
- data/lib/steep/server/base_worker.rb +43 -7
- data/lib/steep/server/change_buffer.rb +63 -0
- data/lib/steep/server/interaction_worker.rb +73 -56
- data/lib/steep/server/master.rb +245 -109
- data/lib/steep/server/type_check_worker.rb +122 -0
- data/lib/steep/server/worker_process.rb +17 -15
- data/lib/steep/{project → services}/completion_provider.rb +3 -3
- data/lib/steep/services/content_change.rb +61 -0
- data/lib/steep/services/file_loader.rb +48 -0
- data/lib/steep/{project → services}/hover_content.rb +14 -16
- data/lib/steep/services/path_assignment.rb +29 -0
- data/lib/steep/services/signature_service.rb +369 -0
- data/lib/steep/services/stats_calculator.rb +69 -0
- data/lib/steep/services/type_check_service.rb +342 -0
- data/lib/steep/signature/validator.rb +174 -32
- data/lib/steep/subtyping/check.rb +248 -47
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/type_construction.rb +565 -295
- data/lib/steep/type_inference/constant_env.rb +5 -1
- data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
- data/lib/steep/type_inference/logic_type_interpreter.rb +99 -26
- data/lib/steep/type_inference/type_env.rb +43 -17
- data/lib/steep/typing.rb +8 -2
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/a.rb +0 -3
- data/smoke/alias/b.rb +0 -1
- data/smoke/alias/c.rb +0 -2
- data/smoke/alias/test_expectations.yml +96 -0
- data/smoke/and/a.rb +0 -3
- data/smoke/and/test_expectations.yml +31 -0
- data/smoke/array/a.rb +0 -3
- data/smoke/array/b.rb +0 -2
- data/smoke/array/c.rb +0 -1
- data/smoke/array/test_expectations.yml +103 -0
- data/smoke/block/a.rb +0 -2
- data/smoke/block/b.rb +0 -2
- data/smoke/block/d.rb +0 -4
- data/smoke/block/test_expectations.yml +125 -0
- data/smoke/case/a.rb +0 -3
- data/smoke/case/test_expectations.yml +47 -0
- data/smoke/class/a.rb +0 -3
- data/smoke/class/c.rb +0 -1
- data/smoke/class/f.rb +0 -1
- data/smoke/class/g.rb +0 -2
- data/smoke/class/i.rb +0 -2
- data/smoke/class/test_expectations.yml +120 -0
- data/smoke/const/a.rb +0 -3
- data/smoke/const/b.rb +7 -0
- data/smoke/const/b.rbs +5 -0
- data/smoke/const/test_expectations.yml +139 -0
- data/smoke/diagnostics-rbs-duplicated/Steepfile +5 -0
- data/smoke/diagnostics-rbs-duplicated/a.rbs +5 -0
- data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
- data/smoke/diagnostics-rbs/Steepfile +8 -0
- data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +20 -0
- data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +7 -0
- data/smoke/diagnostics-rbs/invalid-method-overload.rbs +3 -0
- data/smoke/diagnostics-rbs/invalid-type-application.rbs +7 -0
- data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +3 -0
- data/smoke/diagnostics-rbs/recursive-alias.rbs +5 -0
- data/smoke/diagnostics-rbs/recursive-class.rbs +8 -0
- data/smoke/diagnostics-rbs/superclass-mismatch.rbs +7 -0
- data/smoke/diagnostics-rbs/test_expectations.yml +231 -0
- data/smoke/diagnostics-rbs/unknown-method-alias.rbs +3 -0
- data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
- data/smoke/diagnostics-rbs/unknown-type-name.rbs +13 -0
- data/smoke/diagnostics/Steepfile +5 -0
- data/smoke/diagnostics/a.rbs +26 -0
- data/smoke/diagnostics/argument_type_mismatch.rb +1 -0
- data/smoke/diagnostics/block_body_type_mismatch.rb +1 -0
- data/smoke/diagnostics/block_type_mismatch.rb +3 -0
- data/smoke/diagnostics/break_type_mismatch.rb +1 -0
- data/smoke/diagnostics/else_on_exhaustive_case.rb +12 -0
- data/smoke/diagnostics/incompatible_annotation.rb +6 -0
- data/smoke/diagnostics/incompatible_argument.rb +1 -0
- data/smoke/diagnostics/incompatible_assignment.rb +8 -0
- data/smoke/diagnostics/method_arity_mismatch.rb +11 -0
- data/smoke/diagnostics/method_body_type_mismatch.rb +6 -0
- data/smoke/diagnostics/method_definition_missing.rb +2 -0
- data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +7 -0
- data/smoke/diagnostics/missing_keyword.rb +1 -0
- data/smoke/diagnostics/no_method.rb +1 -0
- data/smoke/diagnostics/required_block_missing.rb +1 -0
- data/smoke/diagnostics/return_type_mismatch.rb +6 -0
- data/smoke/diagnostics/test_expectations.yml +477 -0
- data/smoke/diagnostics/unexpected_block_given.rb +1 -0
- data/smoke/diagnostics/unexpected_dynamic_method.rb +3 -0
- data/smoke/diagnostics/unexpected_jump.rb +4 -0
- data/smoke/diagnostics/unexpected_jump_value.rb +3 -0
- data/smoke/diagnostics/unexpected_keyword.rb +1 -0
- data/smoke/diagnostics/unexpected_splat.rb +1 -0
- data/smoke/diagnostics/unexpected_yield.rb +6 -0
- data/smoke/diagnostics/unknown_constant_assigned.rb +7 -0
- data/smoke/diagnostics/unresolved_overloading.rb +1 -0
- data/smoke/diagnostics/unsatisfiable_constraint.rb +7 -0
- data/smoke/diagnostics/unsupported_syntax.rb +2 -0
- data/smoke/dstr/a.rb +0 -1
- data/smoke/dstr/test_expectations.yml +13 -0
- data/smoke/ensure/a.rb +0 -4
- data/smoke/ensure/test_expectations.yml +62 -0
- data/smoke/enumerator/a.rb +0 -6
- data/smoke/enumerator/b.rb +0 -3
- data/smoke/enumerator/test_expectations.yml +135 -0
- data/smoke/extension/a.rb +0 -1
- data/smoke/extension/b.rb +0 -2
- data/smoke/extension/c.rb +0 -1
- data/smoke/extension/f.rb +2 -0
- data/smoke/extension/f.rbs +3 -0
- data/smoke/extension/test_expectations.yml +73 -0
- data/smoke/hash/b.rb +0 -1
- data/smoke/hash/c.rb +0 -3
- data/smoke/hash/d.rb +0 -1
- data/smoke/hash/e.rb +0 -1
- data/smoke/hash/test_expectations.yml +81 -0
- data/smoke/hello/hello.rb +0 -2
- data/smoke/hello/test_expectations.yml +25 -0
- data/smoke/if/a.rb +0 -2
- data/smoke/if/test_expectations.yml +34 -0
- data/smoke/implements/a.rb +0 -2
- data/smoke/implements/test_expectations.yml +23 -0
- data/smoke/initialize/test_expectations.yml +1 -0
- data/smoke/integer/a.rb +0 -7
- data/smoke/integer/test_expectations.yml +101 -0
- data/smoke/interface/a.rb +0 -2
- data/smoke/interface/test_expectations.yml +23 -0
- data/smoke/kwbegin/a.rb +0 -1
- data/smoke/kwbegin/test_expectations.yml +17 -0
- data/smoke/lambda/a.rb +1 -4
- data/smoke/lambda/test_expectations.yml +39 -0
- data/smoke/literal/a.rb +0 -5
- data/smoke/literal/b.rb +0 -2
- data/smoke/literal/test_expectations.yml +106 -0
- data/smoke/map/test_expectations.yml +1 -0
- data/smoke/method/a.rb +0 -5
- data/smoke/method/b.rb +0 -1
- data/smoke/method/test_expectations.yml +90 -0
- data/smoke/module/a.rb +0 -2
- data/smoke/module/b.rb +0 -2
- data/smoke/module/c.rb +0 -1
- data/smoke/module/d.rb +0 -1
- data/smoke/module/f.rb +0 -2
- data/smoke/module/test_expectations.yml +75 -0
- data/smoke/regexp/a.rb +0 -38
- data/smoke/regexp/b.rb +0 -26
- data/smoke/regexp/test_expectations.yml +615 -0
- data/smoke/regression/set_divide.rb +0 -4
- data/smoke/regression/test_expectations.yml +43 -0
- data/smoke/rescue/a.rb +0 -5
- data/smoke/rescue/test_expectations.yml +79 -0
- data/smoke/self/a.rb +0 -2
- data/smoke/self/test_expectations.yml +23 -0
- data/smoke/skip/skip.rb +0 -2
- data/smoke/skip/test_expectations.yml +23 -0
- data/smoke/stdout/test_expectations.yml +1 -0
- data/smoke/super/a.rb +0 -4
- data/smoke/super/test_expectations.yml +79 -0
- data/smoke/toplevel/a.rb +0 -1
- data/smoke/toplevel/test_expectations.yml +15 -0
- data/smoke/tsort/Steepfile +2 -0
- data/smoke/tsort/a.rb +0 -3
- data/smoke/tsort/test_expectations.yml +63 -0
- data/smoke/type_case/a.rb +0 -4
- data/smoke/type_case/test_expectations.yml +48 -0
- data/smoke/unexpected/Steepfile +5 -0
- data/smoke/unexpected/test_expectations.yml +25 -0
- data/smoke/unexpected/unexpected.rb +1 -0
- data/smoke/unexpected/unexpected.rbs +3 -0
- data/smoke/yield/a.rb +0 -3
- data/smoke/yield/b.rb +6 -0
- data/smoke/yield/test_expectations.yml +68 -0
- data/steep.gemspec +4 -3
- metadata +144 -29
- data/bin/smoke_runner.rb +0 -139
- data/lib/steep/drivers/signature_error_printer.rb +0 -25
- data/lib/steep/errors.rb +0 -565
- data/lib/steep/project/file_loader.rb +0 -68
- data/lib/steep/project/signature_file.rb +0 -33
- data/lib/steep/project/source_file.rb +0 -129
- data/lib/steep/server/code_worker.rb +0 -137
- data/lib/steep/server/signature_worker.rb +0 -152
- data/lib/steep/server/utils.rb +0 -69
- data/lib/steep/signature/errors.rb +0 -82
- data/lib/steep/type_assignability.rb +0 -367
@@ -0,0 +1,99 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class DiagnosticPrinter
|
4
|
+
LSP = LanguageServer::Protocol
|
5
|
+
|
6
|
+
attr_reader :stdout
|
7
|
+
attr_reader :buffer
|
8
|
+
|
9
|
+
def initialize(stdout:, buffer:)
|
10
|
+
@stdout = stdout
|
11
|
+
@buffer = buffer
|
12
|
+
end
|
13
|
+
|
14
|
+
def path
|
15
|
+
buffer.name
|
16
|
+
end
|
17
|
+
|
18
|
+
def color_severity(string, severity:)
|
19
|
+
s = Rainbow(string)
|
20
|
+
|
21
|
+
case severity
|
22
|
+
when LSP::Constant::DiagnosticSeverity::ERROR
|
23
|
+
s.red
|
24
|
+
when LSP::Constant::DiagnosticSeverity::WARNING
|
25
|
+
s.yellow
|
26
|
+
when LSP::Constant::DiagnosticSeverity::INFORMATION
|
27
|
+
s.blue
|
28
|
+
else
|
29
|
+
s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def severity_message(severity)
|
34
|
+
string = case severity
|
35
|
+
when LSP::Constant::DiagnosticSeverity::ERROR
|
36
|
+
"error"
|
37
|
+
when LSP::Constant::DiagnosticSeverity::WARNING
|
38
|
+
"warning"
|
39
|
+
when LSP::Constant::DiagnosticSeverity::INFORMATION
|
40
|
+
"information"
|
41
|
+
when LSP::Constant::DiagnosticSeverity::HINT
|
42
|
+
"hint"
|
43
|
+
end
|
44
|
+
|
45
|
+
color_severity(string, severity: severity)
|
46
|
+
end
|
47
|
+
|
48
|
+
def location(diagnostic)
|
49
|
+
start = diagnostic[:range][:start]
|
50
|
+
Rainbow("#{path}:#{start[:line]+1}:#{start[:character]}").magenta
|
51
|
+
end
|
52
|
+
|
53
|
+
def print(diagnostic, prefix: "", source: true)
|
54
|
+
header, *rest = diagnostic[:message].split(/\n/)
|
55
|
+
|
56
|
+
stdout.puts "#{prefix}#{location(diagnostic)}: [#{severity_message(diagnostic[:severity])}] #{Rainbow(header).underline}"
|
57
|
+
|
58
|
+
unless rest.empty?
|
59
|
+
rest.each do |message|
|
60
|
+
stdout.puts "#{prefix}│ #{message}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if diagnostic[:code]
|
65
|
+
stdout.puts "#{prefix}│" unless rest.empty?
|
66
|
+
stdout.puts "#{prefix}│ Diagnostic ID: #{diagnostic[:code]}"
|
67
|
+
end
|
68
|
+
|
69
|
+
stdout.puts "#{prefix}│"
|
70
|
+
|
71
|
+
if source
|
72
|
+
print_source_line(diagnostic, prefix: prefix)
|
73
|
+
else
|
74
|
+
stdout.puts "#{prefix}└ (no source code available)"
|
75
|
+
stdout.puts "#{prefix}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def print_source_line(diagnostic, prefix: "")
|
80
|
+
start_pos = diagnostic[:range][:start]
|
81
|
+
end_pos = diagnostic[:range][:end]
|
82
|
+
|
83
|
+
line = buffer.lines[start_pos[:line]]
|
84
|
+
|
85
|
+
leading = line[0...start_pos[:character]]
|
86
|
+
if start_pos[:line] == end_pos[:line]
|
87
|
+
subject = line[start_pos[:character]...end_pos[:character]]
|
88
|
+
trailing = (line[end_pos[:character]...] || "").chomp
|
89
|
+
else
|
90
|
+
subject = line[start_pos[:character]...].chomp
|
91
|
+
trailing = ""
|
92
|
+
end
|
93
|
+
|
94
|
+
stdout.puts "#{prefix}└ #{leading}#{color_severity(subject, severity: diagnostic[:severity])}#{trailing}"
|
95
|
+
stdout.puts "#{prefix} #{" " * leading.size}#{"~" * subject.size}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -10,6 +10,7 @@ module Steep
|
|
10
10
|
attr_reader :type_check_thread
|
11
11
|
|
12
12
|
include Utils::DriverHelper
|
13
|
+
include Utils::JobsCount
|
13
14
|
|
14
15
|
TypeCheckRequest = Struct.new(:version, keyword_init: true)
|
15
16
|
|
@@ -36,21 +37,15 @@ module Steep
|
|
36
37
|
def run
|
37
38
|
@project = load_config()
|
38
39
|
|
39
|
-
loader = Project::FileLoader.new(project: project)
|
40
|
-
loader.load_sources([])
|
41
|
-
loader.load_signatures()
|
42
|
-
|
43
40
|
interaction_worker = Server::WorkerProcess.spawn_worker(:interaction, name: "interaction", steepfile: project.steepfile_path)
|
44
|
-
|
45
|
-
code_workers = Server::WorkerProcess.spawn_code_workers(steepfile: project.steepfile_path)
|
41
|
+
typecheck_workers = Server::WorkerProcess.spawn_typecheck_workers(steepfile: project.steepfile_path, args: [], count: jobs_count)
|
46
42
|
|
47
43
|
master = Server::Master.new(
|
48
44
|
project: project,
|
49
45
|
reader: reader,
|
50
46
|
writer: writer,
|
51
47
|
interaction_worker: interaction_worker,
|
52
|
-
|
53
|
-
code_workers: code_workers
|
48
|
+
typecheck_workers: typecheck_workers
|
54
49
|
)
|
55
50
|
|
56
51
|
master.start()
|
@@ -14,33 +14,34 @@ module Steep
|
|
14
14
|
def run
|
15
15
|
project = load_config()
|
16
16
|
|
17
|
-
loader =
|
18
|
-
loader.load_sources([])
|
19
|
-
loader.load_signatures()
|
17
|
+
loader = Services::FileLoader.new(base_dir: project.base_dir)
|
20
18
|
|
21
19
|
project.targets.each do |target|
|
20
|
+
source_changes = loader.load_changes(target.source_pattern, changes: {})
|
21
|
+
signature_changes = loader.load_changes(target.signature_pattern, changes: {})
|
22
|
+
|
22
23
|
stdout.puts "Target:"
|
23
24
|
stdout.puts " #{target.name}:"
|
24
25
|
stdout.puts " sources:"
|
25
26
|
stdout.puts " patterns:"
|
26
|
-
target.
|
27
|
+
target.source_pattern.patterns.each do |pattern|
|
27
28
|
stdout.puts " - #{pattern}"
|
28
29
|
end
|
29
30
|
stdout.puts " ignores:"
|
30
|
-
target.
|
31
|
+
target.source_pattern.ignores.each do |pattern|
|
31
32
|
stdout.puts " - #{pattern}"
|
32
33
|
end
|
33
34
|
stdout.puts " files:"
|
34
|
-
|
35
|
+
source_changes.each_key do |path|
|
35
36
|
stdout.puts " - #{path}"
|
36
37
|
end
|
37
38
|
stdout.puts " signatures:"
|
38
39
|
stdout.puts " patterns:"
|
39
|
-
target.
|
40
|
+
target.signature_pattern.patterns.each do |pattern|
|
40
41
|
stdout.puts " - #{pattern}"
|
41
42
|
end
|
42
43
|
stdout.puts " files:"
|
43
|
-
|
44
|
+
signature_changes.each_key do |path|
|
44
45
|
stdout.puts " - #{path}"
|
45
46
|
end
|
46
47
|
stdout.puts " libraries:"
|
@@ -48,7 +49,7 @@ module Steep
|
|
48
49
|
stdout.puts " - #{lib}"
|
49
50
|
end
|
50
51
|
stdout.puts " library dirs:"
|
51
|
-
|
52
|
+
target.new_env_loader.tap do |loader|
|
52
53
|
loader.each_dir do |lib, path|
|
53
54
|
case lib
|
54
55
|
when :core
|
data/lib/steep/drivers/stats.rb
CHANGED
@@ -8,6 +8,7 @@ module Steep
|
|
8
8
|
attr_reader :command_line_patterns
|
9
9
|
|
10
10
|
include Utils::DriverHelper
|
11
|
+
include Utils::JobsCount
|
11
12
|
|
12
13
|
def initialize(stdout:, stderr:)
|
13
14
|
@stdout = stdout
|
@@ -18,49 +19,140 @@ module Steep
|
|
18
19
|
def run
|
19
20
|
project = load_config()
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
loader.load_signatures()
|
22
|
+
stderr.puts Rainbow("# Calculating stats:").bold
|
23
|
+
stderr.puts
|
24
24
|
|
25
|
-
|
25
|
+
client_read, server_write = IO.pipe
|
26
|
+
server_read, client_write = IO.pipe
|
27
|
+
|
28
|
+
client_reader = LanguageServer::Protocol::Transport::Io::Reader.new(client_read)
|
29
|
+
client_writer = LanguageServer::Protocol::Transport::Io::Writer.new(client_write)
|
30
|
+
|
31
|
+
server_reader = LanguageServer::Protocol::Transport::Io::Reader.new(server_read)
|
32
|
+
server_writer = LanguageServer::Protocol::Transport::Io::Writer.new(server_write)
|
33
|
+
|
34
|
+
typecheck_workers = Server::WorkerProcess.spawn_typecheck_workers(
|
35
|
+
steepfile: project.steepfile_path,
|
36
|
+
delay_shutdown: true,
|
37
|
+
args: command_line_patterns,
|
38
|
+
count: jobs_count
|
39
|
+
)
|
40
|
+
|
41
|
+
master = Server::Master.new(
|
42
|
+
project: project,
|
43
|
+
reader: server_reader,
|
44
|
+
writer: server_writer,
|
45
|
+
interaction_worker: nil,
|
46
|
+
typecheck_workers: typecheck_workers
|
47
|
+
)
|
48
|
+
|
49
|
+
main_thread = Thread.start do
|
50
|
+
master.start()
|
51
|
+
end
|
52
|
+
main_thread.abort_on_exception = true
|
53
|
+
|
54
|
+
client_writer.write({ method: :initialize, id: 0 })
|
55
|
+
|
56
|
+
stats_id = -1
|
57
|
+
client_writer.write(
|
58
|
+
{
|
59
|
+
id: stats_id,
|
60
|
+
method: "workspace/executeCommand",
|
61
|
+
params: { command: "steep/stats", arguments: [] }
|
62
|
+
})
|
63
|
+
|
64
|
+
stats_result = []
|
65
|
+
client_reader.read do |response|
|
66
|
+
if response[:id] == stats_id
|
67
|
+
stats_result.push(*response[:result])
|
68
|
+
break
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
shutdown_id = -2
|
73
|
+
client_writer.write({ method: :shutdown, id: shutdown_id })
|
74
|
+
|
75
|
+
client_reader.read do |response|
|
76
|
+
if response[:id] == shutdown_id
|
77
|
+
break
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
client_writer.write({ method: "exit" })
|
82
|
+
main_thread.join()
|
26
83
|
|
27
84
|
stdout.puts(
|
28
85
|
CSV.generate do |csv|
|
29
86
|
csv << ["Target", "File", "Status", "Typed calls", "Untyped calls", "All calls", "Typed %"]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
total = 0
|
42
|
-
typing.method_calls.each_value do |call|
|
43
|
-
case call
|
44
|
-
when TypeInference::MethodCall::Typed
|
45
|
-
typed += 1
|
46
|
-
when TypeInference::MethodCall::Untyped
|
47
|
-
untyped += 1
|
48
|
-
end
|
49
|
-
|
50
|
-
total += 1
|
51
|
-
end
|
52
|
-
|
53
|
-
csv << format_stats(target, source_file.path, "success", typed, untyped, total)
|
54
|
-
when Project::SourceFile::TypeCheckErrorStatus
|
55
|
-
csv << format_stats(target, source_file.path, "error", 0, 0, 0)
|
87
|
+
stats_result.each do |row|
|
88
|
+
if row[:type] == "success"
|
89
|
+
csv << [
|
90
|
+
row[:target],
|
91
|
+
row[:path],
|
92
|
+
row[:type],
|
93
|
+
row[:typed_calls],
|
94
|
+
row[:untyped_calls],
|
95
|
+
row[:total_calls],
|
96
|
+
if row[:total_calls].nonzero?
|
97
|
+
(row[:typed_calls].to_f / row[:total_calls] * 100).to_i
|
56
98
|
else
|
57
|
-
|
99
|
+
100
|
58
100
|
end
|
59
|
-
|
101
|
+
]
|
102
|
+
else
|
103
|
+
csv << [
|
104
|
+
row[:target],
|
105
|
+
row[:path],
|
106
|
+
row[:type],
|
107
|
+
0,
|
108
|
+
0,
|
109
|
+
0,
|
110
|
+
0
|
111
|
+
]
|
60
112
|
end
|
61
113
|
end
|
62
114
|
end
|
63
115
|
)
|
116
|
+
#
|
117
|
+
# type_check(project)
|
118
|
+
#
|
119
|
+
# stdout.puts(
|
120
|
+
# CSV.generate do |csv|
|
121
|
+
# csv << ["Target", "File", "Status", "Typed calls", "Untyped calls", "All calls", "Typed %"]
|
122
|
+
#
|
123
|
+
# project.targets.each do |target|
|
124
|
+
# case (status = target.status)
|
125
|
+
# when Project::Target::TypeCheckStatus
|
126
|
+
# status.type_check_sources.each do |source_file|
|
127
|
+
# case source_file.status
|
128
|
+
# when Project::SourceFile::TypeCheckStatus
|
129
|
+
# typing = source_file.status.typing
|
130
|
+
#
|
131
|
+
# typed = 0
|
132
|
+
# untyped = 0
|
133
|
+
# total = 0
|
134
|
+
# typing.method_calls.each_value do |call|
|
135
|
+
# case call
|
136
|
+
# when TypeInference::MethodCall::Typed
|
137
|
+
# typed += 1
|
138
|
+
# when TypeInference::MethodCall::Untyped
|
139
|
+
# untyped += 1
|
140
|
+
# end
|
141
|
+
#
|
142
|
+
# total += 1
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
# csv << format_stats(target, source_file.path, "success", typed, untyped, total)
|
146
|
+
# when Project::SourceFile::TypeCheckErrorStatus
|
147
|
+
# csv << format_stats(target, source_file.path, "error", 0, 0, 0)
|
148
|
+
# else
|
149
|
+
# csv << format_stats(target, source_file.path, "unknown (#{source_file.status.class.to_s.split(/::/).last})", 0, 0, 0)
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
# end
|
153
|
+
# end
|
154
|
+
# end
|
155
|
+
# )
|
64
156
|
|
65
157
|
0
|
66
158
|
end
|
@@ -9,7 +9,7 @@ module Steep
|
|
9
9
|
|
10
10
|
def print(trace, level: 0)
|
11
11
|
trace.each.with_index do |t, i|
|
12
|
-
prefix = "
|
12
|
+
prefix = " " * (i + level)
|
13
13
|
case t[0]
|
14
14
|
when :type
|
15
15
|
io.puts "#{prefix}#{t[1]} <: #{t[2]}"
|
@@ -17,6 +17,10 @@ module Steep
|
|
17
17
|
io.puts "#{prefix}(#{t[3]}) #{t[1]} <: #{t[2]}"
|
18
18
|
when :method_type
|
19
19
|
io.puts "#{prefix}#{t[1]} <: #{t[2]}"
|
20
|
+
when :interface
|
21
|
+
# nop
|
22
|
+
else
|
23
|
+
Steep.logger.error { "Unexpected trace item: #{t[0]}" }
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -13,26 +13,44 @@ module Steep
|
|
13
13
|
|
14
14
|
def run
|
15
15
|
project = load_config()
|
16
|
+
file_loader = Services::FileLoader.new(base_dir: project.base_dir)
|
16
17
|
|
17
|
-
|
18
|
-
loader.load_signatures()
|
19
|
-
|
20
|
-
type_check(project)
|
18
|
+
any_error = false
|
21
19
|
|
22
20
|
project.targets.each do |target|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
controller = Services::SignatureService.load_from(target.new_env_loader)
|
22
|
+
|
23
|
+
changes = file_loader.load_changes(target.signature_pattern, changes: {})
|
24
|
+
controller.update(changes)
|
25
|
+
|
26
|
+
errors =
|
27
|
+
Steep.measure "Validation" do
|
28
|
+
case controller.status
|
29
|
+
when Services::SignatureService::SyntaxErrorStatus, Services::SignatureService::AncestorErrorStatus
|
30
|
+
controller.status.diagnostics
|
31
|
+
when Services::SignatureService::LoadedStatus
|
32
|
+
check = Subtyping::Check.new(factory: AST::Types::Factory.new(builder: controller.latest_builder))
|
33
|
+
Signature::Validator.new(checker: check).tap {|v| v.validate() }.each_error.to_a
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
any_error ||= !errors.empty?
|
38
|
+
|
39
|
+
formatter = Diagnostic::LSPFormatter.new
|
40
|
+
diagnostics = errors.group_by {|e| e.location.buffer }.transform_values do |errors|
|
41
|
+
errors.map {|error| formatter.format(error) }
|
42
|
+
end
|
43
|
+
|
44
|
+
diagnostics.each do |buffer, ds|
|
45
|
+
printer = DiagnosticPrinter.new(stdout: stdout, buffer: buffer)
|
46
|
+
ds.each do |d|
|
47
|
+
printer.print(d)
|
48
|
+
stdout.puts
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
34
52
|
|
35
|
-
|
53
|
+
any_error ? 1 : 0
|
36
54
|
end
|
37
55
|
end
|
38
56
|
end
|