steep 1.4.0.dev.2 → 1.4.0.dev.3

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -2
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +7 -9
  5. data/Gemfile.steep +1 -2
  6. data/Gemfile.steep.lock +9 -10
  7. data/README.md +7 -1
  8. data/Steepfile +0 -3
  9. data/bin/rbs +0 -1
  10. data/guides/README.md +5 -0
  11. data/guides/src/gem-rbs-collection/gem-rbs-collection.md +143 -0
  12. data/guides/src/getting-started/getting-started.md +164 -0
  13. data/guides/src/nil-optional/nil-optional.md +195 -0
  14. data/lib/steep/diagnostic/ruby.rb +79 -4
  15. data/lib/steep/drivers/check.rb +4 -4
  16. data/lib/steep/interface/block.rb +10 -0
  17. data/lib/steep/module_helper.rb +13 -11
  18. data/lib/steep/path_helper.rb +4 -0
  19. data/lib/steep/server/interaction_worker.rb +105 -92
  20. data/lib/steep/services/type_name_completion.rb +157 -0
  21. data/lib/steep/source.rb +1 -0
  22. data/lib/steep/type_construction.rb +402 -229
  23. data/lib/steep/type_inference/block_params.rb +13 -0
  24. data/lib/steep/type_inference/context.rb +3 -3
  25. data/lib/steep/type_inference/method_params.rb +42 -16
  26. data/lib/steep/type_inference/send_args.rb +79 -50
  27. data/lib/steep/type_inference/type_env.rb +7 -1
  28. data/lib/steep/version.rb +1 -1
  29. data/lib/steep.rb +1 -0
  30. data/rbs_collection.steep.lock.yaml +0 -28
  31. data/rbs_collection.steep.yaml +10 -9
  32. data/sample/lib/conference.rb +12 -0
  33. data/sample/sig/conference.rbs +5 -0
  34. data/sig/shims/language-server_protocol.rbs +12 -0
  35. data/sig/shims/parser/nodes.rbs +37 -0
  36. data/sig/shims/parser.rbs +1 -0
  37. data/sig/shims/string.rbs +4 -0
  38. data/sig/steep/ast/types/factory.rbs +10 -8
  39. data/sig/steep/diagnostic/lsp_formatter.rbs +1 -1
  40. data/sig/steep/diagnostic/ruby.rbs +38 -2
  41. data/sig/steep/drivers/check.rbs +1 -1
  42. data/sig/steep/drivers/checkfile.rbs +1 -1
  43. data/sig/steep/drivers/diagnostic_printer.rbs +1 -1
  44. data/sig/steep/drivers/watch.rbs +1 -1
  45. data/sig/steep/index/signature_symbol_provider.rbs +1 -1
  46. data/sig/steep/interface/block.rbs +2 -0
  47. data/sig/steep/interface/builder.rbs +5 -3
  48. data/sig/steep/interface/method_type.rbs +5 -3
  49. data/sig/steep/module_helper.rbs +9 -0
  50. data/sig/steep/path_helper.rbs +3 -1
  51. data/sig/steep/server/base_worker.rbs +1 -1
  52. data/sig/steep/server/interaction_worker.rbs +46 -17
  53. data/sig/steep/server/master.rbs +1 -1
  54. data/sig/steep/server/type_check_worker.rbs +7 -5
  55. data/sig/steep/server/worker_process.rbs +6 -4
  56. data/sig/steep/services/completion_provider.rbs +2 -0
  57. data/sig/steep/services/type_name_completion.rbs +122 -0
  58. data/sig/steep/type_construction.rbs +99 -30
  59. data/sig/steep/type_inference/block_params.rbs +4 -0
  60. data/sig/steep/type_inference/context.rbs +70 -22
  61. data/sig/steep/type_inference/method_params.rbs +43 -24
  62. data/sig/steep/type_inference/multiple_assignment.rbs +1 -1
  63. data/sig/steep/type_inference/send_args.rbs +13 -3
  64. data/sig/steep/typing.rbs +7 -2
  65. data/smoke/diagnostics/test_expectations.yml +1 -0
  66. data/steep.gemspec +0 -1
  67. metadata +10 -16
@@ -24,9 +24,15 @@ module Steep
24
24
  end
25
25
 
26
26
  module ResultPrinter : _DiagnosticWithResult
27
- def relation_message: (untyped relation) -> untyped
27
+ def relation_message: (Subtyping::Relation[untyped] relation) -> String?
28
28
 
