rbs 2.6.0 → 2.7.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +5 -0
  4. data/CHANGELOG.md +48 -1
  5. data/Gemfile.lock +10 -9
  6. data/Rakefile +0 -5
  7. data/Steepfile +1 -0
  8. data/core/basic_object.rbs +2 -2
  9. data/core/fiber.rbs +304 -14
  10. data/core/float.rbs +2 -0
  11. data/core/io.rbs +95 -1
  12. data/core/kernel.rbs +1 -1
  13. data/core/module.rbs +1 -1
  14. data/core/regexp.rbs +1 -1
  15. data/core/string_io.rbs +1 -1
  16. data/core/warning.rbs +1 -1
  17. data/ext/rbs_extension/parser.c +36 -10
  18. data/ext/rbs_extension/ruby_objs.c +4 -2
  19. data/ext/rbs_extension/ruby_objs.h +2 -2
  20. data/lib/rbs/ancestor_graph.rb +2 -0
  21. data/lib/rbs/annotate/annotations.rb +2 -0
  22. data/lib/rbs/annotate/formatter.rb +4 -2
  23. data/lib/rbs/annotate/rdoc_annotator.rb +2 -0
  24. data/lib/rbs/annotate/rdoc_source.rb +2 -0
  25. data/lib/rbs/annotate.rb +2 -0
  26. data/lib/rbs/ast/annotation.rb +2 -0
  27. data/lib/rbs/ast/comment.rb +2 -0
  28. data/lib/rbs/ast/declarations.rb +2 -0
  29. data/lib/rbs/ast/members.rb +2 -0
  30. data/lib/rbs/ast/type_param.rb +3 -1
  31. data/lib/rbs/buffer.rb +2 -0
  32. data/lib/rbs/builtin_names.rb +2 -0
  33. data/lib/rbs/cli.rb +39 -2
  34. data/lib/rbs/collection/cleaner.rb +2 -0
  35. data/lib/rbs/collection/config/lockfile_generator.rb +8 -3
  36. data/lib/rbs/collection/config.rb +2 -0
  37. data/lib/rbs/collection/installer.rb +2 -0
  38. data/lib/rbs/collection/sources/base.rb +14 -0
  39. data/lib/rbs/collection/sources/git.rb +3 -0
  40. data/lib/rbs/collection/sources/rubygems.rb +3 -0
  41. data/lib/rbs/collection/sources/stdlib.rb +12 -7
  42. data/lib/rbs/collection/sources.rb +3 -0
  43. data/lib/rbs/collection.rb +2 -0
  44. data/lib/rbs/constant.rb +2 -0
  45. data/lib/rbs/constant_table.rb +5 -3
  46. data/lib/rbs/definition.rb +13 -1
  47. data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
  48. data/lib/rbs/definition_builder/method_builder.rb +2 -0
  49. data/lib/rbs/definition_builder.rb +75 -13
  50. data/lib/rbs/environment.rb +2 -0
  51. data/lib/rbs/environment_loader.rb +25 -5
  52. data/lib/rbs/environment_walker.rb +2 -0
  53. data/lib/rbs/errors.rb +3 -1
  54. data/lib/rbs/factory.rb +2 -0
  55. data/lib/rbs/location_aux.rb +3 -1
  56. data/lib/rbs/locator.rb +2 -0
  57. data/lib/rbs/method_type.rb +7 -5
  58. data/lib/rbs/namespace.rb +9 -5
  59. data/lib/rbs/parser_aux.rb +2 -0
  60. data/lib/rbs/parser_compat/lexer_error.rb +2 -0
  61. data/lib/rbs/parser_compat/located_value.rb +2 -0
  62. data/lib/rbs/parser_compat/semantics_error.rb +2 -0
  63. data/lib/rbs/parser_compat/syntax_error.rb +2 -0
  64. data/lib/rbs/prototype/helpers.rb +13 -8
  65. data/lib/rbs/prototype/rb.rb +2 -0
  66. data/lib/rbs/prototype/rbi.rb +11 -6
  67. data/lib/rbs/prototype/runtime.rb +13 -4
  68. data/lib/rbs/repository.rb +4 -4
  69. data/lib/rbs/resolver/constant_resolver.rb +2 -0
  70. data/lib/rbs/resolver/type_name_resolver.rb +2 -0
  71. data/lib/rbs/sorter.rb +168 -0
  72. data/lib/rbs/substitution.rb +2 -0
  73. data/lib/rbs/test/errors.rb +2 -0
  74. data/lib/rbs/test/hook.rb +2 -0
  75. data/lib/rbs/test/observer.rb +2 -0
  76. data/lib/rbs/test/setup.rb +2 -0
  77. data/lib/rbs/test/setup_helper.rb +2 -0
  78. data/lib/rbs/test/spy.rb +2 -0
  79. data/lib/rbs/test/tester.rb +2 -0
  80. data/lib/rbs/test/type_check.rb +2 -0
  81. data/lib/rbs/test.rb +2 -0
  82. data/lib/rbs/type_alias_dependency.rb +2 -0
  83. data/lib/rbs/type_alias_regularity.rb +2 -0
  84. data/lib/rbs/type_name.rb +2 -0
  85. data/lib/rbs/type_name_resolver.rb +4 -2
  86. data/lib/rbs/types.rb +68 -18
  87. data/lib/rbs/validator.rb +2 -0
  88. data/lib/rbs/variance_calculator.rb +2 -0
  89. data/lib/rbs/vendorer.rb +2 -0
  90. data/lib/rbs/version.rb +3 -1
  91. data/lib/rbs/writer.rb +3 -1
  92. data/lib/rbs.rb +4 -2
  93. data/lib/rdoc/discover.rb +20 -0
  94. data/lib/rdoc_plugin/parser.rb +163 -0
  95. data/schema/methodType.json +7 -1
  96. data/schema/types.json +13 -1
  97. data/sig/ancestor_builder.rbs +66 -7
  98. data/sig/annotation.rbs +7 -6
  99. data/sig/builtin_names.rbs +2 -0
  100. data/sig/cli.rbs +8 -0
  101. data/sig/collection/config.rbs +13 -4
  102. data/sig/collection/installer.rbs +2 -0
  103. data/sig/collection/sources.rbs +23 -4
  104. data/sig/definition.rbs +8 -0
  105. data/sig/definition_builder.rbs +64 -7
  106. data/sig/environment.rbs +4 -0
  107. data/sig/environment_loader.rbs +4 -2
  108. data/sig/location.rbs +8 -4
  109. data/sig/manifest.yaml +1 -0
  110. data/sig/members.rbs +1 -1
  111. data/sig/method_builder.rbs +10 -0
  112. data/sig/namespace.rbs +54 -31
  113. data/sig/prototype/rb.rbs +4 -0
  114. data/sig/rbs.rbs +8 -6
  115. data/sig/rdoc/rbs.rbs +63 -0
  116. data/sig/{polyfill.rbs → shims.rbs} +1 -31
  117. data/sig/sorter.rbs +23 -0
  118. data/sig/types.rbs +14 -2
  119. data/sig/vendorer.rbs +32 -25
  120. data/stdlib/bigdecimal/0/big_decimal.rbs +250 -0
  121. data/stdlib/erb/0/erb.rbs +107 -0
  122. data/stdlib/logger/0/logger.rbs +2 -2
  123. data/stdlib/rdoc/0/rdoc.rbs +758 -0
  124. data/steep/Gemfile.lock +8 -8
  125. metadata +12 -6
  126. data/stdlib/fiber/0/fiber.rbs +0 -99
