steep 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/exe/rbs +1 -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 +55 -55
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/langserver.rb +6 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/project/completion_provider.rb +5 -11
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +42 -46
- data/lib/steep/project/hover_content.rb +11 -5
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +10 -4
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +8 -8
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +987 -711
- data/lib/steep/type_inference/constant_env.rb +1 -1
- data/lib/steep/type_inference/context.rb +7 -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/lib/steep.rb +6 -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 +1 -1
- data/vendor/ruby-signature/.gitignore +2 -2
- data/vendor/ruby-signature/README.md +2 -2
- data/vendor/ruby-signature/Rakefile +2 -2
- data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
- data/vendor/ruby-signature/bin/console +1 -1
- data/vendor/ruby-signature/bin/sort +7 -6
- data/vendor/ruby-signature/bin/test_runner.rb +0 -1
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
- data/vendor/ruby-signature/docs/sigs.md +3 -3
- data/vendor/ruby-signature/docs/stdlib.md +1 -1
- data/vendor/ruby-signature/docs/syntax.md +9 -9
- data/vendor/ruby-signature/exe/rbs +5 -1
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
- data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
- data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
- data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
- data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
- data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
- data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
- data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
- data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
- data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
- data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
- data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
- data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
- data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
- data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
- data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
- data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
- data/vendor/ruby-signature/lib/rbs.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
- data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
- data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
- metadata +49 -44
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- 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/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/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- 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/test.rb +0 -28
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 498c3c95c9c03e8ef047c774aff47158d8681e2ae485d5b0449a74fae33cd06b
|
|
4
|
+
data.tar.gz: 64e9572dc4ec5b5fea6035c1a1fbb7241a758f76c5d328d2ac0011c37e176044
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: acef7a13109ecd0660d72dff4559b4432f96c62f79aa4dcb762722f9a96678bb6f68f0bd288017381c6ebef65f9648a24f2b349d2af28f1a6f0c66560d56aee6
|
|
7
|
+
data.tar.gz: 9d31c49a37770c7493cefcde0f608ee6b6c94bd5fa1935c3ce963bae70b3e526b678000ae1b2b9f59d94a775c5103cbabf7effd480262725db476f70e6124dcf
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## master
|
|
4
4
|
|
|
5
|
+
## 0.15.0 (2020-05-05)
|
|
6
|
+
|
|
7
|
+
* Add type checking configuration to dsl ([#132](https://github.com/soutaro/steep/pull/132))
|
|
8
|
+
* More flow sensitive type checking
|
|
9
|
+
|
|
5
10
|
## 0.14.0 (2020-02-24)
|
|
6
11
|
|
|
7
12
|
* Implementat LSP _completion_. ([#119](https://github.com/soutaro/steep/pull/119))
|
data/exe/rbs
CHANGED
|
@@ -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
|
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]
|
|
@@ -234,6 +234,11 @@ module Steep
|
|
|
234
234
|
source.errors.map {|error| diagnostic_for_type_error(error) }
|
|
235
235
|
when Project::SourceFile::AnnotationSyntaxErrorStatus
|
|
236
236
|
[diagnostics_raw(source.status.error.message, source.status.location)]
|
|
237
|
+
when Project::SourceFile::ParseErrorStatus
|
|
238
|
+
[]
|
|
239
|
+
when Project::SourceFile::TypeCheckErrorStatus
|
|
240
|
+
Steep.log_error source.status.error
|
|
241
|
+
[]
|
|
237
242
|
end
|
|
238
243
|
|
|
239
244
|
if diagnostics
|
|
@@ -441,7 +446,7 @@ HOVER
|
|
|
441
446
|
|
|
442
447
|
|
|
443
448
|
block = if method_type.block
|
|
444
|
-
open, space, close = if method_type.block.type.return_type.is_a?(
|
|
449
|
+
open, space, close = if method_type.block.type.return_type.is_a?(RBS::Types::Bases::Void)
|
|
445
450
|
["do", " ", "end"]
|
|
446
451
|
else
|
|
447
452
|
["{", "", "}"]
|
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
|
|
@@ -99,10 +99,11 @@ module Steep
|
|
|
99
99
|
|
|
100
100
|
items = []
|
|
101
101
|
|
|
102
|
+
context = typing.context_at(line: position.line, column: position.column)
|
|
103
|
+
|
|
102
104
|
case
|
|
103
105
|
when node.type == :send && node.children[0] == nil && at_end?(position, of: node.loc.selector)
|
|
104
106
|
# foo ←
|
|
105
|
-
context = typing.context_of(node: node)
|
|
106
107
|
prefix = node.children[1].to_s
|
|
107
108
|
|
|
108
109
|
method_items_for_receiver_type(context.self_type,
|
|
@@ -114,12 +115,10 @@ module Steep
|
|
|
114
115
|
|
|
115
116
|
when node.type == :lvar && at_end?(position, of: node.loc)
|
|
116
117
|
# foo ← (lvar)
|
|
117
|
-
context = typing.context_of(node: node)
|
|
118
118
|
local_variable_items_for_context(context, position: position, prefix: node.children[0].name.to_s, items: items)
|
|
119
119
|
|
|
120
120
|
when node.type == :send && node.children[0] && at_end?(position, of: node.loc.selector)
|
|
121
121
|
# foo.ba ←
|
|
122
|
-
context = typing.context_of(node: node)
|
|
123
122
|
receiver_type = case (type = typing.type_of(node: node.children[0]))
|
|
124
123
|
when AST::Types::Self
|
|
125
124
|
context.self_type
|
|
@@ -136,7 +135,6 @@ module Steep
|
|
|
136
135
|
|
|
137
136
|
when node.type == :const && node.children[0] == nil && at_end?(position, of: node.loc)
|
|
138
137
|
# Foo ← (const)
|
|
139
|
-
context = typing.context_of(node: node)
|
|
140
138
|
prefix = node.children[1].to_s
|
|
141
139
|
|
|
142
140
|
method_items_for_receiver_type(context.self_type,
|
|
@@ -147,7 +145,6 @@ module Steep
|
|
|
147
145
|
|
|
148
146
|
when node.type == :send && at_end?(position, of: node.loc.dot)
|
|
149
147
|
# foo.← ba
|
|
150
|
-
context = typing.context_of(node: node)
|
|
151
148
|
receiver_type = case (type = typing.type_of(node: node.children[0]))
|
|
152
149
|
when AST::Types::Self
|
|
153
150
|
context.self_type
|
|
@@ -163,12 +160,9 @@ module Steep
|
|
|
163
160
|
|
|
164
161
|
when node.type == :ivar && at_end?(position, of: node.loc)
|
|
165
162
|
# @fo ←
|
|
166
|
-
context = typing.context_of(node: node)
|
|
167
163
|
instance_variable_items_for_context(context, position: position, prefix: node.children[0].to_s, items: items)
|
|
168
164
|
|
|
169
165
|
else
|
|
170
|
-
context = typing.context_of(node: node)
|
|
171
|
-
|
|
172
166
|
method_items_for_receiver_type(context.self_type,
|
|
173
167
|
include_private: true,
|
|
174
168
|
prefix: "",
|
|
@@ -190,7 +184,7 @@ module Steep
|
|
|
190
184
|
return [] unless node
|
|
191
185
|
|
|
192
186
|
if at_end?(shift_pos, of: node.loc)
|
|
193
|
-
context = typing.
|
|
187
|
+
context = typing.context_at(line: position.line, column: position.column)
|
|
194
188
|
receiver_type = case (type = typing.type_of(node: node))
|
|
195
189
|
when AST::Types::Self
|
|
196
190
|
context.self_type
|
|
@@ -218,7 +212,7 @@ module Steep
|
|
|
218
212
|
|
|
219
213
|
return [] unless node
|
|
220
214
|
|
|
221
|
-
context = typing.
|
|
215
|
+
context = typing.context_at(line: position.line, column: position.column)
|
|
222
216
|
items = []
|
|
223
217
|
instance_variable_items_for_context(context, prefix: "", position: position, items: items)
|
|
224
218
|
items
|
|
@@ -263,7 +257,7 @@ module Steep
|
|
|
263
257
|
|
|
264
258
|
def local_variable_items_for_context(context, position:, prefix:, items:)
|
|
265
259
|
range = range_for(position, prefix: prefix)
|
|
266
|
-
context.
|
|
260
|
+
context.lvar_env.each do |name, type|
|
|
267
261
|
if name.to_s.start_with?(prefix)
|
|
268
262
|
items << LocalVariableItem.new(identifier: name,
|
|
269
263
|
range: range,
|
data/lib/steep/project/dsl.rb
CHANGED
|
@@ -9,6 +9,7 @@ module Steep
|
|
|
9
9
|
attr_reader :ignored_sources
|
|
10
10
|
attr_reader :no_builtin
|
|
11
11
|
attr_reader :vendor_dir
|
|
12
|
+
attr_reader :strictness_level
|
|
12
13
|
|
|
13
14
|
def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources: [])
|
|
14
15
|
@name = name
|
|
@@ -17,6 +18,7 @@ module Steep
|
|
|
17
18
|
@signatures = signatures
|
|
18
19
|
@ignored_sources = ignored_sources
|
|
19
20
|
@vendor_dir = nil
|
|
21
|
+
@strictness_level = :default
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def initialize_copy(other)
|
|
@@ -26,6 +28,7 @@ module Steep
|
|
|
26
28
|
@signatures = other.signatures.dup
|
|
27
29
|
@ignored_sources = other.ignored_sources.dup
|
|
28
30
|
@vendor_dir = other.vendor_dir
|
|
31
|
+
@strictness_level = other.strictness_level
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
def check(*args)
|
|
@@ -40,6 +43,10 @@ module Steep
|
|
|
40
43
|
libraries.push(*args)
|
|
41
44
|
end
|
|
42
45
|
|
|
46
|
+
def typing_options(level)
|
|
47
|
+
@strictness_level = level
|
|
48
|
+
end
|
|
49
|
+
|
|
43
50
|
def signature(*args)
|
|
44
51
|
signatures.push(*args)
|
|
45
52
|
end
|
|
@@ -114,6 +121,13 @@ module Steep
|
|
|
114
121
|
options: Options.new.tap do |options|
|
|
115
122
|
options.libraries.push(*target.libraries)
|
|
116
123
|
|
|
124
|
+
case target.strictness_level
|
|
125
|
+
when :strict
|
|
126
|
+
options.apply_strict_typing_options!
|
|
127
|
+
when :lenient
|
|
128
|
+
options.apply_lenient_typing_options!
|
|
129
|
+
end
|
|
130
|
+
|
|
117
131
|
case target.vendor_dir
|
|
118
132
|
when Array
|
|
119
133
|
options.vendored_stdlib_path = target.vendor_dir[0]
|