steep 0.15.0 → 0.17.0
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 +25 -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 +12 -1
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +1 -12
- data/lib/steep/drivers/langserver.rb +13 -462
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- 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 +4 -2
- data/lib/steep/project/file.rb +2 -1
- data/lib/steep/project/hover_content.rb +6 -3
- data/lib/steep/project/options.rb +15 -0
- data/lib/steep/project/target.rb +30 -20
- 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/validator.rb +5 -5
- data/lib/steep/type_construction.rb +13 -19
- data/lib/steep/type_inference/constant_env.rb +2 -10
- data/lib/steep/type_inference/context.rb +1 -0
- data/lib/steep/version.rb +1 -1
- data/steep.gemspec +7 -8
- metadata +22 -142
- data/exe/rbs +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 -67
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
- 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 -89
- data/vendor/ruby-signature/bin/test_runner.rb +0 -16
- 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 -7
- data/vendor/ruby-signature/lib/rbs.rb +0 -64
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
- data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
- data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
- data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
- data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
- data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
- data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
- data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
- data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
- data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
- data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
- data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
- data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
- data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
- data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
- data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
- data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
- data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
- data/vendor/ruby-signature/rbs.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
- 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 -44
- 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 -413
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
- 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 -194
- 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 -1076
- 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 -243
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
- 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 -429
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
- 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 -57
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
- 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 -1901
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
- 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 -301
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -8,7 +8,7 @@ module Steep
|
|
8
8
|
raise "Cannot find a configuration at #{path}: `steep init` to scaffold" unless path.file?
|
9
9
|
|
10
10
|
steep_file_path = path.absolute? ? path : Pathname.pwd + path
|
11
|
-
Project.new(
|
11
|
+
Project.new(steepfile_path: steep_file_path).tap do |project|
|
12
12
|
Project::DSL.parse(project, path.read, filename: path.to_s)
|
13
13
|
end
|
14
14
|
end
|
data/lib/steep/drivers/watch.rb
CHANGED
@@ -15,110 +15,122 @@ module Steep
|
|
15
15
|
@queue = Thread::Queue.new
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
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]
|
26
|
-
end
|
18
|
+
def run()
|
19
|
+
if dirs.empty?
|
20
|
+
stdout.puts "Specify directories to watch"
|
21
|
+
return 1
|
27
22
|
end
|
28
|
-
end
|
29
23
|
|
30
|
-
|
31
|
-
until queue.closed?
|
32
|
-
stdout.puts "🚥 Waiting for updates..."
|
24
|
+
project = load_config()
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
events << queue.deq(nonblock: true)
|
38
|
-
end
|
26
|
+
loader = Project::FileLoader.new(project: project)
|
27
|
+
loader.load_sources(dirs)
|
28
|
+
loader.load_signatures()
|
39
29
|
|
40
|
-
|
41
|
-
|
42
|
-
path = Pathname(name).relative_path_from(Pathname.pwd)
|
30
|
+
client_read, server_write = IO.pipe
|
31
|
+
server_read, client_write = IO.pipe
|
43
32
|
|
44
|
-
|
45
|
-
|
46
|
-
target.update_signature path, path.read if target.signature_file?(path)
|
47
|
-
end
|
48
|
-
end
|
33
|
+
client_reader = LanguageServer::Protocol::Transport::Io::Reader.new(client_read)
|
34
|
+
client_writer = LanguageServer::Protocol::Transport::Io::Writer.new(client_write)
|
49
35
|
|
50
|
-
|
51
|
-
|
36
|
+
server_reader = LanguageServer::Protocol::Transport::Io::Reader.new(server_read)
|
37
|
+
server_writer = LanguageServer::Protocol::Transport::Io::Writer.new(server_write)
|
52
38
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
39
|
+
interaction_worker = Server::WorkerProcess.spawn_worker(:interaction, name: "interaction", steepfile: project.steepfile_path)
|
40
|
+
signature_worker = Server::WorkerProcess.spawn_worker(:signature, name: "signature", steepfile: project.steepfile_path)
|
41
|
+
code_workers = Server::WorkerProcess.spawn_code_workers(steepfile: project.steepfile_path)
|
58
42
|
|
59
|
-
|
60
|
-
|
43
|
+
master = Server::Master.new(
|
44
|
+
project: project,
|
45
|
+
reader: server_reader,
|
46
|
+
writer: server_writer,
|
47
|
+
interaction_worker: interaction_worker,
|
48
|
+
signature_worker: signature_worker,
|
49
|
+
code_workers: code_workers
|
50
|
+
)
|
61
51
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
main_thread = Thread.start do
|
53
|
+
master.start()
|
54
|
+
end
|
55
|
+
main_thread.abort_on_exception = true
|
56
|
+
|
57
|
+
client_writer.write(method: "initialize", id: 0)
|
58
|
+
|
59
|
+
Steep.logger.info "Watching #{dirs.join(", ")}..."
|
60
|
+
listener = Listen.to(*dirs.map(&:to_s)) do |modified, added, removed|
|
61
|
+
stdout.puts "🔬 Type checking updated files..."
|
62
|
+
|
63
|
+
version = Time.now.to_i
|
64
|
+
Steep.logger.tagged "watch" do
|
65
|
+
Steep.logger.info "Received file system updates: modified=[#{modified.join(",")}], added=[#{added.join(",")}], removed=[#{removed.join(",")}]"
|
66
|
+
|
67
|
+
(modified + added).each do |path|
|
68
|
+
client_writer.write(
|
69
|
+
method: "textDocument/didChange",
|
70
|
+
params: {
|
71
|
+
textDocument: {
|
72
|
+
uri: "file://#{path}",
|
73
|
+
version: version
|
74
|
+
},
|
75
|
+
contentChanges: [
|
76
|
+
{
|
77
|
+
text: Pathname(path).read
|
78
|
+
}
|
79
|
+
]
|
80
|
+
}
|
81
|
+
)
|
66
82
|
end
|
67
|
-
end
|
68
83
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
84
|
+
removed.each do |path|
|
85
|
+
client_writer.write(
|
86
|
+
method: "textDocument/didChange",
|
87
|
+
params: {
|
88
|
+
textDocument: {
|
89
|
+
uri: "file://#{path}",
|
90
|
+
version: version
|
91
|
+
},
|
92
|
+
contentChanges: [
|
93
|
+
{
|
94
|
+
text: ""
|
95
|
+
}
|
96
|
+
]
|
97
|
+
}
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end.tap(&:start)
|
76
102
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
case
|
81
|
-
when
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
103
|
+
begin
|
104
|
+
stdout.puts "👀 Watching directories, Ctrl-C to stop."
|
105
|
+
client_reader.read do |response|
|
106
|
+
case response[:method]
|
107
|
+
when "textDocument/publishDiagnostics"
|
108
|
+
uri = URI.parse(response[:params][:uri])
|
109
|
+
path = project.relative_path(Pathname(uri.path))
|
110
|
+
|
111
|
+
diagnostics = response[:params][:diagnostics]
|
112
|
+
|
113
|
+
unless diagnostics.empty?
|
114
|
+
diagnostics.each do |diagnostic|
|
115
|
+
start = diagnostic[:range][:start]
|
116
|
+
loc = "#{start[:line]+1}:#{start[:character]}"
|
117
|
+
message = diagnostic[:message].chomp.lines.join(" ")
|
118
|
+
|
119
|
+
stdout.puts "#{path}:#{loc}: #{message}"
|
91
120
|
end
|
92
121
|
end
|
93
122
|
end
|
94
123
|
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def run()
|
99
|
-
if dirs.empty?
|
100
|
-
stdout.puts "Specify directories to watch"
|
101
|
-
return 1
|
102
|
-
end
|
103
|
-
|
104
|
-
project = load_config()
|
105
|
-
|
106
|
-
loader = Project::FileLoader.new(project: project)
|
107
|
-
loader.load_sources([])
|
108
|
-
loader.load_signatures()
|
109
|
-
|
110
|
-
type_check project
|
111
|
-
print_project_result project
|
112
|
-
|
113
|
-
listener.start
|
114
|
-
|
115
|
-
stdout.puts "👀 Watching directories, Ctrl-C to stop."
|
116
|
-
begin
|
117
|
-
type_check_loop project
|
118
124
|
rescue Interrupt
|
119
|
-
|
125
|
+
stdout.puts "Shutting down workers..."
|
126
|
+
client_writer.write({ method: :shutdown, id: 10000 })
|
127
|
+
client_writer.write({ method: :exit })
|
128
|
+
client_writer.io.close()
|
120
129
|
end
|
121
130
|
|
131
|
+
listener.stop
|
132
|
+
main_thread.join
|
133
|
+
|
122
134
|
0
|
123
135
|
end
|
124
136
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class Worker
|
4
|
+
attr_reader :stdout, :stderr, :stdin
|
5
|
+
|
6
|
+
attr_accessor :steepfile_path
|
7
|
+
attr_accessor :worker_type
|
8
|
+
attr_accessor :worker_name
|
9
|
+
|
10
|
+
include Utils::DriverHelper
|
11
|
+
|
12
|
+
def initialize(stdout:, stderr:, stdin:)
|
13
|
+
@stdout = stdout
|
14
|
+
@stderr = stderr
|
15
|
+
@stdin = stdin
|
16
|
+
end
|
17
|
+
|
18
|
+
def run()
|
19
|
+
Steep.logger.tagged("#{worker_type}:#{worker_name}") do
|
20
|
+
project = load_config()
|
21
|
+
|
22
|
+
loader = Project::FileLoader.new(project: project)
|
23
|
+
loader.load_sources([])
|
24
|
+
loader.load_signatures()
|
25
|
+
|
26
|
+
reader = LanguageServer::Protocol::Transport::Io::Reader.new(stdin)
|
27
|
+
writer = LanguageServer::Protocol::Transport::Io::Writer.new(stdout)
|
28
|
+
|
29
|
+
worker = case worker_type
|
30
|
+
when :code
|
31
|
+
Server::CodeWorker.new(project: project, reader: reader, writer: writer)
|
32
|
+
when :signature
|
33
|
+
Server::SignatureWorker.new(project: project, reader: reader, writer: writer)
|
34
|
+
when :interaction
|
35
|
+
Server::InteractionWorker.new(project: project, reader: reader, writer: writer)
|
36
|
+
else
|
37
|
+
raise "Unknown worker type: #{worker_type}"
|
38
|
+
end
|
39
|
+
|
40
|
+
Steep.logger.info "Starting #{worker_type} worker..."
|
41
|
+
|
42
|
+
worker.run()
|
43
|
+
rescue Interrupt
|
44
|
+
Steep.logger.info "Shutting down by interrupt..."
|
45
|
+
end
|
46
|
+
|
47
|
+
0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/steep/project.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module Steep
|
2
2
|
class Project
|
3
3
|
attr_reader :targets
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :steepfile_path
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(steepfile_path:)
|
7
7
|
@targets = []
|
8
|
-
@
|
8
|
+
@steepfile_path = steepfile_path
|
9
9
|
|
10
|
-
unless
|
11
|
-
raise "Project#initialize(
|
10
|
+
unless steepfile_path.absolute?
|
11
|
+
raise "Project#initialize(steepfile_path:): steepfile_path should be absolute path"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def base_dir
|
16
|
+
steepfile_path.parent
|
17
|
+
end
|
18
|
+
|
15
19
|
def relative_path(path)
|
16
20
|
path.relative_path_from(base_dir)
|
17
21
|
end
|
@@ -47,8 +47,10 @@ module Steep
|
|
47
47
|
position = Position.new(line: line, column: column)
|
48
48
|
|
49
49
|
begin
|
50
|
-
Steep.
|
51
|
-
type_check!
|
50
|
+
Steep.logger.tagged "completion_provider#run(line: #{line}, column: #{column})" do
|
51
|
+
Steep.measure "type_check!" do
|
52
|
+
type_check!(source_text)
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
Steep.measure "completion item collection" do
|
data/lib/steep/project/file.rb
CHANGED
@@ -42,7 +42,7 @@ module Steep
|
|
42
42
|
|
43
43
|
def self.type_check(source, subtyping:)
|
44
44
|
annotations = source.annotations(block: source.node, factory: subtyping.factory, current_module: AST::Namespace.root)
|
45
|
-
const_env = TypeInference::ConstantEnv.new(factory: subtyping.factory, context:
|
45
|
+
const_env = TypeInference::ConstantEnv.new(factory: subtyping.factory, context: [AST::Namespace.root])
|
46
46
|
type_env = TypeInference::TypeEnv.build(annotations: annotations,
|
47
47
|
subtyping: subtyping,
|
48
48
|
const_env: const_env,
|
@@ -96,6 +96,7 @@ module Steep
|
|
96
96
|
timestamp: Time.now
|
97
97
|
)
|
98
98
|
rescue => exn
|
99
|
+
Steep.log_error(exn)
|
99
100
|
@status = TypeCheckErrorStatus.new(error: exn)
|
100
101
|
end
|
101
102
|
|
@@ -33,9 +33,12 @@ module Steep
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def content_for(path:, line:, column:)
|
36
|
-
|
36
|
+
target = project.targets.find {|target| target.source_file?(path) }
|
37
|
+
|
38
|
+
if target
|
39
|
+
source_file = target.source_files[path]
|
40
|
+
target.type_check(target_sources: [source_file], validate_signatures: false)
|
37
41
|
|
38
|
-
if source_file
|
39
42
|
case (status = source_file.status)
|
40
43
|
when SourceFile::TypeCheckStatus
|
41
44
|
node, *parents = status.source.find_nodes(line: line, column: column)
|
@@ -107,7 +110,7 @@ module Steep
|
|
107
110
|
context = status.typing.context_at(line: line, column: column)
|
108
111
|
method_context = context.method_context
|
109
112
|
|
110
|
-
if method_context
|
113
|
+
if method_context && method_context.method
|
111
114
|
DefinitionContent.new(
|
112
115
|
node: node,
|
113
116
|
method_name: method_context.name,
|
@@ -37,6 +37,21 @@ module Steep
|
|
37
37
|
self.allow_unknown_constant_assignment = true
|
38
38
|
self.allow_unknown_method_calls = true
|
39
39
|
end
|
40
|
+
|
41
|
+
def error_to_report?(error)
|
42
|
+
case
|
43
|
+
when error.is_a?(Errors::FallbackAny)
|
44
|
+
!allow_fallback_any
|
45
|
+
when error.is_a?(Errors::MethodDefinitionMissing)
|
46
|
+
!allow_missing_definitions
|
47
|
+
when error.is_a?(Errors::NoMethod)
|
48
|
+
!allow_unknown_method_calls
|
49
|
+
when error.is_a?(Errors::UnknownConstantAssigned)
|
50
|
+
!allow_unknown_constant_assignment
|
51
|
+
else
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
42
57
|
end
|
data/lib/steep/project/target.rb
CHANGED
@@ -67,24 +67,30 @@ module Steep
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def possible_source_file?(path)
|
70
|
-
self.class.test_pattern(source_patterns, path) &&
|
71
|
-
!self.class.test_pattern(ignore_patterns, path)
|
70
|
+
self.class.test_pattern(source_patterns, path, ext: ".rb") &&
|
71
|
+
!self.class.test_pattern(ignore_patterns, path, ext: ".rb")
|
72
72
|
end
|
73
73
|
|
74
74
|
def possible_signature_file?(path)
|
75
|
-
self.class.test_pattern(signature_patterns, path)
|
75
|
+
self.class.test_pattern(signature_patterns, path, ext: ".rbs")
|
76
76
|
end
|
77
77
|
|
78
|
-
def self.test_pattern(patterns, path)
|
78
|
+
def self.test_pattern(patterns, path, ext:)
|
79
79
|
patterns.any? do |pattern|
|
80
80
|
p = pattern.end_with?(File::Separator) ? pattern : pattern + File::Separator
|
81
|
-
path.to_s.start_with?(p) || File.fnmatch(pattern, path.to_s)
|
81
|
+
(path.to_s.start_with?(p) && path.extname == ext) || File.fnmatch(pattern, path.to_s)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def type_check
|
86
|
-
|
87
|
-
|
85
|
+
def type_check(target_sources: source_files.values, validate_signatures: true)
|
86
|
+
Steep.logger.tagged "target#type_check(target_sources: [#{target_sources.map(&:path).join(", ")}], validate_signatures: #{validate_signatures})" do
|
87
|
+
Steep.measure "load signature and type check" do
|
88
|
+
load_signatures(validate: validate_signatures) do |env, check, timestamp|
|
89
|
+
Steep.measure "type checking #{target_sources.size} files" do
|
90
|
+
run_type_check(env, check, timestamp, target_sources: target_sources)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
88
94
|
end
|
89
95
|
end
|
90
96
|
|
@@ -100,7 +106,7 @@ module Steep
|
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
103
|
-
def load_signatures
|
109
|
+
def load_signatures(validate:)
|
104
110
|
timestamp = case status
|
105
111
|
when TypeCheckStatus
|
106
112
|
status.timestamp
|
@@ -133,16 +139,20 @@ module Steep
|
|
133
139
|
factory = AST::Types::Factory.new(builder: definition_builder)
|
134
140
|
check = Subtyping::Check.new(factory: factory)
|
135
141
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
142
|
+
if validate
|
143
|
+
validator = Signature::Validator.new(checker: check)
|
144
|
+
validator.validate()
|
145
|
+
|
146
|
+
if validator.no_error?
|
147
|
+
yield env, check, Time.now
|
148
|
+
else
|
149
|
+
@status = SignatureValidationErrorStatus.new(
|
150
|
+
errors: validator.each_error.to_a,
|
151
|
+
timestamp: Time.now
|
152
|
+
)
|
153
|
+
end
|
141
154
|
else
|
142
|
-
|
143
|
-
errors: validator.each_error.to_a,
|
144
|
-
timestamp: Time.now
|
145
|
-
)
|
155
|
+
yield env, check, Time.now
|
146
156
|
end
|
147
157
|
end
|
148
158
|
|
@@ -160,10 +170,10 @@ module Steep
|
|
160
170
|
end
|
161
171
|
end
|
162
172
|
|
163
|
-
def run_type_check(env, check, timestamp)
|
173
|
+
def run_type_check(env, check, timestamp, target_sources: source_files.values)
|
164
174
|
type_check_sources = []
|
165
175
|
|
166
|
-
|
176
|
+
target_sources.each do |file|
|
167
177
|
if file.type_check(check, timestamp)
|
168
178
|
type_check_sources << file
|
169
179
|
end
|