data/core/module.rbs CHANGED
@@ -1401,7 +1401,7 @@ class Module < Object
1401
1401
  #
1402
1402
  # Returns a module, where refined methods are defined.
1403
1403
  #
1404
- def refine: (Class arg0) { (untyped arg0) -> untyped } -> self
1404
+ def refine: (Module mod) { () -> void } -> Refinement
1405
1405
 
1406
1406
  # <!--
1407
1407
  # rdoc-file=object.c
data/core/regexp.rbs CHANGED
@@ -760,7 +760,7 @@ class Regexp
760
760
  # r3 = Regexp.new(r2) #=> /cat/i
761
761
  # r4 = Regexp.new('dog', Regexp::EXTENDED | Regexp::IGNORECASE) #=> /dog/ix
762
762
  #
763
- def initialize: (String string, ?Integer | nil | false options, ?String kcode) -> Object
763
+ def initialize: (String string, ?Integer | nil | false | top options, ?String kcode) -> Object
764
764
  | (Regexp regexp) -> void
765
765
 
766
766
  # <!--
data/core/string_io.rbs CHANGED
@@ -450,7 +450,7 @@ class StringIO
450
450
  # opened for writing. If the argument is not a string, it will be converted to
451
451
  # a string using `to_s`. Returns the number of bytes written. See IO#write.
