rbs 1.1.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -1
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +81 -0
  5. data/README.md +1 -1
  6. data/Rakefile +11 -0
  7. data/Steepfile +1 -0
  8. data/core/array.rbs +2 -2
  9. data/core/basic_object.rbs +1 -1
  10. data/core/enumerable.rbs +1 -1
  11. data/core/hash.rbs +13 -5
  12. data/core/io.rbs +4 -4
  13. data/core/kernel.rbs +2 -2
  14. data/core/marshal.rbs +4 -3
  15. data/core/module.rbs +1 -1
  16. data/core/numeric.rbs +10 -0
  17. data/core/proc.rbs +1 -1
  18. data/core/random.rbs +4 -2
  19. data/core/range.rbs +2 -2
  20. data/core/struct.rbs +3 -2
  21. data/core/thread.rbs +1 -1
  22. data/docs/CONTRIBUTING.md +5 -3
  23. data/docs/rbs_by_example.md +328 -0
  24. data/docs/sigs.md +21 -2
  25. data/docs/stdlib.md +1 -1
  26. data/docs/syntax.md +11 -14
  27. data/lib/rbs.rb +1 -0
  28. data/lib/rbs/ast/annotation.rb +2 -2
  29. data/lib/rbs/ast/comment.rb +2 -2
  30. data/lib/rbs/ast/declarations.rb +37 -22
  31. data/lib/rbs/ast/members.rb +26 -26
  32. data/lib/rbs/cli.rb +3 -0
  33. data/lib/rbs/constant_table.rb +4 -1
  34. data/lib/rbs/definition.rb +1 -1
  35. data/lib/rbs/definition_builder.rb +16 -18
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +10 -2
  37. data/lib/rbs/definition_builder/method_builder.rb +4 -2
  38. data/lib/rbs/errors.rb +36 -0
  39. data/lib/rbs/location.rb +106 -2
  40. data/lib/rbs/locator.rb +205 -0
  41. data/lib/rbs/method_type.rb +2 -2
  42. data/lib/rbs/parser.rb +1315 -962
  43. data/lib/rbs/parser.y +411 -75
  44. data/lib/rbs/prototype/rb.rb +7 -3
  45. data/lib/rbs/prototype/runtime.rb +118 -42
  46. data/lib/rbs/test/hook.rb +8 -2
  47. data/lib/rbs/type_name.rb +2 -3
  48. data/lib/rbs/type_name_resolver.rb +1 -1
  49. data/lib/rbs/types.rb +36 -34
  50. data/lib/rbs/version.rb +1 -1
  51. data/lib/rbs/writer.rb +4 -2
  52. data/rbs.gemspec +1 -1
  53. data/sig/ancestor_builder.rbs +2 -0
  54. data/sig/annotation.rbs +1 -1
  55. data/sig/cli.rbs +31 -21
  56. data/sig/comment.rbs +1 -1
  57. data/sig/declarations.rbs +106 -21
  58. data/sig/environment.rbs +2 -2
  59. data/sig/errors.rbs +15 -0
  60. data/sig/location.rbs +84 -3
  61. data/sig/locator.rbs +44 -0
  62. data/sig/members.rbs +76 -12
  63. data/sig/method_builder.rbs +1 -1
  64. data/sig/method_types.rbs +1 -1
  65. data/sig/namespace.rbs +1 -1
  66. data/sig/polyfill.rbs +4 -17
  67. data/sig/rbs.rbs +8 -4
  68. data/sig/typename.rbs +1 -1
  69. data/sig/types.rbs +60 -19
  70. data/sig/util.rbs +0 -4
  71. data/sig/writer.rbs +8 -2
  72. data/stdlib/dbm/0/dbm.rbs +43 -30
  73. data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
  74. data/stdlib/net-http/0/net-http.rbs +1846 -0
  75. data/stdlib/optparse/0/optparse.rbs +1214 -0
  76. data/stdlib/resolv/0/resolv.rbs +1504 -0
  77. data/stdlib/rubygems/0/requirement.rbs +84 -2
  78. data/stdlib/rubygems/0/version.rbs +2 -1
  79. data/stdlib/shellwords/0/shellwords.rbs +252 -0
  80. data/stdlib/socket/0/addrinfo.rbs +469 -0
  81. data/stdlib/socket/0/basic_socket.rbs +503 -0
  82. data/stdlib/socket/0/ip_socket.rbs +72 -0
  83. data/stdlib/socket/0/socket.rbs +2687 -0
  84. data/stdlib/socket/0/tcp_server.rbs +177 -0
  85. data/stdlib/socket/0/tcp_socket.rbs +35 -0
  86. data/stdlib/socket/0/udp_socket.rbs +111 -0
  87. data/stdlib/socket/0/unix_server.rbs +154 -0
  88. data/stdlib/socket/0/unix_socket.rbs +132 -0
  89. data/stdlib/timeout/0/timeout.rbs +5 -0
  90. data/steep/Gemfile.lock +19 -16
  91. metadata +18 -11
  92. data/bin/annotate-with-rdoc +0 -153
  93. data/bin/console +0 -14
  94. data/bin/query-rdoc +0 -103
  95. data/bin/rbs-prof +0 -9
  96. data/bin/run_in_md.rb +0 -49
  97. data/bin/setup +0 -8
  98. data/bin/sort +0 -89
  99. data/bin/steep +0 -4
  100. data/bin/test_runner.rb +0 -29
