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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 551b6bb90b8fe98210d56cf53f62fb57e1bf0ce74e4c40ad931ddfe598507437
|
4
|
+
data.tar.gz: b01aed4e95d34dd6fad93fbeac1e5a427dbfa94e5ea9ce4130d2e89f14693159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7aa1961819c9998182ef50ddd6d50c18985a9c2697715d35e062a069c87cd71bff416cb900a3bb3b5fff5c0a85970e3cb7f9e2183ca99656be6f87a4a4fdb5
|
7
|
+
data.tar.gz: 846810f3de6b4ec1a0e9f0a07ee3755c2e1258de6e7344339eef3e35b1912d6b591e36c55ef6e108f60c79a06ff9fed7ee940512ade80ba91bdab1a21e71bc28
|
data/.gitmodules
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,34 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.16.2 (2020-05-27)
|
6
|
+
|
7
|
+
* Update gems ([144](https://github.com/soutaro/steep/pull/144), [145](https://github.com/soutaro/steep/pull/145))
|
8
|
+
|
9
|
+
## 0.16.1 (2020-05-22)
|
10
|
+
|
11
|
+
* Fix constant resolution ([#143](https://github.com/soutaro/steep/pull/143))
|
12
|
+
* Fix RBS diagnostics line number in LSP ([142](https://github.com/soutaro/steep/pull/142))
|
13
|
+
* Fix crash caused by hover on `def` in LSP ([140](https://github.com/soutaro/steep/pull/140))
|
14
|
+
|
15
|
+
## 0.16.0 (2020-05-19)
|
16
|
+
|
17
|
+
* Spawn workers for type check performance ([#137](https://github.com/soutaro/steep/pull/137))
|
18
|
+
* Fix `check` and `signature` methods in Steepfile ([8f3e4c7](https://github.com/soutaro/steep/pull/137/commits/8f3e4c75b29ac26920f02294be06d6c68dbd4dca))
|
19
|
+
|
20
|
+
## 0.15.0 (2020-05-05)
|
21
|
+
|
22
|
+
* Add type checking configuration to dsl ([#132](https://github.com/soutaro/steep/pull/132))
|
23
|
+
* More flow sensitive type checking
|
24
|
+
|
25
|
+
## 0.14.0 (2020-02-24)
|
26
|
+
|
27
|
+
* Implementat LSP _completion_. ([#119](https://github.com/soutaro/steep/pull/119))
|
28
|
+
* Update ruby-signature. ([#120](https://github.com/soutaro/steep/pull/120))
|
29
|
+
* Rescue errors during `langserver`. ([#121](https://github.com/soutaro/steep/pull/121))
|
30
|
+
* Pass hint when type checking `return`. ([#122](https://github.com/soutaro/steep/pull/122))
|
31
|
+
* Remove trailing spaces from Steepfile. ([#118](https://github.com/soutaro/steep/pull/118))
|
32
|
+
|
5
33
|
## 0.13.0 (2020-02-16)
|
6
34
|
|
7
35
|
* Improve LSP _hover_ support. ([#117](https://github.com/soutaro/steep/pull/117))
|
data/Rakefile
CHANGED
@@ -8,19 +8,6 @@ Rake::TestTask.new(:test) do |t|
|
|
8
8
|
end
|
9
9
|
|
10
10
|
task :default => :test
|
11
|
-
task :build => :parser
|
12
|
-
task :test => :parser
|
13
|
-
task :install => [:reset, :parser]
|
14
|
-
|
15
|
-
task :parser do
|
16
|
-
Dir.chdir "vendor/ruby-signature" do
|
17
|
-
sh "bundle exec rake parser"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
task :reset do
|
22
|
-
sh "git submodule update -f --init"
|
23
|
-
end
|
24
11
|
|
25
12
|
task :smoke do
|
26
13
|
sh "bundle", "exec", "bin/smoke_runner.rb", *Dir.glob("smoke/*")
|
data/bin/setup
CHANGED
data/bin/smoke_runner.rb
CHANGED
data/exe/steep
CHANGED
data/lib/steep.rb
CHANGED
@@ -10,8 +10,10 @@ require "rainbow"
|
|
10
10
|
require "listen"
|
11
11
|
require 'pry'
|
12
12
|
require 'language_server-protocol'
|
13
|
+
require "etc"
|
14
|
+
require "open3"
|
13
15
|
|
14
|
-
require "
|
16
|
+
require "rbs"
|
15
17
|
|
16
18
|
require "steep/ast/namespace"
|
17
19
|
require "steep/names"
|
@@ -61,12 +63,23 @@ require "steep/typing"
|
|
61
63
|
require "steep/errors"
|
62
64
|
require "steep/type_construction"
|
63
65
|
require "steep/type_inference/context"
|
66
|
+
require "steep/type_inference/context_array"
|
64
67
|
require "steep/type_inference/send_args"
|
65
68
|
require "steep/type_inference/block_params"
|
66
69
|
require "steep/type_inference/constant_env"
|
67
70
|
require "steep/type_inference/type_env"
|
71
|
+
require "steep/type_inference/local_variable_type_env"
|
72
|
+
require "steep/type_inference/logic"
|
68
73
|
require "steep/ast/types"
|
69
74
|
|
75
|
+
require "steep/server/utils"
|
76
|
+
require "steep/server/base_worker"
|
77
|
+
require "steep/server/code_worker"
|
78
|
+
require "steep/server/signature_worker"
|
79
|
+
require "steep/server/worker_process"
|
80
|
+
require "steep/server/interaction_worker"
|
81
|
+
require "steep/server/master"
|
82
|
+
|
70
83
|
require "steep/project"
|
71
84
|
require "steep/project/file"
|
72
85
|
require "steep/project/options"
|
@@ -74,6 +87,7 @@ require "steep/project/target"
|
|
74
87
|
require "steep/project/dsl"
|
75
88
|
require "steep/project/file_loader"
|
76
89
|
require "steep/project/hover_content"
|
90
|
+
require "steep/project/completion_provider"
|
77
91
|
require "steep/drivers/utils/driver_helper"
|
78
92
|
require "steep/drivers/check"
|
79
93
|
require "steep/drivers/validate"
|
@@ -85,11 +99,14 @@ require "steep/drivers/trace_printer"
|
|
85
99
|
require "steep/drivers/print_project"
|
86
100
|
require "steep/drivers/init"
|
87
101
|
require "steep/drivers/vendor"
|
102
|
+
require "steep/drivers/worker"
|
88
103
|
|
89
104
|
if ENV["NO_COLOR"]
|
90
105
|
Rainbow.enabled = false
|
91
106
|
end
|
92
107
|
|
108
|
+
$stderr = STDERR
|
109
|
+
|
93
110
|
module Steep
|
94
111
|
def self.logger
|
95
112
|
@logger
|
@@ -114,4 +131,19 @@ module Steep
|
|
114
131
|
|
115
132
|
@logger = nil
|
116
133
|
self.log_output = STDERR
|
134
|
+
|
135
|
+
def self.measure(message)
|
136
|
+
start = Time.now
|
137
|
+
yield.tap do
|
138
|
+
time = Time.now - start
|
139
|
+
self.logger.info "#{message} took #{time} seconds"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.log_error(exn, message: "Unexpected error: #{exn.inspect}")
|
144
|
+
Steep.logger.error message
|
145
|
+
exn.backtrace.each do |loc|
|
146
|
+
Steep.logger.warn " #{loc}"
|
147
|
+
end
|
148
|
+
end
|
117
149
|
end
|
@@ -2,7 +2,7 @@ module Steep
|
|
2
2
|
class AnnotationParser
|
3
3
|
VAR_NAME = /[a-z][A-Za-z0-9_]*/
|
4
4
|
METHOD_NAME = Regexp.union(
|
5
|
-
/[
|
5
|
+
/[^.:\s]+/
|
6
6
|
)
|
7
7
|
CONST_NAME = Regexp.union(
|
8
8
|
/(::)?([A-Z][A-Za-z0-9_]*::)*[A-Z][A-Za-z0-9_]*/
|
@@ -34,7 +34,7 @@ module Steep
|
|
34
34
|
TYPE_PARAMS = /(\[(?<params>#{PARAM}(,\s*#{PARAM})*)\])?/
|
35
35
|
|
36
36
|
def parse_type(string)
|
37
|
-
factory.type(
|
37
|
+
factory.type(RBS::Parser.parse_type(string))
|
38
38
|
end
|
39
39
|
|
40
40
|
# @type ${keyword} ${name}: ${type}
|
@@ -68,7 +68,7 @@ module Steep
|
|
68
68
|
name = match[:name]
|
69
69
|
type = match[:type]
|
70
70
|
|
71
|
-
method_type = factory.method_type(
|
71
|
+
method_type = factory.method_type(RBS::Parser.parse_method_type(type), self_type: AST::Types::Self.new)
|
72
72
|
|
73
73
|
AST::Annotation::MethodType.new(name: name.to_sym,
|
74
74
|
type: method_type,
|
@@ -160,7 +160,7 @@ module Steep
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
rescue
|
163
|
+
rescue RBS::Parser::SyntaxError, RBS::Parser::SemanticsError => exn
|
164
164
|
raise SyntaxError.new(source: src, location: location, exn: exn)
|
165
165
|
end
|
166
166
|
end
|
data/lib/steep/ast/buffer.rb
CHANGED
@@ -10,21 +10,25 @@ module Steep
|
|
10
10
|
@name = name
|
11
11
|
@content = content
|
12
12
|
|
13
|
-
@lines = content.
|
13
|
+
@lines = content.split(/\n/, -1)
|
14
14
|
|
15
15
|
@ranges = []
|
16
16
|
offset = 0
|
17
|
-
lines.each do |line|
|
18
|
-
size
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
lines.each.with_index do |line, index|
|
18
|
+
if index == lines.size - 1
|
19
|
+
ranges << (offset..offset)
|
20
|
+
else
|
21
|
+
size = line.size
|
22
|
+
range = offset..(offset+size)
|
23
|
+
ranges << range
|
24
|
+
offset += size+1
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
def pos_to_loc(pos)
|
26
30
|
index = ranges.bsearch_index do |range|
|
27
|
-
pos
|
31
|
+
pos <= range.end
|
28
32
|
end
|
29
33
|
|
30
34
|
if index
|
data/lib/steep/ast/builtin.rb
CHANGED
@@ -88,6 +88,14 @@ module Steep
|
|
88
88
|
AST::Types::Boolean.new
|
89
89
|
end
|
90
90
|
|
91
|
+
def self.bottom_type
|
92
|
+
AST::Types::Bot.new
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.top_type
|
96
|
+
AST::Types::Top.new
|
97
|
+
end
|
98
|
+
|
91
99
|
def self.optional(type)
|
92
100
|
AST::Types::Union.build(types: [type, nil_type])
|
93
101
|
end
|
@@ -10,56 +10,56 @@ module Steep
|
|
10
10
|
|
11
11
|
def type(type)
|
12
12
|
case type
|
13
|
-
when
|
13
|
+
when RBS::Types::Bases::Any
|
14
14
|
Any.new(location: nil)
|
15
|
-
when
|
15
|
+
when RBS::Types::Bases::Class
|
16
16
|
Class.new(location: nil)
|
17
|
-
when
|
17
|
+
when RBS::Types::Bases::Instance
|
18
18
|
Instance.new(location: nil)
|
19
|
-
when
|
19
|
+
when RBS::Types::Bases::Self
|
20
20
|
Self.new(location: nil)
|
21
|
-
when
|
21
|
+
when RBS::Types::Bases::Top
|
22
22
|
Top.new(location: nil)
|
23
|
-
when
|
23
|
+
when RBS::Types::Bases::Bottom
|
24
24
|
Bot.new(location: nil)
|
25
|
-
when
|
25
|
+
when RBS::Types::Bases::Bool
|
26
26
|
Boolean.new(location: nil)
|
27
|
-
when
|
27
|
+
when RBS::Types::Bases::Void
|
28
28
|
Void.new(location: nil)
|
29
|
-
when
|
29
|
+
when RBS::Types::Bases::Nil
|
30
30
|
Nil.new(location: nil)
|
31
|
-
when
|
31
|
+
when RBS::Types::Variable
|
32
32
|
Var.new(name: type.name, location: nil)
|
33
|
-
when
|
33
|
+
when RBS::Types::ClassSingleton
|
34
34
|
type_name = type_name(type.name)
|
35
35
|
Name::Class.new(name: type_name, location: nil, constructor: nil)
|
36
|
-
when
|
36
|
+
when RBS::Types::ClassInstance
|
37
37
|
type_name = type_name(type.name)
|
38
38
|
args = type.args.map {|arg| type(arg) }
|
39
39
|
Name::Instance.new(name: type_name, args: args, location: nil)
|
40
|
-
when
|
40
|
+
when RBS::Types::Interface
|
41
41
|
type_name = type_name(type.name)
|
42
42
|
args = type.args.map {|arg| type(arg) }
|
43
43
|
Name::Interface.new(name: type_name, args: args, location: nil)
|
44
|
-
when
|
44
|
+
when RBS::Types::Alias
|
45
45
|
type_name = type_name(type.name)
|
46
46
|
Name::Alias.new(name: type_name, args: [], location: nil)
|
47
|
-
when
|
47
|
+
when RBS::Types::Union
|
48
48
|
Union.build(types: type.types.map {|ty| type(ty) }, location: nil)
|
49
|
-
when
|
49
|
+
when RBS::Types::Intersection
|
50
50
|
Intersection.build(types: type.types.map {|ty| type(ty) }, location: nil)
|
51
|
-
when
|
51
|
+
when RBS::Types::Optional
|
52
52
|
Union.build(types: [type(type.type), Nil.new(location: nil)], location: nil)
|
53
|
-
when
|
53
|
+
when RBS::Types::Literal
|
54
54
|
Literal.new(value: type.literal, location: nil)
|
55
|
-
when
|
55
|
+
when RBS::Types::Tuple
|
56
56
|
Tuple.new(types: type.types.map {|ty| type(ty) }, location: nil)
|
57
|
-
when
|
57
|
+
when RBS::Types::Record
|
58
58
|
elements = type.fields.each.with_object({}) do |(key, value), hash|
|
59
59
|
hash[key] = type(value)
|
60
60
|
end
|
61
61
|
Record.new(elements: elements, location: nil)
|
62
|
-
when
|
62
|
+
when RBS::Types::Proc
|
63
63
|
params = params(type.type)
|
64
64
|
return_type = type(type.type.return_type)
|
65
65
|
Proc.new(params: params, return_type: return_type, location: nil)
|
@@ -71,56 +71,56 @@ module Steep
|
|
71
71
|
def type_1(type)
|
72
72
|
case type
|
73
73
|
when Any
|
74
|
-
|
74
|
+
RBS::Types::Bases::Any.new(location: nil)
|
75
75
|
when Class
|
76
|
-
|
76
|
+
RBS::Types::Bases::Class.new(location: nil)
|
77
77
|
when Instance
|
78
|
-
|
78
|
+
RBS::Types::Bases::Instance.new(location: nil)
|
79
79
|
when Self
|
80
|
-
|
80
|
+
RBS::Types::Bases::Self.new(location: nil)
|
81
81
|
when Top
|
82
|
-
|
82
|
+
RBS::Types::Bases::Top.new(location: nil)
|
83
83
|
when Bot
|
84
|
-
|
84
|
+
RBS::Types::Bases::Bottom.new(location: nil)
|
85
85
|
when Boolean
|
86
|
-
|
86
|
+
RBS::Types::Bases::Bool.new(location: nil)
|
87
87
|
when Void
|
88
|
-
|
88
|
+
RBS::Types::Bases::Void.new(location: nil)
|
89
89
|
when Nil
|
90
|
-
|
90
|
+
RBS::Types::Bases::Nil.new(location: nil)
|
91
91
|
when Var
|
92
|
-
|
92
|
+
RBS::Types::Variable.new(name: type.name, location: nil)
|
93
93
|
when Name::Class, Name::Module
|
94
|
-
|
94
|
+
RBS::Types::ClassSingleton.new(name: type_name_1(type.name), location: nil)
|
95
95
|
when Name::Instance
|
96
|
-
|
96
|
+
RBS::Types::ClassInstance.new(
|
97
97
|
name: type_name_1(type.name),
|
98
98
|
args: type.args.map {|arg| type_1(arg) },
|
99
99
|
location: nil
|
100
100
|
)
|
101
101
|
when Name::Interface
|
102
|
-
|
102
|
+
RBS::Types::Interface.new(
|
103
103
|
name: type_name_1(type.name),
|
104
104
|
args: type.args.map {|arg| type_1(arg) },
|
105
105
|
location: nil
|
106
106
|
)
|
107
107
|
when Name::Alias
|
108
108
|
type.args.empty? or raise "alias type with args is not supported"
|
109
|
-
|
109
|
+
RBS::Types::Alias.new(name: type_name_1(type.name), location: nil)
|
110
110
|
when Union
|
111
|
-
|
111
|
+
RBS::Types::Union.new(
|
112
112
|
types: type.types.map {|ty| type_1(ty) },
|
113
113
|
location: nil
|
114
114
|
)
|
115
115
|
when Intersection
|
116
|
-
|
116
|
+
RBS::Types::Intersection.new(
|
117
117
|
types: type.types.map {|ty| type_1(ty) },
|
118
118
|
location: nil
|
119
119
|
)
|
120
120
|
when Literal
|
121
|
-
|
121
|
+
RBS::Types::Literal.new(literal: type.value, location: nil)
|
122
122
|
when Tuple
|
123
|
-
|
123
|
+
RBS::Types::Tuple.new(
|
124
124
|
types: type.types.map {|ty| type_1(ty) },
|
125
125
|
location: nil
|
126
126
|
)
|
@@ -128,9 +128,9 @@ module Steep
|
|
128
128
|
fields = type.elements.each.with_object({}) do |(key, value), hash|
|
129
129
|
hash[key] = type_1(value)
|
130
130
|
end
|
131
|
-
|
131
|
+
RBS::Types::Record.new(fields: fields, location: nil)
|
132
132
|
when Proc
|
133
|
-
|
133
|
+
RBS::Types::Proc.new(
|
134
134
|
type: function_1(type.params, type.return_type),
|
135
135
|
location: nil
|
136
136
|
)
|
@@ -151,7 +151,7 @@ module Steep
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def type_name_1(name)
|
154
|
-
|
154
|
+
RBS::TypeName.new(name: name.name, namespace: namespace_1(name.namespace))
|
155
155
|
end
|
156
156
|
|
157
157
|
def namespace(namespace)
|
@@ -159,18 +159,18 @@ module Steep
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def namespace_1(namespace)
|
162
|
-
|
162
|
+
RBS::Namespace.parse(namespace.to_s)
|
163
163
|
end
|
164
164
|
|
165
165
|
def function_1(params, return_type)
|
166
|
-
|
167
|
-
required_positionals: params.required.map {|type|
|
168
|
-
optional_positionals: params.optional.map {|type|
|
169
|
-
rest_positionals: params.rest&.yield_self {|type|
|
166
|
+
RBS::Types::Function.new(
|
167
|
+
required_positionals: params.required.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
|
168
|
+
optional_positionals: params.optional.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
|
169
|
+
rest_positionals: params.rest&.yield_self {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
|
170
170
|
trailing_positionals: [],
|
171
|
-
required_keywords: params.required_keywords.transform_values {|type|
|
172
|
-
optional_keywords: params.optional_keywords.transform_values {|type|
|
173
|
-
rest_keywords: params.rest_keywords&.yield_self {|type|
|
171
|
+
required_keywords: params.required_keywords.transform_values {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
|
172
|
+
optional_keywords: params.optional_keywords.transform_values {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
|
173
|
+
rest_keywords: params.rest_keywords&.yield_self {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
|
174
174
|
return_type: type_1(return_type)
|
175
175
|
)
|
176
176
|
end
|
@@ -187,47 +187,82 @@ module Steep
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def method_type(method_type, self_type:)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
else
|
205
|
-
type_params << name
|
206
|
-
end
|
190
|
+
fvs = self_type.free_variables()
|
191
|
+
|
192
|
+
type_params = []
|
193
|
+
alpha_vars = []
|
194
|
+
alpha_types = []
|
195
|
+
|
196
|
+
method_type.type_params.map do |name|
|
197
|
+
if fvs.include?(name)
|
198
|
+
type = Types::Var.fresh(name)
|
199
|
+
alpha_vars << name
|
200
|
+
alpha_types << type
|
201
|
+
type_params << type.name
|
202
|
+
else
|
203
|
+
type_params << name
|
207
204
|
end
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
205
|
+
end
|
206
|
+
subst = Interface::Substitution.build(alpha_vars, alpha_types)
|
207
|
+
|
208
|
+
type = Interface::MethodType.new(
|
209
|
+
type_params: type_params,
|
210
|
+
return_type: type(method_type.type.return_type).subst(subst),
|
211
|
+
params: params(method_type.type).subst(subst),
|
212
|
+
location: nil,
|
213
|
+
block: method_type.block&.yield_self do |block|
|
214
|
+
Interface::Block.new(
|
215
|
+
optional: !block.required,
|
216
|
+
type: Proc.new(params: params(block.type).subst(subst),
|
217
|
+
return_type: type(block.type.return_type).subst(subst), location: nil)
|
218
|
+
)
|
219
|
+
end
|
220
|
+
)
|
221
|
+
|
222
|
+
if block_given?
|
223
|
+
yield type
|
224
|
+
else
|
225
|
+
type
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def method_type_1(method_type, self_type:)
|
230
|
+
fvs = self_type.free_variables()
|
223
231
|
|
224
|
-
|
225
|
-
|
232
|
+
type_params = []
|
233
|
+
alpha_vars = []
|
234
|
+
alpha_types = []
|
235
|
+
|
236
|
+
method_type.type_params.map do |name|
|
237
|
+
if fvs.include?(name)
|
238
|
+
type = RBS::Types::Variable.new(name: name, location: nil),
|
239
|
+
alpha_vars << name
|
240
|
+
alpha_types << type
|
241
|
+
type_params << type.name
|
226
242
|
else
|
227
|
-
|
243
|
+
type_params << name
|
228
244
|
end
|
229
|
-
|
230
|
-
|
245
|
+
end
|
246
|
+
subst = Interface::Substitution.build(alpha_vars, alpha_types)
|
247
|
+
|
248
|
+
type = RBS::MethodType.new(
|
249
|
+
type_params: type_params,
|
250
|
+
type: function_1(method_type.params.subst(subst), method_type.return_type.subst(subst)),
|
251
|
+
block: method_type.block&.yield_self do |block|
|
252
|
+
block_type = block.type.subst(subst)
|
253
|
+
|
254
|
+
RBS::MethodType::Block.new(
|
255
|
+
type: function_1(block_type.params, block_type.return_type),
|
256
|
+
required: !block.optional
|
257
|
+
)
|
258
|
+
end,
|
259
|
+
location: nil
|
260
|
+
)
|
261
|
+
|
262
|
+
if block_given?
|
263
|
+
yield type
|
264
|
+
else
|
265
|
+
type
|
231
266
|
end
|
232
267
|
end
|
233
268
|
|
@@ -508,12 +543,12 @@ module Steep
|
|
508
543
|
|
509
544
|
def module_name?(type_name)
|
510
545
|
name = type_name_1(type_name)
|
511
|
-
env.class?(name) && env.find_class(name).is_a?(
|
546
|
+
env.class?(name) && env.find_class(name).is_a?(RBS::AST::Declarations::Module)
|
512
547
|
end
|
513
548
|
|
514
549
|
def class_name?(type_name)
|
515
550
|
name = type_name_1(type_name)
|
516
|
-
env.class?(name) && env.find_class(name).is_a?(
|
551
|
+
env.class?(name) && env.find_class(name).is_a?(RBS::AST::Declarations::Class)
|
517
552
|
end
|
518
553
|
|
519
554
|
def env
|