tapioca 0.19.0 → 0.19.2

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -27
  3. data/lib/tapioca/cli.rb +11 -1
  4. data/lib/tapioca/commands/abstract_dsl.rb +6 -1
  5. data/lib/tapioca/commands/check_shims.rb +3 -0
  6. data/lib/tapioca/commands/configure.rb +1 -0
  7. data/lib/tapioca/commands/dsl_generate.rb +15 -0
  8. data/lib/tapioca/commands/todo.rb +8 -2
  9. data/lib/tapioca/dsl/compiler.rb +13 -13
  10. data/lib/tapioca/dsl/compilers/aasm.rb +1 -1
  11. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +2 -2
  12. data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -1
  13. data/lib/tapioca/dsl/compilers/action_text.rb +1 -1
  14. data/lib/tapioca/dsl/compilers/active_job.rb +1 -1
  15. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -1
  16. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +1 -1
  17. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -1
  18. data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -1
  19. data/lib/tapioca/dsl/compilers/active_record_columns.rb +1 -1
  20. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +65 -17
  21. data/lib/tapioca/dsl/compilers/active_record_enum.rb +1 -1
  22. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -1
  23. data/lib/tapioca/dsl/compilers/active_record_relations.rb +1 -1
  24. data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -1
  25. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -1
  26. data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -1
  27. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -1
  28. data/lib/tapioca/dsl/compilers/active_resource.rb +1 -1
  29. data/lib/tapioca/dsl/compilers/active_storage.rb +2 -2
  30. data/lib/tapioca/dsl/compilers/active_support_concern.rb +6 -6
  31. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +1 -1
  32. data/lib/tapioca/dsl/compilers/active_support_environment_inquirer.rb +1 -1
  33. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +1 -1
  34. data/lib/tapioca/dsl/compilers/config.rb +2 -2
  35. data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -1
  36. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -1
  37. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -1
  38. data/lib/tapioca/dsl/compilers/identity_cache.rb +2 -2
  39. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +1 -1
  40. data/lib/tapioca/dsl/compilers/kredis.rb +1 -1
  41. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +2 -2
  42. data/lib/tapioca/dsl/compilers/protobuf.rb +1 -1
  43. data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -1
  44. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -1
  45. data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -1
  46. data/lib/tapioca/dsl/compilers/state_machines.rb +2 -2
  47. data/lib/tapioca/dsl/compilers/url_helpers.rb +7 -7
  48. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +4 -2
  49. data/lib/tapioca/dsl/pipeline.rb +13 -37
  50. data/lib/tapioca/gem/events.rb +7 -7
  51. data/lib/tapioca/gem/listeners/methods.rb +8 -8
  52. data/lib/tapioca/gem/listeners/mixins.rb +3 -3
  53. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +5 -3
  54. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +1 -1
  55. data/lib/tapioca/gem/pipeline.rb +18 -18
  56. data/lib/tapioca/helpers/sorbet_helper.rb +19 -0
  57. data/lib/tapioca/helpers/test/dsl_compiler.rb +2 -9
  58. data/lib/tapioca/internal.rb +2 -0
  59. data/lib/tapioca/rbi_ext/model.rb +8 -5
  60. data/lib/tapioca/rbs/rewriter.rb +80 -25
  61. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +6 -6
  62. data/lib/tapioca/runtime/generic_type_registry.rb +17 -18
  63. data/lib/tapioca/runtime/reflection.rb +20 -20
  64. data/lib/tapioca/runtime/trackers/constant_definition.rb +3 -3
  65. data/lib/tapioca/runtime/trackers/method_definition.rb +4 -4
  66. data/lib/tapioca/runtime/trackers/mixin.rb +5 -5
  67. data/lib/tapioca/runtime/trackers/required_ancestor.rb +2 -2
  68. data/lib/tapioca/runtime/trackers/tracker.rb +1 -1
  69. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +1 -21
  70. data/lib/tapioca/sorbet_ext/generic_type_patch.rb +48 -0
  71. data/lib/tapioca/sorbet_ext/void_patch.rb +29 -0
  72. data/lib/tapioca/static/symbol_loader.rb +19 -1
  73. data/lib/tapioca/version.rb +1 -1
  74. metadata +8 -6