@@ -0,0 +1,132 @@
1
+ # UNIXSocket represents a UNIX domain stream client socket.
2
+ class UNIXSocket < BasicSocket
3
+ # Creates a pair of sockets connected to each other.
4
+ #
5
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
6
+ #
7
+ # *protocol* should be a protocol defined in the domain. 0 is default protocol
8
+ # for the domain.
9
+ #
10
+ # s1, s2 = UNIXSocket.pair
11
+ # s1.send "a", 0
12
+ # s1.send "b", 0
13
+ # p s2.recv(10) #=> "ab"
14
+ #
15
+ def self.pair: (?Symbol socktype, ?Integer protocol) -> [instance, instance]
16
+
17
+ # Creates a pair of sockets connected to each other.
18
+ #
19
+ # *socktype* should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
20
+ #
21
+ # *protocol* should be a protocol defined in the domain. 0 is default protocol
22
+ # for the domain.
23
+ #
24
+ # s1, s2 = UNIXSocket.pair
25
+ # s1.send "a", 0
26
+ # s1.send "b", 0
27
+ # p s2.recv(10) #=> "ab"
28
+ #
29
+ def self.socketpair: (?Symbol socktype, ?Integer protocol) -> [instance, instance]
30
+
31
+ public
32
+
33
+ # Returns the local address as an array which contains address_family and
34
+ # unix_path.
35
+ #
36
+ # Example
37
+ # serv = UNIXServer.new("/tmp/sock")
38
+ # p serv.addr #=> ["AF_UNIX", "/tmp/sock"]
39
+ #
40
+ def addr: () -> [String, String]
41
+
42
+ # Returns the path of the local address of unixsocket.
43
+ #
44
+ # s = UNIXServer.new("/tmp/sock")
45
+ # p s.path #=> "/tmp/sock"
46
+ #
47
+ def path: () -> String
48
+
49
+ # Returns the remote address as an array which contains address_family and
50
+ # unix_path.
51
+ #
52
+ # Example
53
+ # serv = UNIXServer.new("/tmp/sock")
54
+ # c = UNIXSocket.new("/tmp/sock")
55
+ # p c.peeraddr #=> ["AF_UNIX", "/tmp/sock"]
56
+ #
57
+ def peeraddr: () -> [String, String]
58
+
59
+ # Example
60
+ #
61
+ # UNIXServer.open("/tmp/sock") {|serv|
62
+ # UNIXSocket.open("/tmp/sock") {|c|
63
+ # s = serv.accept
64
+ #
65
+ # c.send_io STDOUT
66
+ # stdout = s.recv_io
67
+ #
68
+ # p STDOUT.fileno #=> 1
69
+ # p stdout.fileno #=> 7
70
+ #
71
+ # stdout.puts "hello" # outputs "hello\n" to standard output.
72
+ # }
73
+ # }
74
+ #
75
+ # *klass* will determine the class of *io* returned (using the IO.for_fd
76
+ # singleton method or similar). If *klass* is `nil`, an integer file descriptor
77
+ # is returned.
78
+ #
79
+ # *mode* is the same as the argument passed to IO.for_fd
80
+ #
81
+ def recv_io: (?singleton(BasicSocket), ?String mode) -> BasicSocket
82
+
83
+ # Receives a message via *unixsocket*.
84
+ #
85
+ # *maxlen* is the maximum number of bytes to receive.
86
+ #
87
+ # *flags* should be a bitwise OR of Socket::MSG_* constants.
88
+ #
89
+ # *outbuf* will contain only the received data after the method call even if it
90
+ # is not empty at the beginning.
91
+ #
92
+ # s1 = Socket.new(:UNIX, :DGRAM, 0)
93
+ # s1_ai = Addrinfo.unix("/tmp/sock1")
94
+ # s1.bind(s1_ai)
95
+ #
96
+ # s2 = Socket.new(:UNIX, :DGRAM, 0)
97
+ # s2_ai = Addrinfo.unix("/tmp/sock2")
98
+ # s2.bind(s2_ai)
99
+ # s3 = UNIXSocket.for_fd(s2.fileno)
100
+ #
101
+ # s1.send "a", 0, s2_ai
102
+ # p s3.recvfrom(10) #=> ["a", ["AF_UNIX", "/tmp/sock1"]]
103
+ #
104
+ def recvfrom: (Integer maxlen, ?Integer flags, ?String outbuf) -> [String, [String, String]]
105
+
106
+ # Sends *io* as file descriptor passing.
107
+ #
108
+ # s1, s2 = UNIXSocket.pair
109
+ #
110
+ # s1.send_io STDOUT
111
+ # stdout = s2.recv_io
112
+ #
113
+ # p STDOUT.fileno #=> 1
114
+ # p stdout.fileno #=> 6
115
+ #
116
+ # stdout.puts "hello" # outputs "hello\n" to standard output.
117
+ #
118
+ # *io* may be any kind of IO object or integer file descriptor.
119
+ #
120
+ def send_io: (BasicSocket | Integer) -> void
121
+
122
+ private
123
+
124
+ # Creates a new UNIX client socket connected to *path*.
125
+ #
126
+ # require 'socket'
127
+ #
128
+ # s = UNIXSocket.new("/tmp/sock")
129
+ # s.send "hello", 0
130
+ #
131
+ def initialize: (String path) -> untyped
132
+ end
@@ -54,4 +54,9 @@ module Timeout
54
54
  def self?.timeout: [T] (Numeric? sec, ?singleton(Exception) klass, ?String message) { (Numeric sec) -> T } -> T
