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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -0
  3. data/exe/tapioca +6 -1
  4. data/lib/ruby_lsp/tapioca/addon.rb +73 -43
  5. data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +43 -43
  6. data/lib/ruby_lsp/tapioca/server_addon.rb +13 -10
  7. data/lib/tapioca/bundler_ext/auto_require_hook.rb +6 -14
  8. data/lib/tapioca/cli.rb +16 -8
  9. data/lib/tapioca/commands/abstract_dsl.rb +39 -66
  10. data/lib/tapioca/commands/abstract_gem.rb +25 -46
  11. data/lib/tapioca/commands/annotations.rb +28 -34
  12. data/lib/tapioca/commands/check_shims.rb +6 -15
  13. data/lib/tapioca/commands/command.rb +12 -26
  14. data/lib/tapioca/commands/command_without_tracker.rb +2 -5
  15. data/lib/tapioca/commands/configure.rb +11 -16
  16. data/lib/tapioca/commands/dsl_compiler_list.rb +2 -1
  17. data/lib/tapioca/commands/dsl_generate.rb +2 -1
  18. data/lib/tapioca/commands/dsl_verify.rb +2 -1
  19. data/lib/tapioca/commands/gem_generate.rb +5 -9
  20. data/lib/tapioca/commands/gem_sync.rb +2 -1
  21. data/lib/tapioca/commands/gem_verify.rb +3 -2
  22. data/lib/tapioca/commands/require.rb +3 -7
  23. data/lib/tapioca/commands/todo.rb +6 -10
  24. data/lib/tapioca/dsl/compiler.rb +36 -63
  25. data/lib/tapioca/dsl/compilers/aasm.rb +33 -44
  26. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +8 -7
  27. data/lib/tapioca/dsl/compilers/action_mailer.rb +6 -5
  28. data/lib/tapioca/dsl/compilers/action_text.rb +6 -5
  29. data/lib/tapioca/dsl/compilers/active_job.rb +6 -10
  30. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +10 -11
  31. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +5 -6
  32. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +5 -12
  33. data/lib/tapioca/dsl/compilers/active_record_associations.rb +17 -44
  34. data/lib/tapioca/dsl/compilers/active_record_columns.rb +20 -26
  35. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +9 -8
  36. data/lib/tapioca/dsl/compilers/active_record_enum.rb +7 -6
  37. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +54 -62
  38. data/lib/tapioca/dsl/compilers/active_record_relations.rb +148 -209
  39. data/lib/tapioca/dsl/compilers/active_record_scope.rb +8 -13
  40. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +5 -4
  41. data/lib/tapioca/dsl/compilers/active_record_store.rb +5 -4
  42. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +19 -28
  43. data/lib/tapioca/dsl/compilers/active_resource.rb +19 -21
  44. data/lib/tapioca/dsl/compilers/active_storage.rb +6 -14
  45. data/lib/tapioca/dsl/compilers/active_support_concern.rb +9 -8
  46. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +8 -7
  47. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +5 -4
  48. data/lib/tapioca/dsl/compilers/config.rb +5 -4
  49. data/lib/tapioca/dsl/compilers/frozen_record.rb +7 -11
  50. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +9 -10
  51. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +6 -10
  52. data/lib/tapioca/dsl/compilers/identity_cache.rb +11 -39
  53. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +9 -18
  54. data/lib/tapioca/dsl/compilers/kredis.rb +7 -8
  55. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +5 -4
  56. data/lib/tapioca/dsl/compilers/protobuf.rb +13 -26
  57. data/lib/tapioca/dsl/compilers/rails_generators.rb +9 -11
  58. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +23 -13
  59. data/lib/tapioca/dsl/compilers/smart_properties.rb +32 -38
  60. data/lib/tapioca/dsl/compilers/state_machines.rb +15 -26
  61. data/lib/tapioca/dsl/compilers/url_helpers.rb +10 -9
  62. data/lib/tapioca/dsl/compilers.rb +4 -7
  63. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +13 -16
  64. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +13 -28
  65. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +19 -15
  66. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +5 -24
  67. data/lib/tapioca/dsl/pipeline.rb +30 -58
  68. data/lib/tapioca/executor.rb +6 -12
  69. data/lib/tapioca/gem/events.rb +24 -34
  70. data/lib/tapioca/gem/listeners/base.rb +7 -10
  71. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +4 -2
  72. data/lib/tapioca/gem/listeners/foreign_constants.rb +5 -7
  73. data/lib/tapioca/gem/listeners/methods.rb +36 -47
  74. data/lib/tapioca/gem/listeners/mixins.rb +6 -18
  75. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +4 -2
  76. data/lib/tapioca/gem/listeners/sorbet_enums.rb +4 -2
  77. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +4 -2
  78. data/lib/tapioca/gem/listeners/sorbet_props.rb +4 -2
  79. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +4 -2
  80. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +7 -5
  81. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +6 -4
  82. data/lib/tapioca/gem/listeners/source_location.rb +15 -8
  83. data/lib/tapioca/gem/listeners/subconstants.rb +5 -4
  84. data/lib/tapioca/gem/listeners/yard_doc.rb +30 -23
  85. data/lib/tapioca/gem/pipeline.rb +107 -91
  86. data/lib/tapioca/gem_info.rb +1 -1
  87. data/lib/tapioca/gemfile.rb +64 -73
  88. data/lib/tapioca/helpers/cli_helper.rb +4 -7
  89. data/lib/tapioca/helpers/config_helper.rb +17 -29
  90. data/lib/tapioca/helpers/env_helper.rb +2 -5
  91. data/lib/tapioca/helpers/gem_helper.rb +5 -5
  92. data/lib/tapioca/helpers/git_attributes.rb +3 -3
  93. data/lib/tapioca/helpers/rbi_files_helper.rb +76 -73
  94. data/lib/tapioca/helpers/rbi_helper.rb +14 -22
  95. data/lib/tapioca/helpers/sorbet_helper.rb +9 -18
  96. data/lib/tapioca/helpers/source_uri.rb +15 -25
  97. data/lib/tapioca/helpers/test/content.rb +7 -10
  98. data/lib/tapioca/helpers/test/dsl_compiler.rb +20 -33
  99. data/lib/tapioca/helpers/test/isolation.rb +10 -14
  100. data/lib/tapioca/helpers/test/template.rb +6 -11
  101. data/lib/tapioca/internal.rb +18 -8
  102. data/lib/tapioca/loaders/dsl.rb +11 -19
  103. data/lib/tapioca/loaders/gem.rb +6 -21
  104. data/lib/tapioca/loaders/loader.rb +21 -39
  105. data/lib/tapioca/rbi_ext/model.rb +12 -37
  106. data/lib/tapioca/rbi_formatter.rb +10 -19
  107. data/lib/tapioca/rbs/rewriter.rb +55 -0
  108. data/lib/tapioca/repo_index.rb +7 -9
  109. data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
  110. data/lib/tapioca/runtime/attached_class_of_legacy.rb +2 -5
  111. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +23 -23
  112. data/lib/tapioca/runtime/generic_type_registry.rb +13 -23
  113. data/lib/tapioca/runtime/reflection.rb +81 -60
  114. data/lib/tapioca/runtime/source_location.rb +44 -0
  115. data/lib/tapioca/runtime/trackers/autoload.rb +7 -9
  116. data/lib/tapioca/runtime/trackers/constant_definition.rb +18 -14
  117. data/lib/tapioca/runtime/trackers/method_definition.rb +65 -0
  118. data/lib/tapioca/runtime/trackers/mixin.rb +8 -11
  119. data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
  120. data/lib/tapioca/runtime/trackers/tracker.rb +3 -6
  121. data/lib/tapioca/runtime/trackers.rb +5 -8
  122. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
  123. data/lib/tapioca/sorbet_ext/name_patch.rb +2 -2
  124. data/lib/tapioca/sorbet_ext/proc_bind_patch.rb +1 -1
  125. data/lib/tapioca/static/requires_compiler.rb +6 -6
  126. data/lib/tapioca/static/symbol_loader.rb +14 -16
  127. data/lib/tapioca/static/symbol_table_parser.rb +8 -8
  128. data/lib/tapioca/version.rb +1 -1
  129. data/lib/tapioca.rb +22 -29
  130. metadata +27 -10
