tapioca 0.16.9 → 0.17.7
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/README.md +21 -0
- data/exe/tapioca +6 -1
- data/lib/ruby_lsp/tapioca/addon.rb +73 -43
- data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +43 -43
- data/lib/ruby_lsp/tapioca/server_addon.rb +13 -10
- data/lib/tapioca/bundler_ext/auto_require_hook.rb +6 -14
- data/lib/tapioca/cli.rb +16 -8
- data/lib/tapioca/commands/abstract_dsl.rb +39 -66
- data/lib/tapioca/commands/abstract_gem.rb +25 -46
- data/lib/tapioca/commands/annotations.rb +28 -34
- data/lib/tapioca/commands/check_shims.rb +6 -15
- data/lib/tapioca/commands/command.rb +12 -26
- data/lib/tapioca/commands/command_without_tracker.rb +2 -5
- 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 +5 -9
- 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 +36 -63
- data/lib/tapioca/dsl/compilers/aasm.rb +33 -44
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +8 -7
- data/lib/tapioca/dsl/compilers/action_mailer.rb +6 -5
- data/lib/tapioca/dsl/compilers/action_text.rb +6 -5
- data/lib/tapioca/dsl/compilers/active_job.rb +6 -10
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +10 -11
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +5 -6
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +5 -12
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +17 -44
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +20 -26
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +9 -8
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +7 -6
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +54 -62
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +148 -209
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +8 -13
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +5 -4
- data/lib/tapioca/dsl/compilers/active_record_store.rb +5 -4
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +19 -28
- data/lib/tapioca/dsl/compilers/active_resource.rb +19 -21
- data/lib/tapioca/dsl/compilers/active_storage.rb +6 -14
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +9 -8
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +8 -7
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +5 -4
- data/lib/tapioca/dsl/compilers/config.rb +5 -4
- data/lib/tapioca/dsl/compilers/frozen_record.rb +7 -11
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +9 -10
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +6 -10
- data/lib/tapioca/dsl/compilers/identity_cache.rb +11 -39
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +9 -18
- data/lib/tapioca/dsl/compilers/kredis.rb +7 -8
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +5 -4
- data/lib/tapioca/dsl/compilers/protobuf.rb +13 -26
- data/lib/tapioca/dsl/compilers/rails_generators.rb +9 -11
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +23 -13
- data/lib/tapioca/dsl/compilers/smart_properties.rb +32 -38
- data/lib/tapioca/dsl/compilers/state_machines.rb +15 -26
- data/lib/tapioca/dsl/compilers/url_helpers.rb +10 -9
- 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 +30 -58
- data/lib/tapioca/executor.rb +6 -12
- data/lib/tapioca/gem/events.rb +24 -34
- data/lib/tapioca/gem/listeners/base.rb +7 -10
- 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 +36 -47
- 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 +15 -8
- data/lib/tapioca/gem/listeners/subconstants.rb +5 -4
- data/lib/tapioca/gem/listeners/yard_doc.rb +30 -23
- data/lib/tapioca/gem/pipeline.rb +107 -91
- data/lib/tapioca/gem_info.rb +1 -1
- data/lib/tapioca/gemfile.rb +64 -73
- data/lib/tapioca/helpers/cli_helper.rb +4 -7
- data/lib/tapioca/helpers/config_helper.rb +17 -29
- data/lib/tapioca/helpers/env_helper.rb +2 -5
- 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 +76 -73
- 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 +7 -10
- data/lib/tapioca/helpers/test/dsl_compiler.rb +20 -33
- data/lib/tapioca/helpers/test/isolation.rb +10 -14
- data/lib/tapioca/helpers/test/template.rb +6 -11
- data/lib/tapioca/internal.rb +18 -8
- data/lib/tapioca/loaders/dsl.rb +11 -19
- data/lib/tapioca/loaders/gem.rb +6 -21
- data/lib/tapioca/loaders/loader.rb +21 -39
- 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 -9
- data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
- data/lib/tapioca/runtime/attached_class_of_legacy.rb +2 -5
- 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 +81 -60
- data/lib/tapioca/runtime/source_location.rb +44 -0
- data/lib/tapioca/runtime/trackers/autoload.rb +7 -9
- data/lib/tapioca/runtime/trackers/constant_definition.rb +18 -14
- data/lib/tapioca/runtime/trackers/method_definition.rb +65 -0
- data/lib/tapioca/runtime/trackers/mixin.rb +8 -11
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
- data/lib/tapioca/runtime/trackers/tracker.rb +3 -6
- data/lib/tapioca/runtime/trackers.rb +5 -8
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
- data/lib/tapioca/sorbet_ext/name_patch.rb +2 -2
- 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 +27 -10
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
|
|
@@ -126,40 +107,71 @@ module Tapioca
|
|
|
126
107
|
@payload_symbols.include?(symbol_name)
|
|
127
108
|
end
|
|
128
109
|
|
|
129
|
-
|
|
130
|
-
# "(eval at /path/to/file.rb:123)"
|
|
131
|
-
# and we are just interested in the "/path/to/file.rb" part
|
|
132
|
-
EVAL_SOURCE_FILE_PATTERN = T.let(/\(eval at (.+):\d+\)/, Regexp)
|
|
133
|
-
|
|
134
|
-
sig { params(name: T.any(String, Symbol)).returns(T::Boolean) }
|
|
110
|
+
#: ((String | Symbol) name) -> bool
|
|
135
111
|
def constant_in_gem?(name)
|
|
136
|
-
|
|
112
|
+
loc = const_source_location(name)
|
|
137
113
|
|
|
138
|
-
|
|
139
|
-
return true
|
|
140
|
-
# If the source location of the constant is "(eval)", all bets are off.
|
|
141
|
-
return true if source_file == "(eval)"
|
|
114
|
+
# If the source location of the constant isn't available or is "(eval)", all bets are off.
|
|
115
|
+
return true if loc.nil? || loc.file.nil? || loc.file == "(eval)"
|
|
142
116
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# file being something like `(eval at /path/to/file.rb:123)`. We try to parse
|
|
146
|
-
# this string to get the actual source file.
|
|
147
|
-
source_file = source_file.sub(EVAL_SOURCE_FILE_PATTERN, "\\1")
|
|
117
|
+
gem.contains_path?(loc.file)
|
|
118
|
+
end
|
|
148
119
|
|
|
149
|
-
|
|
120
|
+
class MethodDefinitionLookupResult
|
|
121
|
+
extend T::Helpers
|
|
122
|
+
abstract!
|
|
150
123
|
end
|
|
151
124
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
125
|
+
# The method doesn't seem to exist
|
|
126
|
+
class MethodUnknown < MethodDefinitionLookupResult; end
|
|
127
|
+
|
|
128
|
+
# The method is not defined in the gem
|
|
129
|
+
class MethodNotInGem < MethodDefinitionLookupResult; end
|
|
130
|
+
|
|
131
|
+
# The method probably defined in the gem but doesn't have a source location
|
|
132
|
+
class MethodInGemWithoutLocation < MethodDefinitionLookupResult; end
|
|
133
|
+
|
|
134
|
+
# The method defined in gem and has a source location
|
|
135
|
+
class MethodInGemWithLocation < MethodDefinitionLookupResult
|
|
136
|
+
extend T::Sig
|
|
137
|
+
|
|
138
|
+
#: Runtime::SourceLocation
|
|
139
|
+
attr_reader :location
|
|
140
|
+
|
|
141
|
+
#: (Runtime::SourceLocation location) -> void
|
|
142
|
+
def initialize(location)
|
|
143
|
+
@location = location
|
|
144
|
+
super()
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
#: (Symbol method_name, Module owner) -> MethodDefinitionLookupResult
|
|
149
|
+
def method_definition_in_gem(method_name, owner)
|
|
150
|
+
definitions = Tapioca::Runtime::Trackers::MethodDefinition.method_definitions_for(method_name, owner)
|
|
151
|
+
|
|
152
|
+
# If the source location of the method isn't available, signal that by returning nil.
|
|
153
|
+
return MethodUnknown.new if definitions.empty?
|
|
154
|
+
|
|
155
|
+
# Look up the first entry that matches a file in the gem.
|
|
156
|
+
found = definitions.find { |loc| @gem.contains_path?(loc.file) }
|
|
157
|
+
|
|
158
|
+
unless found
|
|
159
|
+
# If the source location of the method is "(eval)", err on the side of caution and include the method.
|
|
160
|
+
found = definitions.find { |loc| loc.file == "(eval)" }
|
|
161
|
+
# However, we can just return true to signal that the method should be included.
|
|
162
|
+
# We can't provide a source location for it, but we want it to be included in the gem RBI.
|
|
163
|
+
return MethodInGemWithoutLocation.new if found
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# If we searched but couldn't find a source location in the gem, return false to signal that.
|
|
167
|
+
return MethodNotInGem.new unless found
|
|
156
168
|
|
|
157
|
-
|
|
169
|
+
MethodInGemWithLocation.new(found)
|
|
158
170
|
end
|
|
159
171
|
|
|
160
172
|
# Helpers
|
|
161
173
|
|
|
162
|
-
|
|
174
|
+
#: (Module constant) -> String?
|
|
163
175
|
def name_of(constant)
|
|
164
176
|
name = name_of_proxy_target(constant, super(class_of(constant)))
|
|
165
177
|
return name if name
|
|
@@ -174,7 +186,7 @@ module Tapioca
|
|
|
174
186
|
|
|
175
187
|
private
|
|
176
188
|
|
|
177
|
-
|
|
189
|
+
#: (Gemfile::GemSpec gem) -> Set[String]
|
|
178
190
|
def load_bootstrap_symbols(gem)
|
|
179
191
|
engine_symbols = Static::SymbolLoader.engine_symbols(gem)
|
|
180
192
|
gem_symbols = Static::SymbolLoader.gem_symbols(gem)
|
|
@@ -184,12 +196,12 @@ module Tapioca
|
|
|
184
196
|
|
|
185
197
|
# Events handling
|
|
186
198
|
|
|
187
|
-
|
|
199
|
+
#: -> Gem::Event
|
|
188
200
|
def next_event
|
|
189
201
|
T.must(@events.shift)
|
|
190
202
|
end
|
|
191
203
|
|
|
192
|
-
|
|
204
|
+
#: (Gem::Event event) -> void
|
|
193
205
|
def dispatch(event)
|
|
194
206
|
case event
|
|
195
207
|
when Gem::SymbolFound
|
|
@@ -203,7 +215,7 @@ module Tapioca
|
|
|
203
215
|
end
|
|
204
216
|
end
|
|
205
217
|
|
|
206
|
-
|
|
218
|
+
#: (Gem::SymbolFound event) -> void
|
|
207
219
|
def on_symbol(event)
|
|
208
220
|
symbol = event.symbol.delete_prefix("::")
|
|
209
221
|
return if skip_symbol?(symbol)
|
|
@@ -212,7 +224,7 @@ module Tapioca
|
|
|
212
224
|
push_constant(symbol, constant) if Runtime::Reflection.constant_defined?(constant)
|
|
213
225
|
end
|
|
214
226
|
|
|
215
|
-
|
|
227
|
+
#: (Gem::ConstantFound event) -> void
|
|
216
228
|
def on_constant(event)
|
|
217
229
|
name = event.symbol
|
|
218
230
|
return if skip_constant?(name, event.constant)
|
|
@@ -224,14 +236,14 @@ module Tapioca
|
|
|
224
236
|
end
|
|
225
237
|
end
|
|
226
238
|
|
|
227
|
-
|
|
239
|
+
#: (Gem::NodeAdded event) -> void
|
|
228
240
|
def on_node(event)
|
|
229
241
|
@node_listeners.each { |listener| listener.dispatch(event) }
|
|
230
242
|
end
|
|
231
243
|
|
|
232
244
|
# Compiling
|
|
233
245
|
|
|
234
|
-
|
|
246
|
+
#: (String symbol, Module constant) -> void
|
|
235
247
|
def compile_foreign_constant(symbol, constant)
|
|
236
248
|
return if skip_foreign_constant?(symbol, constant)
|
|
237
249
|
return if seen?(symbol)
|
|
@@ -242,7 +254,8 @@ module Tapioca
|
|
|
242
254
|
push_foreign_scope(symbol, constant, scope)
|
|
243
255
|
end
|
|
244
256
|
|
|
245
|
-
|
|
257
|
+
# @without_runtime
|
|
258
|
+
#: (String symbol, BasicObject constant) -> void
|
|
246
259
|
def compile_constant(symbol, constant)
|
|
247
260
|
case constant
|
|
248
261
|
when Module
|
|
@@ -256,7 +269,7 @@ module Tapioca
|
|
|
256
269
|
end
|
|
257
270
|
end
|
|
258
271
|
|
|
259
|
-
|
|
272
|
+
#: (String name, Module constant) -> void
|
|
260
273
|
def compile_alias(name, constant)
|
|
261
274
|
return if seen?(name)
|
|
262
275
|
|
|
@@ -277,7 +290,8 @@ module Tapioca
|
|
|
277
290
|
@root << node
|
|
278
291
|
end
|
|
279
292
|
|
|
280
|
-
|
|
293
|
+
# @without_runtime
|
|
294
|
+
#: (String name, BasicObject value) -> void
|
|
281
295
|
def compile_object(name, value)
|
|
282
296
|
return if seen?(name)
|
|
283
297
|
|
|
@@ -310,7 +324,7 @@ module Tapioca
|
|
|
310
324
|
@root << node
|
|
311
325
|
end
|
|
312
326
|
|
|
313
|
-
|
|
327
|
+
#: (String name, Module constant) -> void
|
|
314
328
|
def compile_module(name, constant)
|
|
315
329
|
return if skip_module?(name, constant)
|
|
316
330
|
return if seen?(name)
|
|
@@ -321,7 +335,7 @@ module Tapioca
|
|
|
321
335
|
push_scope(name, constant, scope)
|
|
322
336
|
end
|
|
323
337
|
|
|
324
|
-
|
|
338
|
+
#: (String name, Module constant) -> RBI::Scope
|
|
325
339
|
def compile_scope(name, constant)
|
|
326
340
|
scope = if constant.is_a?(Class)
|
|
327
341
|
superclass = compile_superclass(constant)
|
|
@@ -335,9 +349,9 @@ module Tapioca
|
|
|
335
349
|
scope
|
|
336
350
|
end
|
|
337
351
|
|
|
338
|
-
|
|
352
|
+
#: (Class[top] constant) -> String?
|
|
339
353
|
def compile_superclass(constant)
|
|
340
|
-
superclass =
|
|
354
|
+
superclass = nil #: Class[top]? # rubocop:disable Lint/UselessAssignment
|
|
341
355
|
|
|
342
356
|
while (superclass = superclass_of(constant))
|
|
343
357
|
constant_name = name_of(constant)
|
|
@@ -386,12 +400,13 @@ module Tapioca
|
|
|
386
400
|
|
|
387
401
|
# Constants and properties filtering
|
|
388
402
|
|
|
389
|
-
|
|
403
|
+
#: (String name) -> bool
|
|
390
404
|
def skip_symbol?(name)
|
|
391
405
|
symbol_in_payload?(name) && !@bootstrap_symbols.include?(name)
|
|
392
406
|
end
|
|
393
407
|
|
|
394
|
-
|
|
408
|
+
# @without_runtime
|
|
409
|
+
#: (String name, top constant) -> bool
|
|
395
410
|
def skip_constant?(name, constant)
|
|
396
411
|
return true if name.strip.empty?
|
|
397
412
|
return true if name.start_with?("#<")
|
|
@@ -403,7 +418,7 @@ module Tapioca
|
|
|
403
418
|
false
|
|
404
419
|
end
|
|
405
420
|
|
|
406
|
-
|
|
421
|
+
#: (String name, Module constant) -> bool
|
|
407
422
|
def skip_alias?(name, constant)
|
|
408
423
|
return true if symbol_in_payload?(name)
|
|
409
424
|
return true unless constant_in_gem?(name)
|
|
@@ -412,7 +427,8 @@ module Tapioca
|
|
|
412
427
|
false
|
|
413
428
|
end
|
|
414
429
|
|
|
415
|
-
|
|
430
|
+
# @without_runtime
|
|
431
|
+
#: (String name, BasicObject constant) -> bool
|
|
416
432
|
def skip_object?(name, constant)
|
|
417
433
|
return true if symbol_in_payload?(name)
|
|
418
434
|
return true unless constant_in_gem?(name)
|
|
@@ -420,12 +436,12 @@ module Tapioca
|
|
|
420
436
|
false
|
|
421
437
|
end
|
|
422
438
|
|
|
423
|
-
|
|
439
|
+
#: (String name, Module constant) -> bool
|
|
424
440
|
def skip_foreign_constant?(name, constant)
|
|
425
441
|
Tapioca::TypeVariableModule === constant
|
|
426
442
|
end
|
|
427
443
|
|
|
428
|
-
|
|
444
|
+
#: (String name, Module constant) -> bool
|
|
429
445
|
def skip_module?(name, constant)
|
|
430
446
|
return true unless defined_in_gem?(constant, strict: false)
|
|
431
447
|
return true if Tapioca::TypeVariableModule === constant
|
|
@@ -433,7 +449,7 @@ module Tapioca
|
|
|
433
449
|
false
|
|
434
450
|
end
|
|
435
451
|
|
|
436
|
-
|
|
452
|
+
#: (Module constant, ?strict: bool) -> bool
|
|
437
453
|
def defined_in_gem?(constant, strict: true)
|
|
438
454
|
files = get_file_candidates(constant)
|
|
439
455
|
.merge(Runtime::Trackers::ConstantDefinition.files_for(constant))
|
|
@@ -445,38 +461,38 @@ module Tapioca
|
|
|
445
461
|
end
|
|
446
462
|
end
|
|
447
463
|
|
|
448
|
-
|
|
464
|
+
#: (Module constant) -> Set[String]
|
|
449
465
|
def get_file_candidates(constant)
|
|
450
466
|
file_candidates_for(constant)
|
|
451
467
|
rescue ArgumentError, NameError
|
|
452
468
|
Set.new
|
|
453
469
|
end
|
|
454
470
|
|
|
455
|
-
|
|
471
|
+
#: (String name) -> void
|
|
456
472
|
def add_to_alias_namespace(name)
|
|
457
473
|
@alias_namespace.add("#{name}::")
|
|
458
474
|
end
|
|
459
475
|
|
|
460
|
-
|
|
476
|
+
#: (String name) -> bool
|
|
461
477
|
def alias_namespaced?(name)
|
|
462
478
|
@alias_namespace.any? do |namespace|
|
|
463
479
|
name.start_with?(namespace)
|
|
464
480
|
end
|
|
465
481
|
end
|
|
466
482
|
|
|
467
|
-
|
|
483
|
+
#: (String name) -> void
|
|
468
484
|
def seen!(name)
|
|
469
485
|
@seen.add(name)
|
|
470
486
|
end
|
|
471
487
|
|
|
472
|
-
|
|
488
|
+
#: (String name) -> bool
|
|
473
489
|
def seen?(name)
|
|
474
490
|
@seen.include?(name)
|
|
475
491
|
end
|
|
476
492
|
|
|
477
493
|
# Helpers
|
|
478
494
|
|
|
479
|
-
|
|
495
|
+
#: ((Module & T::Generic) constant) -> String
|
|
480
496
|
def generic_name_of(constant)
|
|
481
497
|
type_name = T.must(constant.name)
|
|
482
498
|
return type_name if type_name =~ /\[.*\]$/
|
|
@@ -492,7 +508,7 @@ module Tapioca
|
|
|
492
508
|
"#{type_name}[#{type_variable_names}]"
|
|
493
509
|
end
|
|
494
510
|
|
|
495
|
-
|
|
511
|
+
#: (Module constant, String? class_name) -> String?
|
|
496
512
|
def name_of_proxy_target(constant, class_name)
|
|
497
513
|
return unless class_name == "ActiveSupport::Deprecation::DeprecatedConstantProxy"
|
|
498
514
|
|
data/lib/tapioca/gem_info.rb
CHANGED