55
55
  end
56
56
 
57
+ # Raised by Timeout.timeout when the block times out.
58
+ class Timeout::Error < RuntimeError
59
+ attr_reader thread: Thread?
60
+ end
61
+
57
62
  Timeout::VERSION: String
data/steep/Gemfile.lock CHANGED
@@ -1,41 +1,44 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (6.1.2.1)
4
+ activesupport (6.1.3.2)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 1.6, < 2)
7
7
  minitest (>= 5.1)
8
8
  tzinfo (~> 2.0)
9
9
  zeitwerk (~> 2.3)
10
10
  ast (2.4.2)
11
- ast_utils (0.4.0)
12
- parser (>= 2.7.0)
13
11
  concurrent-ruby (1.1.8)
14
- ffi (1.14.2)
15
- i18n (1.8.8)
12
+ ffi (1.15.1)
13
+ i18n (1.8.10)
16
14
  concurrent-ruby (~> 1.0)
17
- language_server-protocol (3.15.0.1)
18
- listen (3.4.1)
15
+ language_server-protocol (3.16.0.1)
16
+ listen (3.5.1)
19
17
  rb-fsevent (~> 0.10, >= 0.10.3)
20
18
  rb-inotify (~> 0.9, >= 0.9.10)
21
- minitest (5.14.3)
22
- parser (3.0.0.0)
19
+ minitest (5.14.4)
20
+ parallel (1.20.1)
21
+ parser (3.0.1.1)
23
22
  ast (~> 2.4.1)
24
23
  rainbow (3.0.0)
25
- rb-fsevent (0.10.4)
24
+ rb-fsevent (0.11.0)
26
25
  rb-inotify (0.10.1)
27
26
  ffi (~> 1.0)
28
- rbs (1.0.4)
29
- steep (0.41.0)
27
+ rbs (1.2.0)
28
+ steep (0.44.1)
30
29
  activesupport (>= 5.1)
31
- ast_utils (>= 0.4.0)
32
- language_server-protocol (~> 3.15.0.1)
30
+ language_server-protocol (>= 3.15, < 4.0)
33
31
  listen (~> 3.0)
32
+ parallel (>= 1.0.0)
34
33
  parser (>= 2.7)
35
34
  rainbow (>= 2.2.2, < 4.0)