@@ -8,17 +8,7 @@ module Tapioca
8
8
  include SorbetHelper
9
9
  include RBIFilesHelper
10
10
 
11
- sig do
12
- params(
13
- gem_rbi_dir: String,
14
- dsl_rbi_dir: String,
15
- annotations_rbi_dir: String,
16
- shim_rbi_dir: String,
17
- todo_rbi_file: String,
18
- payload: T::Boolean,
19
- number_of_workers: T.nilable(Integer),
20
- ).void
21
- end
11
+ #: (gem_rbi_dir: String, dsl_rbi_dir: String, annotations_rbi_dir: String, shim_rbi_dir: String, todo_rbi_file: String, payload: bool, number_of_workers: Integer?) -> void
22
12
  def initialize(
23
13
  gem_rbi_dir:,
24
14
  dsl_rbi_dir:,
@@ -40,7 +30,8 @@ module Tapioca
40
30
 
41
31
  private
42
32
 
43
- sig { override.void }
33
+ # @override
34
+ #: -> void
44
35
  def execute
45
36
  index = RBI::Index.new
46
37
 
@@ -50,7 +41,7 @@ module Tapioca
50
41
  return
51
42
  end
52
43
 
53
- payload_path = T.let(nil, T.nilable(String))
44
+ payload_path = nil #: String?
54
45
 
55
46
  if @payload
56
47
  Dir.mktmpdir do |dir|
@@ -58,7 +49,7 @@ module Tapioca
58
49
  result = sorbet("--no-config --print=payload-sources:#{payload_path}")
59
50
 
60
51
  unless result.status
61
- raise Thor::Error, <<~ERROR
52
+ raise Tapioca::Error, <<~ERROR
62
53
  "Sorbet failed to dump payload"
63
54
  #{result.err}
64
55
  ERROR
@@ -96,7 +87,7 @@ module Tapioca
96
87
  "\nPlease remove the duplicated definitions from #{@shim_rbi_dir} and #{@todo_rbi_file}", :red
97
88
  )
