steep 1.2.1 → 1.3.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/Gemfile.lock +4 -4
  4. data/Gemfile.steep +1 -1
  5. data/Gemfile.steep.lock +13 -3
  6. data/Steepfile +0 -1
  7. data/lib/steep/annotation_parser.rb +34 -28
  8. data/lib/steep/ast/annotation.rb +16 -5
  9. data/lib/steep/ast/node/type_application.rb +74 -0
  10. data/lib/steep/ast/node/type_assertion.rb +56 -0
  11. data/lib/steep/ast/types/factory.rb +5 -1
  12. data/lib/steep/diagnostic/helper.rb +2 -1
  13. data/lib/steep/diagnostic/lsp_formatter.rb +3 -1
  14. data/lib/steep/diagnostic/ruby.rb +70 -5
  15. data/lib/steep/diagnostic/signature.rb +21 -8
  16. data/lib/steep/drivers/check.rb +1 -1
  17. data/lib/steep/drivers/checkfile.rb +1 -1
  18. data/lib/steep/drivers/langserver.rb +2 -2
  19. data/lib/steep/drivers/stats.rb +1 -1
  20. data/lib/steep/drivers/watch.rb +1 -1
  21. data/lib/steep/drivers/worker.rb +0 -1
  22. data/lib/steep/server/lsp_formatter.rb +13 -3
  23. data/lib/steep/server/master.rb +4 -1
  24. data/lib/steep/server/worker_process.rb +86 -14
  25. data/lib/steep/services/hover_provider/rbs.rb +7 -7
  26. data/lib/steep/services/hover_provider/ruby.rb +19 -4
  27. data/lib/steep/services/signature_service.rb +7 -4
  28. data/lib/steep/signature/validator.rb +36 -13
  29. data/lib/steep/source.rb +189 -71
  30. data/lib/steep/type_construction.rb +232 -126
  31. data/lib/steep/type_inference/logic_type_interpreter.rb +3 -1
  32. data/lib/steep/version.rb +1 -1
  33. data/lib/steep.rb +2 -0
  34. data/rbs_collection.steep.lock.yaml +27 -10
  35. data/rbs_collection.steep.yaml +0 -1
  36. data/sig/shims/exception.rbs +4 -0
  37. data/sig/shims/parser/comment.rbs +33 -0
  38. data/sig/shims/parser.rbs +30 -2
  39. data/sig/steep/annotation_parser.rbs +59 -0
  40. data/sig/steep/ast/annotation.rbs +21 -26
  41. data/sig/steep/ast/node/type_application.rbs +31 -0
  42. data/sig/steep/ast/node/type_assertion.rbs +26 -0
  43. data/sig/steep/ast/types/factory.rbs +0 -2
  44. data/sig/steep/diagnostic/helper.rbs +9 -3
  45. data/sig/steep/diagnostic/lsp_formatter.rbs +12 -8
  46. data/sig/steep/diagnostic/ruby.rbs +62 -8
  47. data/sig/steep/diagnostic/signature.rbs +118 -85
  48. data/sig/steep/drivers/worker.rbs +11 -13
  49. data/sig/steep/range_extension.rbs +7 -0
  50. data/sig/steep/server/lsp_formatter.rbs +14 -7
  51. data/sig/steep/server/worker_process.rbs +74 -12
  52. data/sig/steep/services/hover_provider/rbs.rbs +27 -7
  53. data/sig/steep/services/hover_provider/ruby.rbs +18 -4
  54. data/sig/steep/services/hover_provider/singleton_methods.rbs +1 -1
  55. data/sig/steep/signature/validator.rbs +76 -0
  56. data/sig/steep/source.rbs +54 -30
  57. data/sig/steep/type_construction.rbs +85 -27
  58. data/sig/steep/type_inference/method_call.rbs +1 -1
  59. data/smoke/diagnostics-rbs/inherit-module.rbs +2 -0
  60. data/smoke/diagnostics-rbs/test_expectations.yml +12 -0
  61. data/steep.gemspec +1 -1
  62. metadata +16 -6
