tapioca 0.16.11 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ruby_lsp/tapioca/addon.rb +23 -19
- data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +20 -20
- data/lib/tapioca/bundler_ext/auto_require_hook.rb +5 -10
- data/lib/tapioca/commands/abstract_dsl.rb +26 -59
- data/lib/tapioca/commands/abstract_gem.rb +23 -43
- data/lib/tapioca/commands/annotations.rb +27 -33
- data/lib/tapioca/commands/check_shims.rb +4 -13
- data/lib/tapioca/commands/command.rb +8 -20
- data/lib/tapioca/commands/command_without_tracker.rb +1 -1
- data/lib/tapioca/commands/configure.rb +11 -16
- data/lib/tapioca/commands/dsl_compiler_list.rb +2 -1
- data/lib/tapioca/commands/dsl_generate.rb +2 -1
- data/lib/tapioca/commands/dsl_verify.rb +2 -1
- data/lib/tapioca/commands/gem_generate.rb +4 -8
- data/lib/tapioca/commands/gem_sync.rb +2 -1
- data/lib/tapioca/commands/gem_verify.rb +3 -2
- data/lib/tapioca/commands/require.rb +3 -7
- data/lib/tapioca/commands/todo.rb +6 -10
- data/lib/tapioca/dsl/compiler.rb +28 -53
- data/lib/tapioca/dsl/compilers/aasm.rb +31 -41
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +7 -5
- data/lib/tapioca/dsl/compilers/action_mailer.rb +5 -3
- data/lib/tapioca/dsl/compilers/action_text.rb +5 -3
- data/lib/tapioca/dsl/compilers/active_job.rb +5 -8
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +9 -7
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +4 -2
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +4 -2
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +16 -42
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +19 -24
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +7 -5
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +6 -4
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +53 -61
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +86 -119
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +7 -11
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +4 -2
- data/lib/tapioca/dsl/compilers/active_record_store.rb +4 -2
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +18 -26
- data/lib/tapioca/dsl/compilers/active_resource.rb +18 -19
- data/lib/tapioca/dsl/compilers/active_storage.rb +5 -5
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +8 -6
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +7 -5
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +4 -2
- data/lib/tapioca/dsl/compilers/config.rb +4 -2
- data/lib/tapioca/dsl/compilers/frozen_record.rb +6 -9
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +8 -8
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +5 -8
- data/lib/tapioca/dsl/compilers/identity_cache.rb +10 -37
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +8 -16
- data/lib/tapioca/dsl/compilers/kredis.rb +6 -4
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +4 -2
- data/lib/tapioca/dsl/compilers/protobuf.rb +12 -24
- data/lib/tapioca/dsl/compilers/rails_generators.rb +8 -9
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +22 -11
- data/lib/tapioca/dsl/compilers/smart_properties.rb +11 -20
- data/lib/tapioca/dsl/compilers/state_machines.rb +14 -24
- data/lib/tapioca/dsl/compilers/url_helpers.rb +9 -7
- data/lib/tapioca/dsl/compilers.rb +4 -7
- data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +13 -16
- data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +13 -28
- data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +19 -15
- data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +5 -24
- data/lib/tapioca/dsl/pipeline.rb +23 -55
- data/lib/tapioca/executor.rb +6 -12
- data/lib/tapioca/gem/events.rb +22 -28
- data/lib/tapioca/gem/listeners/base.rb +6 -6
- data/lib/tapioca/gem/listeners/dynamic_mixins.rb +4 -2
- data/lib/tapioca/gem/listeners/foreign_constants.rb +5 -7
- data/lib/tapioca/gem/listeners/methods.rb +15 -34
- data/lib/tapioca/gem/listeners/mixins.rb +6 -18
- data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +4 -2
- data/lib/tapioca/gem/listeners/sorbet_enums.rb +4 -2
- data/lib/tapioca/gem/listeners/sorbet_helpers.rb +4 -2
- data/lib/tapioca/gem/listeners/sorbet_props.rb +4 -2
- data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +4 -2
- data/lib/tapioca/gem/listeners/sorbet_signatures.rb +7 -5
- data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +6 -4
- data/lib/tapioca/gem/listeners/source_location.rb +7 -4
- data/lib/tapioca/gem/listeners/subconstants.rb +4 -2
- data/lib/tapioca/gem/listeners/yard_doc.rb +23 -22
- data/lib/tapioca/gem/pipeline.rb +57 -72
- data/lib/tapioca/gem_info.rb +1 -1
- data/lib/tapioca/gemfile.rb +64 -73
- data/lib/tapioca/helpers/cli_helper.rb +3 -3
- data/lib/tapioca/helpers/config_helper.rb +15 -24
- data/lib/tapioca/helpers/env_helper.rb +1 -1
- data/lib/tapioca/helpers/gem_helper.rb +5 -5
- data/lib/tapioca/helpers/git_attributes.rb +3 -3
- data/lib/tapioca/helpers/rbi_files_helper.rb +73 -67
- data/lib/tapioca/helpers/rbi_helper.rb +14 -22
- data/lib/tapioca/helpers/sorbet_helper.rb +9 -18
- data/lib/tapioca/helpers/source_uri.rb +15 -25
- data/lib/tapioca/helpers/test/content.rb +6 -6
- data/lib/tapioca/helpers/test/dsl_compiler.rb +19 -29
- data/lib/tapioca/helpers/test/isolation.rb +4 -4
- data/lib/tapioca/helpers/test/template.rb +5 -7
- data/lib/tapioca/internal.rb +5 -1
- data/lib/tapioca/loaders/dsl.rb +11 -19
- data/lib/tapioca/loaders/gem.rb +6 -21
- data/lib/tapioca/loaders/loader.rb +15 -27
- data/lib/tapioca/rbi_ext/model.rb +12 -37
- data/lib/tapioca/rbi_formatter.rb +10 -19
- data/lib/tapioca/rbs/rewriter.rb +55 -0
- data/lib/tapioca/repo_index.rb +7 -7
- data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
- data/lib/tapioca/runtime/attached_class_of_legacy.rb +1 -1
- data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +23 -23
- data/lib/tapioca/runtime/generic_type_registry.rb +13 -23
- data/lib/tapioca/runtime/reflection.rb +48 -56
- data/lib/tapioca/runtime/trackers/autoload.rb +4 -8
- data/lib/tapioca/runtime/trackers/mixin.rb +6 -10
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
- data/lib/tapioca/runtime/trackers/tracker.rb +2 -2
- data/lib/tapioca/runtime/trackers.rb +4 -8
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
- data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
- data/lib/tapioca/sorbet_ext/proc_bind_patch.rb +1 -1
- data/lib/tapioca/static/requires_compiler.rb +6 -6
- data/lib/tapioca/static/symbol_loader.rb +14 -16
- data/lib/tapioca/static/symbol_table_parser.rb +8 -8
- data/lib/tapioca/version.rb +1 -1
- data/lib/tapioca.rb +22 -29
- metadata +25 -10
@@ -10,7 +10,8 @@ module Tapioca
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
|
13
|
+
# @override
|
14
|
+
#: (ScopeNodeAdded event) -> void
|
14
15
|
def on_scope(event)
|
15
16
|
constant = event.constant
|
16
17
|
node = event.node
|
@@ -29,7 +30,8 @@ module Tapioca
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
+
# @override
|
34
|
+
#: (NodeAdded event) -> bool
|
33
35
|
def ignore?(event)
|
34
36
|
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
|
35
37
|
end
|
@@ -9,7 +9,8 @@ module Tapioca
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
|
12
|
+
# @override
|
13
|
+
#: (ScopeNodeAdded event) -> void
|
13
14
|
def on_scope(event)
|
14
15
|
ancestors = Runtime::Trackers::RequiredAncestor.required_ancestors_by(event.constant)
|
15
16
|
ancestors.each do |ancestor|
|
@@ -19,7 +20,8 @@ module Tapioca
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
+
# @override
|
24
|
+
#: (NodeAdded event) -> bool
|
23
25
|
def ignore?(event)
|
24
26
|
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
|
25
27
|
end
|
@@ -14,7 +14,8 @@ module Tapioca
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
|
17
|
+
# @override
|
18
|
+
#: (MethodNodeAdded event) -> void
|
18
19
|
def on_method(event)
|
19
20
|
signature = event.signature
|
20
21
|
return unless signature
|
@@ -22,9 +23,9 @@ module Tapioca
|
|
22
23
|
event.node.sigs << compile_signature(signature, event.parameters)
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
+
#: (untyped signature, Array[[Symbol, String]] parameters) -> RBI::Sig
|
26
27
|
def compile_signature(signature, parameters)
|
27
|
-
parameter_types =
|
28
|
+
parameter_types = signature.arg_types.to_h #: Hash[Symbol, T::Types::Base]
|
28
29
|
parameter_types.merge!(signature.kwarg_types)
|
29
30
|
parameter_types[signature.rest_name] = signature.rest_type if signature.has_rest
|
30
31
|
parameter_types[signature.keyrest_name] = signature.keyrest_type if signature.has_keyrest
|
@@ -64,7 +65,7 @@ module Tapioca
|
|
64
65
|
sig
|
65
66
|
end
|
66
67
|
|
67
|
-
|
68
|
+
#: (untyped signature) -> bool
|
68
69
|
def signature_final?(signature)
|
69
70
|
modules_with_final = T::Private::Methods.instance_variable_get(:@modules_with_final)
|
70
71
|
# In https://github.com/sorbet/sorbet/pull/7531, Sorbet changed internal hashes to be compared by identity,
|
@@ -75,7 +76,8 @@ module Tapioca
|
|
75
76
|
final_methods.include?(signature.method_name)
|
76
77
|
end
|
77
78
|
|
78
|
-
|
79
|
+
# @override
|
80
|
+
#: (NodeAdded event) -> bool
|
79
81
|
def ignore?(event)
|
80
82
|
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
|
81
83
|
end
|
@@ -11,7 +11,8 @@ module Tapioca
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
|
14
|
+
# @override
|
15
|
+
#: (ScopeNodeAdded event) -> void
|
15
16
|
def on_scope(event)
|
16
17
|
constant = event.constant
|
17
18
|
node = event.node
|
@@ -23,7 +24,7 @@ module Tapioca
|
|
23
24
|
node << sclass if sclass.nodes.length > 1
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
+
#: (RBI::Tree tree, Module constant) -> void
|
27
28
|
def compile_type_variable_declarations(tree, constant)
|
28
29
|
# Try to find the type variables defined on this constant, bail if we can't
|
29
30
|
type_variables = Runtime::GenericTypeRegistry.lookup_type_variables(constant)
|
@@ -46,7 +47,7 @@ module Tapioca
|
|
46
47
|
tree << RBI::Extend.new("T::Generic")
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
+
#: (Tapioca::TypeVariableModule type_variable) -> RBI::Node?
|
50
51
|
def node_from_type_variable(type_variable)
|
51
52
|
case type_variable.type
|
52
53
|
when Tapioca::TypeVariableModule::Type::HasAttachedClass
|
@@ -59,7 +60,8 @@ module Tapioca
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
+
# @override
|
64
|
+
#: (NodeAdded event) -> bool
|
63
65
|
def ignore?(event)
|
64
66
|
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
|
65
67
|
end
|
@@ -9,13 +9,15 @@ module Tapioca
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
|
12
|
+
# @override
|
13
|
+
#: (ConstNodeAdded event) -> void
|
13
14
|
def on_const(event)
|
14
15
|
file, line = Object.const_source_location(event.symbol)
|
15
16
|
add_source_location_comment(event.node, file, line)
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
+
# @override
|
20
|
+
#: (ScopeNodeAdded event) -> void
|
19
21
|
def on_scope(event)
|
20
22
|
# Instead of using `const_source_location`, which always reports the first place where a constant is defined,
|
21
23
|
# we filter the locations tracked by ConstantDefinition. This allows us to provide the correct location for
|
@@ -31,13 +33,14 @@ module Tapioca
|
|
31
33
|
add_source_location_comment(event.node, location.path, location.lineno) unless location.nil?
|
32
34
|
end
|
33
35
|
|
34
|
-
|
36
|
+
# @override
|
37
|
+
#: (MethodNodeAdded event) -> void
|
35
38
|
def on_method(event)
|
36
39
|
file, line = event.method.source_location
|
37
40
|
add_source_location_comment(event.node, file, line)
|
38
41
|
end
|
39
42
|
|
40
|
-
|
43
|
+
#: (RBI::NodeWithComments node, String? file, Integer? line) -> void
|
41
44
|
def add_source_location_comment(node, file, line)
|
42
45
|
return unless file && line
|
43
46
|
|
@@ -11,7 +11,8 @@ module Tapioca
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
|
14
|
+
# @override
|
15
|
+
#: (ScopeNodeAdded event) -> void
|
15
16
|
def on_scope(event)
|
16
17
|
symbol = event.symbol
|
17
18
|
constant = event.constant
|
@@ -31,7 +32,8 @@ module Tapioca
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
# @override
|
36
|
+
#: (NodeAdded event) -> bool
|
35
37
|
def ignore?(event)
|
36
38
|
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
|
37
39
|
end
|
@@ -7,23 +7,20 @@ module Tapioca
|
|
7
7
|
class YardDoc < Base
|
8
8
|
extend T::Sig
|
9
9
|
|
10
|
-
IGNORED_COMMENTS =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
IGNORED_SIG_TAGS = T.let(["param", "return"], T::Array[String])
|
25
|
-
|
26
|
-
sig { params(pipeline: Pipeline).void }
|
10
|
+
IGNORED_COMMENTS = [
|
11
|
+
":doc:",
|
12
|
+
":nodoc:",
|
13
|
+
"typed:",
|
14
|
+
"frozen_string_literal:",
|
15
|
+
"encoding:",
|
16
|
+
"warn_indent:",
|
17
|
+
"shareable_constant_value:",
|
18
|
+
"rubocop:",
|
19
|
+
] #: Array[String]
|
20
|
+
|
21
|
+
IGNORED_SIG_TAGS = ["param", "return"] #: Array[String]
|
22
|
+
|
23
|
+
#: (Pipeline pipeline) -> void
|
27
24
|
def initialize(pipeline)
|
28
25
|
YARD::Registry.clear
|
29
26
|
super(pipeline)
|
@@ -32,17 +29,20 @@ module Tapioca
|
|
32
29
|
|
33
30
|
private
|
34
31
|
|
35
|
-
|
32
|
+
# @override
|
33
|
+
#: (ConstNodeAdded event) -> void
|
36
34
|
def on_const(event)
|
37
35
|
event.node.comments = documentation_comments(event.symbol)
|
38
36
|
end
|
39
37
|
|
40
|
-
|
38
|
+
# @override
|
39
|
+
#: (ScopeNodeAdded event) -> void
|
41
40
|
def on_scope(event)
|
42
41
|
event.node.comments = documentation_comments(event.symbol)
|
43
42
|
end
|
44
43
|
|
45
|
-
|
44
|
+
# @override
|
45
|
+
#: (MethodNodeAdded event) -> void
|
46
46
|
def on_method(event)
|
47
47
|
separator = event.constant.singleton_class? ? "." : "#"
|
48
48
|
event.node.comments = documentation_comments(
|
@@ -51,7 +51,7 @@ module Tapioca
|
|
51
51
|
)
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
#: (String name, ?sigs: Array[RBI::Sig]) -> Array[RBI::Comment]
|
55
55
|
def documentation_comments(name, sigs: [])
|
56
56
|
yard_docs = YARD::Registry.at(name)
|
57
57
|
return [] unless yard_docs
|
@@ -95,7 +95,8 @@ module Tapioca
|
|
95
95
|
comments
|
96
96
|
end
|
97
97
|
|
98
|
-
|
98
|
+
# @override
|
99
|
+
#: (NodeAdded event) -> bool
|
99
100
|
def ignore?(event)
|
100
101
|
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
|
101
102
|
end
|
data/lib/tapioca/gem/pipeline.rb
CHANGED
@@ -8,42 +8,35 @@ module Tapioca
|
|
8
8
|
include Runtime::Reflection
|
9
9
|
include RBIHelper
|
10
10
|
|
11
|
-
IGNORED_SYMBOLS =
|
11
|
+
IGNORED_SYMBOLS = ["YAML", "MiniTest", "Mutex"] #: Array[String]
|
12
12
|
|
13
|
-
|
13
|
+
#: Gemfile::GemSpec
|
14
14
|
attr_reader :gem
|
15
15
|
|
16
|
-
|
16
|
+
#: ^(String error) -> void
|
17
17
|
attr_reader :error_handler
|
18
18
|
|
19
|
-
|
20
|
-
params(
|
21
|
-
gem: Gemfile::GemSpec,
|
22
|
-
error_handler: T.proc.params(error: String).void,
|
23
|
-
include_doc: T::Boolean,
|
24
|
-
include_loc: T::Boolean,
|
25
|
-
).void
|
26
|
-
end
|
19
|
+
#: (Gemfile::GemSpec gem, error_handler: ^(String error) -> void, ?include_doc: bool, ?include_loc: bool) -> void
|
27
20
|
def initialize(
|
28
21
|
gem,
|
29
22
|
error_handler:,
|
30
23
|
include_doc: false,
|
31
24
|
include_loc: false
|
32
25
|
)
|
33
|
-
@root =
|
26
|
+
@root = RBI::Tree.new #: RBI::Tree
|
34
27
|
@gem = gem
|
35
|
-
@seen =
|
36
|
-
@alias_namespace =
|
28
|
+
@seen = Set.new #: Set[String]
|
29
|
+
@alias_namespace = Set.new #: Set[String]
|
37
30
|
@error_handler = error_handler
|
38
31
|
|
39
|
-
@events =
|
32
|
+
@events = [] #: Array[Gem::Event]
|
40
33
|
|
41
|
-
@payload_symbols =
|
42
|
-
@bootstrap_symbols =
|
34
|
+
@payload_symbols = Static::SymbolLoader.payload_symbols #: Set[String]
|
35
|
+
@bootstrap_symbols = load_bootstrap_symbols(@gem) #: Set[String]
|
43
36
|
|
44
37
|
@bootstrap_symbols.each { |symbol| push_symbol(symbol) }
|
45
38
|
|
46
|
-
@node_listeners =
|
39
|
+
@node_listeners = [] #: Array[Gem::Listeners::Base]
|
47
40
|
@node_listeners << Gem::Listeners::SorbetTypeVariables.new(self)
|
48
41
|
@node_listeners << Gem::Listeners::Mixins.new(self)
|
49
42
|
@node_listeners << Gem::Listeners::DynamicMixins.new(self)
|
@@ -60,7 +53,7 @@ module Tapioca
|
|
60
53
|
@node_listeners << Gem::Listeners::RemoveEmptyPayloadScopes.new(self)
|
61
54
|
end
|
62
55
|
|
63
|
-
|
56
|
+
#: -> RBI::Tree
|
64
57
|
def compile
|
65
58
|
dispatch(next_event) until @events.empty?
|
66
59
|
@root
|
@@ -68,57 +61,45 @@ module Tapioca
|
|
68
61
|
|
69
62
|
# Events handling
|
70
63
|
|
71
|
-
|
64
|
+
#: (String symbol) -> void
|
72
65
|
def push_symbol(symbol)
|
73
66
|
@events << Gem::SymbolFound.new(symbol)
|
74
67
|
end
|
75
68
|
|
76
|
-
|
69
|
+
# @without_runtime
|
70
|
+
#: (String symbol, BasicObject constant) -> void
|
77
71
|
def push_constant(symbol, constant)
|
78
72
|
@events << Gem::ConstantFound.new(symbol, constant)
|
79
73
|
end
|
80
74
|
|
81
|
-
|
75
|
+
#: (String symbol, Module constant) -> void
|
82
76
|
def push_foreign_constant(symbol, constant)
|
83
77
|
@events << Gem::ForeignConstantFound.new(symbol, constant)
|
84
78
|
end
|
85
79
|
|
86
|
-
|
80
|
+
#: (String symbol, Module constant, RBI::Const node) -> void
|
87
81
|
def push_const(symbol, constant, node)
|
88
82
|
@events << Gem::ConstNodeAdded.new(symbol, constant, node)
|
89
83
|
end
|
90
84
|
|
91
|
-
|
92
|
-
params(symbol: String, constant: Module, node: RBI::Scope).void.checked(:never)
|
93
|
-
end
|
85
|
+
#: (String symbol, Module constant, RBI::Scope node) -> void
|
94
86
|
def push_scope(symbol, constant, node)
|
95
87
|
@events << Gem::ScopeNodeAdded.new(symbol, constant, node)
|
96
88
|
end
|
97
89
|
|
98
|
-
|
99
|
-
params(symbol: String, constant: Module, node: RBI::Scope).void.checked(:never)
|
100
|
-
end
|
90
|
+
#: (String symbol, Module constant, RBI::Scope node) -> void
|
101
91
|
def push_foreign_scope(symbol, constant, node)
|
102
92
|
@events << Gem::ForeignScopeNodeAdded.new(symbol, constant, node)
|
103
93
|
end
|
104
94
|
|
105
|
-
|
106
|
-
params(
|
107
|
-
symbol: String,
|
108
|
-
constant: Module,
|
109
|
-
method: UnboundMethod,
|
110
|
-
node: RBI::Method,
|
111
|
-
signature: T.untyped,
|
112
|
-
parameters: T::Array[[Symbol, String]],
|
113
|
-
).void.checked(:never)
|
114
|
-
end
|
95
|
+
#: (String symbol, Module constant, UnboundMethod method, RBI::Method node, untyped signature, Array[[Symbol, String]] parameters) -> void
|
115
96
|
def push_method(symbol, constant, method, node, signature, parameters) # rubocop:disable Metrics/ParameterLists
|
116
97
|
@events << Gem::MethodNodeAdded.new(symbol, constant, method, node, signature, parameters)
|
117
98
|
end
|
118
99
|
|
119
100
|
# Constants and properties filtering
|
120
101
|
|
121
|
-
|
102
|
+
#: (String symbol_name) -> bool
|
122
103
|
def symbol_in_payload?(symbol_name)
|
123
104
|
symbol_name = symbol_name[2..-1] if symbol_name.start_with?("::")
|
124
105
|
return false unless symbol_name
|
@@ -129,9 +110,9 @@ module Tapioca
|
|
129
110
|
# this looks something like:
|
130
111
|
# "(eval at /path/to/file.rb:123)"
|
131
112
|
# and we are just interested in the "/path/to/file.rb" part
|
132
|
-
EVAL_SOURCE_FILE_PATTERN =
|
113
|
+
EVAL_SOURCE_FILE_PATTERN = /\(eval at (.+):\d+\)/ #: Regexp
|
133
114
|
|
134
|
-
|
115
|
+
#: ((String | Symbol) name) -> bool
|
135
116
|
def constant_in_gem?(name)
|
136
117
|
return true unless Object.respond_to?(:const_source_location)
|
137
118
|
|
@@ -149,7 +130,7 @@ module Tapioca
|
|
149
130
|
gem.contains_path?(source_file)
|
150
131
|
end
|
151
132
|
|
152
|
-
|
133
|
+
#: (UnboundMethod method) -> bool
|
153
134
|
def method_in_gem?(method)
|
154
135
|
source_location = method.source_location&.first
|
155
136
|
return false if source_location.nil?
|
@@ -159,7 +140,7 @@ module Tapioca
|
|
159
140
|
|
160
141
|
# Helpers
|
161
142
|
|
162
|
-
|
143
|
+
#: (Module constant) -> String?
|
163
144
|
def name_of(constant)
|
164
145
|
name = name_of_proxy_target(constant, super(class_of(constant)))
|
165
146
|
return name if name
|
@@ -174,7 +155,7 @@ module Tapioca
|
|
174
155
|
|
175
156
|
private
|
176
157
|
|
177
|
-
|
158
|
+
#: (Gemfile::GemSpec gem) -> Set[String]
|
178
159
|
def load_bootstrap_symbols(gem)
|
179
160
|
engine_symbols = Static::SymbolLoader.engine_symbols(gem)
|
180
161
|
gem_symbols = Static::SymbolLoader.gem_symbols(gem)
|
@@ -184,12 +165,12 @@ module Tapioca
|
|
184
165
|
|
185
166
|
# Events handling
|
186
167
|
|
187
|
-
|
168
|
+
#: -> Gem::Event
|
188
169
|
def next_event
|
189
170
|
T.must(@events.shift)
|
190
171
|
end
|
191
172
|
|
192
|
-
|
173
|
+
#: (Gem::Event event) -> void
|
193
174
|
def dispatch(event)
|
194
175
|
case event
|
195
176
|
when Gem::SymbolFound
|
@@ -203,7 +184,7 @@ module Tapioca
|
|
203
184
|
end
|
204
185
|
end
|
205
186
|
|
206
|
-
|
187
|
+
#: (Gem::SymbolFound event) -> void
|
207
188
|
def on_symbol(event)
|
208
189
|
symbol = event.symbol.delete_prefix("::")
|
209
190
|
return if skip_symbol?(symbol)
|
@@ -212,7 +193,7 @@ module Tapioca
|
|
212
193
|
push_constant(symbol, constant) if Runtime::Reflection.constant_defined?(constant)
|
213
194
|
end
|
214
195
|
|
215
|
-
|
196
|
+
#: (Gem::ConstantFound event) -> void
|
216
197
|
def on_constant(event)
|
217
198
|
name = event.symbol
|
218
199
|
return if skip_constant?(name, event.constant)
|
@@ -224,14 +205,14 @@ module Tapioca
|
|
224
205
|
end
|
225
206
|
end
|
226
207
|
|
227
|
-
|
208
|
+
#: (Gem::NodeAdded event) -> void
|
228
209
|
def on_node(event)
|
229
210
|
@node_listeners.each { |listener| listener.dispatch(event) }
|
230
211
|
end
|
231
212
|
|
232
213
|
# Compiling
|
233
214
|
|
234
|
-
|
215
|
+
#: (String symbol, Module constant) -> void
|
235
216
|
def compile_foreign_constant(symbol, constant)
|
236
217
|
return if skip_foreign_constant?(symbol, constant)
|
237
218
|
return if seen?(symbol)
|
@@ -242,7 +223,8 @@ module Tapioca
|
|
242
223
|
push_foreign_scope(symbol, constant, scope)
|
243
224
|
end
|
244
225
|
|
245
|
-
|
226
|
+
# @without_runtime
|
227
|
+
#: (String symbol, BasicObject constant) -> void
|
246
228
|
def compile_constant(symbol, constant)
|
247
229
|
case constant
|
248
230
|
when Module
|
@@ -256,7 +238,7 @@ module Tapioca
|
|
256
238
|
end
|
257
239
|
end
|
258
240
|
|
259
|
-
|
241
|
+
#: (String name, Module constant) -> void
|
260
242
|
def compile_alias(name, constant)
|
261
243
|
return if seen?(name)
|
262
244
|
|
@@ -277,7 +259,8 @@ module Tapioca
|
|
277
259
|
@root << node
|
278
260
|
end
|
279
261
|
|
280
|
-
|
262
|
+
# @without_runtime
|
263
|
+
#: (String name, BasicObject value) -> void
|
281
264
|
def compile_object(name, value)
|
282
265
|
return if seen?(name)
|
283
266
|
|
@@ -310,7 +293,7 @@ module Tapioca
|
|
310
293
|
@root << node
|
311
294
|
end
|
312
295
|
|
313
|
-
|
296
|
+
#: (String name, Module constant) -> void
|
314
297
|
def compile_module(name, constant)
|
315
298
|
return if skip_module?(name, constant)
|
316
299
|
return if seen?(name)
|
@@ -321,7 +304,7 @@ module Tapioca
|
|
321
304
|
push_scope(name, constant, scope)
|
322
305
|
end
|
323
306
|
|
324
|
-
|
307
|
+
#: (String name, Module constant) -> RBI::Scope
|
325
308
|
def compile_scope(name, constant)
|
326
309
|
scope = if constant.is_a?(Class)
|
327
310
|
superclass = compile_superclass(constant)
|
@@ -335,9 +318,9 @@ module Tapioca
|
|
335
318
|
scope
|
336
319
|
end
|
337
320
|
|
338
|
-
|
321
|
+
#: (Class[top] constant) -> String?
|
339
322
|
def compile_superclass(constant)
|
340
|
-
superclass =
|
323
|
+
superclass = nil #: Class[top]? # rubocop:disable Lint/UselessAssignment
|
341
324
|
|
342
325
|
while (superclass = superclass_of(constant))
|
343
326
|
constant_name = name_of(constant)
|
@@ -386,12 +369,13 @@ module Tapioca
|
|
386
369
|
|
387
370
|
# Constants and properties filtering
|
388
371
|
|
389
|
-
|
372
|
+
#: (String name) -> bool
|
390
373
|
def skip_symbol?(name)
|
391
374
|
symbol_in_payload?(name) && !@bootstrap_symbols.include?(name)
|
392
375
|
end
|
393
376
|
|
394
|
-
|
377
|
+
# @without_runtime
|
378
|
+
#: (String name, top constant) -> bool
|
395
379
|
def skip_constant?(name, constant)
|
396
380
|
return true if name.strip.empty?
|
397
381
|
return true if name.start_with?("#<")
|
@@ -403,7 +387,7 @@ module Tapioca
|
|
403
387
|
false
|
404
388
|
end
|
405
389
|
|
406
|
-
|
390
|
+
#: (String name, Module constant) -> bool
|
407
391
|
def skip_alias?(name, constant)
|
408
392
|
return true if symbol_in_payload?(name)
|
409
393
|
return true unless constant_in_gem?(name)
|
@@ -412,7 +396,8 @@ module Tapioca
|
|
412
396
|
false
|
413
397
|
end
|
414
398
|
|
415
|
-
|
399
|
+
# @without_runtime
|
400
|
+
#: (String name, BasicObject constant) -> bool
|
416
401
|
def skip_object?(name, constant)
|
417
402
|
return true if symbol_in_payload?(name)
|
418
403
|
return true unless constant_in_gem?(name)
|
@@ -420,12 +405,12 @@ module Tapioca
|
|
420
405
|
false
|
421
406
|
end
|
422
407
|
|
423
|
-
|
408
|
+
#: (String name, Module constant) -> bool
|
424
409
|
def skip_foreign_constant?(name, constant)
|
425
410
|
Tapioca::TypeVariableModule === constant
|
426
411
|
end
|
427
412
|
|
428
|
-
|
413
|
+
#: (String name, Module constant) -> bool
|
429
414
|
def skip_module?(name, constant)
|
430
415
|
return true unless defined_in_gem?(constant, strict: false)
|
431
416
|
return true if Tapioca::TypeVariableModule === constant
|
@@ -433,7 +418,7 @@ module Tapioca
|
|
433
418
|
false
|
434
419
|
end
|
435
420
|
|
436
|
-
|
421
|
+
#: (Module constant, ?strict: bool) -> bool
|
437
422
|
def defined_in_gem?(constant, strict: true)
|
438
423
|
files = get_file_candidates(constant)
|
439
424
|
.merge(Runtime::Trackers::ConstantDefinition.files_for(constant))
|
@@ -445,38 +430,38 @@ module Tapioca
|
|
445
430
|
end
|
446
431
|
end
|
447
432
|
|
448
|
-
|
433
|
+
#: (Module constant) -> Set[String]
|
449
434
|
def get_file_candidates(constant)
|
450
435
|
file_candidates_for(constant)
|
451
436
|
rescue ArgumentError, NameError
|
452
437
|
Set.new
|
453
438
|
end
|
454
439
|
|
455
|
-
|
440
|
+
#: (String name) -> void
|
456
441
|
def add_to_alias_namespace(name)
|
457
442
|
@alias_namespace.add("#{name}::")
|
458
443
|
end
|
459
444
|
|
460
|
-
|
445
|
+
#: (String name) -> bool
|
461
446
|
def alias_namespaced?(name)
|
462
447
|
@alias_namespace.any? do |namespace|
|
463
448
|
name.start_with?(namespace)
|
464
449
|
end
|
465
450
|
end
|
466
451
|
|
467
|
-
|
452
|
+
#: (String name) -> void
|
468
453
|
def seen!(name)
|
469
454
|
@seen.add(name)
|
470
455
|
end
|
471
456
|
|
472
|
-
|
457
|
+
#: (String name) -> bool
|
473
458
|
def seen?(name)
|
474
459
|
@seen.include?(name)
|
475
460
|
end
|
476
461
|
|
477
462
|
# Helpers
|
478
463
|
|
479
|
-
|
464
|
+
#: ((Module & T::Generic) constant) -> String
|
480
465
|
def generic_name_of(constant)
|
481
466
|
type_name = T.must(constant.name)
|
482
467
|
return type_name if type_name =~ /\[.*\]$/
|
@@ -492,7 +477,7 @@ module Tapioca
|
|
492
477
|
"#{type_name}[#{type_variable_names}]"
|
493
478
|
end
|
494
479
|
|
495
|
-
|
480
|
+
#: (Module constant, String? class_name) -> String?
|
496
481
|
def name_of_proxy_target(constant, class_name)
|
497
482
|
return unless class_name == "ActiveSupport::Deprecation::DeprecatedConstantProxy"
|
498
483
|
|
data/lib/tapioca/gem_info.rb
CHANGED