rbs 2.8.4 → 3.0.0.dev.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +0 -28
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +16 -16
  5. data/Rakefile +1 -9
  6. data/ext/rbs_extension/constants.c +2 -0
  7. data/ext/rbs_extension/constants.h +1 -0
  8. data/ext/rbs_extension/extconf.rb +1 -1
  9. data/ext/rbs_extension/parser.c +23 -13
  10. data/ext/rbs_extension/ruby_objs.c +15 -3
  11. data/ext/rbs_extension/ruby_objs.h +2 -1
  12. data/lib/rbs/ast/members.rb +49 -15
  13. data/lib/rbs/cli.rb +6 -1
  14. data/lib/rbs/collection/config/lockfile.rb +115 -0
  15. data/lib/rbs/collection/config/lockfile_generator.rb +89 -48
  16. data/lib/rbs/collection/config.rb +11 -39
  17. data/lib/rbs/collection/installer.rb +9 -13
  18. data/lib/rbs/collection/sources/base.rb +2 -2
  19. data/lib/rbs/collection/sources/git.rb +135 -62
  20. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  21. data/lib/rbs/collection/sources/stdlib.rb +10 -13
  22. data/lib/rbs/collection/sources.rb +7 -1
  23. data/lib/rbs/collection.rb +1 -0
  24. data/lib/rbs/definition.rb +1 -1
  25. data/lib/rbs/definition_builder/method_builder.rb +3 -3
  26. data/lib/rbs/definition_builder.rb +449 -572
  27. data/lib/rbs/environment.rb +5 -3
  28. data/lib/rbs/environment_loader.rb +11 -10
  29. data/lib/rbs/locator.rb +2 -2
  30. data/lib/rbs/prototype/helpers.rb +29 -13
  31. data/lib/rbs/prototype/node_usage.rb +99 -0
  32. data/lib/rbs/prototype/rb.rb +3 -2
  33. data/lib/rbs/prototype/rbi.rb +6 -4
  34. data/lib/rbs/prototype/runtime.rb +25 -12
  35. data/lib/rbs/substitution.rb +19 -0
  36. data/lib/rbs/types.rb +1 -5
  37. data/lib/rbs/validator.rb +2 -1
  38. data/lib/rbs/version.rb +1 -1
  39. data/lib/rbs/writer.rb +26 -17
  40. data/lib/rbs.rb +1 -0
  41. data/lib/rdoc_plugin/parser.rb +1 -1
  42. data/rbs.gemspec +1 -1
  43. data/schema/members.json +15 -10
  44. data/sig/collection/config/lockfile.rbs +80 -0
  45. data/sig/collection/config/lockfile_generator.rbs +55 -0
  46. data/sig/collection/config.rbs +5 -48
  47. data/sig/collection/installer.rbs +1 -1
  48. data/sig/collection/sources.rbs +66 -29
  49. data/sig/definition_builder.rbs +94 -81
  50. data/sig/environment_loader.rbs +1 -1
  51. data/sig/errors.rbs +21 -0
  52. data/sig/members.rbs +31 -7
  53. data/sig/prototype/node_usage.rbs +20 -0
  54. data/sig/shims/bundler.rbs +13 -0
  55. data/sig/shims/rubygems.rbs +9 -0
  56. data/sig/shims.rbs +0 -22
  57. data/sig/substitution.rbs +6 -0
  58. data/sig/writer.rbs +2 -0
  59. data/steep/Gemfile +3 -0
  60. data/steep/Gemfile.lock +61 -0
  61. metadata +13 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '038fda245a80a2e3eb408a3e8aa872f50e36b24a994ff4a6c4d8576cab7d6634'
4
- data.tar.gz: ccc5db43cae3907aa594ac0ce53df343bb6b942b484fb507d9248fc33305be81
3
+ metadata.gz: 7a07433a652ee9bdc6b90162eb974d289fafabed916044ffa8e83b78063b8c0b
4
+ data.tar.gz: 1339eae3040ab4714dd241497bbc20d643ae5eaef62b03a02138806ecf4737c5
5
5
  SHA512:
6
- metadata.gz: 1b8fe38a58cca575ac24d8cfb3745c39ac19a3638c45e665cd7cda7923ccc46f7304c6e9cc86126ca5f159118d0bf5e9d055aff1134ebdedf79fec17998f1558
7
- data.tar.gz: 1cefb1986f35af43f6a903452545a61622df14358acb06b70a3b94f4ceb3ba697cfaf2c364d5d77b2c4e77a962f03326fc30194e1e81c3ba51e2931a63954597
6
+ metadata.gz: 8b414da0d750aefbfdaadcd0a309d2ee4157969112f6806149597fd402b4ca43aaae5cbf162e14f7bfe0a21e3369fad2b94a54f5d3610e15362afd2bd9d83d8f
7
+ data.tar.gz: 884514e8cf52edbd3e17b6c214cd113b58a6107b4a00f73f826d471521d883997a3bee6c3f0c3e7a2770e23468e6a964878504f1a5cf7de9a6ab2d5ec66fbb4e
data/CHANGELOG.md CHANGED
@@ -2,34 +2,6 @@
2
2
 
3
3
  ## master
4
4
 
5
- ## 2.8.4 (2023-01-20)
6
-
7
- ### Miscellaneous
8
-
9
- * Make `rake stdlib_test` run with single process (Backport [#1207](https://github.com/ruby/rbs/pull/1207), [#1211](https://github.com/ruby/rbs/pull/1211))
10
- * Remove `steep/*` files from `.gem` (Backport [#1214](https://github.com/ruby/rbs/pull/1214), [#1216](https://github.com/ruby/rbs/pull/1216))
11
-
12
- ## 2.8.3 (2023-01-06)
13
-
14
- ### Library changes
15
-
16
- * Use `-std=gnu99` instead of `-std=c99` (Backport [#973](https://github.com/ruby/rbs/pull/973))
17
- * Add `rbs_` prefix to `skip` function (Backport [#1186](https://github.com/ruby/rbs/pull/1186))
18
-
19
- ## 2.8.2 (2022-12-21)
20
-
21
- ### Signature updates
22
-
23
- * `YAML.load` ([#1170](https://github.com/ruby/rbs/pull/1170))
24
-
25
- ### Library changes
26
-
27
- * Add the methods of the `prepend`ed module itself ([#1182](https://github.com/ruby/rbs/pull/1182))
28
-
29
- ### Miscellaneous
30
-
31
- * Add `TestSkip` module to skip tests that fails in ruby CI ([#1167](https://github.com/ruby/rbs/pull/1167))
32
-
33
5
  ## 2.8.1 (2022-11-28)
34
6
 
35
7
  ### Signature updates
data/Gemfile CHANGED
@@ -18,7 +18,7 @@ gem "dbm"
18
18
  gem 'digest'
19
19
  gem 'tempfile'
20
20
  gem "prime"
21
- gem "rdoc"
21
+ gem "rdoc", "< 6.5.0"
22
22
 
23
23
  # Test gems
24
24
  gem "rbs-amber", path: "test/assets/test-gem"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs (2.8.4)
4
+ rbs (3.0.0.dev.1)
5
5
 
6
6
  PATH
7
7
  remote: test/assets/test-gem
@@ -19,35 +19,35 @@ GEM
19
19
  debase-ruby_core_source (>= 0.10.12)
20
20
  debase-ruby_core_source (0.10.16)
21
21
  diff-lcs (1.5.0)
22
- digest (3.1.0)
22
+ digest (3.1.1)
23
23
  forwardable (1.3.2)
24
24
  goodcheck (3.1.0)
25
25
  marcel (>= 1.0, < 2.0)
26
26
  psych (>= 3.1, < 5.0)
27
27
  rainbow (>= 3.0, < 4.0)
28
28
  strong_json (>= 1.1, < 2.2)
29
- json (2.6.2)
29
+ json (2.6.3)
30
30
  json-schema (3.0.0)
31
31
  addressable (>= 2.8)
32
32
  marcel (1.0.2)
33
- minitest (5.16.3)
33
+ minitest (5.17.0)
34
34
  parallel (1.22.1)
35
- parser (3.1.2.1)
35
+ parser (3.1.3.0)
36
36
  ast (~> 2.4.1)
37
- power_assert (2.0.1)
37
+ power_assert (2.0.2)
38
38
  prime (0.1.2)
39
39
  forwardable
40
40
  singleton
41
- psych (4.0.4)
41
+ psych (4.0.6)
42
42
  stringio
43
43
  public_suffix (4.0.7)
44
44
  rainbow (3.1.1)
45
45
  rake (13.0.6)
46
- rake-compiler (1.2.0)
46
+ rake-compiler (1.2.1)
47
47
  rake
48
48
  rdoc (6.4.0)
49
49
  psych (>= 4.0.0)
50
- regexp_parser (2.6.0)
50
+ regexp_parser (2.6.1)
51
51
  rexml (3.2.5)
52
52
  rspec (3.12.0)
53
53
  rspec-core (~> 3.12.0)
@@ -62,7 +62,7 @@ GEM
62
62
  diff-lcs (>= 1.2.0, < 2.0)
63
63
  rspec-support (~> 3.12.0)
64
64
  rspec-support (3.12.0)
65
- rubocop (1.39.0)
65
+ rubocop (1.40.0)
66
66
  json (~> 2.3)
67
67
  parallel (~> 1.10)
68
68
  parser (>= 3.1.2.1)
@@ -72,7 +72,7 @@ GEM
72
72
  rubocop-ast (>= 1.23.0, < 2.0)
73
73
  ruby-progressbar (~> 1.7)
74
74
  unicode-display_width (>= 1.4.0, < 3.0)
75
- rubocop-ast (1.23.0)
75
+ rubocop-ast (1.24.0)
76
76
  parser (>= 3.1.1.0)
77
77
  rubocop-rubycw (0.1.6)
78
78
  rubocop (~> 1.0)
@@ -80,11 +80,11 @@ GEM
80
80
  rake (>= 0.8.1)
81
81
  ruby-progressbar (1.11.0)
82
82
  singleton (0.1.1)
83
- stackprof (0.2.22)
84
- stringio (3.0.2)
83
+ stackprof (0.2.23)
84
+ stringio (3.0.4)
85
85
  strong_json (2.1.2)
86
- tempfile (0.1.2)
87
- test-unit (3.5.5)
86
+ tempfile (0.1.3)
87
+ test-unit (3.5.7)
88
88
  power_assert
89
89
  unicode-display_width (2.3.0)
90
90
 
@@ -105,7 +105,7 @@ DEPENDENCIES
105
105
  rake-compiler
106
106
  rbs!
107
107
  rbs-amber!
108
- rdoc
108
+ rdoc (< 6.5.0)
109
109
  rspec
110
110
  rubocop
111
111
  rubocop-rubycw
data/Rakefile CHANGED
@@ -69,15 +69,7 @@ FileList["test/stdlib/**/*_test.rb"].each do |test|
69
69
  task test => :compile do
70
70
  sh "#{ruby} -Ilib #{bin}/test_runner.rb #{test}"
71
71
  end
72
- end
73
-
74
- task :stdlib_test do
75
- test_files = FileList["test/stdlib/**/*_test.rb"].reject do |path|
76
- path =~ %r{Ractor}
77
- end
78
- sh "#{ruby} -Ilib #{bin}/test_runner.rb #{test_files.join(' ')}"
79
- # TODO: Ractor tests need to be run in a separate process
80
- sh "#{ruby} -Ilib #{bin}/test_runner.rb test/stdlib/Ractor_test.rb"
72
+ task stdlib_test: test
81
73
  end
82
74
 
83
75
  task :rubocop do
@@ -30,6 +30,7 @@ VALUE RBS_AST_Members_Extend;
30
30
  VALUE RBS_AST_Members_Include;
31
31
  VALUE RBS_AST_Members_InstanceVariable;
32
32
  VALUE RBS_AST_Members_MethodDefinition;
33
+ VALUE RBS_AST_Members_MethodDefinition_Overload;
33
34
  VALUE RBS_AST_Members_Prepend;
34
35
  VALUE RBS_AST_Members_Private;
35
36
  VALUE RBS_AST_Members_Public;
@@ -99,6 +100,7 @@ void rbs__init_constants(void) {
99
100
  RBS_AST_Members_Include = rb_const_get(RBS_AST_Members, rb_intern("Include"));
100
101
  RBS_AST_Members_InstanceVariable = rb_const_get(RBS_AST_Members, rb_intern("InstanceVariable"));
101
102
  RBS_AST_Members_MethodDefinition = rb_const_get(RBS_AST_Members, rb_intern("MethodDefinition"));
103
+ RBS_AST_Members_MethodDefinition_Overload = rb_const_get(RBS_AST_Members_MethodDefinition, rb_intern("Overload"));
102
104
  RBS_AST_Members_Prepend = rb_const_get(RBS_AST_Members, rb_intern("Prepend"));
103
105
  RBS_AST_Members_Private = rb_const_get(RBS_AST_Members, rb_intern("Private"));
104
106
  RBS_AST_Members_Public = rb_const_get(RBS_AST_Members, rb_intern("Public"));
@@ -29,6 +29,7 @@ extern VALUE RBS_AST_Members_Extend;
29
29
  extern VALUE RBS_AST_Members_Include;
30
30
  extern VALUE RBS_AST_Members_InstanceVariable;
31
31
  extern VALUE RBS_AST_Members_MethodDefinition;
32
+ extern VALUE RBS_AST_Members_MethodDefinition_Overload;
32
33
  extern VALUE RBS_AST_Members_Prepend;
33
34
  extern VALUE RBS_AST_Members_Private;
34
35
  extern VALUE RBS_AST_Members_Public;
@@ -1,4 +1,4 @@
1
1
  require 'mkmf'
2
2
  $INCFLAGS << " -I$(top_srcdir)" if $extmk
3
- append_cflags ['-std=gnu99']
3
+ append_cflags ['-std=c99']
4
4
  create_makefile 'rbs_extension'
@@ -1485,7 +1485,7 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
1485
1485
  range keyword_range;
1486
1486
  range name_range;
1487
1487
  range kind_range;
1488
- range overload_range = NULL_RANGE;
1488
+ range overloading_range = NULL_RANGE;
1489
1489
 
1490
1490
  VALUE visibility;
1491
1491
 
@@ -1524,8 +1524,8 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
1524
1524
  }
1525
1525
 
1526
1526
  VALUE name = parse_method_name(state, &name_range);
1527
- VALUE method_types = rb_ary_new();
1528
- VALUE overload = Qfalse;
1527
+ VALUE overloads = rb_ary_new();
1528
+ VALUE overloading = Qfalse;
1529
1529
 
1530
1530
  if (state->next_token.type == pDOT && RB_SYM2ID(name) == rb_intern("self?")) {
1531
1531
  raise_syntax_error(
@@ -1541,23 +1541,33 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
1541
1541
 
1542
1542
  bool loop = true;
1543
1543
  while (loop) {
1544
+ VALUE annotations = rb_ary_new();
1545
+ position overload_annot_pos = NullPosition;
1546
+
1547
+ if (state->next_token.type == tANNOTATION) {
1548
+ parse_annotations(state, annotations, &overload_annot_pos);
1549
+ }
1550
+
1544
1551
  switch (state->next_token.type) {
1545
1552
  case pLPAREN:
1546
1553
  case pARROW:
1547
1554
  case pLBRACE:
1548
1555
  case pLBRACKET:
1549
1556
  case pQUESTION:
1550
- rb_ary_push(method_types, parse_method_type(state));
1551
- member_range.end = state->current_token.range.end;
1552
- break;
1557
+ {
1558
+ VALUE method_type = parse_method_type(state);
1559
+ rb_ary_push(overloads, rbs_ast_members_method_definition_overload(annotations, method_type));
1560
+ member_range.end = state->current_token.range.end;
1561
+ break;
1562
+ }
1553
1563
 
1554
1564
  case pDOT3:
1555
1565
  if (accept_overload) {
1556
- overload = Qtrue;
1566
+ overloading = Qtrue;
1557
1567
  parser_advance(state);
1558
1568
  loop = false;
1559
- overload_range = state->current_token.range;
1560
- member_range.end = overload_range.end;
1569
+ overloading_range = state->current_token.range;
1570
+ member_range.end = overloading_range.end;
1561
1571
  break;
1562
1572
  } else {
1563
1573
  raise_syntax_error(
@@ -1604,17 +1614,17 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
1604
1614
  rbs_loc_add_required_child(loc, rb_intern("keyword"), keyword_range);
1605
1615
  rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
1606
1616
  rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
1607
- rbs_loc_add_optional_child(loc, rb_intern("overload"), overload_range);
1617
+ rbs_loc_add_optional_child(loc, rb_intern("overloading"), overloading_range);
1608
1618
  rbs_loc_add_optional_child(loc, rb_intern("visibility"), visibility_range);
1609
1619
 
1610
1620
  return rbs_ast_members_method_definition(
1611
1621
  name,
1612
1622
  k,
1613
- method_types,
1623
+ overloads,
1614
1624
  annotations,
1615
1625
  location,
1616
1626
  comment,
1617
- overload,
1627
+ overloading,
1618
1628
  visibility
1619
1629
  );
1620
1630
  }
@@ -2343,7 +2353,7 @@ VALUE parse_class_decl_super(parserstate *state, range *lt_range) {
2343
2353
  args = rb_ary_new();
2344
2354
  class_instance_name(state, CLASS_NAME, &name, args, &name_range, &args_range);
2345
2355
 
2346
- super_range.end = args_range.end;
2356
+ super_range.end = state->current_token.range.end;
2347
2357
 
2348
2358
  location = rbs_new_location(state->buffer, super_range);
2349
2359
  loc = rbs_check_location(location);
@@ -402,15 +402,27 @@ VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE
402
402
  );
403
403
  }
404
404
 
405
- VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload, VALUE visibility) {
405
+ VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type) {
406
+ VALUE args = rb_hash_new();
407
+ rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
408
+ rb_hash_aset(args, ID2SYM(rb_intern("method_type")), method_type);
409
+
410
+ return CLASS_NEW_INSTANCE(
411
+ RBS_AST_Members_MethodDefinition_Overload,
412
+ 1,
413
+ &args
414
+ );
415
+ }
416
+
417
+ VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility) {
406
418
  VALUE args = rb_hash_new();
407
419
  rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
408
420
  rb_hash_aset(args, ID2SYM(rb_intern("kind")), kind);
409
- rb_hash_aset(args, ID2SYM(rb_intern("types")), types);
421
+ rb_hash_aset(args, ID2SYM(rb_intern("overloads")), overloads);
410
422
  rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
411
423
  rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
412
424
  rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
413
- rb_hash_aset(args, ID2SYM(rb_intern("overload")), overload);
425
+ rb_hash_aset(args, ID2SYM(rb_intern("overloading")), overloading);
414
426
  rb_hash_aset(args, ID2SYM(rb_intern("visibility")), visibility);
415
427
 
416
428
  return CLASS_NEW_INSTANCE(
@@ -17,7 +17,8 @@ VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
17
17
  VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
18
18
  VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
19
19
  VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
20
- VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload, VALUE visibility);
20
+ VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE overloads, VALUE annotations, VALUE location, VALUE comment, VALUE overloading, VALUE visibility);
21
+ VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method_type);
21
22
  VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
22
23
  VALUE rbs_ast_members_variable(VALUE klass, VALUE name, VALUE type, VALUE location, VALUE comment);
23
24
  VALUE rbs_ast_members_visibility(VALUE klass, VALUE location);
@@ -7,23 +7,57 @@ module RBS
7
7
  end
8
8
 
9
9
  class MethodDefinition < Base
10
+ class Overload
11
+ attr_reader :method_type, :annotations
12
+
13
+ def initialize(method_type:, annotations:)
14
+ @method_type = method_type
15
+ @annotations = annotations
16
+ end
17
+
18
+ def ==(other)
19
+ other.is_a?(Overload) && other.method_type == method_type && other.annotations == annotations
20
+ end
21
+
22
+ def hash
23
+ method_type.hash ^ annotations.hash
24
+ end
25
+
26
+ alias eql? ==
27
+
28
+ def update(annotations: self.annotations, method_type: self.method_type)
29
+ Overload.new(annotations: annotations, method_type: method_type)
30
+ end
31
+
32
+ def sub(subst)
33
+ update(method_type: self.method_type.sub(subst))
34
+ end
35
+
36
+ def to_json(state = _ = nil)
37
+ {
38
+ annotations: annotations,
39
+ method_type: method_type
40
+ }.to_json(state)
41
+ end
42
+ end
43
+
10
44
  attr_reader :name
11
45
  attr_reader :kind
12
- attr_reader :types
46
+ attr_reader :overloads
13
47
  attr_reader :annotations
14
48
  attr_reader :location
15
49
  attr_reader :comment
16
- attr_reader :overload
50
+ attr_reader :overloading
17
51
  attr_reader :visibility
18
52
 
19
- def initialize(name:, kind:, types:, annotations:, location:, comment:, overload:, visibility: nil)
53
+ def initialize(name:, kind:, overloads:, annotations:, location:, comment:, overloading:, visibility:)
20
54
  @name = name
21
55
  @kind = kind
22
- @types = types
56
+ @overloads = overloads
23
57
  @annotations = annotations
24
58
  @location = location
25
59
  @comment = comment
26
- @overload = overload ? true : false
60
+ @overloading = overloading
27
61
  @visibility = visibility
28
62
  end
29
63
 
@@ -31,15 +65,15 @@ module RBS
31
65
  other.is_a?(MethodDefinition) &&
32
66
  other.name == name &&
33
67
  other.kind == kind &&
34
- other.types == types &&
35
- other.overload == overload &&
68
+ other.overloads == overloads &&
69
+ other.overloading? == overloading? &&
36
70
  other.visibility == visibility
37
71
  end
38
72
 
39
73
  alias eql? ==
40
74
 
41
75
  def hash
42
- name.hash ^ kind.hash ^ types.hash ^ overload.hash
76
+ name.hash ^ kind.hash ^ overloads.hash ^ overloading?.hash ^ visibility.hash
43
77
  end
44
78
 
45
79
  def instance?
@@ -50,19 +84,19 @@ module RBS
50
84
  kind == :singleton || kind == :singleton_instance
51
85
  end
52
86
 
53
- def overload?
54
- overload
87
+ def overloading?
88
+ overloading
55
89
  end
56
90
 
57
- def update(name: self.name, kind: self.kind, types: self.types, annotations: self.annotations, location: self.location, comment: self.comment, overload: self.overload, visibility: self.visibility)
91
+ def update(name: self.name, kind: self.kind, overloads: self.overloads, annotations: self.annotations, location: self.location, comment: self.comment, overloading: self.overloading?, visibility: self.visibility)
58
92
  self.class.new(
59
93
  name: name,
60
94
  kind: kind,
61
- types: types,
95
+ overloads: overloads,
62
96
  annotations: annotations,
63
97
  location: location,
64
98
  comment: comment,
65
- overload: overload,
99
+ overloading: overloading,
66
100
  visibility: visibility
67
101
  )
68
102
  end
@@ -72,11 +106,11 @@ module RBS
72
106
  member: :method_definition,
73
107
  name: name,
74
108
  kind: kind,
75
- types: types,
109
+ overloads: overloads,
76
110
  annotations: annotations,
77
111
  location: location,
78
112
  comment: comment,
79
- overload: overload,
113
+ overloading: overloading?,
80
114
  visibility: visibility
81
115
  }.to_json(state)
82
116
  end
data/lib/rbs/cli.rb CHANGED
@@ -29,7 +29,12 @@ module RBS
29
29
  end
30
30
 
31
31
  loader = EnvironmentLoader.new(core_root: core_root, repository: repository)
32
- lock = config_path&.then { |p| Collection::Config.lockfile_of(p) }
32
+ if config_path
33
+ lock_path = Collection::Config.to_lockfile_path(config_path)
34
+ if lock_path.file?
35
+ lock = Collection::Config::Lockfile.from_lockfile(lockfile_path: lock_path, data: YAML.load_file(lock_path.to_s))
36
+ end
37
+ end
33
38
  loader.add_collection(lock) if lock
34
39
 
35
40
  dirs.each do |dir|
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ module Collection
5
+ class Config
6
+ class Lockfile
7
+ attr_reader :lockfile_path, :lockfile_dir, :path, :gemfile_lock_path, :sources, :gems
8
+
9
+ def initialize(lockfile_path:, path:, gemfile_lock_path:)
10
+ @lockfile_path = lockfile_path
11
+ @lockfile_dir = lockfile_path.parent
12
+ @path = path
13
+ @gemfile_lock_path = gemfile_lock_path
14
+
15
+ @sources = {}
16
+ @gems = {}
17
+ end
18
+
19
+ def fullpath
20
+ lockfile_dir + path
21
+ end
22
+
23
+ def gemfile_lock_fullpath
24
+ if gemfile_lock_path
25
+ lockfile_dir + gemfile_lock_path
26
+ end
27
+ end
28
+
29
+ def each_source(&block)
30
+ if block
31
+ sources.each_value(&block)
32
+ yield Sources::Rubygems.instance
33
+ yield Sources::Stdlib.instance
34
+ else
35
+ enum_for :each_source
36
+ end
37
+ end
38
+
39
+ def to_lockfile
40
+ # @type var data: lockfile_data
41
+
42
+ data = {
43
+ "sources" => sources.each_value.sort_by {|s| s.name }.map {|source| source.to_lockfile },
44
+ "path" => path.to_s,
45
+ "gems" => gems.each_value.sort_by {|g| g[:name] }.map {|hash| library_data(hash) },
46
+ "gemfile_lock_path" => gemfile_lock_path.to_s
47
+ }
48
+
49
+ data.delete("sources") if sources.empty?
50
+ data.delete("gems") if gems.empty?
51
+
52
+ data
53
+ end
54
+
55
+ def self.from_lockfile(lockfile_path:, data:)
56
+ path = Pathname(data["path"])
57
+ if p = data["gemfile_lock_path"]
58
+ gemfile_lock_path = Pathname(p)
59
+ end
60
+
61
+ lockfile = Lockfile.new(lockfile_path: lockfile_path, path: path, gemfile_lock_path: gemfile_lock_path)
62
+
63
+ if sources = data["sources"]
64
+ sources.each do |src|
65
+ git = Sources::Git.new(
66
+ name: src["name"],
67
+ revision: src["revision"],
68
+ remote: src["remote"],
69
+ repo_dir: src["repo_dir"]
70
+ )
71
+ lockfile.sources[git.name] = git
72
+ end
73
+ end
74
+
75
+ if gems = data["gems"]
76
+ gems.each do |gem|
77
+ src = gem["source"]
78
+ source = Sources.from_config_entry(src)
79
+ lockfile.gems[gem["name"]] = {
80
+ name: gem["name"],
81
+ version: gem["version"],
82
+ source: source
83
+ }
84
+ end
85
+ end
86
+
87
+ lockfile
88
+ end
89
+
90
+ def library_data(lib)
91
+ {
92
+ "name" => lib[:name],
93
+ "version" => lib[:version],
94
+ "source" => lib[:source].to_lockfile
95
+ }
96
+ end
97
+
98
+ def check_rbs_availability!
99
+ raise CollectionNotAvailable unless fullpath.exist?
100
+
101
+ gems.each_value do |gem|
102
+ source = gem[:source]
103
+
104
+ case source
105
+ when Sources::Git
106
+ meta_path = fullpath.join(gem[:name], gem[:version], Sources::Git::METADATA_FILENAME)
107
+ raise CollectionNotAvailable unless meta_path.exist?
108
+ raise CollectionNotAvailable unless library_data(gem) == YAML.load(meta_path.read)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end