@@ -0,0 +1,33 @@
1
+ module Parser
2
+ module Source
3
+ class Comment
4
+ def self.associate: (untyped ast, untyped comments) -> untyped
5
+
6
+ def self.associate_by_identity: (untyped ast, untyped comments) -> untyped
7
+
8
+ def self.associate_locations: (untyped ast, untyped comments) -> untyped
9
+
10
+ public
11
+
12
+ def ==: (untyped other) -> bool
13
+
14
+ def document?: () -> bool
15
+
16
+ def inline?: () -> bool
17
+
18
+ def inspect: () -> String
19
+
20
+ alias loc location
21
+
22
+ def location: () -> Map
23
+
24
+ def text: () -> String
25
+
26
+ def type: () -> (:inline | :document)
27
+
28
+ private
29
+
30
+ def initialize: (untyped range) -> void
31
+ end
32
+ end
33
+ end
data/sig/shims/parser.rbs CHANGED
@@ -5,13 +5,41 @@ module Parser
5
5
 
6
6
  attr_reader children: Array[untyped]
7
7
 
8
- def initialize: (Symbol `type`, Array[untyped] children) -> void
8
+ def initialize: (Symbol `type`, ?Array[untyped] children, ?Hash[Symbol, untyped] properties) -> void
9
9
 
10
- def updated: (?Symbol?, ?Array[untyped]?) -> Node
10
+ def updated: (?Symbol?, ?Array[untyped]?, ?Hash[Symbol, untyped]? properties) -> Node
11
11
 
12
12
  attr_reader location: Source::Map
13
13
 
14
14
  alias loc location
15
15
  end
16
16
  end
17
+
18
+ class Ruby31
19
+ def initialize: (untyped builder) -> void
20
+
21
+ def parse: (Source::Buffer) -> AST
22
+
23
+ def parse_with_comments: (Source::Buffer) -> [AST::Node, Array[Source::Comment]]
24
+
25
+ attr_reader diagnostics: untyped
26
+ end
27
+
28
+ module Source
29
+ class Buffer
30
+ def initialize: (String file, Integer lineno, source: String) -> void
31
+ end
32
+ end
33
+
34
+ module Builders
35
+ class Default
36
+ attr_accessor self.emit_lambda: bool
37
+ attr_accessor self.emit_procarg0: bool
38
+ attr_accessor self.emit_kwargs: bool
39
+
40
+ def string_value: (untyped) -> untyped
41
+
42
+ def value: (untyped) -> untyped
43
+ end
44
+ end
17
45
  end
@@ -0,0 +1,59 @@
1
+ module Steep
2
+ class AnnotationParser
3
+ VAR_NAME: Regexp
4
+
5
+ METHOD_NAME: Regexp
6
+
7
+ CONST_NAME: Regexp
8
+
9
+ DYNAMIC_NAME: Regexp
10
+
11
+ IVAR_NAME: Regexp
12
+
13
+ attr_reader factory: AST::Types::Factory
14
+
15
+ def initialize: (factory: AST::Types::Factory) -> void
16
+
17
+ class SyntaxError < StandardError
18
+ attr_reader source: String
19
+
20
+ attr_reader location: RBS::Location[untyped, untyped]
21
+
22
+ def initialize: (source: String, location: RBS::Location[untyped, untyped], ?exn: Exception?) -> void
23
+ end
24
+
25
+ TYPE: Regexp
26
+
27
+ COLON: Regexp
28
+
29
+ PARAM: Regexp
30
+
31
+ TYPE_PARAMS: Regexp
32
+
33
+ def parse_type: (String) -> AST::Types::t
34
+
35
+ # ```
36
+ # @type ${keyword} ${name}: ${type}
37
+ # ```
38
+ #
39
+ # Example:
40
+ #
41
+ # - `@type const Foo::Bar: String`
42
+ # - `@type var xyzzy: Array[String]`
43
+ #
44
+ def keyword_subject_type: (String keyword, Regexp name) -> Regexp
45
+
46
+ # ```
47
+ # @type ${keyword}: ${type}
48
+ # ```
49
+ #
50
+ # Example:
51
+ #
52
+ # - `@type break: String`
53
+ # - `@type self: Foo`
54
+ #
55
+ def keyword_and_type: (String keyword) -> ::Regexp
56
+
57
+ def parse: (String src, location: RBS::Location[untyped, untyped]) -> AST::Annotation::t?
58
+ end
59
+ end
@@ -7,14 +7,20 @@ module Steep
7
7
 