452
452
  #
453
- def write: (String arg0) -> Integer
453
+ def write: (*_ToS) -> Integer
454
454
 
455
455
  # This is a deprecated alias for #each_byte.
456
456
  #
data/core/warning.rbs CHANGED
@@ -38,5 +38,5 @@ module Warning
38
38
  #
39
39
  # See the documentation of the Warning module for how to customize this.
40
40
  #
41
- def warn: (String) -> nil
41
+ def self?.warn: (String message, ?category: :deprecated | :experimental | nil) -> nil
42
42
  end
@@ -566,13 +566,30 @@ static void initialize_method_params(method_params *params){
566
566
  }
567
567
 
568
568
  /*
569
- function ::= {} `(` params `)` `{` `(` params `)` `->` optional `}` `->` <optional>
570
- | {} `(` params `)` `->` <optional>
571
- | {} `{` `(` params `)` `->` optional `}` `->` <optional>
572
- | {} `{` `->` optional `}` `->` <optional>
573
- | {} `->` <optional>
569
+ self_type_binding ::= {} <>
570
+ | {} `[` `self` `:` type <`]`>
574
571
  */
575
- static void parse_function(parserstate *state, VALUE *function, VALUE *block) {
572
+ static VALUE parse_self_type_binding(parserstate *state) {
573
+ if (state->next_token.type == pLBRACKET) {
574
+ parser_advance(state);
575
+ parser_advance_assert(state, kSELF);
576
+ parser_advance_assert(state, pCOLON);
577
+ VALUE type = parse_type(state);
578
+ parser_advance_assert(state, pRBRACKET);
579
+ return type;
580
+ } else {
581
+ return Qnil;
582
+ }
583
+ }
584
+
585
+ /*
586
+ function ::= {} `(` params `)` self_type_binding? `{` `(` params `)` self_type_binding? `->` optional `}` `->` <optional>
587
+ | {} `(` params `)` self_type_binding? `->` <optional>
588
+ | {} self_type_binding? `{` `(` params `)` self_type_binding? `->` optional `}` `->` <optional>
589
+ | {} self_type_binding? `{` self_type_binding `->` optional `}` `->` <optional>
590
+ | {} self_type_binding? `->` <optional>
591
+ */
592
+ static void parse_function(parserstate *state, VALUE *function, VALUE *block, VALUE *function_self_type) {
576
593
  method_params params;
577
594
  initialize_method_params(&params);
578
595
 
@@ -582,6 +599,11 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block) {
582
599
  parser_advance_assert(state, pRPAREN);
583
600
  }
584
601
 
602
+ // Passing NULL to function_self_type means the function itself doesn't accept self type binding. (== method type)
603
+ if (function_self_type) {
604
+ *function_self_type = parse_self_type_binding(state);
605
+ }
606
+
585
607
  VALUE required = Qtrue;
586
608
  if (state->next_token.type == pQUESTION && state->next_token2.type == pLBRACE) {
587
609
  // Optional block
@@ -600,6 +622,8 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block) {
600
622
  parser_advance_assert(state, pRPAREN);
601
623
  }
602
624
 
625
+ VALUE block_self_type = parse_self_type_binding(state);
626
+
603
627
  parser_advance_assert(state, pARROW);
604
628
  VALUE block_return_type = parse_optional(state);
605
629
 
@@ -614,7 +638,8 @@ static void parse_function(parserstate *state, VALUE *function, VALUE *block) {
614
638
  block_params.rest_keywords,
615
639
  block_return_type
616
640
  ),
617
- required
641
+ required,
642
+ block_self_type
618
643
  );