29
- def detail_lines: () -> untyped
29
+ def detail_lines: () -> String?
30
+ end
31
+
32
+ module ResultPrinter2 : _DiagnosticWithResult
33
+ def result_line: (Subtyping::Result::t result) -> String?
34
+
35
+ def detail_lines: () -> String?
30
36
  end
31
37
 
32
38
  class IncompatibleAssignment < Base
@@ -524,6 +530,36 @@ module Steep
524
530
  def header_line: () -> String
525
531
  end
526
532
 
533
+ # Argument forwarding `...` cannot be done safely, because of
534
+ #
535
+ # 1. The arguments are incompatible, or
536
+ # 2. The blocks are incompatible
537
+ #
538
+ class IncompatibleArgumentForwarding < Base
539
+ attr_reader method_name: Symbol
540
+
541
+ attr_reader params_pair: [Interface::Function::Params, Interface::Function::Params]?
542
+
543
+ attr_reader block_pair: [Interface::Block?, Interface::Block?]?
544
+
545
+ attr_reader result: Subtyping::Result::Base
546
+
547
+ include ResultPrinter2
548
+
549
+ # One of `params_pair:` or `block_pair:` is specified where the first object is of the source method (`#foo`) and the second value is of the target method (`#bar`)
550
+ #
551
+ # ```ruby
552
+ # def foo(...)
553
+ # bar(...)
554
+ # end
555
+ # ```
556
+ #
557
+ def initialize: (node: Parser::AST::Node, method_name: Symbol, params_pair: [Interface::Function::Params, Interface::Function::Params], result: Subtyping::Result::Base) -> void
558
+ | (node: Parser::AST::Node, method_name: Symbol, block_pair: [Interface::Block?, Interface::Block?], result: Subtyping::Result::Base) -> void
559
+
560
+ def header_line: () -> String
561
+ end
562
+
527
563
  ALL: Array[singleton(Base)]
528
564
 
529
565
  type template = Hash[singleton(Base), LSPFormatter::severity]
@@ -1,7 +1,7 @@
1
1
  module Steep
2
2
  module Drivers
3
3
  class Check
4
- LSP: untyped
4
+ module LSP = LanguageServer::Protocol
5
5
 
6
6
  attr_reader stdout: untyped
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Steep
2
2
  module Drivers
3
3
  class Checkfile
4
- LSP: singleton(LanguageServer::Protocol)
4
+ module LSP = LanguageServer::Protocol
5
5
 
6
6
  attr_reader stdout: IO
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Steep
2
2
  module Drivers
3
3
  class DiagnosticPrinter
4
- LSP: untyped
4
+ module LSP = LanguageServer::Protocol
5
5
 
6
6
  attr_reader stdout: untyped
7
7
 
@@ -15,7 +15,7 @@ module Steep
15
15
 
16
16
  include Utils::DriverHelper
17
17
 
18
- LSP: singleton(LanguageServer::Protocol)
18
+ module LSP = LanguageServer::Protocol
19
19
 
20
20
  def initialize: (stdout: IO, stderr: IO) -> void
21
21
 
@@ -1,7 +1,7 @@
1
1
  module Steep
2
2
  module Index
3
3
  class SignatureSymbolProvider
4
- LSP: untyped
4
+ module LSP = LanguageServer::Protocol
5
5
 
6
6
  SymbolInformation: untyped
7
7
 
@@ -32,6 +32,8 @@ module Steep
32
32
  def map_type: () { (AST::Types::t) -> AST::Types::t } -> Block
33
33
 
34
34
  def +: (Block other) -> Block
35
+
36
+ def to_proc_type: () -> AST::Types::t
35
37
  end
36
38
  end
37
39
  end
@@ -1,3 +1,5 @@
1
+ use RBS::TypeName
2
+
1
3
  module Steep
2
4
  module Interface
3
5
  class Builder
@@ -85,11 +87,11 @@ module Steep
85
87
  attr_reader cache: Hash[cache_key, Shape?]
86
88
 
87
89
  # No type application (if generic), no self-instance-module resolution
88
- attr_reader raw_instance_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
90
+ attr_reader raw_instance_object_shape_cache: Hash[[TypeName, bool], Shape]
89
91
 
90
- attr_reader raw_singleton_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
92
+ attr_reader raw_singleton_object_shape_cache: Hash[[TypeName, bool], Shape]
91
93
 
92
- attr_reader raw_interface_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
94
+ attr_reader raw_interface_object_shape_cache: Hash[[TypeName, bool], Shape]
93
95
 
94
96
  def initialize: (AST::Types::Factory) -> void
95
97
 
@@ -1,3 +1,5 @@
1
+ use Steep::TypeInference::MethodCall::MethodDecl
2
+
1
3
  module Steep