@@ -181,7 +181,7 @@ module Tapioca
181
181
 
182
182
  class << self
183
183
  # @override
184
- #: -> Enumerable[T::Module[top]]
184
+ #: -> Enumerable[Module[top]]
185
185
  def gather_constants
186
186
  ActiveRecord::Base.descendants.reject(&:abstract_class?)
187
187
  end
@@ -77,7 +77,7 @@ module Tapioca
77
77
 
78
78
  class << self
79
79
  # @override
80
- #: -> Enumerable[T::Module[top]]
80
+ #: -> Enumerable[Module[top]]
81
81
  def gather_constants
82
82
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
83
83
  end
@@ -57,7 +57,7 @@ module Tapioca
57
57
 
58
58
  class << self
59
59
  # @override
60
- #: -> Enumerable[T::Module[top]]
60
+ #: -> Enumerable[Module[top]]
61
61
  def gather_constants
62
62
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
63
63
  end
@@ -132,7 +132,7 @@ module Tapioca
132
132
 
133
133
  class << self
134
134
  # @override
135
- #: -> Enumerable[T::Module[top]]
135
+ #: -> Enumerable[Module[top]]
136
136
  def gather_constants
137
137
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
138
138
  end
@@ -107,7 +107,7 @@ module Tapioca
107
107
 
108
108
  class << self
109
109
  # @override
110
- #: -> Enumerable[T::Module[top]]
110
+ #: -> Enumerable[Module[top]]
111
111
  def gather_constants
112
112
  descendants_of(::ActiveRecord::Base).select do |klass|
113
113
  klass.include?(ActiveRecord::TypedStore::Behavior)
@@ -70,7 +70,7 @@ module Tapioca
70
70
 
71
71
  class << self
72
72
  # @override
73
- #: -> Enumerable[T::Module[top]]
73
+ #: -> Enumerable[Module[top]]
74
74
  def gather_constants
75
75
  descendants_of(::ActiveResource::Base)
76
76
  end
@@ -38,7 +38,7 @@ module Tapioca
38
38
  # def photo=(attachable); end
39
39
  # end
40
40
  # ~~~
41
- #: [ConstantType = (T::Module[top] & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
41
+ #: [ConstantType = (Module[top] & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
42
42
  class ActiveStorage < Compiler
43
43
  # @override
44
44
  #: -> void
@@ -64,7 +64,7 @@ module Tapioca
64
64
 
65
65
  class << self
66
66
  # @override
67
- #: -> Enumerable[T::Module[top]]
67
+ #: -> Enumerable[Module[top]]
68
68
  def gather_constants
69
69
  descendants_of(::ActiveRecord::Base)
70
70
  .reject(&:abstract_class?)
@@ -37,7 +37,7 @@ module Tapioca
37
37
  # mixes_in_class_methods(::Foo::ClassMethods)
38
38
  # end
39
39
  # ~~~
40
- #: [ConstantType = T::Module[top]]
40
+ #: [ConstantType = Module[top]]
41
41
  class ActiveSupportConcern < Compiler
42
42
  # @override
43
43
  #: -> void
@@ -61,7 +61,7 @@ module Tapioca
61
61
 
62
62
  class << self
63
63
  # @override
64
- #: -> Enumerable[T::Module[top]]
64
+ #: -> Enumerable[Module[top]]
65
65
  def gather_constants
66
66
  all_modules.select do |mod|
67
67
  name_of(mod) && # i.e. not anonymous
@@ -72,10 +72,10 @@ module Tapioca
72
72
  end
73
73
 
74
74
  # Returns true when `mod` includes other concerns
75
- #: (T::Module[top] mod) -> bool
75
+ #: (Module[top] mod) -> bool
76
76
  def has_dependencies?(mod) = dependencies_of(mod).any?
77
77
 