619
644
 
620
645
  parser_advance_assert(state, pRBRACE);
@@ -642,11 +667,12 @@ static VALUE parse_proc_type(parserstate *state) {
642
667
  position start = state->current_token.range.start;
643
668
  VALUE function = Qnil;
644
669
  VALUE block = Qnil;
645
- parse_function(state, &function, &block);
670
+ VALUE proc_self = Qnil;
671
+ parse_function(state, &function, &block, &proc_self);
646
672
  position end = state->current_token.range.end;
647
673
  VALUE loc = rbs_location_pp(state->buffer, &start, &end);
648
674
 
649
- return rbs_proc(function, block, loc);
675
+ return rbs_proc(function, block, loc, proc_self);
650
676
  }
651
677
 
652
678
  /**
@@ -1130,7 +1156,7 @@ VALUE parse_method_type(parserstate *state) {
1130
1156
 
1131
1157
  type_range.start = state->next_token.range.start;
1132
1158
 
1133
- parse_function(state, &function, &block);
1159
+ parse_function(state, &function, &block, NULL);
1134
1160
 
1135
1161
  rg.end = state->current_token.range.end;
1136
1162
  type_range.end = rg.end;
@@ -144,10 +144,11 @@ VALUE rbs_optional(VALUE type, VALUE location) {
144
144
  );
145
145
  }
146
146
 
147
- VALUE rbs_block(VALUE type, VALUE required) {
147
+ VALUE rbs_block(VALUE type, VALUE required, VALUE self_type) {
148
148
  VALUE args = rb_hash_new();
149
149
  rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
150
150
  rb_hash_aset(args, ID2SYM(rb_intern("required")), required);
151
+ rb_hash_aset(args, ID2SYM(rb_intern("self_type")), self_type);
151
152
 
152
153
  return CLASS_NEW_INSTANCE(
153
154
  RBS_Types_Block,
@@ -196,11 +197,12 @@ VALUE rbs_function(
196
197
  );
197
198
  }
198
199
 
199
- VALUE rbs_proc(VALUE function, VALUE block, VALUE location) {
200
+ VALUE rbs_proc(VALUE function, VALUE block, VALUE location, VALUE self_type) {
200
201
  VALUE args = rb_hash_new();
201
202
  rb_hash_aset(args, ID2SYM(rb_intern("type")), function);
202
203
  rb_hash_aset(args, ID2SYM(rb_intern("block")), block);
203
204
  rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
205
+ rb_hash_aset(args, ID2SYM(rb_intern("self_type")), self_type);
204
206
 
205
207
  return CLASS_NEW_INSTANCE(
206
208
  RBS_Types_Proc,
@@ -22,7 +22,7 @@ VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE args, VALUE annotatio
22
22
  VALUE rbs_ast_members_variable(VALUE klass, VALUE name, VALUE type, VALUE location, VALUE comment);
23
23
  VALUE rbs_ast_members_visibility(VALUE klass, VALUE location);
24
24
  VALUE rbs_base_type(VALUE klass, VALUE location);
25
- VALUE rbs_block(VALUE type, VALUE required);
25
+ VALUE rbs_block(VALUE type, VALUE required, VALUE self_type);
26
26
  VALUE rbs_class_instance(VALUE typename, VALUE type_args, VALUE location);
27
27
  VALUE rbs_class_singleton(VALUE typename, VALUE location);
28
28
  VALUE rbs_function_param(VALUE type, VALUE name, VALUE location);
@@ -33,7 +33,7 @@ VALUE rbs_literal(VALUE literal, VALUE location);
33
33
  VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location);
34
34
  VALUE rbs_namespace(VALUE path, VALUE absolute);
35
35
  VALUE rbs_optional(VALUE type, VALUE location);
36
- VALUE rbs_proc(VALUE function, VALUE block, VALUE location);
36
+ VALUE rbs_proc(VALUE function, VALUE block, VALUE location, VALUE self_type);
37
37
  VALUE rbs_record(VALUE fields, VALUE location);
38
38
  VALUE rbs_tuple(VALUE types, VALUE location);
39
39
  VALUE rbs_type_name(VALUE namespace, VALUE name);
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class AncestorGraph
3
5
  InstanceNode = _ = Struct.new(:type_name, keyword_init: true)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Annotate
3
5
  class Annotations
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Annotate
3
5
  class Formatter
4
6
  attr_reader :buffer
5
7
 
6
8
  def initialize()
7
- @buffer = ""
9
+ @buffer = +""
8
10
  @pending_separator = nil
9
11
  end
10
12
 
@@ -14,7 +16,7 @@ module RBS
14
16
  s = self.class.translate(s) or raise
15
17
  end
16
18
 
17
- s.rstrip!
19
+ s = s.rstrip
18
20
 
19
21
  unless s.empty?
20
22
  if ss = @pending_separator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Annotate
3
5
  class RDocAnnotator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Annotate
3
5
  class RDocSource
data/lib/rbs/annotate.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rdoc"
2
4
 
3
5
  require "rbs/annotate/rdoc_annotator"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module AST
3
5
  class Annotation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module AST
3
5
  class Comment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module AST
3
5
  module Declarations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module AST
3
5
  module Members
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module AST
3
5
  class TypeParam
@@ -106,7 +108,7 @@ module RBS
106
108
  end
107
109
 
108
110
  def to_s
109
- s = ""
111
+ s = +""
110
112
 
111
113
  if unchecked?
112
114
  s << "unchecked "
data/lib/rbs/buffer.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Buffer
3
5
  attr_reader :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module BuiltinNames
3
5
  class Name
data/lib/rbs/cli.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "open3"
2
4
  require "optparse"
3
5
  require "shellwords"
@@ -74,6 +76,7 @@ module RBS
74
76
 
75
77
  attr_reader :stdout
76
78
  attr_reader :stderr
79
+ attr_reader :original_args
77
80
 
78
81
  def initialize(stdout:, stderr:)
79
82
  @stdout = stdout
@@ -100,6 +103,8 @@ module RBS
100
103
  end
101
104
 
102
105
  def run(args)
106
+ @original_args = args.dup
107
+
103
108
  options = LibraryOptions.new
104
109
 
105
110
  opts = OptionParser.new
@@ -667,6 +672,8 @@ EOU
667
672
  output_dir = nil
668
673
  # @type var base_dir: Pathname?
669
674
  base_dir = nil
675
+ # @type var force: bool
676
+ force = false
670
677
 
671
678
  opts = OptionParser.new
672
679
  opts.banner = <<EOU
@@ -696,6 +703,10 @@ EOU
696
703
  base_dir = Pathname(path)
697
704
  end
698
705
 
706
+ opts.on("--force", "Overwrite existing RBS files") do
707
+ force = true
708
+ end
709
+
699
710
  opts.parse!(args)
700
711
 
701
712
  unless has_parser?
@@ -722,6 +733,9 @@ EOU
722
733
  input_paths = args.map {|arg| Pathname(arg) }
723
734
 
724
735
  if output_dir
736
+ # @type var skip_paths: Array[Pathname]
737
+ skip_paths = []
738
+
725
739
  # batch mode
726
740
  input_paths.each do |path|
727
741
  stdout.puts "Processing `#{path}`..."
@@ -764,7 +778,17 @@ EOU
764
778
  parser = new_parser[]
765
779
  parser.parse file_path.read()
766
780
 
767
- stdout.puts " Writing RBS to `#{output_path}`..."
781
+ if output_path.file?
782
+ if force
783
+ stdout.puts " - Writing RBS to existing file `#{output_path}`..."
784
+ else
785
+ stdout.puts " - Skipping existing file `#{output_path}`..."
786
+ skip_paths << file_path
787
+ next
788
+ end
789
+ else
790
+ stdout.puts " - Writing RBS to `#{output_path}`..."
791
+ end
768
792
 
769
793
  (output_path.parent).mkpath
770
794
  output_path.open("w") do |io|
@@ -773,6 +797,19 @@ EOU
773
797
  end
774
798
  end
775
799
  end
800
+
801
+ unless skip_paths.empty?
802
+ stdout.puts
803
+ stdout.puts ">>>> Skipped existing #{skip_paths.size} files. Use `--force` option to update the files."
804
+ command = original_args.take(original_args.size - input_paths.size)
805
+
806
+ skip_paths.take(10).each do |path|
807
+ stdout.puts " #{defined?(Bundler) ? "bundle exec " : ""}rbs #{Shellwords.join(command)} --force #{Shellwords.escape(path.to_s)}"
808
+ end
809
+ if skip_paths.size > 10
810
+ stdout.puts " ..."
811
+ end
812
+ end
776
813
  else
777
814
  # file mode
778
815
  parser = new_parser[]
@@ -975,7 +1012,7 @@ EOB
975
1012
  env_hash = {
976
1013
  'RUBYOPT' => "#{ENV['RUBYOPT']} -rrbs/test/setup",
977
1014
  'RBS_TEST_OPT' => test_opt(options),
978
- 'RBS_TEST_LOGLEVEL' => RBS.logger_level,
1015
+ 'RBS_TEST_LOGLEVEL' => %w(DEBUG INFO WARN ERROR FATAL)[RBS.logger_level || 5] || "UNKNOWN",
979
1016
  'RBS_TEST_SAMPLE_SIZE' => sample_size,
980
1017
  'RBS_TEST_DOUBLE_SUITE' => double_suite,
981
1018
  'RBS_TEST_UNCHECKED_CLASSES' => (unchecked_classes.join(',') unless unchecked_classes.empty?),
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Collection
3
5
  class Cleaner
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Collection
3
5
 
@@ -37,6 +39,7 @@ module RBS
37
39
  end
38
40
 
39
41
  private def assign_gem(name:, version:)
42
+ # @type var locked: gem_entry?
40
43
  locked = lock&.gem(name)
41
44
  specified = config.gem(name)
42
45
 
@@ -51,6 +54,7 @@ module RBS
51
54
 
52
55
  installed_version = version
53
56
  best_version = find_best_version(version: installed_version, versions: source.versions({ 'name' => name }))
57
+
54
58
  locked = {
55
59
  'name' => name,
56
60
  'version' => best_version.to_s,
@@ -58,10 +62,11 @@ module RBS
58
62
  }
59
63
  end
60
64
 
65
+ locked or raise
66
+
61
67
  upsert_gem specified, locked
62
- source = Sources.from_config_entry(locked['source'])
63
- manifest = source.manifest_of(locked) or return
64
- manifest['dependencies']&.each do |dep|
68
+ source = Sources.from_config_entry(locked['source'] || raise)
69
+ source.dependencies_of(locked)&.each do |dep|
65
70
  @gem_queue.push({ name: dep['name'], version: nil} )
66
71
  end
67
72
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Collection
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Collection
3
5
  class Installer
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ module Collection
5
+ module Sources
6
+ module Base
7
+ def dependencies_of(config_entry)
8
+ manifest = manifest_of(config_entry) or return
9
+ manifest['dependencies']
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/sha2'
2
4
  require 'open3'
3
5
  require 'find'
@@ -6,6 +8,7 @@ module RBS
6
8
  module Collection
7
9
  module Sources
8
10
  class Git
11
+ include Base
9
12
  METADATA_FILENAME = '.rbs_meta.yaml'
10
13
 
11
14
  class CommandError < StandardError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'singleton'
2
4
 
3
5
  module RBS
@@ -5,6 +7,7 @@ module RBS
5
7
  module Sources
6
8
  # Signatures that are inclduded in gem package as sig/ directory.
7
9
  class Rubygems
10
+ include Base
8
11
  include Singleton
9
12
 
10
13
  def has?(config_entry)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'singleton'
2
4
 
3
5
  module RBS
@@ -5,27 +7,30 @@ module RBS
5
7
  module Sources
6
8
  # signatures that are bundled in rbs gem under the stdlib/ directory
7
9
  class Stdlib
10
+ include Base
8
11
  include Singleton
9
12
 
13
+ REPO = Repository.default
14
+
10
15
  def has?(config_entry)
11
- gem_dir(config_entry).exist?
16
+ lookup(config_entry)
12
17
  end
13
18
 
14
19
  def versions(config_entry)
15
- gem_dir(config_entry).glob('*/').map { |path| path.basename.to_s }
20
+ REPO.gems[config_entry['name']].versions.keys.map(&:to_s)
16
21
  end
