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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_lsp/tapioca/addon.rb +23 -19
  3. data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +20 -20
  4. data/lib/tapioca/bundler_ext/auto_require_hook.rb +5 -10
  5. data/lib/tapioca/commands/abstract_dsl.rb +26 -59
  6. data/lib/tapioca/commands/abstract_gem.rb +23 -43
  7. data/lib/tapioca/commands/annotations.rb +27 -33
  8. data/lib/tapioca/commands/check_shims.rb +4 -13
  9. data/lib/tapioca/commands/command.rb +8 -20
  10. data/lib/tapioca/commands/command_without_tracker.rb +1 -1
  11. data/lib/tapioca/commands/configure.rb +11 -16
  12. data/lib/tapioca/commands/dsl_compiler_list.rb +2 -1
  13. data/lib/tapioca/commands/dsl_generate.rb +2 -1
  14. data/lib/tapioca/commands/dsl_verify.rb +2 -1
  15. data/lib/tapioca/commands/gem_generate.rb +4 -8
  16. data/lib/tapioca/commands/gem_sync.rb +2 -1
  17. data/lib/tapioca/commands/gem_verify.rb +3 -2
  18. data/lib/tapioca/commands/require.rb +3 -7
  19. data/lib/tapioca/commands/todo.rb +6 -10
  20. data/lib/tapioca/dsl/compiler.rb +28 -53
  21. data/lib/tapioca/dsl/compilers/aasm.rb +31 -41
  22. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +7 -5
  23. data/lib/tapioca/dsl/compilers/action_mailer.rb +5 -3
  24. data/lib/tapioca/dsl/compilers/action_text.rb +5 -3
  25. data/lib/tapioca/dsl/compilers/active_job.rb +5 -8
  26. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +9 -7
  27. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +4 -2
  28. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +4 -2
  29. data/lib/tapioca/dsl/compilers/active_record_associations.rb +16 -42
  30. data/lib/tapioca/dsl/compilers/active_record_columns.rb +19 -24
  31. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +7 -5
  32. data/lib/tapioca/dsl/compilers/active_record_enum.rb +6 -4
  33. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +53 -61
  34. data/lib/tapioca/dsl/compilers/active_record_relations.rb +86 -119
  35. data/lib/tapioca/dsl/compilers/active_record_scope.rb +7 -11
  36. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +4 -2
  37. data/lib/tapioca/dsl/compilers/active_record_store.rb +4 -2
  38. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +18 -26
  39. data/lib/tapioca/dsl/compilers/active_resource.rb +18 -19
  40. data/lib/tapioca/dsl/compilers/active_storage.rb +5 -5
  41. data/lib/tapioca/dsl/compilers/active_support_concern.rb +8 -6
  42. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +7 -5
  43. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +4 -2
  44. data/lib/tapioca/dsl/compilers/config.rb +4 -2
  45. data/lib/tapioca/dsl/compilers/frozen_record.rb +6 -9
  46. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +8 -8
  47. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +5 -8
  48. data/lib/tapioca/dsl/compilers/identity_cache.rb +10 -37
  49. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +8 -16
  50. data/lib/tapioca/dsl/compilers/kredis.rb +6 -4
  51. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +4 -2
  52. data/lib/tapioca/dsl/compilers/protobuf.rb +12 -24
  53. data/lib/tapioca/dsl/compilers/rails_generators.rb +8 -9
  54. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +22 -11
  55. data/lib/tapioca/dsl/compilers/smart_properties.rb +11 -20
  56. data/lib/tapioca/dsl/compilers/state_machines.rb +14 -24
  57. data/lib/tapioca/dsl/compilers/url_helpers.rb +9 -7
  58. data/lib/tapioca/dsl/compilers.rb +4 -7
  59. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +13 -16
  60. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +13 -28
  61. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +19 -15
  62. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +5 -24
  63. data/lib/tapioca/dsl/pipeline.rb +23 -55
  64. data/lib/tapioca/executor.rb +6 -12
  65. data/lib/tapioca/gem/events.rb +22 -28
  66. data/lib/tapioca/gem/listeners/base.rb +6 -6
  67. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +4 -2
  68. data/lib/tapioca/gem/listeners/foreign_constants.rb +5 -7
  69. data/lib/tapioca/gem/listeners/methods.rb +15 -34
  70. data/lib/tapioca/gem/listeners/mixins.rb +6 -18
  71. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +4 -2
  72. data/lib/tapioca/gem/listeners/sorbet_enums.rb +4 -2
  73. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +4 -2
  74. data/lib/tapioca/gem/listeners/sorbet_props.rb +4 -2
  75. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +4 -2
  76. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +7 -5
  77. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +6 -4
  78. data/lib/tapioca/gem/listeners/source_location.rb +7 -4
  79. data/lib/tapioca/gem/listeners/subconstants.rb +4 -2
  80. data/lib/tapioca/gem/listeners/yard_doc.rb +23 -22
  81. data/lib/tapioca/gem/pipeline.rb +57 -72
  82. data/lib/tapioca/gem_info.rb +1 -1
  83. data/lib/tapioca/gemfile.rb +64 -73
  84. data/lib/tapioca/helpers/cli_helper.rb +3 -3
  85. data/lib/tapioca/helpers/config_helper.rb +15 -24
  86. data/lib/tapioca/helpers/env_helper.rb +1 -1
  87. data/lib/tapioca/helpers/gem_helper.rb +5 -5
  88. data/lib/tapioca/helpers/git_attributes.rb +3 -3
  89. data/lib/tapioca/helpers/rbi_files_helper.rb +73 -67
  90. data/lib/tapioca/helpers/rbi_helper.rb +14 -22
  91. data/lib/tapioca/helpers/sorbet_helper.rb +9 -18
  92. data/lib/tapioca/helpers/source_uri.rb +15 -25
  93. data/lib/tapioca/helpers/test/content.rb +6 -6
  94. data/lib/tapioca/helpers/test/dsl_compiler.rb +19 -29
  95. data/lib/tapioca/helpers/test/isolation.rb +4 -4
  96. data/lib/tapioca/helpers/test/template.rb +5 -7
  97. data/lib/tapioca/internal.rb +5 -1
  98. data/lib/tapioca/loaders/dsl.rb +11 -19
  99. data/lib/tapioca/loaders/gem.rb +6 -21
  100. data/lib/tapioca/loaders/loader.rb +15 -27
  101. data/lib/tapioca/rbi_ext/model.rb +12 -37
  102. data/lib/tapioca/rbi_formatter.rb +10 -19
  103. data/lib/tapioca/rbs/rewriter.rb +55 -0
  104. data/lib/tapioca/repo_index.rb +7 -7
  105. data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
  106. data/lib/tapioca/runtime/attached_class_of_legacy.rb +1 -1
  107. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +23 -23
  108. data/lib/tapioca/runtime/generic_type_registry.rb +13 -23
  109. data/lib/tapioca/runtime/reflection.rb +48 -56
  110. data/lib/tapioca/runtime/trackers/autoload.rb +4 -8
  111. data/lib/tapioca/runtime/trackers/mixin.rb +6 -10
  112. data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
  113. data/lib/tapioca/runtime/trackers/tracker.rb +2 -2
  114. data/lib/tapioca/runtime/trackers.rb +4 -8
  115. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
  116. data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
  117. data/lib/tapioca/sorbet_ext/proc_bind_patch.rb +1 -1
  118. data/lib/tapioca/static/requires_compiler.rb +6 -6
  119. data/lib/tapioca/static/symbol_loader.rb +14 -16
  120. data/lib/tapioca/static/symbol_table_parser.rb +8 -8
  121. data/lib/tapioca/version.rb +1 -1
  122. data/lib/tapioca.rb +22 -29
  123. metadata +25 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05e19aeab9d997df21ef0b042afe97b1fdcca0b7ce148ecb4f05b0d14b792294