78
- #: (T::Module[top] concern) -> Array[T::Module[top]]
78
+ #: (Module[top] concern) -> Array[Module[top]]
79
79
  def dependencies_of(concern)
80
80
  concern.instance_variable_get(:@_dependencies) || []
81
81
  end
@@ -83,12 +83,12 @@ module Tapioca
83
83
 
84
84
  private
85
85
 
86
- #: (T::Module[top] concern) -> Array[T::Module[top]]
86
+ #: (Module[top] concern) -> Array[Module[top]]
87
87
  def dependencies_of(concern)
88
88
  self.class.dependencies_of(concern)
89
89
  end
90
90
 
91
- #: (?T::Module[top] concern) -> Array[T::Module[top]]
91
+ #: (?Module[top] concern) -> Array[Module[top]]
92
92
  def linearized_dependencies(concern = constant)
93
93
  # Grab all the dependencies of the concern
94
94
  dependencies = dependencies_of(concern)
@@ -93,7 +93,7 @@ module Tapioca
93
93
 
94
94
  class << self
95
95
  # @override
96
- #: -> Enumerable[T::Module[top]]
96
+ #: -> Enumerable[Module[top]]
97
97
  def gather_constants
98
98
  descendants_of(::ActiveSupport::CurrentAttributes)
99
99
  end
@@ -47,7 +47,7 @@ module Tapioca
47
47
 
48
48
  class << self
49
49
  # @override
50
- #: -> T::Enumerable[T::Module[top]]
50
+ #: -> T::Enumerable[Module[top]]
51
51
  def gather_constants
52
52
  return [] unless defined?(Rails.application) && Rails.application
53
53
 
@@ -54,7 +54,7 @@ module Tapioca
54
54
 
55
55
  class << self
56
56
  # @override
57
- #: -> Enumerable[T::Module[top]]
57
+ #: -> Enumerable[Module[top]]
58
58
  def gather_constants
59
59
  [::Time]
60
60
  end
@@ -40,7 +40,7 @@ module Tapioca
40
40
  # def github=(value); end
41
41
  # end
42
42
  # ```
43
- #: [ConstantType = T::Module[top]]
43
+ #: [ConstantType = Module[top]]
44
44
  class Config < Compiler
45
45
  CONFIG_OPTIONS_SUFFIX = "ConfigOptions"
46
46
 
@@ -92,7 +92,7 @@ module Tapioca
92
92
 
93
93
  class << self
94
94
  # @override
95
- #: -> Enumerable[T::Module[top]]
95
+ #: -> Enumerable[Module[top]]
96
96
  def gather_constants
97
97
  name = ::Config.const_name
98
98
  return [] unless Object.const_defined?(name)
@@ -84,7 +84,7 @@ module Tapioca
84
84
 
85
85
  class << self
86
86
  # @override
87
- #: -> Enumerable[T::Module[top]]
87
+ #: -> Enumerable[Module[top]]
88
88
  def gather_constants
89
89
  descendants_of(::FrozenRecord::Base).reject(&:abstract_class?)
90
90
  end
@@ -73,7 +73,7 @@ module Tapioca
73
73
 
74
74
  class << self
75
75
  # @override
76
- #: -> Enumerable[T::Module[top]]
76
+ #: -> Enumerable[Module[top]]
77
77
  def gather_constants
78
78
  all_classes.select { |c| GraphQL::Schema::InputObject > c }
79
79
  end
@@ -70,7 +70,7 @@ module Tapioca
70
70
 
71
71
  class << self
72
72
  # @override
73
- #: -> Enumerable[T::Module[top]]
73
+ #: -> Enumerable[Module[top]]
74
74
  def gather_constants
75
75
  all_classes.select { |c| GraphQL::Schema::Mutation > c && GraphQL::Schema::RelayClassicMutation != c }
76
76
  end
@@ -57,7 +57,7 @@ module Tapioca
57
57
  # ~~~
58
58
  #: [ConstantType = singleton(::ActiveRecord::Base)]
59
59
  class IdentityCache < Compiler
60
- COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((T::Module[top] | String) type) -> String
60
+ COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((Module[top] | String) type) -> String
61
61
 