17
22
 
18
23
  def install(dest:, config_entry:, stdout:)
19
24
  # Do nothing because stdlib RBS is available by default
20
25
  name = config_entry['name']
21
26
  version = config_entry['version'] or raise
22
- from = gem_dir(config_entry) / version
27
+ from = lookup(config_entry)
23
28
  stdout.puts "Using #{name}:#{version} (#{from})"
24
29
  end
25
30
 
26
31
  def manifest_of(config_entry)
27
- version = config_entry['version'] or raise
28
- manifest_path = gem_dir(config_entry).join(version, 'manifest.yaml')
32
+ config_entry['version'] or raise
33
+ manifest_path = (lookup(config_entry) or raise).join('manifest.yaml')
29
34
  YAML.safe_load(manifest_path.read) if manifest_path.exist?
30
35
  end
31
36
 
@@ -35,8 +40,8 @@ module RBS
35
40
  }
36
41
  end
37
42
 
38
- private def gem_dir(config_entry)
39
- Repository::DEFAULT_STDLIB_ROOT.join(config_entry['name'])
43
+ private def lookup(config_entry)
44
+ REPO.lookup(config_entry['name'], config_entry['version'])
40
45
  end
41
46
  end
42
47
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './sources/base'
1
4
  require_relative './sources/git'