98
89
 
99
- raise Thor::Error, messages.join("\n")
90
+ raise Tapioca::Error, messages.join("\n")
100
91
  end
101
92
 
102
93
  say("\nNo duplicates found in shim RBIs", :green)
@@ -3,10 +3,9 @@
3
3
 
4
4
  module Tapioca
5
5
  module Commands
6
+ # @abstract
6
7
  class Command
7
8
  extend T::Sig
8
- extend T::Helpers
9
-
10
9
  class FileWriter < Thor
11
10
  include Thor::Actions
12
11
  end
@@ -14,14 +13,13 @@ module Tapioca
14
13
  include Thor::Base
15
14
  include CliHelper
16
15
 
17
- abstract!
18
-
19
- sig { void }
16
+ #: -> void
20
17
  def initialize
21
- @file_writer = T.let(FileWriter.new, Thor::Actions)
18
+ @file_writer = FileWriter.new #: Thor::Actions
22
19
  end
23
20
 
24
- sig(:final) { void }
21
+ # @final
22
+ #: -> void
25
23
  def run
26
24
  Tapioca.silence_warnings do
27
25
  execute
@@ -30,36 +28,24 @@ module Tapioca
30
28
 
31
29
  private
32
30
 
33
- sig { abstract.void }
34
- def execute; end
31
+ # @abstract
32
+ #: -> void
33
+ def execute = raise NotImplementedError, "Abstract method called"
35
34
 
