rbs 0.13.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +9 -5
- data/.gitignore +0 -1
- data/CHANGELOG.md +33 -1
- data/Gemfile +4 -0
- data/README.md +9 -3
- data/Rakefile +14 -1
- data/Steepfile +1 -1
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/bin/test_runner.rb +15 -1
- data/{stdlib/builtin → core}/array.rbs +124 -120
- data/{stdlib/builtin → core}/basic_object.rbs +54 -54
- data/{stdlib/builtin → core}/binding.rbs +42 -42
- data/core/builtin.rbs +70 -0
- data/{stdlib/builtin → core}/class.rbs +33 -33
- data/{stdlib/builtin → core}/comparable.rbs +0 -0
- data/{stdlib/builtin → core}/complex.rbs +90 -90
- data/{stdlib/builtin → core}/constants.rbs +0 -0
- data/{stdlib/builtin → core}/data.rbs +0 -0
- data/{stdlib/builtin → core}/deprecated.rbs +0 -0
- data/{stdlib/builtin → core}/dir.rbs +1 -1
- data/{stdlib/builtin → core}/encoding.rbs +33 -33
- data/{stdlib/builtin → core}/enumerable.rbs +99 -92
- data/{stdlib/builtin → core}/enumerator.rbs +40 -40
- data/{stdlib/builtin → core}/errno.rbs +0 -0
- data/{stdlib/builtin → core}/errors.rbs +2 -2
- data/{stdlib/builtin → core}/exception.rbs +50 -50
- data/{stdlib/builtin → core}/false_class.rbs +6 -6
- data/{stdlib/builtin → core}/fiber.rbs +14 -14
- data/{stdlib/builtin → core}/fiber_error.rbs +1 -1
- data/{stdlib/builtin → core}/file.rbs +0 -0
- data/{stdlib/builtin → core}/file_test.rbs +0 -0
- data/{stdlib/builtin → core}/float.rbs +161 -161
- data/{stdlib/builtin → core}/gc.rbs +3 -3
- data/{stdlib/builtin → core}/hash.rbs +15 -15
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +89 -89
- data/{stdlib/builtin → core}/kernel.rbs +70 -154
- data/{stdlib/builtin → core}/marshal.rbs +0 -0
- data/{stdlib/builtin → core}/match_data.rbs +1 -1
- data/{stdlib/builtin → core}/math.rbs +0 -0
- data/{stdlib/builtin → core}/method.rbs +19 -19
- data/{stdlib/builtin → core}/module.rbs +13 -13
- data/{stdlib/builtin → core}/nil_class.rbs +20 -20
- data/{stdlib/builtin → core}/numeric.rbs +101 -101
- data/{stdlib/builtin → core}/object.rbs +173 -173
- data/{stdlib/builtin → core}/proc.rbs +91 -91
- data/{stdlib/builtin → core}/process.rbs +0 -0
- data/{stdlib/builtin → core}/random.rbs +1 -1
- data/{stdlib/builtin → core}/range.rbs +4 -6
- data/{stdlib/builtin → core}/rational.rbs +83 -83
- data/{stdlib/builtin → core}/rb_config.rbs +0 -0
- data/{stdlib/builtin → core}/regexp.rbs +0 -0
- data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
- data/{stdlib/builtin → core}/signal.rbs +7 -7
- data/{stdlib/builtin → core}/string.rbs +10 -10
- data/{stdlib/builtin → core}/string_io.rbs +8 -8
- data/{stdlib/builtin → core}/struct.rbs +2 -2
- data/{stdlib/builtin → core}/symbol.rbs +1 -1
- data/{stdlib/builtin → core}/thread.rbs +189 -189
- data/{stdlib/builtin → core}/thread_group.rbs +2 -2
- data/{stdlib/builtin → core}/time.rbs +0 -0
- data/{stdlib/builtin → core}/trace_point.rbs +0 -0
- data/{stdlib/builtin → core}/true_class.rbs +10 -10
- data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
- data/{stdlib/builtin → core}/warning.rbs +1 -1
- data/docs/CONTRIBUTING.md +1 -0
- data/docs/repo.md +125 -0
- data/docs/syntax.md +50 -6
- data/goodcheck.yml +22 -5
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/cli.rb +105 -103
- data/lib/rbs/definition.rb +9 -4
- data/lib/rbs/definition_builder.rb +54 -22
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3153 -0
- data/lib/rbs/parser.y +25 -11
- data/lib/rbs/prototype/rb.rb +47 -9
- data/lib/rbs/prototype/runtime.rb +17 -7
- data/lib/rbs/repository.rb +121 -0
- data/lib/rbs/test/hook.rb +2 -0
- data/lib/rbs/test/setup.rb +5 -3
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/tester.rb +4 -1
- data/lib/rbs/test/type_check.rb +12 -6
- data/lib/rbs/type_name.rb +3 -2
- data/lib/rbs/variance_calculator.rb +1 -1
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +1 -1
- data/sig/cli.rbs +58 -0
- data/sig/constant.rbs +2 -2
- data/sig/constant_table.rbs +11 -11
- data/sig/declarations.rbs +2 -2
- data/sig/definition.rbs +10 -5
- data/sig/definition_builder.rbs +4 -1
- data/sig/environment_loader.rbs +92 -46
- data/sig/members.rbs +2 -2
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +4 -4
- data/sig/parser.rbs +25 -0
- data/sig/polyfill.rbs +42 -0
- data/sig/rbs.rbs +8 -0
- data/sig/repository.rbs +79 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/vendorer.rbs +44 -0
- data/sig/writer.rbs +15 -15
- data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
- data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
- data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +2 -2
- data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
- data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
- data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
- data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
- data/stdlib/date/{date.rbs → 0/date.rbs} +4 -4
- data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
- data/stdlib/dbm/0/dbm.rbs +277 -0
- data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
- data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
- data/stdlib/find/{find.rbs → 0/find.rbs} +12 -12
- data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
- data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
- data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
- data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
- data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
- data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
- data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
- data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
- data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
- data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +40 -40
- data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
- data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
- data/stdlib/pstore/0/pstore.rbs +287 -0
- data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
- data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
- data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +12 -12
- data/stdlib/tsort/0/cyclic.rbs +4 -0
- data/stdlib/tsort/0/interfaces.rbs +19 -0
- data/stdlib/tsort/0/tsort.rbs +363 -0
- data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
- data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
- data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
- data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
- data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
- data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +9 -9
- metadata +104 -93
- data/stdlib/builtin/builtin.rbs +0 -42
data/lib/rbs/definition.rb
CHANGED
@@ -60,12 +60,14 @@ module RBS
|
|
60
60
|
attr_reader :defs
|
61
61
|
attr_reader :accessibility
|
62
62
|
attr_reader :extra_annotations
|
63
|
+
attr_reader :alias_of
|
63
64
|
|
64
|
-
def initialize(super_method:, defs:, accessibility:, annotations: [])
|
65
|
+
def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:)
|
65
66
|
@super_method = super_method
|
66
67
|
@defs = defs
|
67
68
|
@accessibility = accessibility
|
68
69
|
@extra_annotations = annotations
|
70
|
+
@alias_of = alias_of
|
69
71
|
end
|
70
72
|
|
71
73
|
def defined_in
|
@@ -110,7 +112,8 @@ module RBS
|
|
110
112
|
self.class.new(
|
111
113
|
super_method: super_method&.sub(s),
|
112
114
|
defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) },
|
113
|
-
accessibility: @accessibility
|
115
|
+
accessibility: @accessibility,
|
116
|
+
alias_of: alias_of
|
114
117
|
)
|
115
118
|
end
|
116
119
|
|
@@ -118,7 +121,8 @@ module RBS
|
|
118
121
|
self.class.new(
|
119
122
|
super_method: super_method&.map_type(&block),
|
120
123
|
defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) },
|
121
|
-
accessibility: @accessibility
|
124
|
+
accessibility: @accessibility,
|
125
|
+
alias_of: alias_of
|
122
126
|
)
|
123
127
|
end
|
124
128
|
|
@@ -126,7 +130,8 @@ module RBS
|
|
126
130
|
self.class.new(
|
127
131
|
super_method: super_method,
|
128
132
|
defs: defs.map {|defn| defn.update(type: yield(defn.type)) },
|
129
|
-
accessibility: @accessibility
|
133
|
+
accessibility: @accessibility,
|
134
|
+
alias_of: alias_of
|
130
135
|
)
|
131
136
|
end
|
132
137
|
end
|
@@ -40,7 +40,7 @@ module RBS
|
|
40
40
|
if s = super_class
|
41
41
|
yield s
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
self_types&.each(&block)
|
45
45
|
included_modules&.each(&block)
|
46
46
|
prepended_modules&.each(&block)
|
@@ -303,7 +303,7 @@ module RBS
|
|
303
303
|
mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
|
304
304
|
ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
|
305
305
|
end
|
306
|
-
end
|
306
|
+
end
|
307
307
|
end
|
308
308
|
|
309
309
|
ancestors.unshift(self_ancestor)
|
@@ -316,7 +316,7 @@ module RBS
|
|
316
316
|
mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
|
317
317
|
ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
|
318
318
|
end
|
319
|
-
end
|
319
|
+
end
|
320
320
|
end
|
321
321
|
|
322
322
|
building_ancestors.pop
|
@@ -599,10 +599,15 @@ module RBS
|
|
599
599
|
try_cache(type_name, cache: one_instance_cache) do
|
600
600
|
entry = env.class_decls[type_name]
|
601
601
|
|
602
|
+
param_names = entry.type_params.each.map(&:name)
|
602
603
|
self_type = Types::ClassInstance.new(name: type_name,
|
603
|
-
args: Types::Variable.build(
|
604
|
+
args: Types::Variable.build(param_names),
|
604
605
|
location: nil)
|
605
|
-
ancestors =
|
606
|
+
ancestors = Definition::InstanceAncestors.new(
|
607
|
+
type_name: type_name,
|
608
|
+
params: param_names,
|
609
|
+
ancestors: [Definition::Ancestor::Instance.new(name: type_name, args: self_type.args)]
|
610
|
+
)
|
606
611
|
|
607
612
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
608
613
|
method_definition_members(type_name, entry, kind: :instance).each do |method_name, array|
|
@@ -618,13 +623,15 @@ module RBS
|
|
618
623
|
Definition::Method.new(
|
619
624
|
super_method: nil,
|
620
625
|
accessibility: visibility,
|
621
|
-
defs: method_def.defs.map {|defn| defn.update(implemented_in: type_name) }
|
626
|
+
defs: method_def.defs.map {|defn| defn.update(implemented_in: type_name) },
|
627
|
+
alias_of: nil
|
622
628
|
)
|
623
629
|
else
|
624
630
|
Definition::Method.new(
|
625
631
|
super_method: nil,
|
626
632
|
accessibility: visibility,
|
627
|
-
defs: []
|
633
|
+
defs: [],
|
634
|
+
alias_of: nil
|
628
635
|
)
|
629
636
|
end
|
630
637
|
|
@@ -641,7 +648,8 @@ module RBS
|
|
641
648
|
Definition::Method.new(
|
642
649
|
super_method: nil,
|
643
650
|
defs: defs + original.defs,
|
644
|
-
accessibility: original.accessibility
|
651
|
+
accessibility: original.accessibility,
|
652
|
+
alias_of: nil
|
645
653
|
)
|
646
654
|
end
|
647
655
|
end
|
@@ -676,7 +684,8 @@ module RBS
|
|
676
684
|
implemented_in: type_name
|
677
685
|
)
|
678
686
|
],
|
679
|
-
accessibility: accessibility
|
687
|
+
accessibility: accessibility,
|
688
|
+
alias_of: nil
|
680
689
|
)
|
681
690
|
end
|
682
691
|
|
@@ -698,7 +707,8 @@ module RBS
|
|
698
707
|
implemented_in: type_name
|
699
708
|
),
|
700
709
|
],
|
701
|
-
accessibility: accessibility
|
710
|
+
accessibility: accessibility,
|
711
|
+
alias_of: nil
|
702
712
|
)
|
703
713
|
end
|
704
714
|
|
@@ -747,7 +757,15 @@ module RBS
|
|
747
757
|
location: member.location
|
748
758
|
)
|
749
759
|
|
750
|
-
|
760
|
+
original_method = definition.methods[member.old_name]
|
761
|
+
|
762
|
+
definition.methods[member.new_name] = Definition::Method.new(
|
763
|
+
super_method: original_method.super_method,
|
764
|
+
defs: original_method.defs,
|
765
|
+
accessibility: original_method.accessibility,
|
766
|
+
alias_of: original_method,
|
767
|
+
annotations: original_method.annotations
|
768
|
+
)
|
751
769
|
end
|
752
770
|
end
|
753
771
|
end
|
@@ -814,8 +832,7 @@ module RBS
|
|
814
832
|
|
815
833
|
methods.each do |name, method|
|
816
834
|
method.method_types.each do |method_type|
|
817
|
-
|
818
|
-
when MethodType
|
835
|
+
unless name == :initialize
|
819
836
|
result = calculator.in_method_type(method_type: method_type, variables: param_names)
|
820
837
|
|
821
838
|
validate_params_with type_params, result: result do |param|
|
@@ -839,7 +856,10 @@ module RBS
|
|
839
856
|
entry = env.class_decls[type_name]
|
840
857
|
|
841
858
|
self_type = Types::ClassSingleton.new(name: type_name, location: nil)
|
842
|
-
ancestors =
|
859
|
+
ancestors = Definition::SingletonAncestors.new(
|
860
|
+
type_name: type_name,
|
861
|
+
ancestors: [Definition::Ancestor::Singleton.new(name: type_name)]
|
862
|
+
)
|
843
863
|
|
844
864
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
845
865
|
method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array|
|
@@ -856,7 +876,8 @@ module RBS
|
|
856
876
|
defs: method_def&.yield_self do |method_def|
|
857
877
|
method_def.defs.map {|defn| defn.update(implemented_in: type_name) }
|
858
878
|
end || [],
|
859
|
-
accessibility: visibility
|
879
|
+
accessibility: visibility,
|
880
|
+
alias_of: nil
|
860
881
|
)
|
861
882
|
definition.methods[method_name] = members.inject(m) do |original, new|
|
862
883
|
defs = new.types.map do |type|
|
@@ -870,7 +891,8 @@ module RBS
|
|
870
891
|
Definition::Method.new(
|
871
892
|
super_method: nil,
|
872
893
|
defs: defs + original.defs,
|
873
|
-
accessibility: original.accessibility
|
894
|
+
accessibility: original.accessibility,
|
895
|
+
alias_of: nil
|
874
896
|
)
|
875
897
|
end
|
876
898
|
end
|
@@ -894,7 +916,14 @@ module RBS
|
|
894
916
|
location: member.location
|
895
917
|
)
|
896
918
|
|
897
|
-
|
919
|
+
original_method = definition.methods[member.old_name]
|
920
|
+
definition.methods[member.new_name] = Definition::Method.new(
|
921
|
+
super_method: original_method.super_method,
|
922
|
+
defs: original_method.defs,
|
923
|
+
accessibility: original_method.accessibility,
|
924
|
+
alias_of: original_method,
|
925
|
+
annotations: original_method.annotations
|
926
|
+
)
|
898
927
|
end
|
899
928
|
end
|
900
929
|
end
|
@@ -941,12 +970,13 @@ module RBS
|
|
941
970
|
Definition::Method::TypeDef.new(
|
942
971
|
type: method_type,
|
943
972
|
member: initialize_def.member,
|
944
|
-
defined_in:
|
945
|
-
implemented_in:
|
973
|
+
defined_in: initialize_def.defined_in,
|
974
|
+
implemented_in: initialize_def.implemented_in
|
946
975
|
)
|
947
976
|
end,
|
948
977
|
accessibility: :public,
|
949
|
-
annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")]
|
978
|
+
annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")],
|
979
|
+
alias_of: nil
|
950
980
|
)
|
951
981
|
end
|
952
982
|
end
|
@@ -1030,7 +1060,8 @@ module RBS
|
|
1030
1060
|
methods[name] = Definition::Method.new(
|
1031
1061
|
super_method: super_method,
|
1032
1062
|
accessibility: method.accessibility,
|
1033
|
-
defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
|
1063
|
+
defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) },
|
1064
|
+
alias_of: nil
|
1034
1065
|
)
|
1035
1066
|
end
|
1036
1067
|
|
@@ -1124,7 +1155,8 @@ module RBS
|
|
1124
1155
|
implemented_in: nil
|
1125
1156
|
)
|
1126
1157
|
end,
|
1127
|
-
accessibility: :public
|
1158
|
+
accessibility: :public,
|
1159
|
+
alias_of: nil
|
1128
1160
|
)
|
1129
1161
|
definition.methods[member.name] = method
|
1130
1162
|
end
|
data/lib/rbs/environment.rb
CHANGED
@@ -1,156 +1,130 @@
|
|
1
1
|
module RBS
|
2
2
|
class EnvironmentLoader
|
3
|
-
class
|
4
|
-
attr_reader :
|
3
|
+
class UnknownLibraryError < StandardError
|
4
|
+
attr_reader :library
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
-
|
6
|
+
def initialize(lib:)
|
7
|
+
@library = lib
|
8
|
+
|
9
|
+
super("Cannot find type definitions for library: #{lib.name} (#{lib.version || "[nil]"})")
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
Library = _ = Struct.new(:name, :version, keyword_init: true)
|
14
|
+
|
15
|
+
attr_reader :core_root
|
16
|
+
attr_reader :repository
|
14
17
|
|
15
|
-
attr_reader :
|
16
|
-
attr_reader :
|
17
|
-
attr_reader :gem_vendor_path
|
18
|
+
attr_reader :libs
|
19
|
+
attr_reader :dirs
|
18
20
|
|
19
|
-
|
21
|
+
DEFAULT_CORE_ROOT = Pathname(_ = __dir__) + "../../core"
|
20
22
|
|
21
23
|
def self.gem_sig_path(name, version)
|
22
|
-
|
24
|
+
spec = Gem::Specification.find_by_name(name, version)
|
25
|
+
path = Pathname(spec.gem_dir) + "sig"
|
26
|
+
if path.directory?
|
27
|
+
[spec, path]
|
28
|
+
end
|
23
29
|
rescue Gem::MissingSpecError
|
24
30
|
nil
|
25
31
|
end
|
26
32
|
|
27
|
-
def initialize(
|
28
|
-
@
|
29
|
-
@
|
30
|
-
|
31
|
-
@
|
33
|
+
def initialize(core_root: DEFAULT_CORE_ROOT, repository: Repository.new)
|
34
|
+
@core_root = core_root
|
35
|
+
@repository = repository
|
36
|
+
|
37
|
+
@libs = []
|
38
|
+
@dirs = []
|
32
39
|
end
|
33
40
|
|
34
|
-
def add(path: nil, library: nil)
|
41
|
+
def add(path: nil, library: nil, version: nil)
|
35
42
|
case
|
36
43
|
when path
|
37
|
-
|
44
|
+
dirs << path
|
38
45
|
when library
|
39
|
-
name, version
|
40
|
-
|
41
|
-
case
|
42
|
-
when !version && path = stdlib?(name)
|
43
|
-
@paths << LibraryPath.new(name: name, path: path)
|
44
|
-
when (path = gem?(name, version))
|
45
|
-
@paths << GemPath.new(name: name, version: version, path: path)
|
46
|
-
else
|
47
|
-
raise UnknownLibraryNameError.new(name: library)
|
48
|
-
end
|
46
|
+
libs << Library.new(name: library, version: version)
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
|
-
def
|
53
|
-
|
50
|
+
def has_library?(library:, version:)
|
51
|
+
self.class.gem_sig_path(library, version) || repository.lookup(library, version)
|
54
52
|
end
|
55
53
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
def load(env:)
|
55
|
+
# @type var loaded: Array[[AST::Declarations::t, Pathname, source]]
|
56
|
+
loaded = []
|
57
|
+
|
58
|
+
each_decl do |decl, buf, source, path|
|
59
|
+
env << decl
|
60
|
+
loaded << [decl, path, source]
|
60
61
|
end
|
62
|
+
|
63
|
+
loaded
|
61
64
|
end
|
62
65
|
|
63
|
-
def
|
64
|
-
if
|
65
|
-
|
66
|
-
gem_dir = path + name
|
67
|
-
if gem_dir.directory?
|
68
|
-
return gem_dir
|
69
|
-
end
|
66
|
+
def each_dir
|
67
|
+
if root = core_root
|
68
|
+
yield :core, root
|
70
69
|
end
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
libs.each do |lib|
|
72
|
+
unless has_library?(version: lib.version, library: lib.name)
|
73
|
+
raise UnknownLibraryError.new(lib: lib)
|
74
|
+
end
|
75
75
|
|
76
|
-
def each_signature(path, immediate: true, &block)
|
77
|
-
if block
|
78
76
|
case
|
79
|
-
when
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
when path.directory?
|
84
|
-
path.children.each do |child|
|
85
|
-
each_signature child, immediate: false, &block
|
86
|
-
end
|
77
|
+
when from_gem = self.class.gem_sig_path(lib.name, lib.version)
|
78
|
+
yield lib, from_gem[1]
|
79
|
+
when from_repo = repository.lookup(lib.name, lib.version)
|
80
|
+
yield lib, from_repo
|
87
81
|
end
|
88
|
-
else
|
89
|
-
enum_for :each_signature, path, immediate: immediate
|
90
82
|
end
|
91
|
-
end
|
92
83
|
|
93
|
-
|
94
|
-
|
95
|
-
case path
|
96
|
-
when Pathname
|
97
|
-
yield path, path
|
98
|
-
when LibraryPath
|
99
|
-
yield path, path.path
|
100
|
-
when GemPath
|
101
|
-
yield path, path.path
|
102
|
-
end
|
84
|
+
dirs.each do |dir|
|
85
|
+
yield dir, dir
|
103
86
|
end
|
104
87
|
end
|
105
88
|
|
106
|
-
def
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
def no_builtin?
|
112
|
-
@no_builtin
|
113
|
-
end
|
114
|
-
|
115
|
-
def each_decl
|
116
|
-
if block_given?
|
117
|
-
# @type var signature_files: Array[[path | :stdlib, Pathname]]
|
118
|
-
signature_files = []
|
119
|
-
|
120
|
-
unless no_builtin?
|
121
|
-
each_signature(stdlib_root + "builtin") do |path|
|
122
|
-
signature_files << [:stdlib, path]
|
123
|
-
end
|
89
|
+
def each_file(path, immediate:, skip_hidden:, &block)
|
90
|
+
case
|
91
|
+
when path.file?
|
92
|
+
if path.extname == ".rbs" || immediate
|
93
|
+
yield path
|
124
94
|
end
|
125
95
|
|
126
|
-
|
127
|
-
|
128
|
-
|
96
|
+
when path.directory?
|
97
|
+
if path.basename.to_s.start_with?("_")
|
98
|
+
if skip_hidden
|
99
|
+
unless immediate
|
100
|
+
return
|
101
|
+
end
|
129
102
|
end
|
130
103
|
end
|
131
104
|
|
132
|
-
|
133
|
-
|
134
|
-
Parser.parse_signature(buffer).each do |decl|
|
135
|
-
yield decl, buffer, file_path, lib_path
|
136
|
-
end
|
105
|
+
path.each_child do |child|
|
106
|
+
each_file(child, immediate: false, skip_hidden: skip_hidden, &block)
|
137
107
|
end
|
138
|
-
else
|
139
|
-
enum_for :each_decl
|
140
108
|
end
|
141
109
|
end
|
142
110
|
|
143
|
-
def
|
144
|
-
|
145
|
-
loadeds = []
|
111
|
+
def each_decl
|
112
|
+
files = Set[]
|
146
113
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
114
|
+
each_dir do |source, dir|
|
115
|
+
skip_hidden = !source.is_a?(Pathname)
|
116
|
+
|
117
|
+
each_file(dir, skip_hidden: skip_hidden, immediate: true) do |path|
|
118
|
+
next if files.include?(path)
|
152
119
|
|
153
|
-
|
120
|
+
files << path
|
121
|
+
buffer = Buffer.new(name: path.to_s, content: path.read)
|
122
|
+
|
123
|
+
Parser.parse_signature(buffer).each do |decl|
|
124
|
+
yield decl, buffer, source, path
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
154
128
|
end
|
155
129
|
end
|
156
130
|
end
|