2
4
  module Interface
3
5
  class MethodType
@@ -7,11 +9,11 @@ module Steep
7
9
 
8
10
  attr_reader block: Block?
9
11
 
10
- attr_reader method_decls: Set[TypeInference::MethodCall::MethodDecl]
12
+ attr_reader method_decls: Set[MethodDecl]
11
13
 
12
14
  @fvs: Set[Symbol]
13
15
 
14
- def initialize: (type_params: Array[TypeParam], type: Function, block: Block?, method_decls: Set[TypeInference::MethodCall::MethodDecl]) -> void
16
+ def initialize: (type_params: Array[TypeParam], type: Function, block: Block?, method_decls: Set[MethodDecl]) -> void
15
17
 
16
18
  def ==: (untyped other) -> bool
17
19
 
@@ -28,7 +30,7 @@ module Steep
28
30
 
29
31
  def instantiate: (Substitution s) -> MethodType
30
32
 
31
- def with: (?type_params: Array[TypeParam], ?type: Function, ?block: Block?, ?method_decls: Set[TypeInference::MethodCall::MethodDecl]) -> MethodType
33
+ def with: (?type_params: Array[TypeParam], ?type: Function, ?block: Block?, ?method_decls: Set[MethodDecl]) -> MethodType
32
34
 
33
35
  def to_s: () -> ::String
34
36
 
@@ -1,7 +1,16 @@
1
1
  module Steep
2
2
  module ModuleHelper
3
+ # Translate a *const* node to a type name if possible
4
+ #
5
+ # ```ruby
6
+ # Foo::Bar # => `Foo::Bar`
7
+ # foo::Bar # => nil
8
+ # ```
9
+ #
3
10
  def module_name_from_node: (Parser::AST::Node? parent_node, Symbol constant_name) -> RBS::TypeName?
4
11
 
12
+ # Translate a *const* node to a namespace if possible
13
+ #
5
14
  def namespace_from_node: (Parser::AST::Node? node) -> RBS::Namespace?
6
15
  end
7
16
  end
@@ -6,8 +6,10 @@ module Steep
6
6
  #
7
7
  def self?.to_pathname: (String uri, ?dosish: bool) -> Pathname?
8
8
 
9
+ def self?.to_pathname!: (String uri, ?dosish: bool) -> Pathname
10
+
9
11
  # Receives a Pathname and returns a *file* URI
10
- #
12
+ #
11
13
  def self?.to_uri: (Pathname path, ?dosish: bool) -> URI::File
12
14
  end
13
15
  end
@@ -9,7 +9,7 @@ module Steep
9
9
  def close: () -> void
10
10
  end
11
11
 
12
- LSP: untyped
12
+ module LSP = LanguageServer::Protocol
13
13
 
14
14
  @skip_jobs_after_shutdown: bool
15
15
 
@@ -1,41 +1,70 @@
1
+ use LanguageServer::Protocol::Transport::Io::*, Thread::Queue, RBS::AST::Comment
2
+ use Steep::Services::CompletionProvider, Steep::Services::TypeNameCompletion
3
+ use RBS::TypeName, RBS::Namespace
4
+
1
5
  module Steep
2
6
  module Server
3
7
  class InteractionWorker < BaseWorker
4
8
  include ChangeBuffer
5
9
 
6
- ApplyChangeJob: untyped
10
+ class ApplyChangeJob
11
+ end
7
12
 
8
- HoverJob: untyped
13
+ class HoverJob
14
+ attr_reader id: String
9
15
 
10
- CompletionJob: untyped
16
+ attr_reader path: Pathname
11
17
 
12
- LSP: untyped
18
+ attr_reader line: Integer
13
19
 
14
- attr_reader service: untyped
20
+ attr_reader column: Integer
15
21
 
16
- def initialize: (project: untyped, reader: untyped, writer: untyped, ?queue: untyped) -> void
22
+ def initialize: (id: String, path: Pathname, line: Integer, column: Integer) -> void
23
+ end
17
24
 
18
- def handle_job: (untyped job) -> untyped
25
+ class CompletionJob
26
+ attr_reader id: String
19
27
 
20
- def handle_request: (untyped request) -> untyped
28
+ attr_reader path: Pathname
21
29
 
22
- def process_hover: (untyped job) -> untyped
30
+ attr_reader line: Integer
23
31
 
24
- def process_completion: (untyped job) -> untyped
32
+ attr_reader column: Integer
25
33
 
