steep 0.49.1 → 0.52.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/Gemfile +4 -1
  4. data/Gemfile.lock +8 -5
  5. data/lib/steep/ast/annotation/collection.rb +10 -8
  6. data/lib/steep/ast/types/factory.rb +5 -5
  7. data/lib/steep/cli.rb +83 -1
  8. data/lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb +28 -0
  9. data/lib/steep/diagnostic/ruby.rb +21 -15
  10. data/lib/steep/drivers/check.rb +1 -0
  11. data/lib/steep/drivers/langserver.rb +2 -2
  12. data/lib/steep/drivers/stats.rb +1 -0
  13. data/lib/steep/drivers/utils/jobs_count.rb +1 -1
  14. data/lib/steep/drivers/watch.rb +1 -1
  15. data/lib/steep/index/source_index.rb +18 -1
  16. data/lib/steep/interface/function.rb +5 -0
  17. data/lib/steep/module_helper.rb +4 -7
  18. data/lib/steep/project.rb +15 -1
  19. data/lib/steep/server/interaction_worker.rb +47 -4
  20. data/lib/steep/server/master.rb +10 -5
  21. data/lib/steep/server/type_check_worker.rb +19 -4
  22. data/lib/steep/server/worker_process.rb +15 -6
  23. data/lib/steep/services/completion_provider.rb +109 -1
  24. data/lib/steep/services/goto_service.rb +23 -10
  25. data/lib/steep/services/hover_content.rb +52 -4
  26. data/lib/steep/services/type_check_service.rb +6 -3
  27. data/lib/steep/source.rb +71 -18
  28. data/lib/steep/type_construction.rb +209 -162
  29. data/lib/steep/type_inference/constant_env.rb +33 -15
  30. data/lib/steep/type_inference/context.rb +6 -7
  31. data/lib/steep/type_inference/type_env.rb +16 -54
  32. data/lib/steep/version.rb +1 -1
  33. data/smoke/const/test_expectations.yml +24 -19
  34. data/smoke/diagnostics/test_expectations.yml +77 -17
  35. data/smoke/integer/test_expectations.yml +24 -4
  36. data/smoke/method/test_expectations.yml +30 -0
  37. data/smoke/regression/test_expectations.yml +24 -0
  38. data/smoke/yield/test_expectations.yml +20 -0
  39. data/steep.gemspec +1 -1
  40. metadata +5 -4
@@ -48,26 +48,23 @@ module Steep
48
48
  attr_reader :defined_module_methods
49
49
  attr_reader :const_env
50
50
  attr_reader :implement_name
51
- attr_reader :namespaces
52
- attr_reader :current_namespace
53
51
  attr_reader :class_name
54
52
  attr_reader :instance_definition
55
53
  attr_reader :module_definition
56
54
 
57
- def initialize(instance_type:, module_type:, implement_name:, current_namespace:, const_env:, class_name:, instance_definition: nil, module_definition: nil)
55
+ def initialize(instance_type:, module_type:, implement_name:, const_env:, class_name:, instance_definition: nil, module_definition: nil)
58
56
  @instance_type = instance_type
59
57
  @module_type = module_type
60
58
  @defined_instance_methods = Set.new
61
59
  @defined_module_methods = Set.new
62
60
  @implement_name = implement_name
63
- @current_namespace = current_namespace
64
61
  @const_env = const_env
65
62
  @class_name = class_name
66
63
  @instance_definition = instance_definition
67
64
  @module_definition = module_definition
68
65
  end
69
66
 
70
- def const_context
67
+ def nesting
71
68
  const_env.context
72
69
  end
73
70
 
@@ -83,7 +80,6 @@ module Steep
83
80
  instance_type: self.instance_type,
84
81
  module_type: self.module_type,
85
82
  implement_name: self.implement_name,
86
- current_namespace: self.current_namespace,
87
83
  const_env: self.const_env,
88
84
  class_name: self.class_name,
89
85
  instance_definition: self.instance_definition,
@@ -93,7 +89,6 @@ module Steep
93
89
  instance_type: instance_type,
94
90
  module_type: module_type,
95
91
  implement_name: implement_name,
96
- current_namespace: current_namespace,
97
92
  const_env: const_env,
98
93
  class_name: class_name,
99
94
  instance_definition: instance_definition,
@@ -175,6 +170,10 @@ module Steep
175
170
  variable_context: variable_context