62
62
  # @override
63
63
  #: -> void
@@ -91,7 +91,7 @@ module Tapioca
91
91
 
92
92
  class << self
93
93
  # @override
94
- #: -> Enumerable[T::Module[top]]
94
+ #: -> Enumerable[Module[top]]
95
95
  def gather_constants
96
96
  descendants_of(::ActiveRecord::Base).select do |klass|
97
97
  ::IdentityCache::WithoutPrimaryIndex > klass
@@ -105,7 +105,7 @@ module Tapioca
105
105
 
106
106
  class << self
107
107
  # @override
108
- #: -> Enumerable[T::Module[top]]
108
+ #: -> Enumerable[Module[top]]
109
109
  def gather_constants
110
110
  all_modules.select do |c|
111
111
  name_of(c) && ::JsonApiClient::Resource > c
@@ -84,7 +84,7 @@ module Tapioca
84
84
 
85
85
  class << self
86
86
  # @override
87
- #: -> Enumerable[T::Module[top]]
87
+ #: -> Enumerable[Module[top]]
88
88
  def gather_constants
89
89
  all_classes
90
90
  .grep(::Kredis::Attributes::ClassMethods)
@@ -44,7 +44,7 @@ module Tapioca
44
44
  # end
45
45
  # end
46
46
  # ~~~
47
- #: [ConstantType = T::Module[top]]
47
+ #: [ConstantType = Module[top]]
48
48
  class MixedInClassAttributes < Compiler
49
49
  # @override
50
50
  #: -> void
@@ -59,7 +59,7 @@ module Tapioca
59
59
 
60
60
  class << self
61
61
  # @override
62
- #: -> Enumerable[T::Module[top]]
62
+ #: -> Enumerable[Module[top]]
63
63
  def gather_constants
64
64
  # Select all non-anonymous modules that have overridden Module.included
65
65
  all_modules.select do |mod|
@@ -152,7 +152,7 @@ module Tapioca
152
152
 
153
153
  class << self
154
154
  # @override
155
- #: -> Enumerable[T::Module[top]]
155
+ #: -> Enumerable[Module[top]]
156
156
  def gather_constants
157
157
  marker = Google::Protobuf::MessageExts::ClassMethods
158
158
 
@@ -56,7 +56,7 @@ module Tapioca
56
56
 
57
57
  class << self
58
58
  # @override
59
- #: -> Enumerable[T::Module[top]]
59
+ #: -> Enumerable[Module[top]]
60
60
  def gather_constants
61
61
  all_classes.select do |const|
62
62
  name = qualified_name_of(const)
@@ -83,7 +83,7 @@ module Tapioca
83
83
 
84
84
  class << self
85
85
  # @override
86
- #: -> Enumerable[T::Module[top]]
86
+ #: -> Enumerable[Module[top]]
87
87
  def gather_constants
88
88
  all_classes.select { |c| Sidekiq::Worker > c }
89
89
  end
@@ -80,7 +80,7 @@ module Tapioca
80
80
 
81
81
  class << self
82
82
  # @override
83
- #: -> Enumerable[T::Module[top]]
83
+ #: -> Enumerable[Module[top]]
84
84
  def gather_constants
85
85
  all_modules.select do |c|
86
86
  name_of(c) &&
@@ -109,7 +109,7 @@ module Tapioca
109
109
  # end
110
110
  # end
111
111
  # ~~~
112
- #: [ConstantType = (T::Module[top] & ::StateMachines::ClassMethods)]
112
+ #: [ConstantType = (Module[top] & ::StateMachines::ClassMethods)]
113
113
  class StateMachines < Compiler
114
114
  # @override
115
115
  #: -> void
@@ -154,7 +154,7 @@ module Tapioca
154
154
 
155
155
  class << self
156
156
  # @override
157
- #: -> Enumerable[T::Module[top]]
157
+ #: -> Enumerable[Module[top]]
158
158
  def gather_constants
159
159
  all_classes.select { |mod| ::StateMachines::InstanceMethods > mod }
