rbs 2.8.4 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +17 -17
  5. data/README.md +1 -0
  6. data/Rakefile +66 -0
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +18 -2
  12. data/ext/rbs_extension/constants.h +9 -1
  13. data/ext/rbs_extension/lexer.c +834 -777
  14. data/ext/rbs_extension/lexer.h +3 -1
  15. data/ext/rbs_extension/lexer.re +3 -1
  16. data/ext/rbs_extension/lexstate.c +4 -2
  17. data/ext/rbs_extension/parser.c +287 -57
  18. data/ext/rbs_extension/ruby_objs.c +71 -5
  19. data/ext/rbs_extension/ruby_objs.h +9 -2
  20. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  21. data/lib/rbs/ast/declarations.rb +49 -2
  22. data/lib/rbs/ast/directives.rb +39 -0
  23. data/lib/rbs/ast/members.rb +49 -15
  24. data/lib/rbs/cli.rb +38 -19
  25. data/lib/rbs/collection/config/lockfile.rb +115 -0
  26. data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
  27. data/lib/rbs/collection/config.rb +12 -40
  28. data/lib/rbs/collection/installer.rb +9 -13
  29. data/lib/rbs/collection/sources/base.rb +2 -2
  30. data/lib/rbs/collection/sources/git.rb +135 -62
  31. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  32. data/lib/rbs/collection/sources/stdlib.rb +10 -13
  33. data/lib/rbs/collection/sources.rb +7 -1
  34. data/lib/rbs/collection.rb +1 -0
  35. data/lib/rbs/definition.rb +1 -1
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  37. data/lib/rbs/definition_builder/method_builder.rb +3 -3
  38. data/lib/rbs/definition_builder.rb +456 -579
  39. data/lib/rbs/environment/use_map.rb +77 -0
  40. data/lib/rbs/environment.rb +356 -85
  41. data/lib/rbs/environment_loader.rb +20 -17
  42. data/lib/rbs/environment_walker.rb +1 -1
  43. data/lib/rbs/errors.rb +34 -37
  44. data/lib/rbs/locator.rb +3 -3
  45. data/lib/rbs/parser_aux.rb +8 -6
  46. data/lib/rbs/prototype/helpers.rb +29 -13
  47. data/lib/rbs/prototype/node_usage.rb +99 -0
  48. data/lib/rbs/prototype/rb.rb +3 -2
  49. data/lib/rbs/prototype/rbi.rb +6 -4
  50. data/lib/rbs/prototype/runtime.rb +25 -12
  51. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  52. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  53. data/lib/rbs/sorter.rb +3 -3
  54. data/lib/rbs/substitution.rb +19 -0
  55. data/lib/rbs/test/setup.rb +1 -1
  56. data/lib/rbs/type_alias_dependency.rb +1 -1
  57. data/lib/rbs/type_alias_regularity.rb +3 -3
  58. data/lib/rbs/types.rb +1 -5
  59. data/lib/rbs/validator.rb +25 -3
  60. data/lib/rbs/variance_calculator.rb +2 -2
  61. data/lib/rbs/version.rb +1 -1
  62. data/lib/rbs/writer.rb +54 -19
  63. data/lib/rbs.rb +3 -2
  64. data/lib/rdoc_plugin/parser.rb +3 -3
  65. data/schema/members.json +15 -10
  66. data/sig/ancestor_graph.rbs +22 -2
  67. data/sig/collection/config/lockfile.rbs +80 -0
  68. data/sig/collection/config/lockfile_generator.rbs +53 -0
  69. data/sig/collection/config.rbs +5 -48
  70. data/sig/collection/installer.rbs +1 -1
  71. data/sig/collection/sources.rbs +76 -33
  72. data/sig/constant.rbs +1 -1
  73. data/sig/declarations.rbs +36 -3
  74. data/sig/definition.rbs +1 -1
  75. data/sig/definition_builder.rbs +94 -82
  76. data/sig/directives.rbs +61 -0
  77. data/sig/environment.rbs +150 -28
  78. data/sig/environment_loader.rbs +2 -2
  79. data/sig/errors.rbs +42 -0
  80. data/sig/members.rbs +31 -7
  81. data/sig/parser.rbs +8 -15
  82. data/sig/prototype/node_usage.rbs +20 -0
  83. data/sig/resolver/constant_resolver.rbs +1 -2
  84. data/sig/shims/bundler.rbs +31 -0
  85. data/sig/shims/rubygems.rbs +15 -0
  86. data/sig/shims.rbs +0 -22
  87. data/sig/substitution.rbs +6 -0
  88. data/sig/use_map.rbs +35 -0
  89. data/sig/validator.rbs +12 -5
  90. data/sig/writer.rbs +6 -2
  91. metadata +16 -9
  92. data/lib/rbs/constant_table.rb +0 -167
  93. data/lib/rbs/type_name_resolver.rb +0 -67
  94. data/sig/constant_table.rbs +0 -30
  95. data/sig/type_name_resolver.rbs +0 -26
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ class Environment
5
+ class UseMap
6
+ class Table
7
+ attr_reader :known_types, :children
8
+
9
+ def initialize
10
+ @known_types = Set[]
11
+ @children = {}
12
+ end
13
+
14
+ def compute_children
15
+ children.clear
16
+
17
+ known_types.each do |type|
18
+ unless type.namespace.empty?
19
+ children[type.namespace] ||= Set[]
20
+ children[type.namespace] << type
21
+ end
22
+ end
23
+
24
+ self
25
+ end
26
+ end
27
+
28
+ attr_reader :use_dirs
29
+
30
+ def initialize(table:)
31
+ @use_dirs = []
32
+ @map = {}
33
+ @table = table
34
+ end
35
+
36
+ def build_map(clause)
37
+ case clause
38
+ when AST::Directives::Use::SingleClause
39
+ if clause.new_name
40
+ @map[clause.new_name] = clause.type_name.absolute!
41
+ else
42
+ @map[clause.type_name.name] = clause.type_name.absolute!
43
+ end
44
+ when AST::Directives::Use::WildcardClause
45
+ @table.children.fetch(clause.namespace.absolute!).each do |child|
46
+ @map[child.name] = child
47
+ end
48
+ end
49
+
50
+ self
51
+ end
52
+
53
+ def resolve?(type_name)
54
+ return if type_name.absolute?
55
+
56
+ hd, *tl = type_name.namespace.path
57
+
58
+ if hd
59
+ # namespace is not empty
60
+ if tn = @map[hd]
61
+ path = [*tn.namespace.path, tn.name, *tl]
62
+ TypeName.new(
63
+ namespace: Namespace.new(absolute: true, path: path),
64
+ name: type_name.name
65
+ )
66
+ end
67
+ else
68
+ @map[type_name.name]
69
+ end
70
+ end
71
+
72
+ def resolve(type_name)
73
+ resolve?(type_name) || type_name
74
+ end
75
+ end
76
+ end
77
+ end