4
- data.tar.gz: '09a81f179ccc96606f97bfffe3b07a113315ace4adf5d312998f6caae674cd6e'
3
+ metadata.gz: aae584802448b64d85f5d3da609325b145bc698816d6564a09a45696aa338901
4
+ data.tar.gz: d2673e9edcb91ba6fd7253a7bbd1b83505a4f2bb79ecde5159327f8775187d33
5
5
  SHA512:
6
- metadata.gz: ec69dd3c33275760ebd701d92335da1d0afd7da6e8908887ef3622a836fad09d3e1752f2dedab1efc20fb805065968cea6ec7980cc0abd4561318529a45a6559
7
- data.tar.gz: 1258bd043e9edb53e08afcc78fecdcbc5cc228d0a069beb31c4b2c3ef818d894d16751e2aa24f8e1a6c0b7eb144cc7cb47aba1aa834fa86a6502dc1bd9577649
6
+ metadata.gz: c1bbcb3975a85609b72642c849489743d4ba784c6ac5c5d1fe5f698dbadec683d141c8e8b42e63bd537f5c5770571d9446a05d865d381619b21ffe16acea8a89
7
+ data.tar.gz: dc09f320a84af9eac62d79219cfa282c630b2b01b72ddf33971b7e235757a9e96249f7c98c34ba13679c2d1e2a7148bf6609418fb03bbd904b991a665dfe76e1
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.10", "< 0.24")
4
+ RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.10", "< 0.25")
5
5
 
6
6
  begin
7
7
  # The Tapioca add-on depends on the Rails add-on to add a runtime component to the runtime server. We can allow the