160
160
  end
@@ -78,7 +78,7 @@ module Tapioca
78
78
  # include GeneratedUrlHelpersModule
79
79
  # end
80
80
  # ~~~
81
- #: [ConstantType = T::Module[top]]
81
+ #: [ConstantType = Module[top]]
82
82
  class UrlHelpers < Compiler
83
83
  # @override
84
84
  #: -> void
@@ -96,7 +96,7 @@ module Tapioca
96
96
 
97
97
  class << self
98
98
  # @override
99
- #: -> Enumerable[T::Module[top]]
99
+ #: -> Enumerable[Module[top]]
100
100
  def gather_constants
101
101
  return [] unless defined?(Rails.application) && Rails.application
102
102
 
@@ -128,7 +128,7 @@ module Tapioca
128
128
  constants.concat(NON_DISCOVERABLE_INCLUDERS).push(GeneratedUrlHelpersModule, GeneratedPathHelpersModule)
129
129
  end
130
130
 
131
- #: -> Array[T::Module[top]]
131
+ #: -> Array[Module[top]]
132
132
  def gather_non_discoverable_includers
133
133
  [].tap do |includers|
134
134
  if defined?(ActionController::TemplateAssertions) && defined?(ActionDispatch::IntegrationTest)
@@ -143,7 +143,7 @@ module Tapioca
143
143
 
144
144
  # Returns `true` if `mod` "directly" includes `helper`.
145
145
  # For classes, this method will return false if the `helper` is included only by a superclass
146
- #: (T::Module[top] mod, T::Module[top] helper) -> bool
146
+ #: (Module[top] mod, Module[top] helper) -> bool
147
147
  private def includes_helper?(mod, helper)
148
148
  ancestors = ancestors_of(mod)
149
149
 
@@ -158,11 +158,11 @@ module Tapioca
158
158
  end
159
159
  end
160
160
 
161
- NON_DISCOVERABLE_INCLUDERS = gather_non_discoverable_includers #: Array[T::Module[top]]
161
+ NON_DISCOVERABLE_INCLUDERS = gather_non_discoverable_includers #: Array[Module[top]]
162
162
 
163
163
  private
164
164
 
165
- #: (RBI::Tree root, T::Module[top] constant) -> void
165
+ #: (RBI::Tree root, Module[top] constant) -> void
166
166
  def generate_module_for(root, constant)
167
167
  root.create_module(T.must(constant.name)) do |mod|
168
168
  mod.create_include("::ActionDispatch::Routing::UrlFor")
@@ -178,7 +178,7 @@ module Tapioca
178
178
  end
179
179
  end
180
180
 
181
- #: (RBI::Scope mod, T::Module[top] helper_module) -> void
181
+ #: (RBI::Scope mod, Module[top] helper_module) -> void
182
182
  def create_mixins_for(mod, helper_module)
183
183
  include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
184
184
  extend_helper = constant.singleton_class.ancestors.include?(helper_module)
@@ -80,7 +80,9 @@ module Tapioca
80
80
  signature = Runtime::Reflection.signature_of(method)
81
81
  return_type = signature&.return_type
82
82
 
83
- valid_return_type?(return_type) ? return_type.to_s : "T.untyped"
83
+ # Wrap as non-nilable for required arguments. `coerce_input` supports both
84
+ # required and optional; optional arguments are re-wrapped below based on `type.non_null?`
85
+ valid_return_type?(return_type) ? (T::Utils.unwrap_nilable(return_type) || return_type).to_s : "T.untyped"
84
86
  when GraphQL::Schema::InputObject.singleton_class
85
87
  type_for_constant(unwrapped_type)
86
88
  when Module
@@ -110,7 +112,7 @@ module Tapioca
110
112
 
111
113
  private
112
114
 
113
- #: (T::Module[top] constant) -> String
115
+ #: (Module[top] constant) -> String
114
116
  def type_for_constant(constant)
115
117
  if constant.instance_methods.include?(:prepare)
116
118
  prepare_method = constant.instance_method(:prepare)
