steep 1.2.0 → 1.3.0.pre.1
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 +23 -2
- data/Gemfile.lock +14 -4
- data/Gemfile.steep +2 -2
- data/Gemfile.steep.lock +17 -5
- data/Steepfile +7 -9
- data/lib/steep/annotation_parser.rb +34 -28
- data/lib/steep/ast/annotation.rb +16 -5
- data/lib/steep/ast/node/type_application.rb +74 -0
- data/lib/steep/ast/node/type_assertion.rb +56 -0
- data/lib/steep/ast/types/factory.rb +5 -1
- data/lib/steep/diagnostic/helper.rb +2 -1
- data/lib/steep/diagnostic/lsp_formatter.rb +3 -1
- data/lib/steep/diagnostic/ruby.rb +70 -5
- data/lib/steep/diagnostic/signature.rb +21 -8
- data/lib/steep/drivers/check.rb +1 -1
- data/lib/steep/drivers/checkfile.rb +1 -1
- data/lib/steep/drivers/langserver.rb +2 -2
- data/lib/steep/drivers/stats.rb +1 -1
- data/lib/steep/drivers/watch.rb +1 -1
- data/lib/steep/drivers/worker.rb +0 -1
- data/lib/steep/server/lsp_formatter.rb +13 -3
- data/lib/steep/server/master.rb +4 -1
- data/lib/steep/server/worker_process.rb +86 -14
- data/lib/steep/services/hover_provider/rbs.rb +7 -7
- data/lib/steep/services/hover_provider/ruby.rb +19 -4
- data/lib/steep/services/signature_service.rb +7 -4
- data/lib/steep/signature/validator.rb +36 -13
- data/lib/steep/source.rb +189 -71
- data/lib/steep/type_construction.rb +232 -126
- data/lib/steep/type_inference/logic_type_interpreter.rb +31 -5
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +2 -0
- data/rbs_collection.steep.lock.yaml +52 -11
- data/rbs_collection.steep.yaml +1 -1
- data/sig/shims/exception.rbs +4 -0
- data/sig/shims/parser/comment.rbs +33 -0
- data/sig/shims/parser.rbs +30 -2
- data/sig/steep/annotation_parser.rbs +59 -0
- data/sig/steep/ast/annotation.rbs +21 -26
- data/sig/steep/ast/node/type_application.rbs +31 -0
- data/sig/steep/ast/node/type_assertion.rbs +26 -0
- data/sig/steep/ast/types/factory.rbs +0 -2
- data/sig/steep/diagnostic/helper.rbs +9 -3
- data/sig/steep/diagnostic/lsp_formatter.rbs +12 -8
- data/sig/steep/diagnostic/ruby.rbs +62 -8
- data/sig/steep/diagnostic/signature.rbs +118 -85
- data/sig/steep/drivers/worker.rbs +11 -13
- data/sig/steep/range_extension.rbs +7 -0
- data/sig/steep/server/lsp_formatter.rbs +14 -7
- data/sig/steep/server/worker_process.rbs +74 -12
- data/sig/steep/services/hover_provider/rbs.rbs +27 -7
- data/sig/steep/services/hover_provider/ruby.rbs +18 -4
- data/sig/steep/services/hover_provider/singleton_methods.rbs +1 -1
- data/sig/steep/signature/validator.rbs +76 -0
- data/sig/steep/source.rbs +54 -30
- data/sig/steep/type_construction.rbs +85 -27
- data/sig/steep/type_inference/method_call.rbs +1 -1
- data/smoke/diagnostics-rbs/inherit-module.rbs +2 -0
- data/smoke/diagnostics-rbs/test_expectations.yml +12 -0
- data/steep.gemspec +6 -1
- metadata +86 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f43e7d3a3abaa803d24bb2ef587d495e1d000380e9a4de2318d6371403a70238
|
4
|
+
data.tar.gz: d5fd761223ef4dcc6dcc4e76f3eb952a5dab19a5713e73e024871043ae6fbab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 243b110b292f2da9dbde2f348aa9dd23353da8dc0854776cb10f74f21e97103af23f868eff56b48a78c9e400399858062b2d07a72ddb78493abcc33f8bd2fe1d
|
7
|
+
data.tar.gz: 36e71cdf0113ff3b4d3946cf44befd945e8304b0deb16478762f90aa4f7f6a58bca28cc0f09f70155196fc116ea39164543b254a870b4e8c81cb203b6980cbfd
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.3.0.pre.1 (2022-11-22)
|
6
|
+
|
7
|
+
### Type checker core
|
8
|
+
|
9
|
+
* Add type assertion syntax ([#665](https://github.com/soutaro/steep/pull/665))
|
10
|
+
* Add type application syntax ([#670](https://github.com/soutaro/steep/pull/670))
|
11
|
+
|
12
|
+
### Commandline tool
|
13
|
+
|
14
|
+
* Fork when available for quicker startup ([#664](https://github.com/soutaro/steep/pull/664))
|
15
|
+
|
16
|
+
### Miscellaneous
|
17
|
+
|
18
|
+
* Fixes for some RBS errors within steep gem ([#668](https://github.com/soutaro/steep/pull/668))
|
19
|
+
* Upgrade to RBS 2.8 (pre) ([#669](https://github.com/soutaro/steep/pull/669))
|
20
|
+
|
21
|
+
## 1.2.1 (2022-10-22)
|
22
|
+
|
23
|
+
### Type checker core
|
24
|
+
|
25
|
+
* Fix type narrowing on case-when ([#662](https://github.com/soutaro/steep/pull/662))
|
26
|
+
|
5
27
|
## 1.2.0 (2022-10-08)
|
6
28
|
|
7
29
|
### Commandline tool
|
@@ -20,8 +42,7 @@
|
|
20
42
|
* Support type checking block/proc self type binding ([#637](https://github.com/soutaro/steep/pull/637))
|
21
43
|
* Type check multiple assignment on block parameters ([#641](https://github.com/soutaro/steep/pull/641), [#643](https://github.com/soutaro/steep/pull/643))
|
22
44
|
* Make more multiple assignments type check ([#630](https://github.com/soutaro/steep/pull/630))
|
23
|
-
* Refactor *shape* calculation ([#635](https://github.com/soutaro/steep/pull/635), [#649
|
24
|
-
](https://github.com/soutaro/steep/pull/649))
|
45
|
+
* Refactor *shape* calculation ([#635](https://github.com/soutaro/steep/pull/635), [#649](https://github.com/soutaro/steep/pull/649))
|
25
46
|
* Report type errors if argument mismatch on yield ([#640](https://github.com/soutaro/steep/pull/640))
|
26
47
|
* Relax caching requirements to cache more results ([#651](https://github.com/soutaro/steep/pull/651))
|
27
48
|
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
steep (1.
|
4
|
+
steep (1.3.0.pre.1)
|
5
5
|
activesupport (>= 5.1)
|
6
|
+
csv (>= 3.0.9)
|
7
|
+
fileutils (>= 1.1.0)
|
8
|
+
json (>= 2.1.0)
|
6
9
|
language_server-protocol (>= 3.15, < 4.0)
|
7
10
|
listen (~> 3.0)
|
11
|
+
logger (>= 1.3.0)
|
8
12
|
parallel (>= 1.0.0)
|
9
13
|
parser (>= 3.1)
|
10
14
|
rainbow (>= 2.2.2, < 4.0)
|
11
|
-
rbs (>= 2.
|
15
|
+
rbs (>= 2.8.0.pre)
|
12
16
|
securerandom (>= 0.1)
|
17
|
+
strscan (>= 1.0.0)
|
13
18
|
terminal-table (>= 2, < 4)
|
14
19
|
|
15
20
|
GEM
|
@@ -22,16 +27,20 @@ GEM
|
|
22
27
|
tzinfo (~> 2.0)
|
23
28
|
ast (2.4.2)
|
24
29
|
concurrent-ruby (1.1.10)
|
30
|
+
csv (3.2.5)
|
25
31
|
debase (0.2.5.beta2)
|
26
32
|
debase-ruby_core_source (>= 0.10.12)
|
27
33
|
debase-ruby_core_source (0.10.16)
|
28
34
|
ffi (1.15.5)
|
35
|
+
fileutils (1.6.0)
|
29
36
|
i18n (1.12.0)
|
30
37
|
concurrent-ruby (~> 1.0)
|
38
|
+
json (2.6.2)
|
31
39
|
language_server-protocol (3.17.0.1)
|
32
40
|
listen (3.7.1)
|
33
41
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
34
42
|
rb-inotify (~> 0.9, >= 0.9.10)
|
43
|
+
logger (1.5.1)
|
35
44
|
minitest (5.16.3)
|
36
45
|
minitest-hooks (1.5.0)
|
37
46
|
minitest (> 5.3)
|
@@ -45,11 +54,12 @@ GEM
|
|
45
54
|
rb-fsevent (0.11.2)
|
46
55
|
rb-inotify (0.10.1)
|
47
56
|
ffi (~> 1.0)
|
48
|
-
rbs (2.
|
57
|
+
rbs (2.8.0.pre.1)
|
49
58
|
ruby-debug-ide (0.7.3)
|
50
59
|
rake (>= 0.8.1)
|
51
60
|
securerandom (0.2.0)
|
52
|
-
stackprof (0.2.
|
61
|
+
stackprof (0.2.22)
|
62
|
+
strscan (3.0.4)
|
53
63
|
terminal-table (3.0.2)
|
54
64
|
unicode-display_width (>= 1.1.1, < 3)
|
55
65
|
tzinfo (2.0.5)
|
data/Gemfile.steep
CHANGED
data/Gemfile.steep.lock
CHANGED
@@ -8,13 +8,17 @@ GEM
|
|
8
8
|
tzinfo (~> 2.0)
|
9
9
|
ast (2.4.2)
|
10
10
|
concurrent-ruby (1.1.10)
|
11
|
+
csv (3.2.5)
|
11
12
|
ffi (1.15.5)
|
13
|
+
fileutils (1.6.0)
|
12
14
|
i18n (1.12.0)
|
13
15
|
concurrent-ruby (~> 1.0)
|
16
|
+
json (2.6.2)
|
14
17
|
language_server-protocol (3.17.0.1)
|
15
18
|
listen (3.7.1)
|
16
19
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
17
20
|
rb-inotify (~> 0.9, >= 0.9.10)
|
21
|
+
logger (1.5.1)
|
18
22
|
minitest (5.16.3)
|
19
23
|
parallel (1.22.1)
|
20
24
|
parser (3.1.2.1)
|
@@ -23,16 +27,24 @@ GEM
|
|
23
27
|
rb-fsevent (0.11.2)
|
24
28
|
rb-inotify (0.10.1)
|
25
29
|
ffi (~> 1.0)
|
26
|
-
rbs (2.
|
27
|
-
|
30
|
+
rbs (2.8.0.pre.1)
|
31
|
+
securerandom (0.2.0)
|
32
|
+
steep (1.2.1)
|
28
33
|
activesupport (>= 5.1)
|
34
|
+
csv (>= 3.0.9)
|
35
|
+
fileutils (>= 1.1.0)
|
36
|
+
json (>= 2.1.0)
|
29
37
|
language_server-protocol (>= 3.15, < 4.0)
|
30
38
|
listen (~> 3.0)
|
39
|
+
logger (>= 1.3.0)
|
31
40
|
parallel (>= 1.0.0)
|
32
41
|
parser (>= 3.1)
|
33
42
|
rainbow (>= 2.2.2, < 4.0)
|
34
|
-
rbs (>= 2.
|
43
|
+
rbs (>= 2.7.0)
|
44
|
+
securerandom (>= 0.1)
|
45
|
+
strscan (>= 1.0.0)
|
35
46
|
terminal-table (>= 2, < 4)
|
47
|
+
strscan (3.0.4)
|
36
48
|
terminal-table (3.0.2)
|
37
49
|
unicode-display_width (>= 1.1.1, < 3)
|
38
50
|
tzinfo (2.0.5)
|
@@ -43,8 +55,8 @@ PLATFORMS
|
|
43
55
|
arm64-darwin-21
|
44
56
|
|
45
57
|
DEPENDENCIES
|
46
|
-
rbs (~> 2.
|
47
|
-
steep (~> 1.
|
58
|
+
rbs (~> 2.8.0.pre)
|
59
|
+
steep (~> 1.2.0)
|
48
60
|
|
49
61
|
BUNDLED WITH
|
50
62
|
2.3.15
|
data/Steepfile
CHANGED
@@ -1,30 +1,28 @@
|
|
1
|
+
D = Steep::Diagnostic
|
2
|
+
|
1
3
|
target :app do
|
2
4
|
check "lib"
|
3
5
|
signature "sig"
|
4
6
|
|
5
7
|
collection_config "rbs_collection.steep.yaml"
|
6
8
|
|
7
|
-
|
9
|
+
configure_code_diagnostics do |hash| # You can setup everything yourself
|
10
|
+
hash[D::Ruby::MethodDefinitionMissing] = :hint
|
11
|
+
end
|
12
|
+
|
8
13
|
library(
|
9
14
|
"set",
|
10
15
|
"pathname",
|
11
|
-
"json",
|
12
|
-
"logger",
|
13
16
|
"monitor",
|
14
17
|
"tsort",
|
15
18
|
"uri",
|
16
19
|
'yaml',
|
17
|
-
'dbm',
|
18
20
|
'pstore',
|
19
21
|
'singleton',
|
20
22
|
'shellwords',
|
21
|
-
'fileutils',
|
22
23
|
'find',
|
23
24
|
'digest',
|
24
|
-
"strscan",
|
25
|
-
"rubygems",
|
26
25
|
"optparse",
|
27
|
-
"securerandom"
|
28
|
-
"csv"
|
26
|
+
"securerandom"
|
29
27
|
)
|
30
28
|
end
|
@@ -27,7 +27,7 @@ module Steep
|
|
27
27
|
message = case exn
|
28
28
|
when RBS::ParsingError
|
29
29
|
Diagnostic::Signature::SyntaxError.parser_syntax_error_message(exn)
|
30
|
-
|
30
|
+
when Exception
|
31
31
|
exn.message
|
32
32
|
end
|
33
33
|
|
@@ -45,16 +45,10 @@ module Steep
|
|
45
45
|
factory.type(RBS::Parser.parse_type(string))
|
46
46
|
end
|
47
47
|
|
48
|
-
# @type ${keyword} ${name}: ${type}
|
49
|
-
# Example: @type const Foo::Bar: String
|
50
|
-
# @type var xyzzy: Array[String]
|
51
48
|
def keyword_subject_type(keyword, name)
|
52
49
|
/@type\s+#{keyword}\s+(?<name>#{name})#{COLON}#{TYPE}/
|
53
50
|
end
|
54
51
|
|
55
|
-
# @type ${keyword}: ${type}
|
56
|
-
# Example: @type break: String
|
57
|
-
# @type self: Foo
|
58
52
|
def keyword_and_type(keyword)
|
59
53
|
/@type\s+#{keyword}#{COLON}#{TYPE}/
|
60
54
|
end
|
@@ -63,8 +57,9 @@ module Steep
|
|
63
57
|
case src
|
64
58
|
when keyword_subject_type("var", VAR_NAME)
|
65
59
|
Regexp.last_match.yield_self do |match|
|
66
|
-
|
67
|
-
|
60
|
+
match or raise
|
61
|
+
name = match[:name] or raise
|
62
|
+
type = match[:type] or raise
|
68
63
|
|
69
64
|
AST::Annotation::VarType.new(name: name.to_sym,
|
70
65
|
type: parse_type(type),
|
@@ -73,8 +68,9 @@ module Steep
|
|
73
68
|
|
74
69
|
when keyword_subject_type("method", METHOD_NAME)
|
75
70
|
Regexp.last_match.yield_self do |match|
|
76
|
-
|
77
|
-
|
71
|
+
match or raise
|
72
|
+
name = match[:name] or raise
|
73
|
+
type = match[:type] or raise
|
78
74
|
|
79
75
|
method_type = factory.method_type(RBS::Parser.parse_method_type(type), method_decls: Set[])
|
80
76
|
|
@@ -85,16 +81,18 @@ module Steep
|
|
85
81
|
|
86
82
|
when keyword_subject_type("const", CONST_NAME)
|
87
83
|
Regexp.last_match.yield_self do |match|
|
88
|
-
|
89
|
-
|
84
|
+
match or raise
|
85
|
+
name = match[:name] or raise
|
86
|
+
type = parse_type(match[:type] || raise)
|
90
87
|
|
91
88
|
AST::Annotation::ConstType.new(name: TypeName(name), type: type, location: location)
|
92
89
|
end
|
93
90
|
|
94
91
|
when keyword_subject_type("ivar", IVAR_NAME)
|
95
92
|
Regexp.last_match.yield_self do |match|
|
96
|
-
|
97
|
-
|
93
|
+
match or raise
|
94
|
+
name = match[:name] or raise
|
95
|
+
type = parse_type(match[:type] || raise)
|
98
96
|
|
99
97
|
AST::Annotation::IvarType.new(name: name.to_sym,
|
100
98
|
type: type,
|
@@ -103,51 +101,58 @@ module Steep
|
|
103
101
|
|
104
102
|
when keyword_and_type("return")
|
105
103
|
Regexp.last_match.yield_self do |match|
|
106
|
-
|
104
|
+
match or raise
|
105
|
+
type = parse_type(match[:type] || raise)
|
107
106
|
AST::Annotation::ReturnType.new(type: type, location: location)
|
108
107
|
end
|
109
108
|
|
110
109
|
when keyword_and_type("block")
|
111
110
|
Regexp.last_match.yield_self do |match|
|
112
|
-
|
111
|
+
match or raise
|
112
|
+
type = parse_type(match[:type] || raise)
|
113
113
|
AST::Annotation::BlockType.new(type: type, location: location)
|
114
114
|
end
|
115
115
|
|
116
116
|
when keyword_and_type("self")
|
117
117
|
Regexp.last_match.yield_self do |match|
|
118
|
-
|
118
|
+
match or raise
|
119
|
+
type = parse_type(match[:type] || raise)
|
119
120
|
AST::Annotation::SelfType.new(type: type, location: location)
|
120
121
|
end
|
121
122
|
|
122
123
|
when keyword_and_type("instance")
|
123
124
|
Regexp.last_match.yield_self do |match|
|
124
|
-
|
125
|
+
match or raise
|
126
|
+
type = parse_type(match[:type] || raise)
|
125
127
|
AST::Annotation::InstanceType.new(type: type, location: location)
|
126
128
|
end
|
127
129
|
|
128
130
|
when keyword_and_type("module")
|
129
131
|
Regexp.last_match.yield_self do |match|
|
130
|
-
|
132
|
+
match or raise
|
133
|
+
type = parse_type(match[:type] || raise)
|
131
134
|
AST::Annotation::ModuleType.new(type: type, location: location)
|
132
135
|
end
|
133
136
|
|
134
137
|
when keyword_and_type("break")
|
135
138
|
Regexp.last_match.yield_self do |match|
|
136
|
-
|
139
|
+
match or raise
|
140
|
+
type = parse_type(match[:type] || raise)
|
137
141
|
AST::Annotation::BreakType.new(type: type, location: location)
|
138
142
|
end
|
139
143
|
|
140
144
|
when /@dynamic\s+(?<names>(#{DYNAMIC_NAME}\s*,\s*)*#{DYNAMIC_NAME})/
|
141
145
|
Regexp.last_match.yield_self do |match|
|
142
|
-
|
146
|
+
match or raise
|
147
|
+
names = (match[:names] || raise).split(/\s*,\s*/)
|
143
148
|
|
144
149
|
AST::Annotation::Dynamic.new(
|
145
150
|
names: names.map {|name|
|
146
|
-
case
|
147
|
-
when
|
148
|
-
AST::Annotation::Dynamic::Name.new(name: name
|
149
|
-
when
|
150
|
-
AST::Annotation::Dynamic::Name.new(name: name
|
151
|
+
case
|
152
|
+
when name.delete_prefix!("self.")
|
153
|
+
AST::Annotation::Dynamic::Name.new(name: name.to_sym, kind: :module)
|
154
|
+
when name.delete_prefix!("self?.")
|
155
|
+
AST::Annotation::Dynamic::Name.new(name: name.to_sym, kind: :module_instance)
|
151
156
|
else
|
152
157
|
AST::Annotation::Dynamic::Name.new(name: name.to_sym, kind: :instance)
|
153
158
|
end
|
@@ -158,7 +163,8 @@ module Steep
|
|
158
163
|
|
159
164
|
when /@implements\s+(?<name>#{CONST_NAME})#{TYPE_PARAMS}$/
|
160
165
|
Regexp.last_match.yield_self do |match|
|
161
|
-
|
166
|
+
match or raise
|
167
|
+
type_name = TypeName(match[:name] || raise)
|
162
168
|
params = match[:params]&.yield_self {|params| params.split(/,/).map {|param| param.strip.to_sym } } || []
|
163
169
|
|
164
170
|
name = AST::Annotation::Implements::Module.new(name: type_name, args: params)
|
data/lib/steep/ast/annotation.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
module Steep
|
2
2
|
module AST
|
3
3
|
module Annotation
|
4
|
+
module Located
|
5
|
+
attr_reader :location
|
6
|
+
|
7
|
+
def line
|
8
|
+
location&.start_line
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
class Named
|
13
|
+
include Located
|
14
|
+
|
5
15
|
attr_reader :name
|
6
16
|
attr_reader :type
|
7
|
-
attr_reader :location
|
8
17
|
|
9
18
|
def initialize(name:, type:, location: nil)
|
10
19
|
@name = name
|
@@ -20,9 +29,9 @@ module Steep
|
|
20
29
|
end
|
21
30
|
|
22
31
|
class Typed
|
32
|
+
include Located
|
33
|
+
|
23
34
|
attr_reader :type
|
24
|
-
attr_reader :annotation
|
25
|
-
attr_reader :location
|
26
35
|
|
27
36
|
def initialize(type:, location: nil)
|
28
37
|
@type = type
|
@@ -68,7 +77,8 @@ module Steep
|
|
68
77
|
end
|
69
78
|
end
|
70
79
|
|
71
|
-
|
80
|
+
include Located
|
81
|
+
|
72
82
|
attr_reader :name
|
73
83
|
|
74
84
|
def initialize(name:, location: nil)
|
@@ -108,7 +118,8 @@ module Steep
|
|
108
118
|
end
|
109
119
|
end
|
110
120
|
|
111
|
-
|
121
|
+
include Located
|
122
|
+
|
112
123
|
attr_reader :names
|
113
124
|
|
114
125
|
def initialize(names:, location: nil)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Steep
|
2
|
+
module AST
|
3
|
+
module Node
|
4
|
+
class TypeApplication
|
5
|
+
attr_reader :location
|
6
|
+
|
7
|
+
def initialize(location)
|
8
|
+
@location = location
|
9
|
+
end
|
10
|
+
|
11
|
+
def node
|
12
|
+
@node || raise
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_node(node)
|
16
|
+
@node = node
|
17
|
+
end
|
18
|
+
|
19
|
+
def line
|
20
|
+
location.start_line
|
21
|
+
end
|
22
|
+
|
23
|
+
def source
|
24
|
+
location.source
|
25
|
+
end
|
26
|
+
|
27
|
+
def types(context, factory, type_vars)
|
28
|
+
# @type var types: Array[Types::t]
|
29
|
+
types = []
|
30
|
+
|
31
|
+
loc = type_location
|
32
|
+
|
33
|
+
while true
|
34
|
+
ty = RBS::Parser.parse_type(loc.buffer, range: loc.range, variables: type_vars) or break
|
35
|
+
ty = factory.type(ty)
|
36
|
+
types << factory.absolute_type(ty, context: context)
|
37
|
+
|
38
|
+
match = RBS::Location.new(loc.buffer, ty.location.end_pos, type_location.end_pos).source.match(/\A\s*,\s*/) or break
|
39
|
+
offset = match.length
|
40
|
+
loc = RBS::Location.new(loc.buffer, ty.location.end_pos + offset, type_location.end_pos)
|
41
|
+
end
|
42
|
+
|
43
|
+
types
|
44
|
+
rescue ::RBS::ParsingError => exn
|
45
|
+
exn
|
46
|
+
end
|
47
|
+
|
48
|
+
def types?(context, factory, type_vars)
|
49
|
+
case types = types(context, factory, type_vars)
|
50
|
+
when RBS::ParsingError
|
51
|
+
nil
|
52
|
+
else
|
53
|
+
types
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def type_str
|
58
|
+
@type_str ||= source.delete_prefix("$").lstrip
|
59
|
+
end
|
60
|
+
|
61
|
+
def type_location
|
62
|
+
offset = source.size - type_str.size
|
63
|
+
RBS::Location.new(location.buffer, location.start_pos + offset, location.end_pos)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.parse(location)
|
67
|
+
if location.source =~/\A\$\s*(.+)/
|
68
|
+
TypeApplication.new(location)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Steep
|
2
|
+
module AST
|
3
|
+
module Node
|
4
|
+
class TypeAssertion
|
5
|
+
attr_reader :location
|
6
|
+
|
7
|
+
def initialize(location)
|
8
|
+
@location = location
|
9
|
+
end
|
10
|
+
|
11
|
+
def source
|
12
|
+
location.source
|
13
|
+
end
|
14
|
+
|
15
|
+
def line
|
16
|
+
location.start_line
|
17
|
+
end
|
18
|
+
|
19
|
+
def type(context, factory, type_vars)
|
20
|
+
if ty = RBS::Parser.parse_type(type_location.buffer, range: type_location.range, variables: type_vars)
|
21
|
+
ty = factory.type(ty)
|
22
|
+
factory.absolute_type(ty, context: context)
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
rescue ::RBS::ParsingError => exn
|
27
|
+
exn
|
28
|
+
end
|
29
|
+
|
30
|
+
def type?(context, factory, type_vars)
|
31
|
+
case type = type(context, factory, type_vars)
|
32
|
+
when RBS::ParsingError
|
33
|
+
nil
|
34
|
+
else
|
35
|
+
type
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def type_str
|
40
|
+
@type_str ||= source.delete_prefix(":").lstrip
|
41
|
+
end
|
42
|
+
|
43
|
+
def type_location
|
44
|
+
offset = source.size - type_str.size
|
45
|
+
RBS::Location.new(location.buffer, location.start_pos + offset, location.end_pos)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.parse(location)
|
49
|
+
if location.source =~/\A:\s*(.+)/
|
50
|
+
TypeAssertion.new(location)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -41,11 +41,13 @@ module Steep
|
|
41
41
|
severity = severity_for(diagnostic)
|
42
42
|
|
43
43
|
if severity
|
44
|
+
range = diagnostic.location&.as_lsp_range or raise
|
45
|
+
|
44
46
|
LSP::Interface::Diagnostic.new(
|
45
47
|
message: diagnostic.full_message,
|
46
48
|
code: diagnostic.diagnostic_code,
|
47
49
|
severity: severity,
|
48
|
-
range:
|
50
|
+
range: range
|
49
51
|
).to_hash
|
50
52
|
end
|
51
53
|
end
|