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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +0 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -0
- data/Rakefile +66 -0
- data/core/array.rbs +1 -1
- data/core/builtin.rbs +1 -1
- data/core/hash.rbs +1 -1
- data/core/module.rbs +1 -1
- data/ext/rbs_extension/constants.c +18 -2
- data/ext/rbs_extension/constants.h +9 -1
- data/ext/rbs_extension/lexer.c +834 -777
- data/ext/rbs_extension/lexer.h +3 -1
- data/ext/rbs_extension/lexer.re +3 -1
- data/ext/rbs_extension/lexstate.c +4 -2
- data/ext/rbs_extension/parser.c +287 -57
- data/ext/rbs_extension/ruby_objs.c +71 -5
- data/ext/rbs_extension/ruby_objs.h +9 -2
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/ast/declarations.rb +49 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/ast/members.rb +49 -15
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/config/lockfile.rb +115 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
- data/lib/rbs/collection/config.rb +12 -40
- data/lib/rbs/collection/installer.rb +9 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +135 -62
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +10 -13
- data/lib/rbs/collection/sources.rb +7 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder/method_builder.rb +3 -3
- data/lib/rbs/definition_builder.rb +456 -579
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +356 -85
- data/lib/rbs/environment_loader.rb +20 -17
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +34 -37
- data/lib/rbs/locator.rb +3 -3
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/prototype/helpers.rb +29 -13
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +3 -2
- data/lib/rbs/prototype/rbi.rb +6 -4
- data/lib/rbs/prototype/runtime.rb +25 -12
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +3 -3
- data/lib/rbs/substitution.rb +19 -0
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/type_alias_dependency.rb +1 -1
- data/lib/rbs/type_alias_regularity.rb +3 -3
- data/lib/rbs/types.rb +1 -5
- data/lib/rbs/validator.rb +25 -3
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -19
- data/lib/rbs.rb +3 -2
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/schema/members.json +15 -10
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile.rbs +80 -0
- data/sig/collection/config/lockfile_generator.rbs +53 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +76 -33
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +94 -82
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -28
- data/sig/environment_loader.rbs +2 -2
- data/sig/errors.rbs +42 -0
- data/sig/members.rbs +31 -7
- data/sig/parser.rbs +8 -15
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/bundler.rbs +31 -0
- data/sig/shims/rubygems.rbs +15 -0
- data/sig/shims.rbs +0 -22
- data/sig/substitution.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +6 -2
- metadata +16 -9
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- 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
|