@@ -7,13 +7,13 @@ module Tapioca
7
7
  #: Enumerable[singleton(Compiler)]
8
8
  attr_reader :active_compilers
9
9
 
10
- #: Array[T::Module[top]]
10
+ #: Array[Module[top]]
11
11
  attr_reader :requested_constants
12
12
 
13
13
  #: Array[Pathname]
14
14
  attr_reader :requested_paths
15
15
 
16
- #: Array[T::Module[top]]
16
+ #: Array[Module[top]]
17
17
  attr_reader :skipped_constants
18
18
 
19
19
  #: ^(String error) -> void
@@ -23,12 +23,12 @@ module Tapioca
23
23
  attr_reader :errors
24
24
 
25
25
  #: (
26
- #| requested_constants: Array[T::Module[top]],
26
+ #| requested_constants: Array[Module[top]],
27
27
  #| ?requested_paths: Array[Pathname],
28
28
  #| ?requested_compilers: Array[singleton(Compiler)],
29
29
  #| ?excluded_compilers: Array[singleton(Compiler)],
30
30
  #| ?error_handler: ^(String error) -> void,
31
- #| ?skipped_constants: Array[T::Module[top]],
31
+ #| ?skipped_constants: Array[Module[top]],
32
32
  #| ?number_of_workers: Integer?,
33
33
  #| ?compiler_options: Hash[String, untyped],
34
34
  #| ?lsp_addon: bool
@@ -56,7 +56,7 @@ module Tapioca
56
56
  @errors = [] #: Array[String]
57
57
  end
58
58
 
59
- #: [R] { (T::Module[top] constant, RBI::File rbi) -> R } -> Array[R]
59
+ #: [R] { (Module[top] constant, RBI::File rbi) -> R } -> Array[R]
60
60
  def run(&blk)
61
61
  constants_to_process = gather_constants(requested_constants, requested_paths, skipped_constants)
62
62
  .select { |c| Module === c } # Filter value constants out
@@ -128,17 +128,17 @@ module Tapioca
128
128
  end
129
129
 
130
130
  #: (
131
- #| Array[T::Module[top]] requested_constants,
131
+ #| Array[Module[top]] requested_constants,
132
132
  #| Array[Pathname] requested_paths,
133
- #| Array[T::Module[top]] skipped_constants
134
- #| ) -> Set[T::Module[top]]
133
+ #| Array[Module[top]] skipped_constants
134
+ #| ) -> Set[Module[top]]
135
135
  def gather_constants(requested_constants, requested_paths, skipped_constants)
136
136
  Compiler.requested_constants = requested_constants
137
137
  constants = Set.new.compare_by_identity
138
138
  active_compilers.each do |compiler|
139
139
  constants.merge(compiler.processable_constants)
140
140
  end
141
- constants = filter_anonymous_and_reloaded_constants(constants)
141
+ constants = filter_anonymous_constants(constants)
142
142
  constants -= skipped_constants
143
143
 
144
144
  unless requested_constants.empty? && requested_paths.empty?
@@ -153,36 +153,12 @@ module Tapioca
153
153
  constants
154
154
  end
155
155
 
156
- #: (Set[T::Module[top]] constants) -> Set[T::Module[top]]
157
- def filter_anonymous_and_reloaded_constants(constants)
158
- # Group constants by their names
159
- constants_by_name = constants
160
- .group_by { |c| Runtime::Reflection.name_of(c) }
161
- .select { |name, _| !name.nil? }
162
-
163
- constants_by_name = T.cast(constants_by_name, T::Hash[String, T::Array[T::Module[T.anything]]])
164
-
165
- # Find the constants that have been reloaded
166
- reloaded_constants = constants_by_name.select { |_, constants| constants.size > 1 }.keys
167
-
168
- unless reloaded_constants.empty? || @lsp_addon
169
- reloaded_constant_names = reloaded_constants.map { |name| "`#{name}`" }.join(", ")
170
-
171
- $stderr.puts("WARNING: Multiple constants with the same name: #{reloaded_constant_names}")
172
- $stderr.puts("Make sure some object is not holding onto these constants during an app reload.")
173
- end
174
-
175
- # Look up all the constants back from their names. The resulting constant set will be the
176
- # set of constants that are actually in memory with those names.
177
- filtered_constants = constants_by_name
178
- .keys
179
- .map { |name| T.cast(Runtime::Reflection.constantize(name), T::Module[T.anything]) }
180
- .select { |mod| Runtime::Reflection.constant_defined?(mod) }
181
-
182
- Set.new.compare_by_identity.merge(filtered_constants)
156
+ #: (Set[Module[top]] constants) -> Set[Module[top]]
157
+ def filter_anonymous_constants(constants)
158
+ constants.keep_if { |constant| Runtime::Reflection.name_of(constant) }
183
159
  end