8
8
  type loc = RBS::Location[untyped, untyped]
9
9
 
10
- class Named
11
- attr_reader name: Symbol
10
+ module Located
11
+ attr_reader location: loc?
12
12
 
13
- attr_reader type: Types::t
13
+ %a{pure} def line: () -> Integer?
14
+ end
14
15
 
15
- attr_reader location: loc?
16
+ class Named[T, N]
17
+ attr_reader name: N
18
+
19
+ attr_reader type: T
16
20
 
17
- def initialize: (name: Symbol, type: Types::t, ?location: loc?) -> void
21
+ include Located
22
+
23
+ def initialize: (name: N, type: T, ?location: loc?) -> void
18
24
 
19
25
  def ==: (untyped other) -> bool
20
26
  end
@@ -22,13 +28,11 @@ module Steep
22
28
  class Typed
23
29
  attr_reader type: Types::t
24
30
 
25
- attr_reader annotation: untyped
26
-
27
- attr_reader location: loc?
28
-
29
31
  def initialize: (type: Types::t, ?location: loc?) -> void
30
32
 
31
33
  def ==: (untyped other) -> bool
34
+
35
+ include Located
32
36
  end
33
37
 
34
38
  class ReturnType < Typed
@@ -49,34 +53,25 @@ module Steep
49
53
  class BreakType < Typed
50
54
  end
51
55
 
52
- class MethodType < Named
56
+ class MethodType < Named[Interface::MethodType, Symbol]
53
57
  end
54
58
 
55
- class VarType < Named
59
+ class VarType < Named[Types::t, Symbol]
56
60
  end
57
61
 
58
- class ConstType < Named
59
- attr_reader name: RBS::TypeName
60
-
61
- attr_reader type: Types::t
62
-
63
- attr_reader location: loc?
64
-
65
- def initialize: (name: RBS::TypeName, type: untyped, ?location: loc?) -> void
66
-
67
- def ==: (untyped other) -> bool
62
+ class ConstType < Named[Types::t, RBS::TypeName]
68
63
  end
69
64
 
70
- class IvarType < Named
65
+ class IvarType < Named[Types::t, Symbol]
71
66
  end
72
67
 
73
68
  class Implements
74
69
  class Module
75
70
  attr_reader name: RBS::TypeName
76
71
 
77
- attr_reader args: Array[Types::t]
72
+ attr_reader args: Array[Symbol]
78
73
 
79
- def initialize: (name: RBS::TypeName, args: Array[Types::t]) -> void
74
+ def initialize: (name: RBS::TypeName, args: Array[Symbol]) -> void
80
75
 
81
76
  def ==: (untyped other) -> bool
82
77
 
@@ -85,7 +80,7 @@ module Steep
85
80
  def hash: () -> Integer
86
81
  end
87
82
 
88
- attr_reader location: loc?
83
+ include Located
89
84
 
90
85
  attr_reader name: Module
91
86
 
@@ -113,7 +108,7 @@ module Steep
113
108
  def ==: (untyped other) -> bool
114
109
  end
115
110
 
116
- attr_reader location: loc?
111
+ include Located
117
112
 
118
113
  attr_reader names: Array[Name]
119
114
 
