rbs 3.0.0.dev.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/CHANGELOG.md +67 -0
  5. data/Gemfile.lock +11 -11
  6. data/Rakefile +2 -2
  7. data/Steepfile +1 -0
  8. data/core/array.rbs +573 -423
  9. data/core/basic_object.rbs +11 -39
  10. data/core/binding.rbs +1 -1
  11. data/core/builtin.rbs +8 -0
  12. data/core/class.rbs +37 -0
  13. data/core/comparable.rbs +7 -18
  14. data/core/complex.rbs +2 -2
  15. data/core/data.rbs +419 -0
  16. data/core/dir.rbs +52 -104
  17. data/core/encoding.rbs +22 -181
  18. data/core/enumerable.rbs +212 -175
  19. data/core/enumerator/product.rbs +94 -0
  20. data/core/enumerator.rbs +57 -8
  21. data/core/errors.rbs +8 -2
  22. data/core/exception.rbs +41 -0
  23. data/core/fiber.rbs +95 -12
  24. data/core/file.rbs +840 -275
  25. data/core/file_test.rbs +34 -19
  26. data/core/float.rbs +40 -96
  27. data/core/gc.rbs +15 -3
  28. data/core/hash.rbs +113 -175
  29. data/core/integer.rbs +85 -145
  30. data/core/io/buffer.rbs +187 -60
  31. data/core/io/wait.rbs +28 -16
  32. data/core/io.rbs +1859 -1389
  33. data/core/kernel.rbs +525 -961
  34. data/core/match_data.rbs +306 -142
  35. data/core/math.rbs +506 -234
  36. data/core/method.rbs +0 -24
  37. data/core/module.rbs +110 -17
  38. data/core/nil_class.rbs +2 -0
  39. data/core/numeric.rbs +76 -144
  40. data/core/object.rbs +88 -212
  41. data/core/proc.rbs +17 -5
  42. data/core/process.rbs +22 -5
  43. data/core/ractor.rbs +1 -1
  44. data/core/random.rbs +20 -3
  45. data/core/range.rbs +91 -89
  46. data/core/rational.rbs +2 -3
  47. data/core/rbs/unnamed/argf.rbs +177 -120
  48. data/core/rbs/unnamed/env_class.rbs +89 -163
  49. data/core/rbs/unnamed/random.rbs +36 -12
  50. data/core/refinement.rbs +8 -0
  51. data/core/regexp.rbs +462 -272
  52. data/core/ruby_vm.rbs +210 -0
  53. data/{stdlib/set/0 → core}/set.rbs +43 -47
  54. data/core/string.rbs +1403 -1332
  55. data/core/string_io.rbs +191 -107
  56. data/core/struct.rbs +67 -63
  57. data/core/symbol.rbs +187 -201
  58. data/core/thread.rbs +40 -35
  59. data/core/time.rbs +902 -826
  60. data/core/trace_point.rbs +55 -6
  61. data/core/unbound_method.rbs +48 -24
  62. data/docs/collection.md +4 -0
  63. data/docs/syntax.md +55 -0
  64. data/ext/rbs_extension/parser.c +5 -6
  65. data/lib/rbs/cli.rb +11 -1
  66. data/lib/rbs/collection/cleaner.rb +8 -1
  67. data/lib/rbs/collection/config/lockfile.rb +3 -1
  68. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  69. data/lib/rbs/collection/config.rb +1 -1
  70. data/lib/rbs/collection/sources/git.rb +9 -2
  71. data/lib/rbs/collection/sources/local.rb +79 -0
  72. data/lib/rbs/collection/sources.rb +8 -1
  73. data/lib/rbs/environment.rb +11 -27
  74. data/lib/rbs/environment_loader.rb +3 -2
  75. data/lib/rbs/errors.rb +18 -0
  76. data/lib/rbs/locator.rb +26 -7
  77. data/lib/rbs/sorter.rb +2 -2
  78. data/lib/rbs/version.rb +1 -1
  79. data/sig/collection/sources.rbs +32 -3
  80. data/sig/environment.rbs +5 -8
  81. data/sig/locator.rbs +14 -2
  82. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  83. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  84. data/stdlib/cgi/0/core.rbs +16 -0
  85. data/stdlib/coverage/0/coverage.rbs +50 -8
  86. data/stdlib/csv/0/csv.rbs +1 -1
  87. data/stdlib/date/0/date.rbs +856 -726
  88. data/stdlib/date/0/date_time.rbs +83 -210
  89. data/stdlib/erb/0/erb.rbs +13 -36
  90. data/stdlib/etc/0/etc.rbs +127 -20
  91. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  92. data/stdlib/logger/0/logger.rbs +466 -316
  93. data/stdlib/net-http/0/net-http.rbs +2211 -534
  94. data/stdlib/nkf/0/nkf.rbs +5 -5
  95. data/stdlib/objspace/0/objspace.rbs +31 -14
  96. data/stdlib/openssl/0/openssl.rbs +11 -7
  97. data/stdlib/optparse/0/optparse.rbs +20 -17
  98. data/stdlib/pathname/0/pathname.rbs +21 -4
  99. data/stdlib/pstore/0/pstore.rbs +378 -154
  100. data/stdlib/pty/0/pty.rbs +24 -8
  101. data/stdlib/ripper/0/ripper.rbs +1650 -0
  102. data/stdlib/socket/0/addrinfo.rbs +9 -15
  103. data/stdlib/socket/0/socket.rbs +36 -3
  104. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  105. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  106. data/stdlib/time/0/time.rbs +2 -2
  107. data/stdlib/uri/0/file.rbs +5 -0
  108. data/stdlib/uri/0/generic.rbs +2 -2
  109. data/stdlib/yaml/0/yaml.rbs +2 -2
  110. data/stdlib/zlib/0/zlib.rbs +1 -1
  111. metadata +10 -8
  112. data/core/deprecated.rbs +0 -9
  113. data/sig/shims/ripper.rbs +0 -8