26
- def format_completion_item_for_rbs: (Services::SignatureService sig_service, untyped type_name, untyped context, untyped job, untyped prefix) -> (nil | untyped)
34
+ attr_reader trigger: String
27
35
 
28
- def format_comment: (untyped comment) -> (untyped | nil)
36
+ def initialize: (id: String, path: Pathname, line: Integer, column: Integer, trigger: String) -> void
37
+ end
29
38
 
30
- def format_comments: (Array[RBS::AST::Comment] comments) -> untyped?
39
+ type job = ApplyChangeJob | HoverJob | CompletionJob
40
+
41
+ module LSP = LanguageServer::Protocol
42
+
43
+ attr_reader service: Services::TypeCheckService
44
+
45
+ def initialize: (project: Project, reader: Reader, writer: Writer, ?queue: Queue) -> void
46
+
47
+ def handle_job: (job) -> void
48
+
49
+ type lsp_request = { id: String, method: String, params: untyped }
31
50
 
32
- def format_completion_item: (untyped item) -> untyped
51
+ def handle_request: (lsp_request) -> void
52
+
53
+ def process_hover: (HoverJob job) -> untyped
54
+
55
+ def process_completion: (CompletionJob job) -> untyped
56
+
57
+ def format_completion_item_for_rbs: (Services::SignatureService, RBS::TypeName, CompletionJob job, String complete_text, Integer prefix_size) -> untyped
58
+
59
+ def format_comment: (Comment? comment) -> untyped?
60
+
61
+ def format_comments: (Array[RBS::AST::Comment] comments) -> untyped?
33
62
 
34
- def method_type_to_snippet: (untyped method_type) -> ::String
63
+ def format_completion_item: (CompletionProvider::item item) -> untyped
35
64
 
36
- def params_to_snippet: (untyped fun) -> untyped
65
+ def method_type_to_snippet: (RBS::MethodType method_type) -> ::String
37
66
 
38
- def relative_name_in_context: (untyped type_name, untyped context) -> untyped
67
+ def params_to_snippet: (RBS::Types::Function fun) -> String
39
68
  end
40
69
  end
41
70
  end
@@ -1,7 +1,7 @@
1
1
  module Steep
2
2
  module Server
3
3
  class Master
4
- LSP: singleton(LanguageServer::Protocol)
4
+ module LSP = LanguageServer::Protocol
5
5
 
6
6
  class TypeCheckRequest
7
7
  attr_reader guid: String
@@ -1,3 +1,5 @@
1
+ use Steep::Services::*, LanguageServer::Protocol as LSP
2
+
1
3
  module Steep
2
4
  module Server
3
5
  # TypeCheckWorker provides two features:
@@ -15,9 +17,9 @@ module Steep
15
17
  class TypeCheckWorker < BaseWorker
16
18
  attr_reader project: Project
17
19
 
18
- attr_reader assignment: Services::PathAssignment
20
+ attr_reader assignment: PathAssignment
19
21
 
20
- attr_reader service: Services::TypeCheckService
22
+ attr_reader service: TypeCheckService
21
23
 
22
24
  attr_reader commandline_args: Array[String]
23
25
 
@@ -95,9 +97,9 @@ module Steep
95
97
 
96
98
  def initialize: (
97
99
  project: Project,
98
- reader: LanguageServer::Protocol::Transport::Io::Reader,
99
- writer: LanguageServer::Protocol::Transport::Io::Writer,
100
- assignment: Services::PathAssignment,
100
+ reader: LSP::Transport::Io::Reader,
101
+ writer: LSP::Transport::Io::Writer,
102
+ assignment: PathAssignment,
101
103
  commandline_args: Array[String]
102
104
  ) -> void
103
105
 
@@ -1,3 +1,5 @@
1
+ use LanguageServer::Protocol as LSP
2
+
1
3
  module Steep
2
4
  module Server
3
5
  # WorkerProcess class represents a worker process
@@ -21,9 +23,9 @@ module Steep
21
23
  def pid: () -> Integer
22
24
  end
23
25
 
24
- attr_reader reader: LanguageServer::Protocol::Transport::Io::Reader
26
+ attr_reader reader: LSP::Transport::Io::Reader
25
27
 
26
- attr_reader writer: LanguageServer::Protocol::Transport::Io::Writer
28
+ attr_reader writer: LSP::Transport::Io::Writer
27
29
 
28
30
  attr_reader stderr: IO?
29
31
 
@@ -34,8 +36,8 @@ module Steep
34
36
  attr_reader index: Integer?
35
37
 
