rbs 0.15.0 → 0.19.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 +8 -4
- data/CHANGELOG.md +29 -1
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/Rakefile +19 -1
- data/Steepfile +0 -1
- data/bin/test_runner.rb +15 -1
- data/{stdlib/builtin → core}/array.rbs +1 -1
- data/{stdlib/builtin → core}/basic_object.rbs +0 -0
- data/{stdlib/builtin → core}/binding.rbs +0 -0
- data/{stdlib/builtin → core}/builtin.rbs +2 -2
- data/{stdlib/builtin → core}/class.rbs +0 -0
- data/{stdlib/builtin → core}/comparable.rbs +0 -0
- data/{stdlib/builtin → core}/complex.rbs +0 -0
- 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 +0 -0
- data/{stdlib/builtin → core}/enumerable.rbs +41 -40
- data/{stdlib/builtin → core}/enumerator.rbs +5 -5
- data/{stdlib/builtin → core}/errno.rbs +0 -0
- data/{stdlib/builtin → core}/errors.rbs +0 -0
- data/{stdlib/builtin → core}/exception.rbs +0 -0
- data/{stdlib/builtin → core}/false_class.rbs +0 -0
- data/{stdlib/builtin → core}/fiber.rbs +0 -0
- data/{stdlib/builtin → core}/fiber_error.rbs +0 -0
- data/{stdlib/builtin → core}/file.rbs +0 -4
- data/{stdlib/builtin → core}/file_test.rbs +0 -0
- data/{stdlib/builtin → core}/float.rbs +0 -0
- data/{stdlib/builtin → core}/gc.rbs +0 -0
- data/{stdlib/builtin → core}/hash.rbs +8 -8
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +1 -1
- data/{stdlib/builtin → core}/kernel.rbs +0 -0
- data/{stdlib/builtin → core}/marshal.rbs +0 -0
- data/{stdlib/builtin → core}/match_data.rbs +0 -0
- data/{stdlib/builtin → core}/math.rbs +0 -0
- data/{stdlib/builtin → core}/method.rbs +0 -0
- data/{stdlib/builtin → core}/module.rbs +0 -0
- data/{stdlib/builtin → core}/nil_class.rbs +0 -0
- data/{stdlib/builtin → core}/numeric.rbs +0 -0
- data/{stdlib/builtin → core}/object.rbs +0 -0
- data/core/object_space.rbs +98 -0
- data/{stdlib/builtin → core}/proc.rbs +0 -0
- data/{stdlib/builtin → core}/process.rbs +0 -0
- data/{stdlib/builtin → core}/random.rbs +0 -0
- data/{stdlib/builtin → core}/range.rbs +1 -1
- data/{stdlib/builtin → core}/rational.rbs +0 -0
- 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 +0 -0
- data/{stdlib/builtin → core}/string.rbs +0 -0
- data/{stdlib/builtin → core}/string_io.rbs +0 -0
- data/{stdlib/builtin → core}/struct.rbs +1 -1
- data/{stdlib/builtin → core}/symbol.rbs +0 -0
- data/{stdlib/builtin → core}/thread.rbs +0 -0
- data/{stdlib/builtin → core}/thread_group.rbs +0 -0
- data/{stdlib/builtin → core}/time.rbs +0 -0
- data/{stdlib/builtin → core}/trace_point.rbs +0 -0
- data/{stdlib/builtin → core}/true_class.rbs +0 -0
- data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
- data/{stdlib/builtin → core}/warning.rbs +0 -0
- data/docs/repo.md +125 -0
- data/lib/rbs.rb +1 -0
- data/lib/rbs/cli.rb +105 -103
- data/lib/rbs/definition.rb +9 -4
- data/lib/rbs/definition_builder.rb +48 -15
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/environment_walker.rb +70 -35
- data/lib/rbs/parser.rb +306 -301
- data/lib/rbs/parser.y +15 -8
- data/lib/rbs/prototype/rb.rb +150 -21
- data/lib/rbs/prototype/runtime.rb +1 -0
- data/lib/rbs/repository.rb +121 -0
- data/lib/rbs/test/hook.rb +25 -15
- data/lib/rbs/test/setup.rb +5 -3
- data/lib/rbs/test/type_check.rb +6 -1
- data/lib/rbs/type_name.rb +2 -1
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/sig/cli.rbs +58 -0
- data/sig/definition.rbs +8 -3
- data/sig/definition_builder.rbs +4 -1
- data/sig/environment_loader.rbs +92 -46
- data/sig/polyfill.rbs +42 -0
- data/sig/rbs.rbs +8 -0
- data/sig/repository.rbs +79 -0
- data/sig/vendorer.rbs +44 -0
- data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
- data/stdlib/base64/{base64.rbs → 0/base64.rbs} +0 -0
- data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +0 -0
- 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} +0 -0
- data/stdlib/csv/{csv.rbs → 0/csv.rbs} +3 -3
- data/stdlib/date/{date.rbs → 0/date.rbs} +0 -0
- data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +0 -0
- 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} +0 -0
- 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} +0 -0
- data/stdlib/logger/{logger.rbs → 0/logger.rbs} +0 -0
- data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
- data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
- data/stdlib/monitor/0/monitor.rbs +119 -0
- data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
- data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +0 -0
- 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/{pstore.rbs → 0/pstore.rbs} +0 -0
- data/stdlib/pty/{pty.rbs → 0/pty.rbs} +0 -0
- data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
- data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
- data/stdlib/singleton/0/singleton.rbs +111 -0
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +0 -0
- 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} +0 -0
- 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/yaml/0/dbm.rbs +221 -0
- data/stdlib/yaml/0/store.rbs +53 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +9 -9
- metadata +108 -94
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
|
@@ -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
|
@@ -838,7 +856,10 @@ module RBS
|
|
838
856
|
entry = env.class_decls[type_name]
|
839
857
|
|
840
858
|
self_type = Types::ClassSingleton.new(name: type_name, location: nil)
|
841
|
-
ancestors =
|
859
|
+
ancestors = Definition::SingletonAncestors.new(
|
860
|
+
type_name: type_name,
|
861
|
+
ancestors: [Definition::Ancestor::Singleton.new(name: type_name)]
|
862
|
+
)
|
842
863
|
|
843
864
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
844
865
|
method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array|
|
@@ -855,7 +876,8 @@ module RBS
|
|
855
876
|
defs: method_def&.yield_self do |method_def|
|
856
877
|
method_def.defs.map {|defn| defn.update(implemented_in: type_name) }
|
857
878
|
end || [],
|
858
|
-
accessibility: visibility
|
879
|
+
accessibility: visibility,
|
880
|
+
alias_of: nil
|
859
881
|
)
|
860
882
|
definition.methods[method_name] = members.inject(m) do |original, new|
|
861
883
|
defs = new.types.map do |type|
|
@@ -869,7 +891,8 @@ module RBS
|
|
869
891
|
Definition::Method.new(
|
870
892
|
super_method: nil,
|
871
893
|
defs: defs + original.defs,
|
872
|
-
accessibility: original.accessibility
|
894
|
+
accessibility: original.accessibility,
|
895
|
+
alias_of: nil
|
873
896
|
)
|
874
897
|
end
|
875
898
|
end
|
@@ -893,7 +916,14 @@ module RBS
|
|
893
916
|
location: member.location
|
894
917
|
)
|
895
918
|
|
896
|
-
|
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
|
+
)
|
897
927
|
end
|
898
928
|
end
|
899
929
|
end
|
@@ -945,7 +975,8 @@ module RBS
|
|
945
975
|
)
|
946
976
|
end,
|
947
977
|
accessibility: :public,
|
948
|
-
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
|
949
980
|
)
|
950
981
|
end
|
951
982
|
end
|
@@ -1029,7 +1060,8 @@ module RBS
|
|
1029
1060
|
methods[name] = Definition::Method.new(
|
1030
1061
|
super_method: super_method,
|
1031
1062
|
accessibility: method.accessibility,
|
1032
|
-
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
|
1033
1065
|
)
|
1034
1066
|
end
|
1035
1067
|
|
@@ -1123,7 +1155,8 @@ module RBS
|
|
1123
1155
|
implemented_in: nil
|
1124
1156
|
)
|
1125
1157
|
end,
|
1126
|
-
accessibility: :public
|
1158
|
+
accessibility: :public,
|
1159
|
+
alias_of: nil
|
1127
1160
|
)
|
1128
1161
|
definition.methods[member.name] = method
|
1129
1162
|
end
|
@@ -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(encoding: "UTF-8"))
|
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
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module RBS
|
2
2
|
class EnvironmentWalker
|
3
|
+
InstanceNode = Struct.new(:type_name, keyword_init: true)
|
4
|
+
SingletonNode = Struct.new(:type_name, keyword_init: true)
|
5
|
+
TypeNameNode = Struct.new(:type_name, keyword_init: true)
|
6
|
+
|
3
7
|
attr_reader :env
|
4
8
|
|
5
9
|
def initialize(env:)
|
@@ -23,54 +27,80 @@ module RBS
|
|
23
27
|
include TSort
|
24
28
|
|
25
29
|
def tsort_each_node(&block)
|
26
|
-
env.class_decls.each_key
|
27
|
-
|
28
|
-
|
30
|
+
env.class_decls.each_key do |type_name|
|
31
|
+
yield InstanceNode.new(type_name: type_name)
|
32
|
+
yield SingletonNode.new(type_name: type_name)
|
33
|
+
end
|
34
|
+
env.interface_decls.each_key do |type_name|
|
35
|
+
yield TypeNameNode.new(type_name: type_name)
|
36
|
+
end
|
37
|
+
env.alias_decls.each_key do |type_name|
|
38
|
+
yield TypeNameNode.new(type_name: type_name)
|
39
|
+
end
|
29
40
|
end
|
30
41
|
|
31
|
-
def tsort_each_child(
|
42
|
+
def tsort_each_child(node, &block)
|
43
|
+
name = node.type_name
|
44
|
+
|
32
45
|
unless name.namespace.empty?
|
33
|
-
yield name.namespace.to_type_name
|
46
|
+
yield SingletonNode.new(type_name: name.namespace.to_type_name)
|
34
47
|
end
|
35
48
|
|
36
|
-
case
|
37
|
-
when
|
38
|
-
definitions = []
|
39
|
-
|
49
|
+
case node
|
50
|
+
when TypeNameNode
|
40
51
|
case
|
41
|
-
when name.class?
|
42
|
-
definitions << builder.build_instance(name)
|
43
|
-
definitions << builder.build_singleton(name)
|
44
52
|
when name.interface?
|
45
|
-
|
53
|
+
definition = builder.build_interface(name)
|
54
|
+
unless only_ancestors?
|
55
|
+
definition.each_type do |type|
|
56
|
+
each_type_node type, &block
|
57
|
+
end
|
58
|
+
end
|
59
|
+
when name.alias?
|
60
|
+
each_type_node builder.expand_alias(name), &block
|
61
|
+
else
|
62
|
+
raise "Unexpected TypeNameNode with type_name=#{name}"
|
46
63
|
end
|
47
64
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
65
|
+
when InstanceNode, SingletonNode
|
66
|
+
definition = if node.is_a?(InstanceNode)
|
67
|
+
builder.build_instance(name)
|
68
|
+
else
|
69
|
+
builder.build_singleton(name)
|
70
|
+
end
|
52
71
|
|
53
|
-
|
54
|
-
|
72
|
+
if ancestors = definition.ancestors
|
73
|
+
ancestors.ancestors.each do |ancestor|
|
74
|
+
case ancestor
|
75
|
+
when Definition::Ancestor::Instance
|
76
|
+
yield InstanceNode.new(type_name: ancestor.name)
|
77
|
+
|
78
|
+
unless only_ancestors?
|
55
79
|
ancestor.args.each do |type|
|
56
|
-
|
80
|
+
each_type_node type, &block
|
57
81
|
end
|
58
82
|
end
|
83
|
+
when Definition::Ancestor::Singleton
|
84
|
+
yield SingletonNode.new(type_name: ancestor.name)
|
59
85
|
end
|
60
86
|
end
|
87
|
+
end
|
61
88
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
89
|
+
unless only_ancestors?
|
90
|
+
definition.each_type do |type|
|
91
|
+
each_type_node type, &block
|
66
92
|
end
|
67
93
|
end
|
68
|
-
when name.alias?
|
69
|
-
each_type_name builder.expand_alias(name), &block
|
70
94
|
end
|
71
95
|
end
|
72
96
|
|
73
97
|
def each_type_name(type, &block)
|
98
|
+
each_type_node(type) do |node|
|
99
|
+
yield node.type_name
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def each_type_node(type, &block)
|
74
104
|
case type
|
75
105
|
when RBS::Types::Bases::Any
|
76
106
|
when RBS::Types::Bases::Class
|
@@ -83,29 +113,34 @@ module RBS
|
|
83
113
|
when RBS::Types::Bases::Nil
|
84
114
|
when RBS::Types::Variable
|
85
115
|
when RBS::Types::ClassSingleton
|
86
|
-
yield type.name
|
87
|
-
when RBS::Types::ClassInstance
|
88
|
-
yield type.name
|
116
|
+
yield SingletonNode.new(type_name: type.name)
|
117
|
+
when RBS::Types::ClassInstance
|
118
|
+
yield InstanceNode.new(type_name: type.name)
|
119
|
+
type.args.each do |ty|
|
120
|
+
each_type_node(ty, &block)
|
121
|
+
end
|
122
|
+
when RBS::Types::Interface
|
123
|
+
yield TypeNameNode.new(type_name: type.name)
|
89
124
|
type.args.each do |ty|
|
90
|
-
|
125
|
+
each_type_node(ty, &block)
|
91
126
|
end
|
92
127
|
when RBS::Types::Alias
|
93
|
-
yield type.name
|
128
|
+
yield TypeNameNode.new(type_name: type.name)
|
94
129
|
when RBS::Types::Union, RBS::Types::Intersection, RBS::Types::Tuple
|
95
130
|
type.types.each do |ty|
|
96
|
-
|
131
|
+
each_type_node ty, &block
|
97
132
|
end
|
98
133
|
when RBS::Types::Optional
|
99
|
-
|
134
|
+
each_type_node type.type, &block
|
100
135
|
when RBS::Types::Literal
|
101
136
|
# nop
|
102
137
|
when RBS::Types::Record
|
103
138
|
type.fields.each_value do |ty|
|
104
|
-
|
139
|
+
each_type_node ty, &block
|
105
140
|
end
|
106
141
|
when RBS::Types::Proc
|
107
142
|
type.each_type do |ty|
|
108
|
-
|
143
|
+
each_type_node ty, &block
|
109
144
|
end
|
110
145
|
else
|
111
146
|
raise "Unexpected type given: #{type}"
|