steep 1.4.0 → 1.5.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.vscode/steep-shared.code-snippets +41 -0
- data/CHANGELOG.md +37 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +20 -17
- data/Gemfile.steep +1 -1
- data/Gemfile.steep.lock +6 -6
- data/Rakefile +198 -0
- data/Steepfile +3 -1
- data/lib/steep/ast/builtin.rb +9 -7
- data/lib/steep/ast/node/type_application.rb +13 -5
- data/lib/steep/ast/node/type_assertion.rb +28 -9
- data/lib/steep/ast/types/factory.rb +39 -7
- data/lib/steep/cli.rb +2 -1
- data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
- data/lib/steep/diagnostic/lsp_formatter.rb +3 -3
- data/lib/steep/diagnostic/ruby.rb +73 -12
- data/lib/steep/drivers/annotations.rb +1 -0
- data/lib/steep/drivers/check.rb +18 -13
- data/lib/steep/drivers/checkfile.rb +1 -1
- data/lib/steep/drivers/diagnostic_printer.rb +6 -4
- data/lib/steep/drivers/init.rb +2 -1
- data/lib/steep/drivers/print_project.rb +3 -1
- data/lib/steep/drivers/stats.rb +1 -1
- data/lib/steep/drivers/utils/driver_helper.rb +10 -8
- data/lib/steep/drivers/utils/jobs_option.rb +6 -1
- data/lib/steep/drivers/validate.rb +9 -5
- data/lib/steep/drivers/watch.rb +8 -3
- data/lib/steep/expectations.rb +144 -75
- data/lib/steep/index/signature_symbol_provider.rb +22 -13
- data/lib/steep/node_helper.rb +172 -0
- data/lib/steep/server/base_worker.rb +2 -1
- data/lib/steep/server/change_buffer.rb +17 -15
- data/lib/steep/server/interaction_worker.rb +20 -0
- data/lib/steep/server/lsp_formatter.rb +20 -1
- data/lib/steep/server/master.rb +51 -36
- data/lib/steep/server/type_check_worker.rb +18 -2
- data/lib/steep/server/worker_process.rb +19 -2
- data/lib/steep/services/completion_provider.rb +189 -3
- data/lib/steep/services/file_loader.rb +1 -1
- data/lib/steep/services/goto_service.rb +123 -27
- data/lib/steep/services/signature_help_provider.rb +1 -6
- data/lib/steep/signature/validator.rb +6 -1
- data/lib/steep/source.rb +165 -108
- data/lib/steep/subtyping/check.rb +5 -3
- data/lib/steep/subtyping/variable_variance.rb +11 -0
- data/lib/steep/thread_waiter.rb +35 -0
- data/lib/steep/type_construction.rb +416 -171
- data/lib/steep/type_inference/block_params.rb +50 -9
- data/lib/steep/type_inference/context.rb +4 -0
- data/lib/steep/type_inference/context_array.rb +6 -6
- data/lib/steep/type_inference/logic_type_interpreter.rb +202 -68
- data/lib/steep/typing.rb +5 -4
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +21 -14
- data/sample/Steepfile +1 -0
- data/sig/shims/bundler.rbs +3 -0
- data/sig/shims/language-server_protocol.rbs +151 -10
- data/sig/shims/parser/nodes.rbs +210 -0
- data/sig/shims/parser.rbs +10 -0
- data/sig/steep/ast/builtin.rbs +2 -2
- data/sig/steep/ast/node/type_application.rbs +2 -2
- data/sig/steep/ast/node/type_assertion.rbs +8 -2
- data/sig/steep/ast/types/factory.rbs +28 -1
- data/sig/steep/diagnostic/deprecated/else_on_exhaustive_case.rbs +13 -0
- data/sig/steep/diagnostic/lsp_formatter.rbs +5 -2
- data/sig/steep/diagnostic/ruby.rbs +76 -6
- data/sig/steep/drivers/annotations.rbs +5 -5
- data/sig/steep/drivers/check.rbs +11 -11
- data/sig/steep/drivers/diagnostic_printer.rbs +9 -9
- data/sig/steep/drivers/init.rbs +6 -6
- data/sig/steep/drivers/print_project.rbs +4 -4
- data/sig/steep/drivers/utils/driver_helper.rbs +8 -6
- data/sig/steep/drivers/validate.rbs +4 -4
- data/sig/steep/drivers/watch.rbs +1 -1
- data/sig/steep/expectations.rbs +72 -0
- data/sig/steep/index/signature_symbol_provider.rbs +22 -10
- data/sig/steep/interface/block.rbs +2 -0
- data/sig/steep/interface/function.rbs +2 -2
- data/sig/steep/node_helper.rbs +56 -0
- data/sig/steep/path_helper.rbs +1 -1
- data/sig/steep/project/options.rbs +1 -1
- data/sig/steep/range_extension.rbs +2 -2
- data/sig/steep/server/master.rbs +16 -2
- data/sig/steep/server/type_check_worker.rbs +5 -1
- data/sig/steep/server/worker_process.rbs +5 -1
- data/sig/steep/services/completion_provider.rbs +31 -1
- data/sig/steep/services/goto_service.rbs +80 -19
- data/sig/steep/source.rbs +27 -4
- data/sig/steep/subtyping/variable_variance.rbs +9 -9
- data/sig/steep/thread_waiter.rbs +13 -0
- data/sig/steep/type_construction.rbs +26 -9
- data/sig/steep/type_inference/block_params.rbs +13 -1
- data/sig/steep/type_inference/context.rbs +5 -1
- data/sig/steep/type_inference/context_array.rbs +16 -15
- data/sig/steep/type_inference/logic_type_interpreter.rbs +36 -6
- data/sig/steep/type_inference/type_env_builder.rbs +4 -0
- data/sig/steep/typing.rbs +22 -20
- data/sig/steep.rbs +14 -13
- data/smoke/and/a.rb +1 -1
- data/smoke/and/test_expectations.yml +5 -7
- data/smoke/diagnostics/incompatible_annotation.rb +1 -1
- data/smoke/diagnostics/test_expectations.yml +2 -2
- data/smoke/enumerator/a.rb +0 -7
- data/smoke/enumerator/b.rb +0 -2
- data/smoke/enumerator/test_expectations.yml +17 -105
- data/smoke/lambda/a.rb +0 -5
- data/smoke/lambda/test_expectations.yml +0 -22
- data/smoke/type_case/test_expectations.yml +10 -0
- data/steep.gemspec +2 -2
- metadata +16 -9
data/lib/steep.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "steep/version"
|
2
2
|
|
3
3
|
require "pathname"
|
4
|
-
require "parser/
|
4
|
+
require "parser/ruby32"
|
5
5
|
require "active_support"
|
6
6
|
require "active_support/core_ext/object/try"
|
7
7
|
require "active_support/core_ext/string/inflections"
|
@@ -26,6 +26,7 @@ require "steep/path_helper"
|
|
26
26
|
require "steep/shims/filter_map"
|
27
27
|
require "steep/shims/symbol_start_with"
|
28
28
|
|
29
|
+
require "steep/thread_waiter"
|
29
30
|
require "steep/equatable"
|
30
31
|
require "steep/method_name"
|
31
32
|
require "steep/node_helper"
|
@@ -168,6 +169,7 @@ module Steep
|
|
168
169
|
@log_output = output
|
169
170
|
prev_level = @logger&.level
|
170
171
|
@logger = new_logger(output, prev_level)
|
172
|
+
output
|
171
173
|
end
|
172
174
|
|
173
175
|
@logger = nil
|
@@ -175,19 +177,21 @@ module Steep
|
|
175
177
|
|
176
178
|
def self.measure(message, level: :warn)
|
177
179
|
start = Time.now
|
178
|
-
yield
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
self.logger.log(level) { "#{message} took #{time} seconds" }
|
180
|
+
yield
|
181
|
+
ensure
|
182
|
+
time = Time.now - start
|
183
|
+
if level.is_a?(Symbol)
|
184
|
+
level = Logger.const_get(level.to_s.upcase)
|
184
185
|
end
|
186
|
+
self.logger.log(level) { "#{message} took #{time} seconds" }
|
185
187
|
end
|
186
188
|
|
187
189
|
def self.log_error(exn, message: "Unexpected error: #{exn.inspect}")
|
188
190
|
Steep.logger.fatal message
|
189
|
-
exn.backtrace
|
190
|
-
|
191
|
+
if backtrace = exn.backtrace
|
192
|
+
backtrace.each do |loc|
|
193
|
+
Steep.logger.error " #{loc}"
|
194
|
+
end
|
191
195
|
end
|
192
196
|
end
|
193
197
|
|
@@ -198,7 +202,9 @@ module Steep
|
|
198
202
|
|
199
203
|
def sample(message)
|
200
204
|
start = Time.now
|
201
|
-
|
205
|
+
begin
|
206
|
+
yield
|
207
|
+
ensure
|
202
208
|
time = Time.now - start
|
203
209
|
@samples << [message, time]
|
204
210
|
end
|
@@ -220,12 +226,13 @@ module Steep
|
|
220
226
|
if count > 0
|
221
227
|
total/count
|
222
228
|
else
|
223
|
-
0
|
229
|
+
0.to_f
|
224
230
|
end
|
225
231
|
end
|
226
232
|
|
227
233
|
def percentile(p)
|
228
|
-
|
234
|
+
c = [count * p / 100.to_r, 1].max or raise
|
235
|
+
slowests(c.to_i).last&.last || 0.to_f
|
229
236
|
end
|
230
237
|
end
|
231
238
|
|
@@ -257,7 +264,7 @@ klasses = [
|
|
257
264
|
|
258
265
|
klasses.each do |klass|
|
259
266
|
klass.instance_eval do
|
260
|
-
def self.new(*
|
267
|
+
def self.new(*_a, **_b, &_c)
|
261
268
|
super
|
262
269
|
end
|
263
270
|
end
|
@@ -293,7 +300,7 @@ module GCCounter
|
|
293
300
|
|
294
301
|
GC.start(immediate_sweep: true, immediate_mark: true, full_mark: true)
|
295
302
|
|
296
|
-
gceds = []
|
303
|
+
gceds = [] #: Array[[Class, Integer]]
|
297
304
|
|
298
305
|
klasses.each do |klass|
|
299
306
|
count = ObjectSpace.each_object(klass).count
|
data/sample/Steepfile
CHANGED
@@ -9,6 +9,7 @@ target :lib do
|
|
9
9
|
|
10
10
|
# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
|
11
11
|
# configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
|
12
|
+
# configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
|
12
13
|
# configure_code_diagnostics do |hash| # You can setup everything yourself
|
13
14
|
# hash[D::Ruby::NoMethod] = :information
|
14
15
|
# end
|
@@ -18,16 +18,6 @@ module LanguageServer
|
|
18
18
|
end
|
19
19
|
|
20
20
|
module Constant
|
21
|
-
module DiagnosticSeverity
|
22
|
-
ERROR: String
|
23
|
-
|
24
|
-
WARNING: String
|
25
|
-
|
26
|
-
INFORMATION: String
|
27
|
-
|
28
|
-
HINT: String
|
29
|
-
end
|
30
|
-
|
31
21
|
module CompletionItemKind
|
32
22
|
type t = Integer
|
33
23
|
|
@@ -87,6 +77,57 @@ module LanguageServer
|
|
87
77
|
|
88
78
|
MARKDOWN: "markdown"
|
89
79
|
end
|
80
|
+
|
81
|
+
module DiagnosticSeverity
|
82
|
+
type t = 1 | 2 | 3 | 4
|
83
|
+
|
84
|
+
ERROR: 1
|
85
|
+
|
86
|
+
WARNING: 2
|
87
|
+
|
88
|
+
INFORMATION: 3
|
89
|
+
|
90
|
+
HINT: 4
|
91
|
+
end
|
92
|
+
|
93
|
+
module DiagnosticTag
|
94
|
+
type t = 1 | 2
|
95
|
+
|
96
|
+
UNNECESSARY: 1
|
97
|
+
|
98
|
+
DEPRECATED: 2
|
99
|
+
end
|
100
|
+
|
101
|
+
module SymbolKind
|
102
|
+
FILE: 1
|
103
|
+
MODULE: 2
|
104
|
+
NAMESPACE: 3
|
105
|
+
PACKAGE: 4
|
106
|
+
CLASS: 5
|
107
|
+
METHOD: 6
|
108
|
+
PROPERTY: 7
|
109
|
+
FIELD: 8
|
110
|
+
CONSTRUCTOR: 9
|
111
|
+
ENUM: 10
|
112
|
+
INTERFACE: 11
|
113
|
+
FUNCTION: 12
|
114
|
+
VARIABLE: 13
|
115
|
+
CONSTANT: 14
|
116
|
+
STRING: 15
|
117
|
+
NUMBER: 16
|
118
|
+
BOOLEAN: 17
|
119
|
+
ARRAY: 18
|
120
|
+
OBJECT: 19
|
121
|
+
KEY: 20
|
122
|
+
NULL: 21
|
123
|
+
ENUM_MEMBER: 22
|
124
|
+
STRUCT: 23
|
125
|
+
EVENT: 24
|
126
|
+
OPERATOR: 25
|
127
|
+
TYPE_PARAMETER: 26
|
128
|
+
|
129
|
+
type t = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26
|
130
|
+
end
|
90
131
|
end
|
91
132
|
|
92
133
|
module Interface
|
@@ -99,6 +140,8 @@ module LanguageServer
|
|
99
140
|
end
|
100
141
|
|
101
142
|
class Position
|
143
|
+
type json = { line: Integer, character: Integer }
|
144
|
+
|
102
145
|
include _Base
|
103
146
|
|
104
147
|
# 0-origin line number
|
@@ -114,6 +157,11 @@ module LanguageServer
|
|
114
157
|
class Range
|
115
158
|
include _Base
|
116
159
|
|
160
|
+
type json = {
|
161
|
+
start: Position::json,
|
162
|
+
end: Position::json
|
163
|
+
}
|
164
|
+
|
117
165
|
attr_reader start: Position
|
118
166
|
|
119
167
|
attr_reader end: Position
|
@@ -122,6 +170,18 @@ module LanguageServer
|
|
122
170
|
| (Hash[Symbol, untyped]) -> void
|
123
171
|
end
|
124
172
|
|
173
|
+
class Location
|
174
|
+
include _Base
|
175
|
+
|
176
|
+
type json = { uri: String, range: Range::json }
|
177
|
+
|
178
|
+
attr_reader uri: String
|
179
|
+
|
180
|
+
attr_reader range: Range
|
181
|
+
|
182
|
+
def initialize: (uri: String, range: Range) -> void
|
183
|
+
end
|
184
|
+
|
125
185
|
class MarkupContent
|
126
186
|
include _Base
|
127
187
|
|
@@ -292,6 +352,87 @@ module LanguageServer
|
|
292
352
|
|
293
353
|
def initialize: (signatures: Array[SignatureInformation], ?active_signature: Integer?, ?active_parameter: Integer?) -> void
|
294
354
|
end
|
355
|
+
|
356
|
+
class PublishDiagnosticsParams
|
357
|
+
include _Base
|
358
|
+
|
359
|
+
attr_reader uri: String
|
360
|
+
|
361
|
+
attr_reader version: Integer?
|
362
|
+
|
363
|
+
attr_reader diagnostics: Array[Diagnostic]
|
364
|
+
|
365
|
+
def initialize: (uri: String, ?version: Integer?, diagnostics: Array[Diagnostic]) -> void
|
366
|
+
end
|
367
|
+
|
368
|
+
class Diagnostic
|
369
|
+
type json = {
|
370
|
+
range: Range::json,
|
371
|
+
severity: Constant::DiagnosticSeverity::t?,
|
372
|
+
code: Integer | String | nil,
|
373
|
+
codeDescription: CodeDescription::json?,
|
374
|
+
source: String?,
|
375
|
+
message: String,
|
376
|
+
tags: Array[Constant::DiagnosticTag::t]?,
|
377
|
+
relatedInformation: RelatedInformation::json?,
|
378
|
+
data: untyped?
|
379
|
+
}
|
380
|
+
|
381
|
+
attr_reader range: Range
|
382
|
+
|
383
|
+
attr_reader severity: Constant::DiagnosticSeverity::t?
|
384
|
+
|
385
|
+
attr_reader code: Integer | String | nil
|
386
|
+
|
387
|
+
attr_reader code_description: CodeDescription?
|
388
|
+
|
389
|
+
attr_reader source: String?
|
390
|
+
|
391
|
+
attr_reader message: String
|
392
|
+
|
393
|
+
attr_reader tags: Array[Constant::DiagnosticTag::t]?
|
394
|
+
|
395
|
+
attr_reader related_information: RelatedInformation?
|
396
|
+
|
397
|
+
attr_reader data: untyped?
|
398
|
+
|
399
|
+
def initialize: (
|
400
|
+
range: Range,
|
401
|
+
?severity: Constant::DiagnosticSeverity::t?,
|
402
|
+
?code: Integer | String | nil,
|
403
|
+
?code_description: CodeDescription?,
|
404
|
+
?source: String?,
|
405
|
+
message: String,
|
406
|
+
?tags: Array[Constant::DiagnosticTag::t]?,
|
407
|
+
?related_information: RelatedInformation?,
|
408
|
+
?data: untyped
|
409
|
+
) -> void
|
410
|
+
end
|
411
|
+
|
412
|
+
class RelatedInformation
|
413
|
+
include _Base
|
414
|
+
|
415
|
+
type json = {
|
416
|
+
location: Location::json,
|
417
|
+
message: String
|
418
|
+
}
|
419
|
+
|
420
|
+
attr_reader location: Location
|
421
|
+
|
422
|
+
attr_reader message: String
|
423
|
+
|
424
|
+
def initialize: (location: Location, message: String) -> void
|
425
|
+
end
|
426
|
+
|
427
|
+
class CodeDescription
|
428
|
+
include _Base
|
429
|
+
|
430
|
+
type json = { href: String }
|
431
|
+
|
432
|
+
attr_reader href: String
|
433
|
+
|
434
|
+
def initialize: (href: String) -> void
|
435
|
+
end
|
295
436
|
end
|
296
437
|
end
|
297
438
|
end
|
data/sig/shims/parser/nodes.rbs
CHANGED
@@ -19,6 +19,8 @@ module Parser
|
|
19
19
|
end
|
20
20
|
|
21
21
|
interface _DefLocation
|
22
|
+
def name: () -> Source::Range
|
23
|
+
|
22
24
|
%a{pure} def end: () -> Source::Range?
|
23
25
|
end
|
24
26
|
|
@@ -33,5 +35,213 @@ module Parser
|
|
33
35
|
|
34
36
|
%a{pure} def end: () -> Source::Range
|
35
37
|
end
|
38
|
+
|
39
|
+
interface _NamedLocation
|
40
|
+
%a{pure} def name: () -> Source::Range
|
41
|
+
end
|
42
|
+
|
43
|
+
interface _SelectorLocation
|
44
|
+
%a{pure} def selector: () -> Source::Range
|
45
|
+
end
|
46
|
+
|
47
|
+
# ```ruby
|
48
|
+
# if foo then bar else baz end
|
49
|
+
# #^ => keyword
|
50
|
+
# # ^^^^ => begin
|
51
|
+
# # ^^^^ => else
|
52
|
+
# # ^^^ => end
|
53
|
+
# ```
|
54
|
+
#
|
55
|
+
interface _Condition
|
56
|
+
%a{pure} def keyword: () -> Source::Range
|
57
|
+
|
58
|
+
%a{pure} def begin: () -> Source::Range?
|
59
|
+
|
60
|
+
%a{pure} def else: () -> Source::Range?
|
61
|
+
|
62
|
+
%a{pure} def end: () -> Source::Range?
|
63
|
+
end
|
64
|
+
|
65
|
+
interface _Ternary
|
66
|
+
%a{pure} def question: () -> Source::Range
|
67
|
+
|
68
|
+
%a{pure} def colon: () -> Source::Range
|
69
|
+
end
|
70
|
+
|
71
|
+
interface _Variable
|
72
|
+
%a{pure} def name: () -> Source::Range
|
73
|
+
|
74
|
+
%a{pure} def operator: () -> Source::Range?
|
75
|
+
end
|
76
|
+
|
77
|
+
# ```ruby
|
78
|
+
# foo.bar(baz)
|
79
|
+
# # ^ => dot
|
80
|
+
# # ^^^ => selector
|
81
|
+
# # ^ => begin
|
82
|
+
# # ^ => end
|
83
|
+
#
|
84
|
+
# foo.bar += 1
|
85
|
+
# # ^ => dot
|
86
|
+
# # ^^^ => selector
|
87
|
+
# # ^^ => operator
|
88
|
+
# ```
|
89
|
+
#
|
90
|
+
interface _Send
|
91
|
+
%a{pure} def dot: () -> Source::Range?
|
92
|
+
|
93
|
+
%a{pure} def selector: () -> Source::Range
|
94
|
+
|
95
|
+
%a{pure} def operator: () -> Source::Range?
|
96
|
+
|
97
|
+
%a{pure} def begin: () -> Source::Range?
|
98
|
+
|
99
|
+
%a{pure} def end: () -> Source::Range?
|
100
|
+
end
|
101
|
+
|
102
|
+
# ```ruby
|
103
|
+
# rescue Foo => x then
|
104
|
+
# #^^^^^ => keyword
|
105
|
+
# # ^^ => assoc
|
106
|
+
# # ^^^^ => begin
|
107
|
+
# ```
|
108
|
+
interface _RescueBody
|
109
|
+
%a{pure} def keyword: () -> Source::Range
|
110
|
+
|
111
|
+
%a{pure} def assoc: () -> Source::Range?
|
112
|
+
|
113
|
+
%a{pure} def begin: () -> Source::Range?
|
114
|
+
end
|
115
|
+
|
116
|
+
# ```ruby
|
117
|
+
# +1
|
118
|
+
# ^ => operator
|
119
|
+
# ```
|
120
|
+
interface _Operator
|
121
|
+
%a{pure} def operator: () -> Source::Range?
|
122
|
+
end
|
123
|
+
|
124
|
+
# ```ruby
|
125
|
+
# def self.foo(); end
|
126
|
+
# #^^ => keyword
|
127
|
+
# # ^ => operator
|
128
|
+
# # ^^^ => name
|
129
|
+
# # ^^^ => end
|
130
|
+
#
|
131
|
+
# def foo = bar
|
132
|
+
# #^^ => keyword
|
133
|
+
# # ^^^ => name
|
134
|
+
# # ^ => assignment
|
135
|
+
# ```
|
136
|
+
interface _MethodDefinition
|
137
|
+
%a{pure} def keyword: () -> Source::Range
|
138
|
+
|
139
|
+
%a{pure} def operator: () -> Source::Range?
|
140
|
+
|
141
|
+
%a{pure} def name: () -> Source::Range
|
142
|
+
|
143
|
+
%a{pure} def end: () -> Source::Range?
|
144
|
+
|
145
|
+
%a{pure} def assignment: () -> Source::Range?
|
146
|
+
end
|
147
|
+
|
148
|
+
# ```ruby
|
149
|
+
# when foo then
|
150
|
+
# #^^^ => keyword
|
151
|
+
# # ^^^^ => begin
|
152
|
+
# ```
|
153
|
+
interface _Keyword
|
154
|
+
%a{pure} def keyword: () -> Source::Range
|
155
|
+
|
156
|
+
%a{pure} def begin: () -> Source::Range?
|
157
|
+
|
158
|
+
%a{pure} def end: () -> Source::Range?
|
159
|
+
end
|
160
|
+
|
161
|
+
# ```ruby
|
162
|
+
# foo[1] += 1
|
163
|
+
# # ^ => begin
|
164
|
+
# # ^ => end
|
165
|
+
# # ^^ => operator
|
166
|
+
# ```
|
167
|
+
interface _Index
|
168
|
+
%a{pure} def begin: () -> Source::Range
|
169
|
+
|
170
|
+
%a{pure} def end: () -> Source::Range
|
171
|
+
|
172
|
+
%a{pure} def operator: () -> Source::Range?
|
173
|
+
end
|
174
|
+
|
175
|
+
# ```ruby
|
176
|
+
# <<FOO <= expression
|
177
|
+
# foo <= heredoc_body
|
178
|
+
# FOO <= heredoc_end
|
179
|
+
# ```
|
180
|
+
#
|
181
|
+
interface _Heredoc
|
182
|
+
%a{pure} def heredoc_body: () -> Source::Range
|
183
|
+
|
184
|
+
%a{pure} def heredoc_end: () -> Source::Range
|
185
|
+
end
|
186
|
+
|
187
|
+
# ```ruby
|
188
|
+
# for x in [] then ... end
|
189
|
+
# #^^ => keyword
|
190
|
+
# # ^^ => in
|
191
|
+
# # ^^^^ => begin
|
192
|
+
# # ^^^ => end
|
193
|
+
# ```
|
194
|
+
interface _For
|
195
|
+
%a{pure} def keyword: () -> Source::Range
|
196
|
+
|
197
|
+
%a{pure} def in: () -> Source::Range
|
198
|
+
|
199
|
+
%a{pure} def begin: () -> Source::Range?
|
200
|
+
|
201
|
+
%a{pure} def end: () -> Source::Range
|
202
|
+
end
|
203
|
+
|
204
|
+
# ```ruby
|
205
|
+
# class Foo::Bar < Baz; end
|
206
|
+
# #^^^^ => keyword
|
207
|
+
# # ^^^^^^^^ => name
|
208
|
+
# # ^ => operator
|
209
|
+
# # ^^^ => end
|
210
|
+
# ```
|
211
|
+
interface _Definition
|
212
|
+
%a{pure} def keyword: () -> Source::Range
|
213
|
+
|
214
|
+
%a{pure} def name: () -> Source::Range
|
215
|
+
|
216
|
+
%a{pure} def operator: () -> Source::Range?
|
217
|
+
|
218
|
+
%a{pure} def end: () -> Source::Range
|
219
|
+
end
|
220
|
+
|
221
|
+
# ```ruby
|
222
|
+
# Foo::Bar += 1
|
223
|
+
# # ^^ => double_colon
|
224
|
+
# # ^^^ => name
|
225
|
+
# # ^^ => operator
|
226
|
+
# ```
|
227
|
+
#
|
228
|
+
interface _Constant
|
229
|
+
%a{pure} def double_colon: () -> Source::Range?
|
230
|
+
|
231
|
+
%a{pure} def name: () -> Source::Range
|
232
|
+
|
233
|
+
%a{pure} def operator: () -> Source::Range?
|
234
|
+
end
|
235
|
+
|
236
|
+
# ```ruby
|
237
|
+
# (1)
|
238
|
+
# # ^ => begin
|
239
|
+
# # ^ => end
|
240
|
+
# ```
|
241
|
+
interface _Collection
|
242
|
+
%a{pure} def begin: () -> Source::Range?
|
243
|
+
|
244
|
+
%a{pure} def end: () -> Source::Range?
|
245
|
+
end
|
36
246
|
end
|
37
247
|
end
|
data/sig/shims/parser.rbs
CHANGED
@@ -25,6 +25,16 @@ module Parser
|
|
25
25
|
attr_reader diagnostics: untyped
|
26
26
|
end
|
27
27
|
|
28
|
+
class Ruby32
|
29
|
+
def initialize: (untyped builder) -> void
|
30
|
+
|
31
|
+
def parse: (Source::Buffer) -> AST
|
32
|
+
|
33
|
+
def parse_with_comments: (Source::Buffer) -> [AST::Node, Array[Source::Comment]]
|
34
|
+
|
35
|
+
attr_reader diagnostics: untyped
|
36
|
+
end
|
37
|
+
|
28
38
|
module Source
|
29
39
|
class Buffer
|
30
40
|
def initialize: (String file, Integer lineno, source: String) -> void
|
data/sig/steep/ast/builtin.rbs
CHANGED
@@ -12,9 +12,9 @@ module Steep
|
|
12
12
|
|
13
13
|
def module_type: () -> Types::Name::Singleton
|
14
14
|
|
15
|
-
def instance_type?: (Types::t `type`, ?args: Array[Types::t]?) ->
|
15
|
+
def instance_type?: (Types::t `type`, ?args: Array[Types::t]?) -> Types::Name::Instance?
|
16
16
|
|
17
|
-
def module_type?: (Types::t `type`) ->
|
17
|
+
def module_type?: (Types::t `type`) -> Types::Name::Singleton?
|
18
18
|
end
|
19
19
|
|
20
20
|
Object: Type
|
@@ -12,9 +12,9 @@ module Steep
|
|
12
12
|
|
13
13
|
def initialize: (RBS::Location[untyped, untyped]) -> void
|
14
14
|
|
15
|
-
def types: (RBS::Resolver::context,
|
15
|
+
def types: (RBS::Resolver::context, Subtyping::Check, Array[Symbol] type_vars) -> (Array[Types::t] | RBS::ParsingError | nil)
|
16
16
|
|
17
|
-
def types?: (RBS::Resolver::context,
|
17
|
+
def types?: (RBS::Resolver::context, Subtyping::Check, Array[Symbol] type_vars) -> Array[Types::t]?
|
18
18
|
|
19
19
|
@type_str: String?
|
20
20
|
def type_str: () -> String
|
@@ -10,15 +10,21 @@ module Steep
|
|
10
10
|
|
11
11
|
def initialize: (RBS::Location[untyped, untyped]) -> void
|
12
12
|
|
13
|
-
def type: (RBS::Resolver::context,
|
13
|
+
def type: (RBS::Resolver::context, Subtyping::Check, Array[Symbol] type_vars) -> (Types::t | RBS::ParsingError | nil)
|
14
14
|
|
15
|
-
def type?: (RBS::Resolver::context,
|
15
|
+
def type?: (RBS::Resolver::context, Subtyping::Check, Array[Symbol] type_vars) -> Types::t?
|
16
16
|
|
17
17
|
@type_str: String?
|
18
18
|
def type_str: () -> String
|
19
19
|
|
20
20
|
def type_location: () -> RBS::Location[untyped, untyped]
|
21
21
|
|
22
|
+
# Returns true if given comment body has a valid type syntax
|
23
|
+
#
|
24
|
+
# This method is used to reject RDoc directives beforehand.
|
25
|
+
#
|
26
|
+
def type_syntax?: () -> bool
|
27
|
+
|
22
28
|
def self.parse: (RBS::Location[untyped, untyped]) -> TypeAssertion?
|
23
29
|
end
|
24
30
|
end
|
@@ -59,7 +59,34 @@ module Steep
|
|
59
59
|
#
|
60
60
|
def flatten_union: (t `type`, ?Array[t] acc) -> Array[t]
|
61
61
|
|
62
|
-
|
62
|
+
# Partition the type components in union types to truthy ones and falsy ones
|
63
|
+
#
|
64
|
+
# * Returns a pair of *truthy* type and *falsy* type
|
65
|
+
# * The pair may contain `nil` if given type always evaluates to truthy or falsy
|
66
|
+
# * Expand (unfold) the type aliases automatically
|
67
|
+
#
|
68
|
+
# ```ruby
|
69
|
+
# partition_union?(`Integer?`) # => [`Integer`, `nil`]
|
70
|
+
# partition_union?(`Integer | String | nil | false`) # => [`Integer | String`, `nil | false`]
|
71
|
+
# partition_union?(`bool`) # => [`bool`, `bool`]
|
72
|
+
# partition_union?(`nil`) # => [nil, `nil`]
|
73
|
+
# ```
|
74
|
+
#
|
75
|
+
def partition_union: (Types::t) -> [Types::t?, Types::t?]
|
76
|
+
|
77
|
+
# Returns a type that doesn't have `nil` in the union component
|
78
|
+
#
|
79
|
+
# * Returns `nil` if given type is `nil`
|
80
|
+
# * **Doesn't expand type alias automatically**
|
81
|
+
#
|
82
|
+
# ```ruby
|
83
|
+
# unwrap_optional(`String?`) # => `String`
|
84
|
+
# unwrap_optional(`String | Integer | false | nil`) # => `String | Integer | false`
|
85
|
+
# unwrap_optional(`nil`) # => nil
|
86
|
+
# unwrap_optional(`boolish`) # => `boolish`
|
87
|
+
# ```
|
88
|
+
#
|
89
|
+
def unwrap_optional: (Types::t) -> Types::t?
|
63
90
|
|
64
91
|
def module_name?: (TypeName type_name) -> bool
|
65
92
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
use LanguageServer::Protocol::Constant::DiagnosticSeverity as LSPDiagnosticSeverity
|
2
|
+
use LanguageServer::Protocol::Interface::Diagnostic as LSPDiagnostic
|
3
|
+
|
1
4
|
module Steep
|
2
5
|
module Diagnostic
|
3
6
|
class LSPFormatter
|
@@ -25,9 +28,9 @@ module Steep
|
|
25
28
|
|
26
29
|
def validate_severity: (Class | :default klass, severity?) -> void
|
27
30
|
|
28
|
-
def format: (Diagnostic::Ruby::Base | Diagnostic::Signature::Base) ->
|
31
|
+
def format: (Diagnostic::Ruby::Base | Diagnostic::Signature::Base) -> LSPDiagnostic::json?
|
29
32
|
|
30
|
-
def severity_for: (Diagnostic::Ruby::Base | Diagnostic::Signature::Base) ->
|
33
|
+
def severity_for: (Diagnostic::Ruby::Base | Diagnostic::Signature::Base) -> LSPDiagnosticSeverity::t?
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|