@@ -0,0 +1,31 @@
1
+ module Steep
2
+ module AST
3
+ module Node
4
+ class TypeApplication
5
+ attr_reader location: RBS::Location[untyped, untyped]
6
+
7
+ attr_reader node: Parser::AST::Node
8
+
9
+ def line: () -> Integer
10
+
11
+ def source: () -> String
12
+
13
+ def initialize: (RBS::Location[untyped, untyped]) -> void
14
+
15
+ def types: (RBS::Resolver::context, Types::Factory, Array[Symbol] type_vars) -> (Array[Types::t] | RBS::ParsingError)
16
+
17
+ def types?: (RBS::Resolver::context, Types::Factory, Array[Symbol] type_vars) -> Array[Types::t]?
18
+
19
+ @type_str: String?
20
+ def type_str: () -> String
21
+
22
+ def type_location: () -> RBS::Location[untyped, untyped]
23
+
24
+ # Set the back reference to the `:tapp` node
25
+ def set_node: (Parser::AST::Node) -> void
26
+
27
+ def self.parse: (RBS::Location[untyped, untyped]) -> TypeApplication?
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ module Steep
2
+ module AST
3
+ module Node
4
+ class TypeAssertion
5
+ attr_reader location: RBS::Location[untyped, untyped]
6
+
7
+ def source: () -> String
8
+
9
+ def line: () -> Integer
10
+
11
+ def initialize: (RBS::Location[untyped, untyped]) -> void
12
+
13
+ def type: (RBS::Resolver::context, Types::Factory, Array[Symbol] type_vars) -> (Types::t | RBS::ParsingError | nil)
14
+
15
+ def type?: (RBS::Resolver::context, Types::Factory, Array[Symbol] type_vars) -> Types::t?
16
+
17
+ @type_str: String?
18
+ def type_str: () -> String
19
+
20
+ def type_location: () -> RBS::Location[untyped, untyped]
21
+
22
+ def self.parse: (RBS::Location[untyped, untyped]) -> TypeAssertion?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -4,8 +4,6 @@ module Steep
4
4
  class Factory
5
5
  @env: RBS::Environment
6
6
 
7
- @type_name_resolver: RBS::Resolver::TypeNameResolver
8
-
9
7
  attr_reader definition_builder: RBS::DefinitionBuilder
10
8
 
11
9
  attr_reader type_cache: Hash[RBS::Types::t, t]
@@ -1,9 +1,15 @@
1
1
  module Steep
2
2
  module Diagnostic
3
- module Helper
4
- def error_name: () -> untyped
3
+ module Helper : _DiagnosticMessage
4
+ def error_name: () -> String
5
5
 
6
- def full_message: () -> ::String
6
+ def full_message: () -> String
7
+ end
8
+
9
+ interface _DiagnosticMessage
10
+ %a{pure} def detail_lines: () -> String?
11
+
12
+ def header_line: () -> String
7
13
  end
8
14
  end
9
15
  end
@@ -1,11 +1,15 @@
1
1
  module Steep
2
2
  module Diagnostic
3
3
  class LSPFormatter
4
- LSP: untyped
4
+ LSP: singleton(LanguageServer::Protocol)
5
5
 
6
- attr_reader config: untyped
6
+ type config = Hash[singleton(Diagnostic::Ruby::Base) | singleton(Diagnostic::Signature::Base), severity?]
7
7
 
8
- attr_reader default_severity: untyped
8
+ type severity = :error | :warning | :information | :hint
9
+
10
+ attr_reader config: config
11
+
12
+ attr_reader default_severity: severity
9
13
 
10
14
  ERROR: :error
11
15
 
@@ -15,15 +19,15 @@ module Steep
15
19
 
16
20
  HINT: :hint
17
21
 
18
- def initialize: (?::Hash[untyped, untyped] config, ?default_severity: untyped) -> void
22
+ def initialize: (?config config, ?default_severity: severity) -> void
19
23
 
20
- def validate_class: (untyped klass) -> (untyped | nil)
24
+ def validate_class: (Class klass) -> void
21
25
 
22
- def validate_severity: (untyped klass, untyped severity) -> untyped
26
+ def validate_severity: (Class | :default klass, severity?) -> void
23
27
 