36
- rbs (~> 1.0.3)
35
+ rbs (>= 1.2.0)
36
+ terminal-table (>= 2, < 4)
37
+ terminal-table (3.0.1)
38
+ unicode-display_width (>= 1.1.1, < 3)
37
39
  tzinfo (2.0.4)
38
40
  concurrent-ruby (~> 1.0)
41
+ unicode-display_width (2.0.0)
39
42
  zeitwerk (2.4.2)
40
43
 
41
44
  PLATFORMS
@@ -45,4 +48,4 @@ DEPENDENCIES
45
48
  steep
46
49
 
47
50
  BUNDLED WITH
48
- 2.2.3
51
+ 2.2.15
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -29,15 +29,6 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - Steepfile
32
- - bin/annotate-with-rdoc
33
- - bin/console
34
- - bin/query-rdoc
35
- - bin/rbs-prof
36
- - bin/run_in_md.rb
37
- - bin/setup
38
- - bin/sort
39
- - bin/steep
40
- - bin/test_runner.rb
41
32
  - core/array.rbs
42
33
  - core/basic_object.rbs
43
34
  - core/binding.rbs
@@ -95,6 +86,7 @@ files:
95
86
  - core/unbound_method.rbs
96
87
  - core/warning.rbs
97
88
  - docs/CONTRIBUTING.md
89
+ - docs/rbs_by_example.md
98
90
  - docs/repo.md
99
91
  - docs/sigs.md
100
92
  - docs/stdlib.md
@@ -123,6 +115,7 @@ files:
123
115
  - lib/rbs/errors.rb
124
116
  - lib/rbs/factory.rb
125
117
  - lib/rbs/location.rb
118
+ - lib/rbs/locator.rb
126
119
  - lib/rbs/method_type.rb
127
120
  - lib/rbs/namespace.rb
128
121
  - lib/rbs/parser.rb
@@ -177,6 +170,7 @@ files:
177
170
  - sig/environment_walker.rbs
178
171
  - sig/errors.rbs
179
172
  - sig/location.rbs
173
+ - sig/locator.rbs
180
174
  - sig/members.rbs
181
175
  - sig/method_builder.rbs
182
176
  - sig/method_types.rbs
@@ -220,12 +214,15 @@ files:
220
214
  - stdlib/logger/0/severity.rbs
221
215
  - stdlib/monitor/0/monitor.rbs
222
216
  - stdlib/mutex_m/0/mutex_m.rbs
217
+ - stdlib/net-http/0/net-http.rbs
218
+ - stdlib/optparse/0/optparse.rbs
223
219
  - stdlib/pathname/0/pathname.rbs
224
220
  - stdlib/prettyprint/0/prettyprint.rbs
225
221
  - stdlib/prime/0/integer-extension.rbs
226
222
  - stdlib/prime/0/prime.rbs
227
223
  - stdlib/pstore/0/pstore.rbs
228
224
  - stdlib/pty/0/pty.rbs
225
+ - stdlib/resolv/0/resolv.rbs
229
226
  - stdlib/rubygems/0/basic_specification.rbs
230
227
  - stdlib/rubygems/0/config_file.rbs
231
228
  - stdlib/rubygems/0/dependency_installer.rbs
@@ -242,7 +239,17 @@ files:
242
239
  - stdlib/rubygems/0/version.rbs
243
240
  - stdlib/securerandom/0/securerandom.rbs
244
241
  - stdlib/set/0/set.rbs
242
+ - stdlib/shellwords/0/shellwords.rbs
245
243
  - stdlib/singleton/0/singleton.rbs
244
+ - stdlib/socket/0/addrinfo.rbs
245
+ - stdlib/socket/0/basic_socket.rbs
246
+ - stdlib/socket/0/ip_socket.rbs
247
+ - stdlib/socket/0/socket.rbs
248
+ - stdlib/socket/0/tcp_server.rbs
249
+ - stdlib/socket/0/tcp_socket.rbs
250
+ - stdlib/socket/0/udp_socket.rbs
251
+ - stdlib/socket/0/unix_server.rbs
252
+ - stdlib/socket/0/unix_socket.rbs
246
253
  - stdlib/strscan/0/string_scanner.rbs
247
254
  - stdlib/time/0/time.rbs