@@ -20,19 +20,20 @@ module RubyLsp
20
20
  class Addon < ::RubyLsp::Addon
21
21
  extend T::Sig
22
22
 
23
- sig { void }
23
+ #: -> void
24
24
  def initialize
25
25
  super
26
26
 
27
- @global_state = T.let(nil, T.nilable(RubyLsp::GlobalState))
28
- @rails_runner_client = T.let(Rails::NullClient.new, RubyLsp::Rails::RunnerClient)
29
- @index = T.let(nil, T.nilable(RubyIndexer::Index))
30
- @file_checksums = T.let({}, T::Hash[String, String])
31
- @lockfile_diff = T.let(nil, T.nilable(String))
32
- @outgoing_queue = T.let(nil, T.nilable(Thread::Queue))
27
+ @global_state = nil #: RubyLsp::GlobalState?
28
+ @rails_runner_client = Rails::NullClient.new #: RubyLsp::Rails::RunnerClient
29
+ @index = nil #: RubyIndexer::Index?
30
+ @file_checksums = {} #: Hash[String, String]
31
+ @lockfile_diff = nil #: String?
32
+ @outgoing_queue = nil #: Thread::Queue?
33
33
  end
34
34
 
35
- sig { override.params(global_state: RubyLsp::GlobalState, outgoing_queue: Thread::Queue).void }
35
+ # @override
36
+ #: (RubyLsp::GlobalState global_state, Thread::Queue outgoing_queue) -> void
36
37
  def activate(global_state, outgoing_queue)
37
38
  @global_state = global_state
38
39
  return unless @global_state.enabled_feature?(:tapiocaAddon)
@@ -67,28 +68,31 @@ module RubyLsp
67
68
  end
68
69
  end
69
70
 
70
- sig { override.void }
71
+ # @override
72
+ #: -> void
71
73
  def deactivate
72
74
  end
73
75
 
74
- sig { override.returns(String) }
76
+ # @override
77
+ #: -> String
75
78
  def name
76
79
  "Tapioca"
77
80
  end
78
81
 
79
- sig { override.returns(String) }
82
+ # @override
83
+ #: -> String
80
84
  def version
81
85
  "0.1.3"
82
86
  end
83
87
 
84
- sig { params(changes: T::Array[{ uri: String, type: Integer }]).void }
88
+ #: (Array[{uri: String, type: Integer}] changes) -> void
85
89
  def workspace_did_change_watched_files(changes)
86
90
  return unless @global_state&.enabled_feature?(:tapiocaAddon)
87
91
  return unless @rails_runner_client.connected?
88
92
 
89
- has_route_change = T.let(false, T::Boolean)
90
- has_fixtures_change = T.let(false, T::Boolean)
91
- needs_compiler_reload = T.let(false, T::Boolean)
93
+ has_route_change = false #: bool
94
+ has_fixtures_change = false #: bool
95
+ needs_compiler_reload = false #: bool
92
96
 
93
97
  constants = changes.flat_map do |change|
94
98
  path = URI(change[:uri]).to_standardized_path
@@ -153,7 +157,7 @@ module RubyLsp
153
157
 
154
158
  private
155
159
 
156
- sig { params(feature_name: String).void }
160
+ #: (String feature_name) -> void
157
161
  def send_usage_telemetry(feature_name)
158
162
  return unless @outgoing_queue && @global_state
159
163
 
@@ -172,7 +176,7 @@ module RubyLsp
172
176
  })
173
177
  end
174
178
 
175
- sig { params(change: T::Hash[Symbol, T.untyped], path: String).returns(T::Boolean) }
179
+ #: (Hash[Symbol, untyped] change, String path) -> bool
176
180
  def file_updated?(change, path)
177
181
  case change[:type]
178
182
  when Constant::FileChangeType::CREATED
@@ -201,7 +205,7 @@ module RubyLsp
201
205
  false
202
206
  end
203
207
 
204
- sig { void }
208
+ #: -> void
205
209
  def run_gem_rbi_check
206
210
  gem_rbi_check = RunGemRbiCheck.new(T.must(@global_state).workspace_path)
207
211
  gem_rbi_check.run
@@ -13,15 +13,15 @@ module RubyLsp
13
13
  attr_reader :stderr
14
14
  attr_reader :status
15
15
 
16
- sig { params(project_path: String).void }
16
+ #: (String project_path) -> void
17
17
  def initialize(project_path)
18
18
  @project_path = project_path
19
- @stdout = T.let("", String)
20
- @stderr = T.let("", String)
21
- @status = T.let(nil, T.nilable(Process::Status))
19
+ @stdout = "" #: String
20
+ @stderr = "" #: String
21
+ @status = nil #: Process::Status?
22
22
  end
23
23
 
24
- sig { void }
24
+ #: -> void
25
25
  def run