36
- sig { params(command: Symbol, args: String).returns(String) }
35
+ #: (Symbol command, *String args) -> String
37
36
  def default_command(command, *args)
38
37
  [Tapioca::BINARY_FILE, command.to_s, *args].join(" ")
39
38
  end
40
39
 
41
- sig { returns(Thor::Actions) }
40
+ #: Thor::Actions
42
41
  attr_reader :file_writer
43
42
 
44
- sig do
45
- params(
46
- path: T.any(String, Pathname),
47
- content: String,
48
- force: T::Boolean,
49
- skip: T::Boolean,
50
- verbose: T::Boolean,
51
- ).void
52
- end
43
+ #: ((String | Pathname) path, String content, ?force: bool, ?skip: bool, ?verbose: bool) -> void
53
44
  def create_file(path, content, force: true, skip: false, verbose: true)
54
45
  file_writer.create_file(path, force: force, skip: skip, verbose: verbose) { content }
55
46
  end
56
47
 
57
- sig do
58
- params(
59
- path: T.any(String, Pathname),
60
- verbose: T::Boolean,
61
- ).void
62
- end
48
+ #: ((String | Pathname) path, ?verbose: bool) -> void
63
49
  def remove_file(path, verbose: true)
64
50
  file_writer.remove_file(path, verbose: verbose)
65
51
  end
@@ -3,12 +3,9 @@
3
3
 
4
4
  module Tapioca
5
5
  module Commands
6
+ # @abstract
6
7
  class CommandWithoutTracker < Command
7
- extend T::Helpers
8
-
9
- abstract!
10
-
11
- sig { void }
8
+ #: -> void
12
9
  def initialize
13
10
  Tapioca::Runtime::Trackers.disable_all!
14
11
  super
@@ -4,13 +4,7 @@
4
4
  module Tapioca
5
5
  module Commands
6
6
  class Configure < CommandWithoutTracker
7
- sig do
8
- params(
9
- sorbet_config: String,
10
- tapioca_config: String,
11
- default_postrequire: String,
12
- ).void
13
- end
7
+ #: (sorbet_config: String, tapioca_config: String, default_postrequire: String) -> void
14
8
  def initialize(
15
9
  sorbet_config:,
16
10
  tapioca_config:,
@@ -22,13 +16,14 @@ module Tapioca
22
16
 
23
17
  super()
24
18
 
25
- @installer = T.let(nil, T.nilable(Bundler::Installer))
26
- @spec = T.let(nil, T.nilable(Bundler::StubSpecification))
19
+ @installer = nil #: Bundler::Installer?
20
+ @spec = nil #: Bundler::StubSpecification?
27
21
  end
28
22
 
29
23
  private
30
24
 
31
- sig { override.void }
25
+ # @override
26
+ #: -> void
32
27
  def execute
33
28
  create_sorbet_config
34
29
  create_tapioca_config
@@ -36,7 +31,7 @@ module Tapioca
36
31
  create_binstub
37
32
  end
38
33
 
39
- sig { void }
34
+ #: -> void
40
35
  def create_sorbet_config
41
36
  create_file(@sorbet_config, <<~CONTENT, skip: true, force: false)
42
37
  --dir
@@ -46,7 +41,7 @@ module Tapioca
46
41
  CONTENT
47
42
  end
48
43
 
49
- sig { void }
44
+ #: -> void
50
45
  def create_tapioca_config
51
46
  create_file(@tapioca_config, <<~YAML, skip: true, force: false)
52
47
  gem:
@@ -65,7 +60,7 @@ module Tapioca
65
60
  YAML
66
61
  end
67
62
 
68
- sig { void }
63
+ #: -> void
69
64
  def create_post_require
70
65
  create_file(@default_postrequire, <<~CONTENT, skip: true, force: false)
71
66
  # typed: true
@@ -75,7 +70,7 @@ module Tapioca
75
70
  CONTENT
76
71
  end
77
72
 
78
- sig { void }
73
+ #: -> void
79
74
  def create_binstub
80
75
  force = File.exist?(Tapioca::BINARY_FILE)
81
76
 
@@ -88,12 +83,12 @@ module Tapioca
88
83
  )
