steep 0.13.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +28 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +33 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +124 -89
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +13 -287
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +298 -0
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +54 -47
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +1004 -727
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +91 -23
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/alias/a.rb +1 -1
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regexp/b.rb +4 -4
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +8 -8
- metadata +38 -138
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -66
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
data/lib/steep/cli.rb
CHANGED
@@ -34,7 +34,7 @@ module Steep
|
|
34
34
|
|
35
35
|
def setup_command
|
36
36
|
@command = argv.shift&.to_sym
|
37
|
-
if CLI.available_commands.include?(@command)
|
37
|
+
if CLI.available_commands.include?(@command) || @command == :worker
|
38
38
|
true
|
39
39
|
else
|
40
40
|
stderr.puts "Unknown command: #{command}"
|
@@ -159,5 +159,20 @@ module Steep
|
|
159
159
|
stdout.puts Steep::VERSION
|
160
160
|
0
|
161
161
|
end
|
162
|
+
|
163
|
+
def process_worker
|
164
|
+
Drivers::Worker.new(stdout: stdout, stderr: stderr, stdin: stdin).tap do |command|
|
165
|
+
OptionParser.new do |opts|
|
166
|
+
opts.banner = "Usage: steep worker [options] [dir]"
|
167
|
+
handle_logging_options opts
|
168
|
+
|
169
|
+
opts.on("--interaction") { command.worker_type = :interaction }
|
170
|
+
opts.on("--code") { command.worker_type = :code }
|
171
|
+
opts.on("--signature") { command.worker_type = :signature }
|
172
|
+
opts.on("--steepfile=PATH") {|path| command.steepfile = Pathname(path) }
|
173
|
+
opts.on("--name=NAME") {|name| command.worker_name = name }
|
174
|
+
end.parse!(argv)
|
175
|
+
end.run
|
176
|
+
end
|
162
177
|
end
|
163
178
|
end
|
@@ -25,7 +25,7 @@ module Steep
|
|
25
25
|
|
26
26
|
project.targets.each do |target|
|
27
27
|
Steep.logger.tagged "target=#{target.name}" do
|
28
|
-
target.load_signatures do |_, subtyping, _|
|
28
|
+
target.load_signatures(validate: false) do |_, subtyping, _|
|
29
29
|
case (status = target.status)
|
30
30
|
when nil # status set on error cases
|
31
31
|
target.source_files.each_value do |file|
|
data/lib/steep/drivers/check.rb
CHANGED
@@ -51,15 +51,31 @@ module Steep
|
|
51
51
|
printer.print_semantic_errors(status.errors)
|
52
52
|
when Project::Target::TypeCheckStatus
|
53
53
|
status.type_check_sources.each do |source_file|
|
54
|
-
source_file.
|
55
|
-
|
54
|
+
case source_file.status
|
55
|
+
when Project::SourceFile::TypeCheckStatus
|
56
|
+
source_file.errors.reject do |error|
|
57
|
+
case
|
58
|
+
when error.is_a?(Errors::FallbackAny)
|
59
|
+
target.options.allow_fallback_any
|
60
|
+
when error.is_a?(Errors::MethodDefinitionMissing)
|
61
|
+
target.options.allow_missing_definitions
|
62
|
+
when error.is_a?(Errors::NoMethod)
|
63
|
+
target.options.allow_unknown_method_calls
|
64
|
+
when error.is_a?(Errors::UnknownConstantAssigned)
|
65
|
+
target.options.allow_unknown_constant_assignment
|
66
|
+
end
|
67
|
+
end.each do |error|
|
68
|
+
error.print_to stdout
|
69
|
+
end
|
70
|
+
when Project::SourceFile::TypeCheckErrorStatus
|
71
|
+
Steep.log_error source_file.status.error
|
56
72
|
end
|
57
73
|
end
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
61
77
|
|
62
|
-
if project.targets.all? {|target| target.status.is_a?(Project::Target::TypeCheckStatus) && target.errors.empty? }
|
78
|
+
if project.targets.all? {|target| target.status.is_a?(Project::Target::TypeCheckStatus) && target.no_error? && target.errors.empty? }
|
63
79
|
Steep.logger.info "No type error found"
|
64
80
|
return 0
|
65
81
|
end
|
@@ -70,7 +86,7 @@ module Steep
|
|
70
86
|
def output_types(typing)
|
71
87
|
lines = []
|
72
88
|
|
73
|
-
typing.
|
89
|
+
typing.each_typing do |node, _|
|
74
90
|
begin
|
75
91
|
type = typing.type_of(node: node)
|
76
92
|
lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, type]
|
data/lib/steep/drivers/init.rb
CHANGED
@@ -10,21 +10,21 @@ module Steep
|
|
10
10
|
TEMPLATE = <<~EOF
|
11
11
|
# target :lib do
|
12
12
|
# signature "sig"
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# check "lib" # Directory name
|
15
15
|
# check "Gemfile" # File name
|
16
16
|
# check "app/models/**/*.rb" # Glob
|
17
|
-
# # ignore "lib/templates/*.rb"
|
18
|
-
#
|
17
|
+
# # ignore "lib/templates/*.rb"
|
18
|
+
#
|
19
19
|
# # library "pathname", "set" # Standard libraries
|
20
20
|
# # library "strong_json" # Gems
|
21
21
|
# end
|
22
22
|
|
23
23
|
# target :spec do
|
24
24
|
# signature "sig", "sig-private"
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# check "spec"
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# # library "pathname", "set" # Standard libraries
|
29
29
|
# # library "rspec"
|
30
30
|
# end
|
@@ -33,11 +33,6 @@ module Steep
|
|
33
33
|
@project or raise "Empty #project"
|
34
34
|
end
|
35
35
|
|
36
|
-
def enqueue_type_check(version)
|
37
|
-
@latest_update_version = version
|
38
|
-
type_check_queue << TypeCheckRequest.new(version: version)
|
39
|
-
end
|
40
|
-
|
41
36
|
def run
|
42
37
|
@project = load_config()
|
43
38
|
|
@@ -45,291 +40,22 @@ module Steep
|
|
45
40
|
loader.load_sources([])
|
46
41
|
loader.load_signatures()
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
0
|
65
|
-
end
|
66
|
-
|
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
|
72
|
-
end
|
73
|
-
|
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
|
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
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
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()
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
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
|
-
when Project::SourceFile::TypeCheckErrorStatus
|
191
|
-
[]
|
192
|
-
end
|
193
|
-
|
194
|
-
report_diagnostics source.path, diagnostics
|
195
|
-
end
|
196
|
-
when Project::Target::SignatureSyntaxErrorStatus
|
197
|
-
Steep.logger.info { "Signature syntax error" }
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def report_diagnostics(path, diagnostics)
|
205
|
-
Steep.logger.info { "Reporting #{diagnostics.size} diagnostics for #{path}..." }
|
206
|
-
write(
|
207
|
-
method: :"textDocument/publishDiagnostics",
|
208
|
-
params: LanguageServer::Protocol::Interface::PublishDiagnosticsParams.new(
|
209
|
-
uri: URI.parse(project.absolute_path(path).to_s).tap {|uri| uri.scheme = "file"},
|
210
|
-
diagnostics: diagnostics,
|
211
|
-
)
|
212
|
-
)
|
213
|
-
end
|
214
|
-
|
215
|
-
def diagnostic_for_validation_error(error)
|
216
|
-
LanguageServer::Protocol::Interface::Diagnostic.new(
|
217
|
-
message: StringIO.new("").tap {|io| error.puts(io) }.string,
|
218
|
-
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
219
|
-
range: LanguageServer::Protocol::Interface::Range.new(
|
220
|
-
start: LanguageServer::Protocol::Interface::Position.new(
|
221
|
-
line: error.location.start_line - 1,
|
222
|
-
character: error.location.start_column,
|
223
|
-
),
|
224
|
-
end: LanguageServer::Protocol::Interface::Position.new(
|
225
|
-
line: error.location.end_line - 1,
|
226
|
-
character: error.location.end_column,
|
227
|
-
),
|
228
|
-
)
|
229
|
-
)
|
230
|
-
end
|
231
|
-
|
232
|
-
def diagnostics_raw(message, loc)
|
233
|
-
LanguageServer::Protocol::Interface::Diagnostic.new(
|
234
|
-
message: message,
|
235
|
-
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
236
|
-
range: LanguageServer::Protocol::Interface::Range.new(
|
237
|
-
start: LanguageServer::Protocol::Interface::Position.new(
|
238
|
-
line: loc.start_line - 1,
|
239
|
-
character: loc.start_column,
|
240
|
-
),
|
241
|
-
end: LanguageServer::Protocol::Interface::Position.new(
|
242
|
-
line: loc.end_line - 1,
|
243
|
-
character: loc.end_column,
|
244
|
-
),
|
245
|
-
)
|
246
|
-
)
|
247
|
-
end
|
248
|
-
|
249
|
-
def diagnostic_for_type_error(error)
|
250
|
-
LanguageServer::Protocol::Interface::Diagnostic.new(
|
251
|
-
message: error.to_s,
|
252
|
-
severity: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
|
253
|
-
range: LanguageServer::Protocol::Interface::Range.new(
|
254
|
-
start: LanguageServer::Protocol::Interface::Position.new(
|
255
|
-
line: error.node.loc.line - 1,
|
256
|
-
character: error.node.loc.column,
|
257
|
-
),
|
258
|
-
end: LanguageServer::Protocol::Interface::Position.new(
|
259
|
-
line: error.node.loc.last_line - 1,
|
260
|
-
character: error.node.loc.last_column,
|
261
|
-
),
|
262
|
-
)
|
43
|
+
interaction_worker = Server::WorkerProcess.spawn_worker(:interaction, name: "interaction", steepfile: project.steepfile_path)
|
44
|
+
signature_worker = Server::WorkerProcess.spawn_worker(:signature, name: "signature", steepfile: project.steepfile_path)
|
45
|
+
code_workers = Server::WorkerProcess.spawn_code_workers(steepfile: project.steepfile_path)
|
46
|
+
|
47
|
+
master = Server::Master.new(
|
48
|
+
project: project,
|
49
|
+
reader: reader,
|
50
|
+
writer: writer,
|
51
|
+
interaction_worker: interaction_worker,
|
52
|
+
signature_worker: signature_worker,
|
53
|
+
code_workers: code_workers
|
263
54
|
)
|
264
|
-
end
|
265
55
|
|
266
|
-
|
267
|
-
Steep.logger.info { "path=#{path}, line=#{line}, column=#{column}" }
|
268
|
-
|
269
|
-
hover = Project::HoverContent.new(project: project)
|
270
|
-
content = hover.content_for(path: path, line: line+1, column: column+1)
|
271
|
-
if content
|
272
|
-
range = content.location.yield_self do |location|
|
273
|
-
start_position = { line: location.line - 1, character: location.column }
|
274
|
-
end_position = { line: location.last_line - 1, character: location.last_column }
|
275
|
-
{ start: start_position, end: end_position }
|
276
|
-
end
|
277
|
-
|
278
|
-
LanguageServer::Protocol::Interface::Hover.new(
|
279
|
-
contents: { kind: "markdown", value: format_hover(content) },
|
280
|
-
range: range
|
281
|
-
)
|
282
|
-
end
|
283
|
-
end
|
56
|
+
master.start()
|
284
57
|
|
285
|
-
|
286
|
-
case content
|
287
|
-
when Project::HoverContent::VariableContent
|
288
|
-
"`#{content.name}`: `#{content.type.to_s}`"
|
289
|
-
when Project::HoverContent::MethodCallContent
|
290
|
-
method_name = case content.method_name
|
291
|
-
when Project::HoverContent::InstanceMethodName
|
292
|
-
"#{content.method_name.class_name}##{content.method_name.method_name}"
|
293
|
-
when Project::HoverContent::SingletonMethodName
|
294
|
-
"#{content.method_name.class_name}.#{content.method_name.method_name}"
|
295
|
-
else
|
296
|
-
nil
|
297
|
-
end
|
298
|
-
|
299
|
-
if method_name
|
300
|
-
string = <<HOVER
|
301
|
-
```
|
302
|
-
#{method_name} ~> #{content.type}
|
303
|
-
```
|
304
|
-
HOVER
|
305
|
-
if content.definition
|
306
|
-
if content.definition.comment
|
307
|
-
string << "\n----\n\n#{content.definition.comment.string}"
|
308
|
-
end
|
309
|
-
|
310
|
-
string << "\n----\n\n#{content.definition.method_types.map {|x| "- `#{x}`\n" }.join()}"
|
311
|
-
end
|
312
|
-
else
|
313
|
-
"`#{content.type}`"
|
314
|
-
end
|
315
|
-
when Project::HoverContent::DefinitionContent
|
316
|
-
string = <<HOVER
|
317
|
-
```
|
318
|
-
def #{content.method_name}: #{content.method_type}
|
319
|
-
```
|
320
|
-
HOVER
|
321
|
-
if (comment = content.definition.comment)
|
322
|
-
string << "\n----\n\n#{comment.string}\n"
|
323
|
-
end
|
324
|
-
|
325
|
-
if content.definition.method_types.size > 1
|
326
|
-
string << "\n----\n\n#{content.definition.method_types.map {|x| "- `#{x}`\n" }.join()}"
|
327
|
-
end
|
328
|
-
|
329
|
-
string
|
330
|
-
when Project::HoverContent::TypeContent
|
331
|
-
"`#{content.type}`"
|
332
|
-
end
|
58
|
+
0
|
333
59
|
end
|
334
60
|
end
|
335
61
|
end
|
@@ -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/vendor.rb
CHANGED
@@ -20,7 +20,7 @@ module Steep
|
|
20
20
|
def run
|
21
21
|
stdout.puts "Vendoring into #{vendor_dir}..."
|
22
22
|
|
23
|
-
vendorer =
|
23
|
+
vendorer = RBS::Vendorer.new(vendor_dir: vendor_dir)
|
24
24
|
|
25
25
|
if clean_before
|
26
26
|
stdout.puts " Cleaning directory..."
|
@@ -32,7 +32,7 @@ module Steep
|
|
32
32
|
|
33
33
|
if defined?(Bundler)
|
34
34
|
Bundler.locked_gems.specs.each do |spec|
|
35
|
-
if
|
35
|
+
if RBS::EnvironmentLoader.gem_sig_path(spec.name, spec.version.to_s).directory?
|
36
36
|
stdout.puts " Vendoring rubygem: #{spec.full_name}..."
|
37
37
|
vendorer.gem! spec.name, spec.version.to_s
|
38
38
|
end
|