184
160
 
185
- #: (T::Module[top] constant) -> RBI::File?
161
+ #: (Module[top] constant) -> RBI::File?
186
162
  def rbi_for_constant(constant)
187
163
  file = RBI::File.new(strictness: "true")
188
164
 
@@ -37,12 +37,12 @@ module Tapioca
37
37
 
38
38
  class ForeignConstantFound < ConstantFound
39
39
  # @override
40
- #: -> T::Module[top]
40
+ #: -> Module[top]
41
41
  def constant
42
42
  T.cast(@constant, T::Module[T.anything])
43
43
  end
44
44
 
45
- #: (String symbol, T::Module[top] constant) -> void
45
+ #: (String symbol, Module[top] constant) -> void
46
46
  def initialize(symbol, constant)
47
47
  super
48
48
  end
@@ -53,10 +53,10 @@ module Tapioca
53
53
  #: String
54
54
  attr_reader :symbol
55
55
 
56
- #: T::Module[top]
56
+ #: Module[top]
57
57
  attr_reader :constant
58
58
 
59
- #: (String symbol, T::Module[top] constant) -> void
59
+ #: (String symbol, Module[top] constant) -> void
60
60
  def initialize(symbol, constant)
61
61
  super()
62
62
  @symbol = symbol
@@ -68,7 +68,7 @@ module Tapioca
68
68
  #: RBI::Const
69
69
  attr_reader :node
70
70
 
71
- #: (String symbol, T::Module[top] constant, RBI::Const node) -> void
71
+ #: (String symbol, Module[top] constant, RBI::Const node) -> void
72
72
  def initialize(symbol, constant, node)
73
73
  super(symbol, constant)
74
74
  @node = node
@@ -79,7 +79,7 @@ module Tapioca
79
79
  #: RBI::Scope
80
80
  attr_reader :node
81
81
 
82
- #: (String symbol, T::Module[top] constant, RBI::Scope node) -> void
82
+ #: (String symbol, Module[top] constant, RBI::Scope node) -> void
83
83
  def initialize(symbol, constant, node)
84
84
  super(symbol, constant)
85
85
  @node = node
@@ -103,7 +103,7 @@ module Tapioca
103
103
 
104
104
  #: (
105
105
  #| String symbol,
106
- #| T::Module[top] constant,
106
+ #| Module[top] constant,
107
107
  #| UnboundMethod method,
108
108
  #| RBI::Method node,
109
109
  #| untyped signature,
@@ -25,9 +25,9 @@ module Tapioca
25
25
  #: (
26
26
  #| RBI::Tree tree,
27
27
  #| String module_name,
28
- #| T::Module[top] mod,
28
+ #| Module[top] mod,
29
29
  #| ?Array[Symbol] for_visibility,
30
- #| ?attached_class: T::Module[top]?
30
+ #| ?attached_class: Module[top]?
31
31
  #| ) -> void