24
- def format: (untyped diagnostic) -> untyped
28
+ def format: (Diagnostic::Ruby::Base | Diagnostic::Signature::Base) -> Hash[Symbol, untyped]?
25
29
 
26
- def severity_for: (untyped diagnostic) -> untyped
30
+ def severity_for: (Diagnostic::Ruby::Base | Diagnostic::Signature::Base) -> String?
27
31
  end
28
32
  end
29
33
  end
@@ -1,7 +1,7 @@
1
1
  module Steep
2
2
  module Diagnostic
3
3
  module Ruby
4
- type location = Parser::Source::Range | Parser::Source::Range
4
+ type location = Parser::Source::Range | RBS::Location[untyped, untyped]
5
5
 
6
6
  class Base
7
7
  include Helper
@@ -384,11 +384,11 @@ module Steep
384
384
  class IncompatibleAnnotation < Base
385
385
  attr_reader result: Subtyping::Result::Base
386
386
 
387
- attr_reader relation: Subtyping::Relation
387
+ attr_reader relation: Subtyping::Relation[untyped]
388
388
 
389
389
  attr_reader var_name: Symbol
390
390
 
391
- def initialize: (node: Parser::AST::Node, var_name: Symbol, result: Subtyping::Result::Base, relation: Subtyping::Relation) -> void
391
+ def initialize: (node: Parser::AST::Node, var_name: Symbol, result: Subtyping::Result::Base, relation: Subtyping::Relation[untyped]) -> void
392
392
 
393
393
  include ResultPrinter
394
394
 
@@ -476,15 +476,69 @@ module Steep
476
476
  def header_line: () -> ::String
477
477
  end
478
478
 
479
- ALL: untyped
479
+ class FalseAssertion < Base
480
+ attr_reader assertion_type: AST::Types::t
480
481
 
481
- def self.all_error: () -> untyped
482
+ attr_reader node_type: AST::Types::t
482
483
 
483
- def self.default: () -> untyped
484
+ def initialize: (node: Parser::AST::Node, assertion_type: AST::Types::t, node_type: AST::Types::t) -> void
484
485
 
485
- def self.strict: () -> untyped
486
+ def header_line: () -> String
487
+ end
488
+
489
+ class UnexpectedTypeArgument < Base
490
+ attr_reader type_arg: AST::Types::t
491
+
492
+ attr_reader method_type: Interface::MethodType
493
+
494
+ def node: () -> nil
495
+
496
+ def initialize: (type_arg: AST::Types::t, method_type: Interface::MethodType) -> void
497
+
498
+ def header_line: () -> String
499
+ end
500
+
501
+ class InsufficientTypeArgument < Base
502
+ attr_reader type_args: Array[AST::Types::t]
503
+
504
+ attr_reader method_type: Interface::MethodType
505
+
506
+ def initialize: (node: Parser::AST::Node, type_args: Array[AST::Types::t], method_type: Interface::MethodType) -> void
507
+
508
+ def header_line: () -> String
509
+ end
510
+
511
+ class TypeArgumentMismatchError < Base
512
+ attr_reader type_argument: AST::Types::t
513
+
514
+ attr_reader type_parameter: Interface::TypeParam
515
+
516
+ attr_reader result: Subtyping::Result::Base
517
+
518
+ include ResultPrinter
519
+
520
+ def node: () -> nil
521
+
522
+ def initialize: (type_arg: AST::Types::t, type_param: Interface::TypeParam, result: Subtyping::Result::Base) -> void
523
+
524
+ def header_line: () -> String
525
+ end
526
+
527
+ ALL: Array[singleton(Base)]
528
+
529
+ type template = Hash[singleton(Base), LSPFormatter::severity]
530
+
531
+ self.@all_error: template?
532
+ def self.all_error: () -> template
533
+
534
+ self.@default: template?
535
+ def self.default: () -> template
536
+
537
+ self.@strict: template?
538
+ def self.strict: () -> template
486
539
 
487
- def self.lenient: () -> untyped
540
+ self.@lenient: template?
541
+ def self.lenient: () -> template
488
542
  end
489
543
  end
490
544
  end