248
255
  - stdlib/timeout/0/timeout.rbs
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
- require "rdoc"
6
-
7
- def store_for_class(name, stores:)
8
- stores.find do |store|
9
- store.find_class_named(name) || store.find_module_named(name)
10
- end
11
- end
12
-
13
- def format_comment(comment)
14
- out = RDoc::Markup::Document.new
15
- out << comment
16
- formatter = RDoc::Markup::ToMarkdown.new
17
- out.accept(formatter).lines.map(&:rstrip).join("\n")
18
- end
19
-
20
- def comment_for_constant(decl, stores:)
21
- class_name = decl.name.namespace.to_type_name.to_s
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- if klass
27
- constant = klass.constants.find do |const|
28
- const.name == decl.name.name.to_s
29
- end
30
-
31
- if constant&.documented?
32
- string = format_comment(constant.comment)
33
- RBS::AST::Comment.new(location: nil, string: string)
34
- end
35
- end
36
- end
37
-
38
- def comment_for_class(decl, stores:)
39
- name = decl.name.to_s
40
- klass = store_for_class(name, stores: stores)&.yield_self {|store|
41
- store.find_class_named(name) || store.find_module_named(name)
42
- }
43
-
44
- if klass&.documented?
45
- string = format_comment(klass.comment)
46
- RBS::AST::Comment.new(location: nil, string: string)
47
- end
48
- end
49
-
50
- def comment_for_method(klass, method, stores:)
51
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
52
-
53
- if method&.documented?
54
- out = RDoc::Markup::Document.new
55
-
56
- out << method.comment
57
-
58
- if method.arglists
59
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
60
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
61
- out << RDoc::Markup::Verbatim.new(*arglists)
62
- end
63
-
64
- string = out.accept(RDoc::Markup::ToMarkdown.new)
65
- RBS::AST::Comment.new(location: nil, string: string)
66
- end
67
-
68
- rescue RDoc::Store::MissingFileError
69
- puts " 👺 No document found for #{klass}#{method}"
70
- nil
71
- end
72
-
73
- if ARGV.empty?
74
- puts 'annotate-with-rdoc [RBS files...]'
75
- exit
76
- end
77
-
78
- def print_members(stores, klass_name, members)
79
- members.each do |member|
80
- case member
81
- when RBS::AST::Members::MethodDefinition
82
- puts " Processing #{member.name}..."
83
-
84
- method_name = case
85
- when member.instance?
86
- "##{member.name}"
87
- when member.singleton?
88
- "::#{member.name}"
89
- end
90
-
91
- comment = comment_for_method(klass_name, method_name, stores: stores)
92
-
93
- unless comment
94
- if member.instance? && member.name == :initialize
95
- comment = comment_for_method(klass_name, '::new', stores: stores)
96
- end
97
- end
98
-
99
- member.instance_variable_set(:@comment, comment)
100
- when RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor, RBS::AST::Members::AttrWriter
101
- puts " 👻 Attributes not supported (#{klass_name})"
102
- when RBS::AST::Members::Alias
103
- puts " Processing #{member.new_name}(alias)..."
104
- prefix = case
105
- when member.instance?
106
- "#"
107
- when member.singleton?
108
- "."
109
- end
110
- name = "#{prefix}#{member.new_name}"
111
-
112
- comment = comment_for_method(klass_name, name, stores: stores)
113
- member.instance_variable_set(:@comment, comment)
114
- end
115
- end
116
- end
117
-
118
- stores = []
119
- RDoc::RI::Paths.each true, true, false, false do |path, type|
120
- puts "Loading store from #{path}..."
121
- store = RDoc::RI::Store.new(path, type)
122
- store.load_all
123
- stores << store
124
- end
125
-
126
- ARGV.map {|f| Pathname(f) }.each do |path|
127
- puts "Opening #{path}..."
128
-
129
- buffer = RBS::Buffer.new(name: path, content: path.read)
130
- sigs = RBS::Parser.parse_signature(buffer)
131
-
132
- sigs.each do |decl|
133
- case decl
134
- when RBS::AST::Declarations::Constant
135
- puts " Importing documentation for #{decl.name}..."
136
- comment = comment_for_constant(decl, stores: stores)
137
- decl.instance_variable_set(:@comment, comment)
138
- when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
139
- puts " Importing documentation for #{decl.name}..."
140
- comment = comment_for_class(decl, stores: stores)
141
- decl.instance_variable_set(:@comment, comment)
142
-
143
- print_members stores, decl.name.to_s, decl.members
144
- end
145
- end
146
-
147
- puts "Writing #{path}..."
148
- path.open('w') do |out|
149
- writer = RBS::Writer.new(out: out)
150
- writer.write sigs
151
- end
152
- end
153
-