89
84
  end
90
85
 
91
- sig { returns(Bundler::Installer) }
86
+ #: -> Bundler::Installer
92
87
  def installer
93
88
  @installer ||= Bundler::Installer.new(Bundler.root, Bundler.definition)
94
89
  end
95
90
 
96
- sig { returns(T.any(Bundler::StubSpecification, ::Gem::Specification)) }
91
+ #: -> (Bundler::StubSpecification | ::Gem::Specification)
97
92
  def spec
98
93
  @spec ||= Bundler.definition.specs.find { |s| s.name == "tapioca" }
99
94
  end
@@ -6,7 +6,8 @@ module Tapioca
6
6
  class DslCompilerList < AbstractDsl
7
7
  private
8
8
 
9
- sig { override.void }
9
+ # @override
10
+ #: -> void
10
11
  def execute
11
12
  load_application
12
13
 
@@ -6,7 +6,8 @@ module Tapioca
6
6
  class DslGenerate < AbstractDsl
7
7
  private
8
8
 
9
- sig { override.void }
9
+ # @override
10
+ #: -> void
10
11
  def execute
11
12
  load_application
12
13
 
@@ -6,7 +6,8 @@ module Tapioca
6
6
  class DslVerify < AbstractDsl
7
7
  private
8
8
 
9
- sig { override.void }
9
+ # @override
10
+ #: -> void
10
11
  def execute
11
12
  load_application
12
13
 
@@ -6,7 +6,8 @@ module Tapioca
6
6
  class GemGenerate < AbstractGem
7
7
  private
8
8
 
9
- sig { override.void }
9
+ # @override
10
+ #: -> void
10
11
  def execute
11
12
  Loaders::Gem.load_application(
12
13
  bundle: @bundle,
@@ -47,7 +48,7 @@ module Tapioca
47
48
  GitAttributes.create_generated_attribute_file(@outpath)
48
49
  end
49
50
 
50
- sig { params(gem_names: T::Array[String]).returns(T::Array[Gemfile::GemSpec]) }
51
+ #: (Array[String] gem_names) -> Array[Gemfile::GemSpec]
51
52
  def gems_to_generate(gem_names)
52
53
  return @bundle.dependencies if gem_names.empty?
53
54
 
@@ -57,7 +58,7 @@ module Tapioca
57
58
  if gem.nil?
58
59
  next if @lsp_addon
59
60
 
60
- raise Thor::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
61
+ raise Tapioca::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red)
61
62
  end
62
63
 
63
64
  gems.concat(gem_dependencies(gem)) if @include_dependencies
@@ -65,12 +66,7 @@ module Tapioca
65
66
  end
66
67
  end
67
68
 
68
- sig do
69
- params(
70
- gem: Gemfile::GemSpec,
71
- dependencies: T::Array[Gemfile::GemSpec],
72
- ).returns(T::Array[Gemfile::GemSpec])
73
- end
69
+ #: (Gemfile::GemSpec gem, ?Array[Gemfile::GemSpec] dependencies) -> Array[Gemfile::GemSpec]
74
70
  def gem_dependencies(gem, dependencies = [])
75
71
  direct_dependencies = gem.dependencies.filter_map { |dependency| @bundle.gem(dependency.name) }
76
72
  gems = dependencies | direct_dependencies
@@ -6,7 +6,8 @@ module Tapioca
6
6
  class GemSync < AbstractGem
7
7
  private
8
8
 
9
- sig { override.void }
9
+ # @override
10
+ #: -> void
10
11
  def execute