26
26
  return log_message("Not a git repository") unless git_repo?
27
27
 
@@ -36,35 +36,35 @@ module RubyLsp
36
36
 
37
37
  attr_reader :project_path
38
38
 
39
- sig { returns(T.nilable(T::Boolean)) }
39
+ #: -> bool?
40
40
  def git_repo?
41
41
  _, status = Open3.capture2e("git", "rev-parse", "--is-inside-work-tree", chdir: project_path)
42
42
  status.success?
43
43
  end
44
44
 
45
- sig { returns(T::Boolean) }
45
+ #: -> bool
46
46
  def lockfile_changed?
47
47
  !lockfile_diff.empty?
48
48
  end
49
49
 
50
- sig { returns(Pathname) }
50
+ #: -> Pathname
51
51
  def lockfile
52
- @lockfile ||= T.let(Pathname(project_path).join("Gemfile.lock"), T.nilable(Pathname))
52
+ @lockfile ||= Pathname(project_path).join("Gemfile.lock") #: Pathname?
53
53
  end
54
54
 
55
- sig { returns(String) }
55
+ #: -> String
56
56
  def lockfile_diff
57
- @lockfile_diff ||= T.let(read_lockfile_diff, T.nilable(String))
57
+ @lockfile_diff ||= read_lockfile_diff #: String?
58
58
  end
59
59
 
60
- sig { returns(String) }
60
+ #: -> String
61
61
  def read_lockfile_diff
62
62
  return "" unless lockfile.exist?
63
63
 
64
64
  execute_in_project_path("git", "diff", lockfile.to_s).strip
65
65
  end
66
66
 
67
- sig { void }
67
+ #: -> void
68
68
  def generate_gem_rbis
69
69
  parser = Tapioca::LockfileDiffParser.new(@lockfile_diff)
70
70
  removed_gems = parser.removed_gems
@@ -78,7 +78,7 @@ module RubyLsp
78
78
  end
79
79
  end
80
80
 
81
- sig { params(gems: T::Array[String]).void }
81
+ #: (Array[String] gems) -> void
82
82
  def execute_tapioca_gem_command(gems)
83
83
  Bundler.with_unbundled_env do
