steep 0.14.0 → 0.16.3
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 +18 -2
- 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 +55 -55
- 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/langserver.rb +13 -457
- 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 +9 -13
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +43 -46
- 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 +996 -726
- 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 +79 -22
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- 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/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 +7 -8
- metadata +26 -141
- 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 -67
- 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 -555
- 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 -1344
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
- 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 -327
- 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 -271
- 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 -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 -1894
- 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: 2b1c04c7f20a2ed355b58570363447b3e8f2bd1710407de1e23c7b9fbe279cb8
|
4
|
+
data.tar.gz: 62101db41144f3fd218ee8478ab377f3414ad1d8a7689ac73356aa28bf7f6842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8ac130b1adb7755709f4b1590939b442d6d4b4aa5ea38a95423db539a1b52b0c4078abf1a543b92a84477d99846d5ab30060dc26c693f52785de0c205041a2d
|
7
|
+
data.tar.gz: e7ccec14707e49d51b88429ab0922c4e6fbbc190bbafb0e107c30ea681b04415245e40708909fd28458a89a565a816fd88a6bfa1c14b76e24185a2ece153148c
|
data/.gitmodules
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.16.3
|
6
|
+
|
7
|
+
* Fix `steep watch` ([#147](https://github.com/soutaro/steep/pull/147))
|
8
|
+
* Stop using pry ([#148](https://github.com/soutaro/steep/pull/148))
|
9
|
+
|
10
|
+
## 0.16.2 (2020-05-27)
|
11
|
+
|
12
|
+
* Update gems ([#144](https://github.com/soutaro/steep/pull/144), [#145](https://github.com/soutaro/steep/pull/145))
|
13
|
+
|
14
|
+
## 0.16.1 (2020-05-22)
|
15
|
+
|
16
|
+
* Fix constant resolution ([#143](https://github.com/soutaro/steep/pull/143))
|
17
|
+
* Fix RBS diagnostics line number in LSP ([#142](https://github.com/soutaro/steep/pull/142))
|
18
|
+
* Fix crash caused by hover on `def` in LSP ([#140](https://github.com/soutaro/steep/pull/140))
|
19
|
+
|
20
|
+
## 0.16.0 (2020-05-19)
|
21
|
+
|
22
|
+
* Spawn workers for type check performance ([#137](https://github.com/soutaro/steep/pull/137))
|
23
|
+
* Fix `check` and `signature` methods in Steepfile ([8f3e4c7](https://github.com/soutaro/steep/pull/137/commits/8f3e4c75b29ac26920f02294be06d6c68dbd4dca))
|
24
|
+
|
25
|
+
## 0.15.0 (2020-05-05)
|
26
|
+
|
27
|
+
* Add type checking configuration to dsl ([#132](https://github.com/soutaro/steep/pull/132))
|
28
|
+
* More flow sensitive type checking
|
29
|
+
|
5
30
|
## 0.14.0 (2020-02-24)
|
6
31
|
|
7
32
|
* Implementat LSP _completion_. ([#119](https://github.com/soutaro/steep/pull/119))
|
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
@@ -8,10 +8,12 @@ require "logger"
|
|
8
8
|
require "active_support/tagged_logging"
|
9
9
|
require "rainbow"
|
10
10
|
require "listen"
|
11
|
-
require 'pry'
|
12
11
|
require 'language_server-protocol'
|
12
|
+
require "etc"
|
13
|
+
require "open3"
|
14
|
+
require "stringio"
|
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"
|
@@ -86,11 +99,14 @@ require "steep/drivers/trace_printer"
|
|
86
99
|
require "steep/drivers/print_project"
|
87
100
|
require "steep/drivers/init"
|
88
101
|
require "steep/drivers/vendor"
|
102
|
+
require "steep/drivers/worker"
|
89
103
|
|
90
104
|
if ENV["NO_COLOR"]
|
91
105
|
Rainbow.enabled = false
|
92
106
|
end
|
93
107
|
|
108
|
+
$stderr = STDERR
|
109
|
+
|
94
110
|
module Steep
|
95
111
|
def self.logger
|
96
112
|
@logger
|
@@ -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
|
@@ -235,7 +235,7 @@ module Steep
|
|
235
235
|
|
236
236
|
method_type.type_params.map do |name|
|
237
237
|
if fvs.include?(name)
|
238
|
-
type =
|
238
|
+
type = RBS::Types::Variable.new(name: name, location: nil),
|
239
239
|
alpha_vars << name
|
240
240
|
alpha_types << type
|
241
241
|
type_params << type.name
|
@@ -245,13 +245,13 @@ module Steep
|
|
245
245
|
end
|
246
246
|
subst = Interface::Substitution.build(alpha_vars, alpha_types)
|
247
247
|
|
248
|
-
type =
|
248
|
+
type = RBS::MethodType.new(
|
249
249
|
type_params: type_params,
|
250
250
|
type: function_1(method_type.params.subst(subst), method_type.return_type.subst(subst)),
|
251
251
|
block: method_type.block&.yield_self do |block|
|
252
252
|
block_type = block.type.subst(subst)
|
253
253
|
|
254
|
-
|
254
|
+
RBS::MethodType::Block.new(
|
255
255
|
type: function_1(block_type.params, block_type.return_type),
|
256
256
|
required: !block.optional
|
257
257
|
)
|
@@ -543,12 +543,12 @@ module Steep
|
|
543
543
|
|
544
544
|
def module_name?(type_name)
|
545
545
|
name = type_name_1(type_name)
|
546
|
-
env.class?(name) && env.find_class(name).is_a?(
|
546
|
+
env.class?(name) && env.find_class(name).is_a?(RBS::AST::Declarations::Module)
|
547
547
|
end
|
548
548
|
|
549
549
|
def class_name?(type_name)
|
550
550
|
name = type_name_1(type_name)
|
551
|
-
env.class?(name) && env.find_class(name).is_a?(
|
551
|
+
env.class?(name) && env.find_class(name).is_a?(RBS::AST::Declarations::Class)
|
552
552
|
end
|
553
553
|
|
554
554
|
def env
|