32
32
  def compile_directly_owned_methods(
33
33
  tree,
@@ -59,7 +59,7 @@ module Tapioca
59
59
  #: (
60
60
  #| RBI::Tree tree,
61
61
  #| String symbol_name,
62
- #| T::Module[top] constant,
62
+ #| Module[top] constant,
63
63
  #| UnboundMethod? method,
64
64
  #| ?RBI::Visibility visibility
65
65
  #| ) -> void
@@ -169,7 +169,7 @@ module Tapioca
169
169
  # This method implements a better way of checking whether a constant defines a method.
170
170
  # It walks up the ancestor tree via the `super_method` method; if any of the super
171
171
  # methods are owned by the constant, it means that the constant declares the method.
172
- #: (UnboundMethod method, T::Module[top] constant) -> bool
172
+ #: (UnboundMethod method, Module[top] constant) -> bool
173
173
  def method_owned_by_constant?(method, constant)
174
174
  # Widen the type of `method` to be nilable
175
175
  method = method #: UnboundMethod?
@@ -183,7 +183,7 @@ module Tapioca
183
183
  false
184
184
  end
185
185
 
186
- #: (T::Module[top] mod) -> Hash[Symbol, Array[Symbol]]
186
+ #: (Module[top] mod) -> Hash[Symbol, Array[Symbol]]
187
187
  def method_names_by_visibility(mod)
188
188
  {
189
189
  public: public_instance_methods_of(mod),
@@ -192,7 +192,7 @@ module Tapioca
192
192
  }
193
193
  end
194
194
 
195
- #: (T::Module[top] constant, String method_name) -> bool
195
+ #: (Module[top] constant, String method_name) -> bool
196
196
  def struct_method?(constant, method_name)
197
197
  return false unless T::Props::ClassMethods === constant
198
198
 
@@ -202,7 +202,7 @@ module Tapioca
202
202
  .include?(method_name.gsub(/=$/, "").to_sym)
203
203
  end
204
204
 
205
- #: (T::Module[top]? attached_class, Symbol method_name) -> bool?
205
+ #: (Module[top]? attached_class, Symbol method_name) -> bool?
206
206
  def method_new_in_abstract_class?(attached_class, method_name)
207
207
  attached_class &&
208
208
  method_name == :new &&
@@ -210,7 +210,7 @@ module Tapioca
210
210
  Class === attached_class.singleton_class
211
211
  end
212
212
 
213
- #: (T::Module[top] constant) -> UnboundMethod?
213
+ #: (Module[top] constant) -> UnboundMethod?
214
214
  def initialize_method_for(constant)
215
215
  constant.instance_method(:initialize)
216
216
  rescue
@@ -30,7 +30,7 @@ module Tapioca
30
30
  add_mixins(node, constant, extends.reverse, Runtime::Trackers::Mixin::Type::Extend)
31
31
  end
32
32
 
33
- #: (RBI::Tree tree, T::Module[top] constant, Array[T::Module[top]] mods, Runtime::Trackers::Mixin::Type mixin_type) -> void
33
+ #: (RBI::Tree tree, Module[top] constant, Array[Module[top]] mods, Runtime::Trackers::Mixin::Type mixin_type) -> void
34
34
  def add_mixins(tree, constant, mods, mixin_type)
35
35
  mods
36
36
  .select do |mod|
@@ -57,7 +57,7 @@ module Tapioca
57
57
  end
58
58
  end
59
59
 
60
- #: (T::Module[top] constant, T::Module[top] mixin, Runtime::Trackers::Mixin::Type mixin_type) -> bool
60
+ #: (Module[top] constant, Module[top] mixin, Runtime::Trackers::Mixin::Type mixin_type) -> bool
61
61
  def mixed_in_by_gem?(constant, mixin, mixin_type)
62
62
  mixin_location = Runtime::Trackers::Mixin.mixin_location(mixin, mixin_type, constant)
63
63
 
@@ -73,7 +73,7 @@ module Tapioca
73
73
  mixin_name.start_with?("T::") && !mixin_name.start_with?("T::Props")
74
74
  end
75
75
 
76
- #: (T::Module[top] constant) -> Array[T::Module[top]]
76
+ #: (Module[top] constant) -> Array[Module[top]]
77
77
  def interesting_ancestors_of(constant)
78
78
  inherited_ancestors = Set.new.compare_by_identity.merge(inherited_ancestors_of(constant))
79
79