84
84
  stdout, stderr, status = T.unsafe(Open3).capture3(
@@ -97,7 +97,7 @@ module RubyLsp
97
97
  end
98
98
  end
99
99
 
100
- sig { params(gems: T::Array[String]).void }
100
+ #: (Array[String] gems) -> void
101
101
  def remove_rbis(gems)
102
102
  files = Dir.glob(
103
103
  "sorbet/rbi/gems/{#{gems.join(",")}}@*.rbi",
@@ -106,7 +106,7 @@ module RubyLsp
106
106
  delete_files(files, "Removed RBIs for")
107
107
  end
108
108
 
109
- sig { void }
109
+ #: -> void
110
110
  def cleanup_orphaned_rbis
111
111
  untracked_files = git_ls_gem_rbis("--others", "--exclude-standard")
112
112
  deleted_files = git_ls_gem_rbis("--deleted")
@@ -115,7 +115,7 @@ module RubyLsp
115
115
  restore_files(deleted_files, "Restored deleted RBIs")
116
116
  end
117
117
 
118
- sig { params(flags: T.untyped).returns(T::Array[String]) }
118
+ #: (*untyped flags) -> Array[String]
119
119
  def git_ls_gem_rbis(*flags)
120
120
  flags = T.unsafe(["git", "ls-files", *flags, "sorbet/rbi/gems/"])
121
121
 
@@ -124,20 +124,20 @@ module RubyLsp
124
124
  .map(&:strip)
125
125
  end
126
126
 
127
- sig { params(files: T::Array[String], message: String).void }
127
+ #: (Array[String] files, String message) -> void
128
128
  def delete_files(files, message)
129
129
  files_to_remove = files.map { |file| File.join(project_path, file) }
130
130
  FileUtils.rm(files_to_remove)
131
131
  log_message("#{message}: #{files.join(", ")}") unless files.empty?
132
132
  end
133
133
 
134
- sig { params(files: T::Array[String], message: String).void }
134
+ #: (Array[String] files, String message) -> void
135
135
  def restore_files(files, message)
136
136
  execute_in_project_path("git", "checkout", "--pathspec-from-file=-", stdin: files.join("\n"))
137
137
  log_message("#{message}: #{files.join(", ")}") unless files.empty?
138
138
  end
139
139
 
140
- sig { params(message: String).void }
140
+ #: (String message) -> void
141
141
  def log_message(message)
142
142
  @stdout += "#{message}\n"
143
143
  end
@@ -12,13 +12,13 @@ module Tapioca
12
12
 
13
13
  requires_ancestor { ::Bundler::Dependency }
14
14
 
15
- @exclude = T.let([], T::Array[String])
16
- @enabled = T.let(false, T::Boolean)
15
+ @exclude = [] #: Array[String]
16
+ @enabled = false #: bool
17
17
 
18
18
  class << self
19
19
  extend T::Sig
20
20
 
21
- sig { params(name: T.untyped).returns(T::Boolean) }
21
+ #: (untyped name) -> bool
22
22
  def excluded?(name)
23
23
  @exclude.include?(name)
24
24
  end
@@ -27,12 +27,7 @@ module Tapioca
27
27
  @enabled
28
28
  end
29
29
 
30
- sig do
31
- type_parameters(:Result).params(
32
- exclude: T::Array[String],
33
- blk: T.proc.returns(T.type_parameter(:Result)),
34
- ).returns(T.type_parameter(:Result))
35
- end
30
+ #: [Result] (exclude: Array[String]) { -> Result } -> Result
36
31
  def override_require_false(exclude:, &blk)
37
32
  @enabled = true
38
33
  @exclude = exclude
@@ -42,7 +37,7 @@ module Tapioca
42
37
  end
43
38
  end
44
39
 
45
- sig { returns(T.untyped).checked(:never) }
40
+ #: -> untyped
46
41
  def autorequire
47
42
  value = super
48
43
 
@@ -9,28 +9,7 @@ module Tapioca
9
9
 
10
10
  abstract!
11
11
 
12
- sig do
13
- params(
14
- requested_constants: T::Array[String],
15
- requested_paths: T::Array[Pathname],
16
- outpath: Pathname,
17
- only: T::Array[String],
18
- exclude: T::Array[String],
19
- file_header: T::Boolean,
20
- tapioca_path: String,
21
- skip_constant: T::Array[String],
22
- quiet: T::Boolean,
23
- verbose: T::Boolean,
24
- number_of_workers: T.nilable(Integer),
25
- auto_strictness: T::Boolean,
26
- gem_dir: String,
27
- rbi_formatter: RBIFormatter,
28
- app_root: String,
29
- halt_upon_load_error: T::Boolean,
30
- compiler_options: T::Hash[String, T.untyped],
31
- lsp_addon: T::Boolean,
32
- ).void
33
- end
12
+ #: (requested_constants: Array[String], requested_paths: Array[Pathname], outpath: Pathname, only: Array[String], exclude: Array[String], file_header: bool, tapioca_path: String, ?skip_constant: Array[String], ?quiet: bool, ?verbose: bool, ?number_of_workers: Integer?, ?auto_strictness: bool, ?gem_dir: String, ?rbi_formatter: RBIFormatter, ?app_root: String, ?halt_upon_load_error: bool, ?compiler_options: Hash[String, untyped], ?lsp_addon: bool) -> void
34
13
  def initialize(
35
14
  requested_constants:,
36
15
  requested_paths:,
@@ -75,7 +54,7 @@ module Tapioca
75
54
 
76
55
  private
77
56
 
78
- sig { params(outpath: Pathname, quiet: T::Boolean).returns(T::Set[Pathname]) }
57
+ #: (Pathname outpath, quiet: bool) -> Set[Pathname]
79
58
  def generate_dsl_rbi_files(outpath, quiet:)
80
59
  if @lsp_addon
81
60
  pipeline.active_compilers.each(&:reset_state)
@@ -103,20 +82,17 @@ module Tapioca
103
82
  files_to_purge
104
83
  end
105
84
 
106
- sig { returns(T::Array[String]) }
85
+ #: -> Array[String]
107
86
  def all_requested_constants
108
- @all_requested_constants ||= T.let(
109
- @requested_constants + constants_from_requested_paths,
110
- T.nilable(T::Array[String]),
111
- )
87
+ @all_requested_constants ||= @requested_constants + constants_from_requested_paths #: Array[String]?
112
88
  end
113
89
 
114
- sig { returns(Tapioca::Dsl::Pipeline) }
90
+ #: -> Tapioca::Dsl::Pipeline
115
91
  def pipeline
116
- @pipeline ||= T.let(create_pipeline, T.nilable(Tapioca::Dsl::Pipeline))
92
+ @pipeline ||= create_pipeline #: Tapioca::Dsl::Pipeline?
117
93
  end
118
94
 
119
- sig { void }
95
+ #: -> void
120
96
  def load_application
121
97
  # Loaded ahead of time when using the add-on to avoid reloading multiple times
122
98
  return if @lsp_addon
@@ -129,7 +105,7 @@ module Tapioca
129
105
  )
130
106
  end
131
107
 
132
- sig { returns(Tapioca::Dsl::Pipeline) }
108
+ #: -> Tapioca::Dsl::Pipeline
133
109
  def create_pipeline
134
110
  error_handler = if @lsp_addon
135
111
  ->(error) {
@@ -154,7 +130,7 @@ module Tapioca
154
130
  )
155
131
  end
156
132
 
157
- sig { params(requested_constants: T::Array[String], path: Pathname).returns(T::Set[Pathname]) }
133
+ #: (Array[String] requested_constants, ?path: Pathname) -> Set[Pathname]
158
134
  def existing_rbi_filenames(requested_constants, path: @outpath)
159
135
  filenames = if requested_constants.empty?
160
136
  Pathname.glob(path / "**/*.rbi")
@@ -168,7 +144,7 @@ module Tapioca
168
144
  filenames.to_set
169
145
  end
170
146
 
171
- sig { params(constant_names: T::Array[String], ignore_missing: T::Boolean).returns(T::Array[Module]) }
147
+ #: (Array[String] constant_names, ?ignore_missing: bool) -> Array[Module]
172
148
  def constantize(constant_names, ignore_missing: false)
173
149
  constant_map = constant_names.to_h do |name|
174
150
  [name, Object.const_get(name)]
@@ -193,7 +169,7 @@ module Tapioca
193
169
  .grep(Module)
194
170
  end
195
171
 
196
- sig { params(compiler_names: T::Array[String]).returns(T::Array[T.class_of(Tapioca::Dsl::Compiler)]) }
172
+ #: (Array[String] compiler_names) -> Array[singleton(Tapioca::Dsl::Compiler)]
197
173
  def constantize_compilers(compiler_names)
198
174
  compiler_map = compiler_names.to_h do |name|
199
175
  [name, resolve(name)]
@@ -213,7 +189,7 @@ module Tapioca
213
189
  T.cast(compiler_map.values, T::Array[T.class_of(Tapioca::Dsl::Compiler)])
214
190
  end
215
191
 
216
- sig { params(name: String).returns(T.nilable(T.class_of(Tapioca::Dsl::Compiler))) }
192
+ #: (String name) -> singleton(Tapioca::Dsl::Compiler)?
217
193
  def resolve(name)
218
194
  # Try to find built-in tapioca compiler first, then globally defined compiler.
219
195
  potentials = Tapioca::Dsl::Compilers::NAMESPACES.map do |namespace|
@@ -226,14 +202,7 @@ module Tapioca
226
202
  potentials.compact.first
227
203
  end
228
204
 
229
- sig do
230
- params(
231
- constant_name: String,
232
- rbi: RBI::File,
233
- outpath: Pathname,
234
- quiet: T::Boolean,
235
- ).returns(T.nilable(Pathname))
236
- end
205
+ #: (String constant_name, RBI::File rbi, ?outpath: Pathname, ?quiet: bool) -> Pathname?
237
206
  def compile_dsl_rbi(constant_name, rbi, outpath: @outpath, quiet: false)
238
207
  return if rbi.empty?
239
208
 
@@ -251,7 +220,7 @@ module Tapioca
251
220
  filename
252
221
  end
253
222
 
254
- sig { params(dir: Pathname).void }
223
+ #: (Pathname dir) -> void
255
224
  def perform_dsl_verification(dir)
256
225
  diff = verify_dsl_rbi(tmp_dir: dir)
257
226
 
@@ -260,7 +229,7 @@ module Tapioca
260
229
  FileUtils.remove_entry(dir)
261
230
  end
262
231
 
263
- sig { params(files: T::Set[Pathname]).void }
232
+ #: (Set[Pathname] files) -> void
264
233
  def purge_stale_dsl_rbi_files(files)
265
234
  if files.any?
266
235
  say("Removing stale RBI files...")
@@ -272,12 +241,12 @@ module Tapioca
272
241
  end
273
242
  end
274
243
 
275
- sig { params(constant_name: String).returns(Pathname) }
244
+ #: (String constant_name) -> Pathname
276
245
  def dsl_rbi_filename(constant_name)
277
246
  @outpath / "#{underscore(constant_name)}.rbi"
278
247
  end
279
248
 
280
- sig { params(tmp_dir: Pathname).returns(T::Hash[String, Symbol]) }
249
+ #: (tmp_dir: Pathname) -> Hash[String, Symbol]
281
250
  def verify_dsl_rbi(tmp_dir:)
282
251
  diff = {}
283
252
 
@@ -309,7 +278,7 @@ module Tapioca
309
278
  diff
310
279
  end
311
280
 
312
- sig { params(cause: Symbol, files: T::Array[String]).returns(String) }
281
+ #: (Symbol cause, Array[String] files) -> String
313
282
  def build_error_for_files(cause, files)
314
283
  filenames = files.map do |file|
315
284
  @outpath / file
@@ -318,7 +287,7 @@ module Tapioca
318
287
  " File(s) #{cause}:\n - #{filenames}"
319
288
  end
320
289
 
321
- sig { params(diff: T::Hash[String, Symbol], command: Symbol).void }
290
+ #: (Hash[String, Symbol] diff, Symbol command) -> void
322
291
  def report_diff_and_exit_if_out_of_date(diff, command)
323
292
  if diff.empty?
324
293
  say("Nothing to do, all RBIs are up-to-date.")
@@ -340,14 +309,14 @@ module Tapioca
340
309
  end
341
310
  end
342
311
 
343
- sig { params(path: Pathname).returns(T::Array[Pathname]) }
312
+ #: (Pathname path) -> Array[Pathname]
344
313
  def rbi_files_in(path)
345
314
  Pathname.glob(path / "**/*.rbi").map do |file|
346
315
  file.relative_path_from(path)
347
316
  end.sort
348
317
  end
349
318
 
350
- sig { params(class_name: String).returns(String) }
319
+ #: (String class_name) -> String
351
320
  def underscore(class_name)
352
321
  return class_name unless /[A-Z-]|::/.match?(class_name)
353
322
 
@@ -359,22 +328,20 @@ module Tapioca
359
328
  word
360
329
  end
361
330
 
362
- sig { params(constant: String).returns(String) }
331
+ #: (String constant) -> String
363
332
  def rbi_filename_for(constant)
364
333
  underscore(constant) + ".rbi"
365
334
  end
366
335
 
367
- sig { params(constant: String).returns(String) }
336
+ #: (String constant) -> String
368
337
  def generate_command_for(constant)
369
338
  default_command(:dsl, constant)
370
339
  end
371
340
 
372
- sig { returns(T::Array[String]) }
341
+ #: -> Array[String]
373
342
  def constants_from_requested_paths
374
- @constants_from_requested_paths ||= T.let(
375
- Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a,
376
- T.nilable(T::Array[String]),
377
- )
343
+ @constants_from_requested_paths ||=
344
+ Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a #: Array[String]?
378
345
  end
379
346
  end
380
347
  end
@@ -9,27 +9,7 @@ module Tapioca
9
9
 
10
10
  abstract!
11
11
 
12
- sig do
13
- params(
14
- gem_names: T::Array[String],
15
- exclude: T::Array[String],
16
- include_dependencies: T::Boolean,
17
- prerequire: T.nilable(String),
18
- postrequire: String,
19
- typed_overrides: T::Hash[String, String],
20
- outpath: Pathname,
21
- file_header: T::Boolean,
22
- include_doc: T::Boolean,
23
- include_loc: T::Boolean,
24
- include_exported_rbis: T::Boolean,
25
- number_of_workers: T.nilable(Integer),
26
- auto_strictness: T::Boolean,
27
- dsl_dir: String,
28
- rbi_formatter: RBIFormatter,
29
- halt_upon_load_error: T::Boolean,
30
- lsp_addon: T.nilable(T::Boolean),
31
- ).void
32
- end
12
+ #: (gem_names: Array[String], exclude: Array[String], include_dependencies: bool, prerequire: String?, postrequire: String, typed_overrides: Hash[String, String], outpath: Pathname, file_header: bool, include_doc: bool, include_loc: bool, include_exported_rbis: bool, ?number_of_workers: Integer?, ?auto_strictness: bool, ?dsl_dir: String, ?rbi_formatter: RBIFormatter, ?halt_upon_load_error: bool, ?lsp_addon: bool?) -> void
33
13
  def initialize(
34
14
  gem_names:,
35
15
  exclude:,
@@ -65,18 +45,18 @@ module Tapioca
65
45
 
66
46
  super()
67
47
 
68
- @bundle = T.let(Gemfile.new(exclude), Gemfile)
69
- @existing_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
70
- @expected_rbis = T.let(nil, T.nilable(T::Hash[String, String]))
71
- @include_doc = T.let(include_doc, T::Boolean)
72
- @include_loc = T.let(include_loc, T::Boolean)
48
+ @bundle = Gemfile.new(exclude) #: Gemfile
49
+ @existing_rbis = nil #: Hash[String, String]?
50
+ @expected_rbis = nil #: Hash[String, String]?
51
+ @include_doc = include_doc #: bool
52
+ @include_loc = include_loc #: bool
73
53
  @include_exported_rbis = include_exported_rbis
74
54
  @halt_upon_load_error = halt_upon_load_error
75
55
  end
76
56
 
77
57
  private
78
58
 
79
- sig { params(gem: Gemfile::GemSpec).void }
59
+ #: (Gemfile::GemSpec gem) -> void
80
60
  def compile_gem_rbi(gem)
81
61
  gem_name = set_color(gem.name, :yellow, :bold)
82
62
 
@@ -116,12 +96,12 @@ module Tapioca
116
96
  end
117
97
  end
118
98
 
119
- sig { void }
99
+ #: -> void
120
100
  def perform_removals
121
101
  say("Removing RBI files of gems that have been removed:", [:blue, :bold])
122
102
  puts
123
103
 
124
- anything_done = T.let(false, T::Boolean)
104
+ anything_done = false #: bool
125
105
 
126
106
  gems = removed_rbis
127
107
 
@@ -143,12 +123,12 @@ module Tapioca
143
123
  anything_done
144
124
  end
145
125
 
146
- sig { void }
126
+ #: -> void
147
127
  def perform_additions
148
128
  say("Generating RBI files of gems that are added or updated:", [:blue, :bold])
149
129
  puts
150
130
 
151
- anything_done = T.let(false, T::Boolean)
131
+ anything_done = false #: bool
152
132
 
153
133
  gems = added_rbis
154
134
 
@@ -186,34 +166,34 @@ module Tapioca
186
166
  anything_done
187
167
  end
188
168
 
189
- sig { returns(T::Array[String]) }
169
+ #: -> Array[String]
190
170
  def removed_rbis
191
171
  (existing_rbis.keys - expected_rbis.keys).sort
192
172
  end
193
173
 
194
- sig { params(gem_name: String).returns(Pathname) }
174
+ #: (String gem_name) -> Pathname
195
175
  def existing_rbi(gem_name)
196
176
  gem_rbi_filename(gem_name, T.must(existing_rbis[gem_name]))
197
177
  end
198
178
 
199
- sig { returns(T::Array[String]) }
179
+ #: -> Array[String]
200
180
  def added_rbis
201
181
  expected_rbis.select do |name, value|
202
182
  existing_rbis[name] != value
203
183
  end.keys.sort
204
184
  end
205
185
 
206
- sig { params(gem_name: String).returns(Pathname) }
186
+ #: (String gem_name) -> Pathname
207
187
  def expected_rbi(gem_name)
208
188
  gem_rbi_filename(gem_name, T.must(expected_rbis[gem_name]))
209
189
  end
210
190
 
211
- sig { params(gem_name: String).returns(T::Boolean) }
191
+ #: (String gem_name) -> bool
212
192
  def gem_rbi_exists?(gem_name)
213
193
  existing_rbis.key?(gem_name)
214
194
  end
215
195
 
216
- sig { params(diff: T::Hash[String, Symbol], command: Symbol).void }
196
+ #: (Hash[String, Symbol] diff, Symbol command) -> void
217
197
  def report_diff_and_exit_if_out_of_date(diff, command)
218
198
  if diff.empty?
219
199
  say("Nothing to do, all RBIs are up-to-date.")
@@ -233,36 +213,36 @@ module Tapioca
233
213
  end
234
214
  end
235
215
 
236
- sig { params(old_filename: Pathname, new_filename: Pathname).void }
216
+ #: (Pathname old_filename, Pathname new_filename) -> void
237
217
  def move(old_filename, new_filename)
238
218
  say("-> Moving: #{old_filename} to #{new_filename}")
239
219
  old_filename.rename(new_filename.to_s)
240
220
  end
241
221
 
242
- sig { returns(T::Hash[String, String]) }
222
+ #: -> Hash[String, String]
243
223
  def existing_rbis
244
224
  @existing_rbis ||= Pathname.glob((@outpath / "*@*.rbi").to_s)
245
225
  .to_h { |f| T.cast(f.basename(".*").to_s.split("@", 2), [String, String]) }
246
226
  end
247
227
 
248
- sig { returns(T::Hash[String, String]) }
228
+ #: -> Hash[String, String]
249
229
  def expected_rbis
250
230
  @expected_rbis ||= @bundle.dependencies
251
231
  .reject { |gem| @exclude.include?(gem.name) }
252
232
  .to_h { |gem| [gem.name, gem.version.to_s] }
253
233
  end
254
234
 
255
- sig { params(gem_name: String, version: String).returns(Pathname) }
235
+ #: (String gem_name, String version) -> Pathname
256
236
  def gem_rbi_filename(gem_name, version)
257
237
  @outpath / "#{gem_name}@#{version}.rbi"
258
238
  end
259
239
 
260
- sig { params(cause: Symbol, files: T::Array[String]).returns(String) }
240
+ #: (Symbol cause, Array[String] files) -> String
261
241
  def build_error_for_files(cause, files)
262
242
  " File(s) #{cause}:\n - #{files.join("\n - ")}"
263
243
  end
264
244
 
265
- sig { params(gem: Gemfile::GemSpec, file: RBI::File).void }
245
+ #: (Gemfile::GemSpec gem, RBI::File file) -> void
266
246
  def merge_with_exported_rbi(gem, file)
267
247
  return file unless gem.export_rbi_files?
268
248