176
171
  )
177
172
  end
173
+
174
+ def env
175
+ type_env.subtyping.factory.env
176
+ end
178
177
  end
179
178
  end
180
179
  end
@@ -44,18 +44,6 @@ module Steep
44
44
  merge!(original_env: env.gvar_types, override_env: gvar_types, self_type: self_type, instance_type: instance_type, class_type: class_type, &block)
45
45
 
46
46
  const_types.each do |name, annotated_type|
47
- original_type = self.const_types[name] || const_env.lookup(name)
48
- if original_type
49
- assert_annotation(
50
- name,
51
- original_type: original_type,
52
- annotated_type: annotated_type,
53
- self_type: self_type,
54
- instance_type: instance_type,
55
- class_type: class_type,
56
- &block
57
- )
58
- end
59
47
  env.const_types[name] = annotated_type
60
48
  end
61
49
  end
@@ -70,14 +58,8 @@ module Steep
70
58
  if const_types.key?(const)
71
59
  const_types[const]
72
60
  else
73
- const_env.lookup(const).yield_self do |type|
74
- if type
75
- type
76
- else
77
- yield
78
- AST::Types::Any.new
79
- end
80
- end
61
+ yield
62
+ AST::Types::Any.new
81
63
  end
82
64
  else
83
65
  lookup_dictionary(ivar: ivar, gvar: gvar) do |var_name, dictionary|
@@ -105,40 +87,20 @@ module Steep
105
87
  # @type method assign: (const: TypeName, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
106
88
  # | (gvar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
107
89
  # | (ivar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
108
- def assign(const: nil, gvar: nil, ivar: nil, type:, self_type:, instance_type:, class_type:, &block)
109
- case
110
- when const
111
- yield_self do
112
- const_type = const_types[const] || const_env.lookup(const)
113
- if const_type
114
- assert_assign(
115
- var_type: const_type,
116
- lhs_type: type,
117
- self_type: self_type,
118
- instance_type: instance_type,
119
- class_type: class_type,
120
- &block
121
- )
122
- else
123
- yield nil
124
- AST::Types::Any.new
125
- end
126
- end
127
- else
128
- lookup_dictionary(ivar: ivar, gvar: gvar) do |var_name, dictionary|
129
- if dictionary.key?(var_name)
130
- assert_assign(
131
- var_type: dictionary[var_name],
132
- lhs_type: type,
133
- self_type: self_type,
134
- instance_type: instance_type,
135
- class_type: class_type,
136
- &block
137
- )
138
- else
139
- yield nil
140
- AST::Types::Any.new
141
- end
90
+ def assign(gvar: nil, ivar: nil, type:, self_type:, instance_type:, class_type:, &block)
91
+ lookup_dictionary(ivar: ivar, gvar: gvar) do |var_name, dictionary|
92
+ if dictionary.key?(var_name)
93
+ assert_assign(
94
+ var_type: dictionary[var_name],
95
+ lhs_type: type,
96
+ self_type: self_type,
97
+ instance_type: instance_type,
98
+ class_type: class_type,
99
+ &block
100
+ )
101
+ else
102
+ yield nil
103
+ AST::Types::Any.new
142
104
  end
143
105
  end
144
106
  end
data/lib/steep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.49.1"
2
+ VERSION = "0.52.0"
3
3
  end
@@ -24,8 +24,18 @@
24
24
  line: 6
25
25
  character: 5
26
26
  severity: ERROR
27
- message: Cannot detect the type of the expression
28
- code: Ruby::FallbackAny
27
+ message: 'Cannot find the declaration of constant: `B`'
28
+ code: Ruby::UnknownConstant
29
+ - range:
30
+ start:
31
+ line: 8
32
+ character: 7
33
+ end:
34
+ line: 8
35
+ character: 8
36
+ severity: ERROR
37
+ message: 'Cannot find the declaration of module: `X`'
38
+ code: Ruby::UnknownConstant
29
39
  - range:
30
40
  start:
31
41
  line: 14
@@ -49,8 +59,8 @@
49
59
  line: 16
50
60
  character: 9
51
61
  severity: ERROR
52
- message: Cannot detect the type of the expression
53
- code: Ruby::FallbackAny
62
+ message: 'Cannot find the declaration of constant: `B`'
63
+ code: Ruby::UnknownConstant
54
64
  - range:
55
65
  start:
56
66
  line: 23
@@ -69,23 +79,18 @@
69
79
  - range:
70
80
  start:
71
81
  line: 26
72
- character: 4
73
- end:
74
- line: 26
75
- character: 10
76
- severity: ERROR
77
- message: Cannot detect the type of the expression
78
- code: Ruby::FallbackAny
79
- - range:
80
- start:
81
- line: 26
82
- character: 4
82
+ character: 0
83
83
  end:
84
84
  line: 26
85
85
  character: 15
86
86
  severity: ERROR
87
- message: Cannot detect the type of the expression
88
- code: Ruby::FallbackAny
87
+ message: |-
88
+ Cannot assign a value of type `::Integer` to a variable of type `::String`
89
+ ::Integer <: ::String
90
+ ::Numeric <: ::String
91
+ ::Object <: ::String
92
+ ::BasicObject <: ::String
93
+ code: Ruby::IncompatibleAssignment
89
94
  - range:
90
95
  start:
91
96
  line: 27
@@ -125,5 +130,5 @@
125
130
  line: 5
126
131
  character: 8
127
132
  severity: ERROR
128
- message: Cannot find the declaration of constant `Baz2`
129
- code: Ruby::UnknownConstantAssigned
133
+ message: 'Cannot find the declaration of constant: `Baz2`'
134
+ code: Ruby::UnknownConstant
@@ -65,6 +65,16 @@
65
65
  code: Ruby::BreakTypeMismatch
66
66
  - file: different_method_parameter_kind.rb
67
67
  diagnostics:
68
+ - range:
69
+ start:
70
+ line: 1
71
+ character: 6
72
+ end:
73
+ line: 1
74
+ character: 34
75
+ severity: ERROR
76
+ message: 'Cannot find the declaration of class: `DifferentMethodParameterKind`'
77
+ code: Ruby::UnknownConstant
68
78
  - range:
69
79
  start:
70
80
  line: 3
@@ -207,6 +217,16 @@
207
217
  code: Ruby::IncompatibleAssignment
208
218
  - file: method_arity_mismatch.rb
209
219
  diagnostics:
220
+ - range:
221
+ start:
222
+ line: 1
223
+ character: 6
224
+ end:
225
+ line: 1
226
+ character: 25
227
+ severity: ERROR
228
+ message: 'Cannot find the declaration of class: `MethodArityMismatch`'
229
+ code: Ruby::UnknownConstant
210
230
  - range:
211
231
  start:
212
232
  line: 3
@@ -230,6 +250,16 @@
230
250
  code: Ruby::MethodArityMismatch
231
251
  - file: method_body_type_mismatch.rb
232
252
  diagnostics:
253
+ - range:
254
+ start:
255
+ line: 1
256
+ character: 6
257
+ end:
258
+ line: 1
259
+ character: 28
260
+ severity: ERROR
261
+ message: 'Cannot find the declaration of class: `MethodBodyTypeMismatch`'
262
+ code: Ruby::UnknownConstant
233
263
  - range:
234
264
  start:
235
265
  line: 3
@@ -258,6 +288,16 @@
258
288
  code: Ruby::MethodDefinitionMissing
259
289
  - file: method_parameter_mismatch.rb
260
290
  diagnostics:
291
+ - range:
292
+ start:
293
+ line: 1
294
+ character: 6
295
+ end:
296
+ line: 1
297
+ character: 29
298
+ severity: ERROR
299
+ message: 'Cannot find the declaration of class: `MethodParameterMismatch`'
300
+ code: Ruby::UnknownConstant
261
301
  - range:
262
302
  start:
263
303
  line: 3
@@ -293,6 +333,16 @@
293
333
  code: Ruby::MethodParameterMismatch
294
334
  - file: method_return_type_annotation_mismatch.rb
295
335
  diagnostics:
336
+ - range:
337
+ start:
338
+ line: 1
339
+ character: 6
340
+ end:
341
+ line: 1
342
+ character: 40
343
+ severity: ERROR
344
+ message: 'Cannot find the declaration of class: `MethodReturnTypeAnnotationMismatch`'
345
+ code: Ruby::UnknownConstant
296
346
  - range:
297
347
  start:
298
348
  line: 3
@@ -358,6 +408,16 @@
358
408
  code: Ruby::RequiredBlockMissing
359
409
  - file: return_type_mismatch.rb