data/lib/rbs/errors.rb CHANGED
@@ -20,7 +20,25 @@ module RBS
20
20
  class LoadingError < BaseError; end
21
21
  class DefinitionError < BaseError; end
22
22
 
23
+ module DetailedMessageable
24
+ def detailed_message(highlight: false, **)
25
+ indent = " " * location.start_column
26
+ marker = "^" * (location.end_column - location.start_column)
27
+
28
+ io = StringIO.new
29
+ io.puts super
30
+ io.puts
31
+ io.print "\e[1m" if highlight
32
+ io.puts " #{location.buffer.lines[location.end_line - 1]}"
33
+ io.puts " #{indent}#{marker}"
34
+ io.print "\e[m" if highlight
35
+ io.string
36
+ end
37
+ end
38
+
23
39
  class ParsingError < BaseError
40
+ include DetailedMessageable
41
+
24
42
  attr_reader :location
25
43
  attr_reader :error_message
26
44
  attr_reader :token_type
data/lib/rbs/locator.rb CHANGED
@@ -2,21 +2,24 @@
2
2
 
3
3
  module RBS
4
4
  class Locator
5
- attr_reader :decls
5
+ attr_reader :decls, :dirs, :buffer
6
6
 
7
- def initialize(decls:)
7
+ def initialize(buffer:, dirs:, decls:)
8
+ @buffer = buffer
9
+ @dirs = dirs
8
10
  @decls = decls
9
11
  end
10
12
 
11
- def buffer
12
- decls[0].location&.buffer or raise
13
- end
14
-
15
13
  def find(line:, column:)
16
14
  pos = buffer.loc_to_pos([line, column])
17
15
 
16
+ dirs.each do |dir|
17
+ array = [] #: Array[component]
18
+ find_in_directive(pos, dir, array) and return array
19
+ end
20
+
18
21
  decls.each do |decl|
19
- array = []
22
+ array = [] #: Array[component]
20
23
  find_in_decl(pos, decl: decl, array: array) and return array
21
24
  end
22
25
 