36
38
  def initialize: (
37
- reader: LanguageServer::Protocol::Transport::Io::Reader,
38
- writer: LanguageServer::Protocol::Transport::Io::Writer,
39
+ reader: LSP::Transport::Io::Reader,
40
+ writer: LSP::Transport::Io::Writer,
39
41
  stderr: IO?,
40
42
  wait_thread: Thread & _ProcessWaitThread,
41
43
  name: String,
@@ -77,6 +77,8 @@ module Steep
77
77
  def inherited?: () -> bool
78
78
  end
79
79
 
80
+ type item = InstanceVariableItem | LocalVariableItem | ConstantItem | MethodNameItem
81
+
80
82
  attr_reader source_text: String
81
83
 
82
84
  attr_reader path: Pathname
@@ -0,0 +1,122 @@
1
+ use RBS::TypeName, RBS::Namespace, RBS::Environment, RBS::Resolver, RBS::AST::Directives
2
+
3
+ module Steep
4
+ module Services
5
+ class TypeNameCompletion
6
+ module Prefix
7
+ type t = nil # no prefix
8
+ | RawIdentPrefix
9
+ | NamespacedIdentPrefix
10
+ | NamespacePrefix
11
+
12
+ # Uident or Lident is given, but no `::` (==namespace)
13
+ #
14
+ # ```
15
+ # Str← Uident
16
+ # c← Lident
17
+ # ```
18
+ #
19
+ class RawIdentPrefix
20
+ attr_reader ident: String
21
+
22
+ # Returns true if the `ident` is a Ruby class name
23
+ #
24
+ def const_name?: () -> bool
25
+
26
+ def initialize: (String ident) -> void
27
+
28
+ def size: () -> Integer
29
+ end
30
+
31
+ # Uident or Lident following a namespace
32
+ #
33
+ # ```
34
+ # ::L← Uident
35
+ # RBS::Enviro← Uident
36
+ # ```
37
+ #
38
+ class NamespacedIdentPrefix
39
+ attr_reader namespace: Namespace
40
+
41
+ attr_reader ident: String
42
+
43
+ def const_name?: () -> bool
44
+
45
+ def initialize: (Namespace, String ident, Integer size) -> void
46
+
47
+ def size: () -> Integer
48
+ end
49
+
50
+ # Namespace is given
51
+ #
52
+ # ```
53
+ # RBS::←
54
+ # ::←
55
+ # ```
56
+ class NamespacePrefix
57
+ attr_reader namespace: Namespace
58
+
59
+ def initialize: (Namespace, Integer size) -> void
60
+
61
+ def size: () -> Integer
62
+ end
63
+
64
+ # line number is 1 origin (Rubyish)
65
+ #
66
+ def self.parse: (RBS::Buffer input, line: Integer, column: Integer) -> t
67
+ end
68
+
69
+ class Item
70
+ # The text to be completed
71
+ #
72
+ attr_reader complete_text: String
73
+
74
+ # The prefix
75
+ attr_reader prefix: Prefix::t?
76
+
77
+ # Name of the type or constant
78
+ #
79
+ attr_reader full_name: TypeName
80
+
81
+ # The text to be inserted after the prefix
82
+ #
83
+ def insert_text: () -> String
84
+
85
+ def initialize: (prefix: Prefix::t?, full_name: TypeName, complete_text: String) -> void
86
+ end
87
+
88
+ attr_reader env: Environment
89
+
90
+ attr_reader context: Resolver::context
91
+
92
+ attr_reader type_name_resolver: Resolver::TypeNameResolver
93
+
94
+ attr_reader map: Environment::UseMap
95
+
96
+ def initialize: (env: Environment, context: Resolver::context, dirs: Array[Directives::t]) -> void
97
+
98
+ def complete_class_name: (RBS::Buffer input, line: Integer, column: Integer) -> Array[Item]
99
+
100
+ # Find type names from the context for RBS
101
+ #
102
+ # Doesn't take account of ancestors of the context.
103
+ #
104
+ def find_type_names: (Prefix::t) -> Array[TypeName]
105
+
106
+ # Returns a pair of
107
+ #
108
+ # * Absolute type name
109
+ # * Relative type name in given context if possible (or absolute name)
110
+ #
111
+ def resolve_name_in_context: (TypeName) -> [TypeName, TypeName]
112
+
113
+ def format_constant_name: (TypeName) -> String
114
+
115
+ def each_type_name: () { (TypeName) -> void } -> void
116
+ | () -> Enumerator[TypeName, void]
117
+
118
+ def each_outer_module: (?Resolver::context) { (Namespace) -> void } -> Namespace
119
+ | () -> Enumerator[Namespace, void]
120
+ end
121
+ end
122
+ end