11
12
  anything_done = [
12
13
  perform_removals,
@@ -6,14 +6,15 @@ module Tapioca
6
6
  class GemVerify < AbstractGem
7
7
  private
8
8
 
9
- sig { override.void }
9
+ # @override
10
+ #: -> void
10
11
  def execute
11
12
  say("Checking for out-of-date RBIs...")
12
13
  say("")
13
14
  perform_sync_verification
14
15
  end
15
16
 
16
- sig { void }
17
+ #: -> void
17
18
  def perform_sync_verification
18
19
  diff = {}
19
20
 
@@ -4,12 +4,7 @@
4
4
  module Tapioca
5
5
  module Commands
6
6
  class Require < CommandWithoutTracker
7
- sig do
8
- params(
9
- requires_path: String,
10
- sorbet_config_path: String,
11
- ).void
12
- end
7
+ #: (requires_path: String, sorbet_config_path: String) -> void
13
8
  def initialize(requires_path:, sorbet_config_path:)
14
9
  @requires_path = requires_path
15
10
  @sorbet_config_path = sorbet_config_path
@@ -19,7 +14,8 @@ module Tapioca
19
14
 
20
15
  private
21
16
 
22
- sig { override.void }
17
+ # @override
18
+ #: -> void
23
19
  def execute
24
20
  compiler = Static::RequiresCompiler.new(@sorbet_config_path)
25
21
  name = set_color(@requires_path, :yellow, :bold)
@@ -17,12 +17,7 @@ module Tapioca
17
17
  4. Manually create an RBI shim defining the missing constants
18
18
  DEPRECATION
19
19
 
20
- sig do
21
- params(
22
- todo_file: String,
23
- file_header: T::Boolean,
24
- ).void
25
- end
20
+ #: (todo_file: String, file_header: bool) -> void
26
21
  def initialize(todo_file:, file_header:)
27
22
  @todo_file = todo_file
28
23
  @file_header = file_header
@@ -30,7 +25,7 @@ module Tapioca
30
25
  super()
31
26
  end
32
27
 
33
- sig { void }
28
+ #: -> void
34
29
  def run_with_deprecation
35
30
  say(DEPRECATION_MESSAGE, :red)
36
31
  say("")
@@ -40,7 +35,8 @@ module Tapioca
40
35
 
41
36
  private
42
37
 
43
- sig { override.void }
38
+ # @override
39
+ #: -> void
44
40
  def execute
45
41
  say("Finding all unresolved constants, this may take a few seconds... ")
46
42
 
@@ -64,7 +60,7 @@ module Tapioca
64
60
  say("Please review changes and commit them.", [:green, :bold])
65
61
  end
66
62
 
67
- sig { params(constants: T::Array[String], command: String).returns(RBI::File) }
63
+ #: (Array[String] constants, command: String) -> RBI::File
68
64
  def rbi(constants, command:)
69
65
  file = RBI::File.new
70
66
 
@@ -84,7 +80,7 @@ module Tapioca
84
80
  file
85
81
  end
86
82
 
87
- sig { returns(T::Array[String]) }
83
+ #: -> Array[String]
88
84
  def unresolved_constants
89
85
  # Taken from https://github.com/sorbet/sorbet/blob/master/gems/sorbet/lib/todo-rbi.rb
90
86
  sorbet("--print=missing-constants", "--quiet", "--stdout-hup-hack", "--no-error-count")
@@ -3,55 +3,49 @@
3
3
 
4
4
  module Tapioca
5
5
  module Dsl
6
+ # @abstract
7
+ #: [ConstantType < Module]
6
8
  class Compiler
7
9
  extend T::Sig
8
- extend T::Helpers
9
- extend T::Generic
10
10
 
11
11
  include RBIHelper
12
12
  include Runtime::Reflection
13
13
  extend Runtime::Reflection
14
14
 
15
- ConstantType = type_member { { upper: Module } }
16
-
17
- abstract!
18
-
19
- sig { returns(ConstantType) }
15
+ #: ConstantType
20
16
  attr_reader :constant
21
17
 
22
- sig { returns(RBI::Tree) }
18
+ #: RBI::Tree
23
19
  attr_reader :root
24
20
 
25
- sig { returns(T::Hash[String, T.untyped]) }
21
+ #: Hash[String, untyped]
26
22
  attr_reader :options
27
23
 
28
- @@requested_constants = T.let([], T::Array[Module]) # rubocop:disable Style/ClassVars
24
+ @@requested_constants = [] #: Array[Module] # rubocop:disable Style/ClassVars
29
25
 
30
26
  class << self
31
27
  extend T::Sig
32
28
 
33
- sig { params(constant: Module).returns(T::Boolean) }
29
+ #: (Module constant) -> bool
34
30
  def handles?(constant)
35
31
  processable_constants.include?(constant)
36
32
  end
37
33
 
38
- sig { abstract.returns(T::Enumerable[Module]) }
39
- def gather_constants; end
34
+ # @abstract
35
+ #: -> T::Enumerable[Module]
36
+ def gather_constants = raise NotImplementedError, "Abstract method called"
40
37
 
41
- sig { returns(T::Set[Module]) }
38
+ #: -> Set[Module]
42
39
  def processable_constants
43
- @processable_constants ||= T.let(
44
- T::Set[Module].new.compare_by_identity.merge(gather_constants),
45
- T.nilable(T::Set[Module]),
46
- )
40
+ @processable_constants ||= T::Set[Module].new.compare_by_identity.merge(gather_constants) #: Set[Module]?
47
41
  end
48
42
 
49
- sig { params(constants: T::Array[Module]).void }
43
+ #: (Array[Module] constants) -> void
50
44
  def requested_constants=(constants)
51
45
  @@requested_constants = constants # rubocop:disable Style/ClassVars
52
46
  end
53
47
 
54
- sig { void }
48
+ #: -> void
55
49
  def reset_state
56
50
  @processable_constants = nil
57
51
  @all_classes = nil
@@ -60,11 +54,7 @@ module Tapioca
60
54
 
61
55
  private
62
56
 
63
- sig do
64
- type_parameters(:U)
65
- .params(klass: T.all(T::Class[T.anything], T.type_parameter(:U)))
66
- .returns(T::Array[T.type_parameter(:U)])
67
- end
57
+ #: [U] ((Class[top] & U) klass) -> Array[U]
68
58
  def descendants_of(klass)
69
59
  if @@requested_constants.any?
70
60
  T.cast(
@@ -78,53 +68,41 @@ module Tapioca
78
68
  end
79
69
  end
80
70
 
81
- sig { returns(T::Enumerable[T::Class[T.anything]]) }
71
+ #: -> T::Enumerable[Class[top]]
82
72
  def all_classes
83
- @all_classes ||= T.let(
84
- all_modules.grep(Class).freeze,
85
- T.nilable(T::Enumerable[T::Class[T.anything]]),
86
- )
73
+ @all_classes ||= all_modules.grep(Class).freeze #: T::Enumerable[Class[top]]?
87
74
  end
88
75
 
89
- sig { returns(T::Enumerable[Module]) }
76
+ #: -> T::Enumerable[Module]
90
77
  def all_modules
91
- @all_modules ||= T.let(
92
- if @@requested_constants.any?
93
- @@requested_constants.grep(Module)
94
- else
95
- ObjectSpace.each_object(Module).to_a
96
- end.freeze,
97
- T.nilable(T::Enumerable[Module]),
98
- )
78
+ @all_modules ||= if @@requested_constants.any?
79
+ @@requested_constants.grep(Module)
80
+ else
81
+ ObjectSpace.each_object(Module).to_a
82
+ end.freeze #: T::Enumerable[Module]?
99
83
  end
100
84
  end
101
85
 
102
- sig do
103
- params(
104
- pipeline: Tapioca::Dsl::Pipeline,
105
- root: RBI::Tree,
106
- constant: ConstantType,
107
- options: T::Hash[String, T.untyped],
108
- ).void
109
- end
86
+ #: (Tapioca::Dsl::Pipeline pipeline, RBI::Tree root, ConstantType constant, ?Hash[String, untyped] options) -> void
110
87
  def initialize(pipeline, root, constant, options = {})
111
88
  @pipeline = pipeline
112
89
  @root = root
113
90
  @constant = constant
114
91
  @options = options
115
- @errors = T.let([], T::Array[String])
92
+ @errors = [] #: Array[String]
116
93
  end
117
94
 
118
- sig { params(compiler_name: String).returns(T::Boolean) }
95
+ #: (String compiler_name) -> bool
119
96
  def compiler_enabled?(compiler_name)
120
97
  @pipeline.compiler_enabled?(compiler_name)
121
98
  end
122
99
 
123
- sig { abstract.void }
124
- def decorate; end
100
+ # @abstract
101
+ #: -> void
102
+ def decorate = raise NotImplementedError, "Abstract method called"
125
103
 
126
104
  # NOTE: This should eventually accept an `Error` object or `Exception` rather than simply a `String`.
127
- sig { params(error: String).void }
105
+ #: (String error) -> void
128
106
  def add_error(error)
129
107
  @pipeline.add_error(error)
130
108
  end
@@ -132,14 +110,9 @@ module Tapioca
132
110
  private
133
111
 
134
112
  # Get the types of each parameter from a method signature
135
- sig do
136
- params(
137
- method_def: T.any(Method, UnboundMethod),
138
- signature: T.untyped, # as `T::Private::Methods::Signature` is private
139
- ).returns(T::Array[String])
140
- end
113
+ #: ((Method | UnboundMethod) method_def, untyped signature) -> Array[String]
141
114
  def parameters_types_from_signature(method_def, signature)
142
- params = T.let([], T::Array[String])
115
+ params = [] #: Array[String]
143
116
 
144
117
  return method_def.parameters.map { "T.untyped" } unless signature
145
118
 
@@ -163,7 +136,7 @@ module Tapioca
163
136
  params
164
137
  end
165
138
 
166
- sig { params(scope: RBI::Scope, method_def: T.any(Method, UnboundMethod), class_method: T::Boolean).void }
139
+ #: (RBI::Scope scope, (Method | UnboundMethod) method_def, ?class_method: bool) -> void
167
140
  def create_method_from_def(scope, method_def, class_method: false)
168
141
  scope.create_method(
169
142
  method_def.name.to_s,
@@ -173,13 +146,13 @@ module Tapioca
173
146
  )
174
147
  end
175
148
 
176
- sig { params(method_def: T.any(Method, UnboundMethod)).returns(T::Array[RBI::TypedParam]) }
149
+ #: ((Method | UnboundMethod) method_def) -> Array[RBI::TypedParam]
177
150
  def compile_method_parameters_to_rbi(method_def)
178
151
  signature = signature_of(method_def)
179
152
  method_def = signature.nil? ? method_def : signature.method
180
153
  method_types = parameters_types_from_signature(method_def, signature)
181
154
 
182
- parameters = T.let(method_def.parameters, T::Array[[Symbol, T.nilable(Symbol)]])
155
+ parameters = method_def.parameters #: Array[[Symbol, Symbol?]]
183
156
 
184
157
  parameters.each_with_index.map do |(type, name), index|
185
158
  fallback_arg_name = "_arg#{index}"
@@ -209,7 +182,7 @@ module Tapioca
209
182
  end
210
183
  end
211
184
 
212
- sig { params(method_def: T.any(Method, UnboundMethod)).returns(String) }
185
+ #: ((Method | UnboundMethod) method_def) -> String
213
186
  def compile_method_return_type_to_rbi(method_def)
214
187
  signature = signature_of(method_def)
215
188
  return_type = signature.nil? ? "T.untyped" : name_of_type(signature.return_type)