@@ -36,6 +39,22 @@ module RBS
36
39
  end
37
40
  end
38
41
 
42
+ def find_in_directive(pos, dir, array)
43
+ if test_loc(pos, location: dir.location)
44
+ array.unshift(dir)
45
+
46
+ dir.clauses.each do |clause|
47
+ if test_loc(pos, location: clause.location)
48
+ array.unshift(clause)
49
+ find_in_loc(pos, location: clause.location, array: array)
50
+ return true
51
+ end
52
+ end
53
+ end
54
+
55
+ false
56
+ end
57
+
39
58
  def find_in_decl(pos, decl:, array:)
40
59
  if test_loc(pos, location: decl.location)
41
60
  array.unshift(decl)
data/lib/rbs/sorter.rb CHANGED
@@ -34,7 +34,7 @@ module RBS
34
34
  -3
35
35
  when Declarations::Constant
36
36
  -2
37
- when Declarations::Class, Declarations::Module
37
+ when Declarations::Class, Declarations::Module, Declarations::Interface
38
38
  -1
39
39
  when Members::Include
40
40
  0.0
@@ -102,7 +102,7 @@ module RBS
102
102
  member.name.to_s
103
103
  when Declarations::TypeAlias
104
104
  member.name.to_s
105
- when Declarations::Class, Declarations::Module
105
+ when Declarations::Class, Declarations::Module, Declarations::Interface
106
106
  member.name.to_s
107
107
  else
108
108
  raise
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "3.0.0.dev.2"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -1,8 +1,8 @@
1
1
  module RBS
2
2
  module Collection
3
3
  module Sources
4
- def self.from_config_entry: (Git::source_entry) -> Git
5
- | (source_entry) -> t
4
+ def self.from_config_entry: (Git::source_entry, base_directory: Pathname) -> Git
5
+ | (source_entry, base_directory: Pathname) -> t
6
6
 
7
7
  interface _Source
8
8
  def has?: (String name, String? version) -> boolish
@@ -13,11 +13,12 @@ module RBS
13
13
  def dependencies_of: (String name, String version) -> Array[manifest_dependency]?
14
14
  end
15
15
 
16
- type t = Git | Stdlib | Rubygems
16
+ type t = Git | Stdlib | Rubygems | Local
17
17
 
18
18
  type source_entry = Git::source_entry
19
19
  | Stdlib::source_entry
20
20
  | Rubygems::source_entry
21
+ | Local::source_entry
21
22
 