360
410
  diagnostics:
411
+ - range:
412
+ start:
413
+ line: 1
414
+ character: 6
415
+ end:
416
+ line: 1
417
+ character: 24
418
+ severity: ERROR
419
+ message: 'Cannot find the declaration of class: `ReturnTypeMismatch`'
420
+ code: Ruby::UnknownConstant
361
421
  - range:
362
422
  start:
363
423
  line: 4
@@ -445,6 +505,16 @@
445
505
  code: Ruby::UnexpectedKeywordArgument
446
506
  - file: unexpected_yield.rb
447
507
  diagnostics:
508
+ - range:
509
+ start:
510
+ line: 1
511
+ character: 6
512
+ end:
513
+ line: 1
514
+ character: 21
515
+ severity: ERROR
516
+ message: 'Cannot find the declaration of class: `UnexpectedYield`'
517
+ code: Ruby::UnknownConstant
448
518
  - range:
449
519
  start:
450
520
  line: 4
@@ -475,8 +545,8 @@
475
545
  line: 2
476
546
  character: 5
477
547
  severity: ERROR
478
- message: Cannot find the declaration of constant `FOO`
479
- code: Ruby::UnknownConstantAssigned
548
+ message: 'Cannot find the declaration of constant: `FOO`'
549
+ code: Ruby::UnknownConstant
480
550
  - range:
481
551
  start:
482
552
  line: 4
@@ -485,28 +555,18 @@
485
555
  line: 4
486
556
  character: 5
487
557
  severity: ERROR
488
- message: Cannot detect the type of the expression
489
- code: Ruby::FallbackAny
490
- - range:
491
- start:
492
- line: 4
493
- character: 2
494
- end:
495
- line: 4
496
- character: 10
497
- severity: ERROR
498
- message: Cannot find the declaration of constant `FOO::BAR`
499
- code: Ruby::UnknownConstantAssigned
558
+ message: 'Cannot find the declaration of constant: `FOO`'
559
+ code: Ruby::UnknownConstant
500
560
  - range:
501
561
  start:
502
562
  line: 6
503
- character: 2
563
+ character: 4
504
564
  end:
505
565
  line: 6
506
566
  character: 7
507
567
  severity: ERROR
508
- message: Cannot find the declaration of constant `::FOO`
509
- code: Ruby::UnknownConstantAssigned
568
+ message: 'Cannot find the declaration of constant: `FOO`'
569
+ code: Ruby::UnknownConstant
510
570
  - file: unresolved_overloading.rb
511
571
  diagnostics:
512
572
  - range:
@@ -21,6 +21,16 @@
21
21
  severity: ERROR
22
22
  message: Type `::Integer` does not have method `foo`
23
23
  code: Ruby::NoMethod
24
+ - range:
25
+ start:
26
+ line: 9
27
+ character: 6
28
+ end:
29
+ line: 9
30
+ character: 15
31
+ severity: ERROR
32
+ message: 'Cannot find the declaration of class: `WithToInt`'
33
+ code: Ruby::UnknownConstant
24
34
  - range:
25
35
  start:
26
36
  line: 12
@@ -29,8 +39,8 @@
29
39
  line: 12
30
40
  character: 29
31
41
  severity: ERROR
32
- message: Cannot detect the type of the expression
33
- code: Ruby::FallbackAny
42
+ message: 'Cannot find the declaration of constant: `WithToInt`'
43
+ code: Ruby::UnknownConstant
34
44
  - range:
35
45
  start:
36
46
  line: 13
@@ -41,6 +51,16 @@
41
51
  severity: ERROR
42
52
  message: Type `::Integer` does not have method `foo`
43
53
  code: Ruby::NoMethod
54
+ - range:
55
+ start:
56
+ line: 15
57
+ character: 6
58
+ end:
59
+ line: 15
60
+ character: 13
61
+ severity: ERROR
62
+ message: 'Cannot find the declaration of class: `WithToI`'
63
+ code: Ruby::UnknownConstant
44
64
  - range:
45
65
  start:
46
66
  line: 18
@@ -49,8 +69,8 @@
49
69
  line: 18
50
70
  character: 27
51
71
  severity: ERROR
52
- message: Cannot detect the type of the expression
53
- code: Ruby::FallbackAny
72
+ message: 'Cannot find the declaration of constant: `WithToI`'
73
+ code: Ruby::UnknownConstant
54
74
  - range:
55
75
  start:
56
76
  line: 19
@@ -74,6 +74,16 @@
74
74
  code: Ruby::IncompatibleAssignment
75
75
  - file: b.rb
76
76
  diagnostics:
77
+ - range:
78
+ start:
79
+ line: 1
80
+ character: 6
81
+ end:
82
+ line: 1
83
+ character: 7
84
+ severity: ERROR
85
+ message: 'Cannot find the declaration of class: `A`'
86
+ code: Ruby::UnknownConstant
77
87
  - range:
78
88
  start:
79
89
  line: 4
@@ -89,3 +99,23 @@
89
99
  ::Object <: ::Integer
90
100
  ::BasicObject <: ::Integer
91
101
  code: Ruby::MethodBodyTypeMismatch
102
+ - range:
103
+ start:
104
+ line: 9
105
+ character: 6
106
+ end:
107
+ line: 9
108
+ character: 7
109
+ severity: ERROR
110
+ message: 'Cannot find the declaration of class: `B`'
111
+ code: Ruby::UnknownConstant
112
+ - range:
113
+ start:
114
+ line: 18
115
+ character: 6
116
+ end:
117
+ line: 18
118
+ character: 7
119
+ severity: ERROR
120
+ message: 'Cannot find the declaration of class: `C`'
121
+ code: Ruby::UnknownConstant
@@ -1,4 +1,28 @@
1
1
  ---
2
+ - file: array.rb
3
+ diagnostics:
4
+ - range:
5
+ start:
6
+ line: 1
7
+ character: 6
8
+ end:
9
+ line: 1
10
+ character: 9
11
+ severity: ERROR
12
+ message: 'Cannot find the declaration of class: `Foo`'
13
+ code: Ruby::UnknownConstant
14
+ - file: hash.rb
15
+ diagnostics:
16
+ - range:
17
+ start:
18
+ line: 1
19
+ character: 6
20
+ end:
21
+ line: 1
22
+ character: 9
23
+ severity: ERROR
24
+ message: 'Cannot find the declaration of class: `Foo`'
25
+ code: Ruby::UnknownConstant
2
26
  - file: issue_332.rb
3
27
  diagnostics:
4
28
  - range:
@@ -1,6 +1,16 @@
1
1
  ---
2
2
  - file: a.rb
3
3
  diagnostics:
4
+ - range:
5
+ start:
6
+ line: 1
7
+ character: 6
8
+ end:
9
+ line: 1
10
+ character: 7
11
+ severity: ERROR
12
+ message: 'Cannot find the declaration of class: `A`'
13
+ code: Ruby::UnknownConstant
4
14
  - range:
5
15
  start:
6
16
  line: 6
@@ -52,6 +62,16 @@
52
62
  code: Ruby::UnexpectedYield
53
63
  - file: b.rb
54
64
  diagnostics:
65
+ - range:
66
+ start:
67
+ line: 1
68
+ character: 6
69
+ end:
70
+ line: 1
71
+ character: 9
72
+ severity: ERROR
73
+ message: 'Cannot find the declaration of class: `Foo`'
74
+ code: Ruby::UnknownConstant
55
75
  - range:
56
76
  start:
57
77
  line: 4
data/steep.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
34
34
  spec.add_runtime_dependency "listen", "~> 3.0"
35
35
  spec.add_runtime_dependency "language_server-protocol", ">= 3.15", "< 4.0"
36
- spec.add_runtime_dependency "rbs", ">= 2.2.0"
36
+ spec.add_runtime_dependency "rbs", ">= 2.3.0"
37
37
  spec.add_runtime_dependency "parallel", ">= 1.0.0"
38
38
  spec.add_runtime_dependency "terminal-table", ">= 2", "< 4"
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.49.1
4
+ version: 0.52.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2022-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: 2.2.0
101
+ version: 2.3.0
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: 2.2.0
108
+ version: 2.3.0
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: parallel
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,7 @@ files:
193
193
  - lib/steep/ast/types/var.rb
194
194
  - lib/steep/ast/types/void.rb
195
195
  - lib/steep/cli.rb
196
+ - lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb
196
197
  - lib/steep/diagnostic/helper.rb
197
198
  - lib/steep/diagnostic/lsp_formatter.rb
198
199
  - lib/steep/diagnostic/ruby.rb