2
5
  require_relative './sources/stdlib'
3
6
  require_relative './sources/rubygems'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'bundler'
3
5
 
data/lib/rbs/constant.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Constant
3
5
  attr_reader :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class ConstantTable
3
5
  attr_reader :definition_builder
@@ -56,9 +58,9 @@ module RBS
56
58
  name_to_constant(TypeName.new(name: head, namespace: Namespace.root))
57
59
  else
58
60
  resolve_constant_reference_context(head, context: context) ||
59
- context.first.yield_self do |first_contet|
60
- raise unless first_contet
61
- resolve_constant_reference_inherit(head, scopes: constant_scopes(first_contet.to_type_name))
61
+ context.first.yield_self do |first_context|
62
+ raise unless first_context
63
+ resolve_constant_reference_inherit(head, scopes: constant_scopes(first_context.to_type_name))
62
64
  end
63
65
  end
64
66
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Definition
3
5
  class Variable
@@ -118,7 +120,7 @@ module RBS
118
120
  end
119
121
 
120
122
  def comments
121
- @comments ||= _ = defs.map(&:comment).compact
123
+ @comments ||= defs.map(&:comment).compact.uniq
122
124
  end
123
125
 
124
126
  def annotations
@@ -172,6 +174,16 @@ module RBS
172
174
  alias_of: alias_of
173
175
  )
174
176
  end
177
+
178
+ def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations)
179
+ self.class.new(
180
+ super_method: super_method,
181
+ defs: defs,
182
+ accessibility: accessibility,
183
+ alias_of: alias_of,
184
+ annotations: annotations
185
+ )
186
+ end
175
187
  end
176
188
 
177
189
  module Ancestor
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class DefinitionBuilder
3
5
  class AncestorBuilder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class DefinitionBuilder
3
5
  class MethodBuilder