22
23
  type manifest_entry = {
23
24
  "dependencies" => Array[manifest_dependency]?,
@@ -126,6 +127,34 @@ module RBS
126
127
  def gems_versions: () -> Hash[String, Set[String]]
127
128
  end
128
129
 
130
+ class Local
131
+ include Base
132
+
133
+ type source_entry = {
134
+ 'type' => 'local',
135
+ 'path' => String,
136
+ }
137
+
138
+ attr_reader path: Pathname
139
+ attr_reader full_path: Pathname
140
+
141
+ def initialize: (path: String, base_directory: Pathname) -> void
142
+
143
+ def has?: (String name, String? version) -> boolish
144
+
145
+ def versions: (String name) -> Array[String]
146
+
147
+ def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
148
+
149
+ def to_lockfile: () -> source_entry
150
+
151
+ def manifest_of: (String name, String version) -> manifest_entry?
152
+
153
+ private
154
+
155
+ def _install: (Pathname src, Pathname dest) -> void
156
+ end
157
+
129
158
  # signatures that are bundled in rbs gem under the stdlib/ directory
130
159
  class Stdlib
131
160
 
data/sig/environment.rbs CHANGED
@@ -111,7 +111,9 @@ module RBS
111
111
  # Global declarations
112
112
  attr_reader global_decls: Hash[Symbol, GlobalEntry]
113
113
 
114
- attr_reader buffer_directives: Hash[Buffer, Array[AST::Directives::t]]
114
+ # A hash from Buffer to it's contents
115
+ #
116
+ attr_reader signatures: Hash[Buffer, [Array[AST::Directives::t], Array[AST::Declarations::t]]]
115
117
 
116
118
  def initialize: () -> void
117
119
 
@@ -141,16 +143,11 @@ module RBS
141
143
 
142
144
  def inspect: () -> String
143
145
 
144
- @buffers: Array[Buffer]
145
-
146
146
  def buffers: () -> Array[Buffer]
147
147
 
148
- def buffers_decls: () -> Hash[Buffer, Array[AST::Declarations::t]]
149
-
150
- # Construct new environment without declarations tested `true` by block.
151
- # Construction of new environment is done with `<<` so that nested declarations will work well.
148
+ # Remove declarations and directives that are loaded from `buffers`
152
149
  #
153
- def reject: () { (AST::Declarations::t) -> boolish } -> Environment
150
+ def unload: (Set[Buffer] buffers) -> Environment
154
151
 
155
152
  # Returns true if an interface with the type name is defined
156
153
  #
data/sig/locator.rbs CHANGED
@@ -10,14 +10,22 @@ module RBS
10
10
  | AST::TypeParam
11
11
  | AST::Declarations::Class::Super
12
12
  | AST::Declarations::Module::Self
13
+ | AST::Directives::t
14
+ | AST::Directives::Use::clause
15
+
16
+ # The buffer the location points to
17
+ #
18
+ attr_reader buffer: Buffer
13
19
 
14
20
  # Array of _top-level_ declarations.
15
21
  #
16
22
  attr_reader decls: Array[AST::Declarations::t]
17
23
 
18
- def initialize: (decls: Array[AST::Declarations::t]) -> void
24
+ # Array of directives.
25
+ #
26
+ attr_reader dirs: Array[AST::Directives::t]
19
27
 
20
- def buffer: () -> Buffer
28
+ def initialize: (buffer: Buffer, decls: Array[AST::Declarations::t], dirs: Array[AST::Directives::t]) -> void
21
29
 
22
30
  # Returns list of components.
23
31
  # Inner component comes first.
@@ -29,6 +37,10 @@ module RBS
29
37
  #
30
38
  def find2: (line: Integer, column: Integer) -> [Symbol?, Array[component]]?
31
39
 
40
+ private
41
+
42
+ def find_in_directive: (Integer pos, AST::Directives::t, Array[component]) -> bool
43
+
32
44
  def find_in_decl: (Integer pos, decl: AST::Declarations::t, array: Array[component]) -> bool
33
45
 
34
46
  def find_in_member: (Integer pos, member: AST::Members::t, array: Array[component]) -> bool
@@ -145,12 +145,8 @@ class BigDecimal < Numeric
145
145
 
146
146
  # <!--
147
147
  # rdoc-file=ext/bigdecimal/bigdecimal.c
148
- # - BigDecimal.double_fig -> integer
148
+ # - double_fig()
149
149
  # -->
150
- # Returns the number of digits a Float object is allowed to have; the result is
151
- # system-dependent:
152
- #
153
- # BigDecimal.double_fig # => 16
154
150
  #
155
151
  def self.double_fig: () -> Integer
156
152
 
@@ -1007,7 +1003,9 @@ class BigDecimal < Numeric
1007
1003
  # -->
1008
1004
  # Returns the sign of the value.
1009
1005
  #
1010
- # Returns a positive value if > 0, a negative value if < 0, and a zero if == 0.
1006
+ # Returns a positive value if > 0, a negative value if < 0. It behaves the same
1007
+ # with zeros - it returns a positive value for a positive zero (BigDecimal('0'))
1008
+ # and a negative value for a negative zero (BigDecimal('-0')).
1011
1009
  #
1012
1010
  # The specific value returned indicates the type and sign of the BigDecimal, as
1013
1011
  # follows:
@@ -1348,12 +1346,15 @@ module Kernel
1348
1346
  # - BigDecimal(value, exception: true) -> bigdecimal
1349
1347
  # - BigDecimal(value, ndigits, exception: true) -> bigdecimal
1350
1348
  # -->
1351
- # Returns the \BigDecimal converted from +value+
1352
- # with a precision of +ndigits+ decimal digits.
1349
+ # Returns the BigDecimal converted from `value` with a precision of `ndigits`
1350
+ # decimal digits.
1351
+ #
1352
+ # When `ndigits` is less than the number of significant digits in the value, the
1353
+ # result is rounded to that number of digits, according to the current rounding
1354
+ # mode; see BigDecimal.mode.
1353
1355
  #
1354
- # When +ndigits+ is less than the number of significant digits
1355
- # in the value, the result is rounded to that number of digits,
1356
- # according to the current rounding mode; see BigDecimal.mode.
1356
+ # When `ndigits` is 0, the number of digits to correctly represent a float
1357
+ # number is determined automatically.
1357
1358
  #
1358
1359
  # Returns `value` converted to a BigDecimal, depending on the type of `value`:
1359
1360
  #
@@ -1486,13 +1487,15 @@ class Float
1486
1487
  # - float.to_d(precision) -> bigdecimal
1487
1488
  # -->
1488
1489
  # Returns the value of `float` as a BigDecimal. The `precision` parameter is
1489
- # used to determine the number of significant digits for the result (the default
1490
- # is Float::DIG).
1490
+ # used to determine the number of significant digits for the result. When
1491
+ # `precision` is set to `0`, the number of digits to represent the float being
1492
+ # converted is determined automatically. The default `precision` is `0`.
1491
1493
  #
1492
1494
  # require 'bigdecimal'
1493
1495
  # require 'bigdecimal/util'
1494
1496
  #
1495
1497
  # 0.5.to_d # => 0.5e0
1498
+ # 1.234.to_d # => 0.1234e1
1496
1499
  # 1.234.to_d(2) # => 0.12e1
1497
1500
  #
1498
1501
  # See also BigDecimal::new.
@@ -882,6 +882,14 @@ class CGI
882
882
  #
883
883
  def escapeHTML: (string str) -> String
884
884
 
885
+ # <!--
886
+ # rdoc-file=ext/cgi/escape/escape.c
887
+ # - CGI.escapeURIComponent(string) -> string
888
+ # -->
889
+ # Returns URL-escaped string following RFC 3986.
890
+ #
891
+ def escapeURIComponent: (string) -> String
892
+
885
893
  # <!--
886
894
  # rdoc-file=ext/cgi/escape/escape.c
887
895
  # - CGI.unescape(string, encoding=@@accept_charset) -> string
@@ -897,6 +905,14 @@ class CGI
897
905
  # Returns HTML-unescaped string.
898
906
  #
899
907
  def unescapeHTML: (string str) -> String
908
+
909
+ # <!--
910
+ # rdoc-file=ext/cgi/escape/escape.c
911
+ # - CGI.unescapeURIComponent(string, encoding=@@accept_charset) -> string
912
+ # -->
913
+ # Returns URL-unescaped string following RFC 3986.
914
+ #
915
+ def unescapeURIComponent: (string) -> String
900
916
  end
901
917
 
902
918
  # <!-- rdoc-file=lib/cgi/core.rb -->
@@ -3,7 +3,7 @@
3
3
  # experimental, so these APIs may be changed in future.
4
4
  #
5
5
  # Caveat: Currently, only process-global coverage measurement is supported. You
6
- # cannot measure per-thread covearge.
6
+ # cannot measure per-thread coverage.
7
7
  #
8
8
  # # Usage
9
9
  #
@@ -153,7 +153,7 @@ module Coverage
153
153
  # - line_stub(file)
154
154
  # -->
155
155
  #
156
- def self.line_stub: () -> Array[Integer?]
156
+ def self.line_stub: (String) -> Array[Integer?]
157
157
 
158
158
  # <!--
159
159
  # rdoc-file=ext/coverage/coverage.c
@@ -190,15 +190,41 @@ module Coverage
190
190
 
191
191
  # <!--
192
192
  # rdoc-file=ext/coverage/coverage.c
193
- # - Coverage.start => nil
194
- # - Coverage.start(:all) => nil
195
- # - Coverage.start(lines: bool, branches: bool, methods: bool) => nil
196
- # - Coverage.start(oneshot_lines: true) => nil
193
+ # - Coverage.setup => nil
194
+ # - Coverage.setup(:all) => nil
195
+ # - Coverage.setup(lines: bool, branches: bool, methods: bool, eval: bool) => nil
196
+ # - Coverage.setup(oneshot_lines: true) => nil
197
+ # -->
198
+ # Set up the coverage measurement.
199
+ #
200
+ # Note that this method does not start the measurement itself. Use
201
+ # Coverage.resume to start the measurement.
202
+ #
203
+ # You may want to use Coverage.start to setup and then start the measurement.
204
+ #
205
+ def self.setup: (?lines: bool, ?branches: bool, ?methods: bool, ?eval: bool) -> nil
206
+ | (oneshot_lines: bool, ?branches: bool, ?methods: bool, ?eval: bool) -> nil
207
+ | (:all) -> nil
208
+
209
+ # <!--
210
+ # rdoc-file=ext/coverage/coverage.c
211
+ # - Coverage.start => nil
212
+ # - Coverage.start(:all) => nil
213
+ # - Coverage.start(lines: bool, branches: bool, methods: bool, eval: bool) => nil
214
+ # - Coverage.start(oneshot_lines: true) => nil
197
215
  # -->
198
216
  # Enables the coverage measurement. See the documentation of Coverage class in
199
217
  # detail. This is equivalent to Coverage.setup and Coverage.resume.
200
218
  #
201
- def self.start: (?lines: boolish, ?branches: boolish, ?methods: boolish, ?oneshot_lines: boolish) -> nil
219
+ alias self.start self.setup
220
+
221
+ # <!--
222
+ # rdoc-file=ext/coverage/coverage.c
223
+ # - Coverage.state => :idle, :suspended, :running
224
+ # -->
225
+ # Returns the state of the coverage measurement.
226
+ #
227
+ def self.state: () -> (:idle | :suspended | :running)
202
228
 
203
229
  # <!--
204
230
  # rdoc-file=ext/coverage/coverage.c
@@ -207,12 +233,28 @@ module Coverage
207
233
  # Start/resume the coverage measurement.
208
234
  #
209
235
  # Caveat: Currently, only process-global coverage measurement is supported. You
210
- # cannot measure per-thread covearge. If your process has multiple thread, using
236
+ # cannot measure per-thread coverage. If your process has multiple thread, using
211
237
  # Coverage.resume/suspend to capture code coverage executed from only a limited
212
238
  # code block, may yield misleading results.
213
239
  #
214
240
  def self.resume: () -> nil
215
241
 
242
+ # <!--
243
+ # rdoc-file=ext/coverage/coverage.c
244
+ # - Coverage.supported?(mode) -> true or false
245
+ # -->
246
+ # Returns true if coverage measurement is supported for the given mode.
247
+ #
248
+ # The mode should be one of the following symbols: `:lines`, `:branches`,
249
+ # `:methods`, `:eval`.
250
+ #
251
+ # Example:
252
+ #
253
+ # Coverage.supported?(:lines) #=> true
254
+ # Coverage.supported?(:all) #=> false
255
+ #
256
+ def self.supported?: (Symbol) -> bool
257
+
216
258
  # <!--
217
259
  # rdoc-file=ext/coverage/coverage.c
218
260
  # - Coverage.suspend => nil
data/stdlib/csv/0/csv.rbs CHANGED
@@ -2488,7 +2488,7 @@ class CSV::Row < Object
2488
2488
  # `index_or_header` and `specifiers`.
2489
2489
  #
2490
2490
  # The nested objects may be instances of various classes. See [Dig
2491
- # Methods](https://docs.ruby-lang.org/en/master/dig_methods_rdoc.html).
2491
+ # Methods](rdoc-ref:dig_methods.rdoc).
2492
2492
  #
2493
2493
  # Examples:
2494
2494
  # source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"