tapioca 0.16.10 → 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 +24 -20
  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 +36 -62
  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 +30 -58
  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 +5 -4
  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: 9b1ddf8615a19929d81d7662c300a28ee8d49d08d7ba984fdaa7644bf70d5dfb
4
- data.tar.gz: 4f2a79db13ce4a0e7614178d14423f5bd0fded127a6c5b6d0503bf7e2d73df7b
3
+ metadata.gz: aae584802448b64d85f5d3da609325b145bc698816d6564a09a45696aa338901
4
+ data.tar.gz: d2673e9edcb91ba6fd7253a7bbd1b83505a4f2bb79ecde5159327f8775187d33
5
5
  SHA512:
6
- metadata.gz: a03a8d4866b5faf46af5cea289d4d7087540d58ee5b4eb759cb30cc23c540cc037c03bdd937cdf73e3f955407b2a47865600297fafe6b495e786e64b99f38942
7
- data.tar.gz: 3a5bf689b47f198577480420b9ea0c1294a6c2170df0f5ba9a6e170a8f60b3d2de73827053f4b33002f1a6ae9f2501a73b70590c250c8306b86d52b244aa7f36
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
- "0.1.2"
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,17 +105,24 @@ module Tapioca
129
105
  )
130
106
  end
131
107
 
132
- sig { returns(Tapioca::Dsl::Pipeline) }
108
+ #: -> Tapioca::Dsl::Pipeline
133
109
  def create_pipeline
110
+ error_handler = if @lsp_addon
111
+ ->(error) {
112
+ say(error)
113
+ }
114
+ else
115
+ ->(error) {
116
+ say_error(error, :bold, :red)
117
+ }
118
+ end
134
119
  Tapioca::Dsl::Pipeline.new(
135
120
  requested_constants:
136
121
  constantize(@requested_constants) + constantize(constants_from_requested_paths, ignore_missing: true),
137
122
  requested_paths: @requested_paths,
138
123
  requested_compilers: constantize_compilers(@only),
139
124
  excluded_compilers: constantize_compilers(@exclude),
140
- error_handler: ->(error) {
141
- say_error(error, :bold, :red)
142
- },
125
+ error_handler: error_handler,
143
126
  skipped_constants: constantize(@skip_constant, ignore_missing: true),
144
127
  number_of_workers: @number_of_workers,
145
128
  compiler_options: @compiler_options,
@@ -147,7 +130,7 @@ module Tapioca
147
130
  )
148
131
  end
149
132
 
150
- sig { params(requested_constants: T::Array[String], path: Pathname).returns(T::Set[Pathname]) }
133
+ #: (Array[String] requested_constants, ?path: Pathname) -> Set[Pathname]
151
134
  def existing_rbi_filenames(requested_constants, path: @outpath)
152
135
  filenames = if requested_constants.empty?
153
136
  Pathname.glob(path / "**/*.rbi")
@@ -161,7 +144,7 @@ module Tapioca
161
144
  filenames.to_set
162
145
  end
163
146
 
164
- 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]
165
148
  def constantize(constant_names, ignore_missing: false)
166
149
  constant_map = constant_names.to_h do |name|
167
150
  [name, Object.const_get(name)]
@@ -186,7 +169,7 @@ module Tapioca
186
169
  .grep(Module)
187
170
  end
188
171
 
189
- 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)]
190
173
  def constantize_compilers(compiler_names)
191
174
  compiler_map = compiler_names.to_h do |name|
192
175
  [name, resolve(name)]
@@ -206,7 +189,7 @@ module Tapioca
206
189
  T.cast(compiler_map.values, T::Array[T.class_of(Tapioca::Dsl::Compiler)])
207
190
  end
208
191
 
209
- sig { params(name: String).returns(T.nilable(T.class_of(Tapioca::Dsl::Compiler))) }
192
+ #: (String name) -> singleton(Tapioca::Dsl::Compiler)?
210
193
  def resolve(name)
211
194
  # Try to find built-in tapioca compiler first, then globally defined compiler.
212
195
  potentials = Tapioca::Dsl::Compilers::NAMESPACES.map do |namespace|
@@ -219,14 +202,7 @@ module Tapioca
219
202
  potentials.compact.first
220
203
  end
221
204
 
222
- sig do
223
- params(
224
- constant_name: String,
225
- rbi: RBI::File,
226
- outpath: Pathname,
227
- quiet: T::Boolean,
228
- ).returns(T.nilable(Pathname))
229
- end
205
+ #: (String constant_name, RBI::File rbi, ?outpath: Pathname, ?quiet: bool) -> Pathname?
230
206
  def compile_dsl_rbi(constant_name, rbi, outpath: @outpath, quiet: false)
231
207
  return if rbi.empty?
232
208
 
@@ -244,7 +220,7 @@ module Tapioca
244
220
  filename
245
221
  end
246
222
 
247
- sig { params(dir: Pathname).void }
223
+ #: (Pathname dir) -> void
248
224
  def perform_dsl_verification(dir)
249
225
  diff = verify_dsl_rbi(tmp_dir: dir)
250
226
 
@@ -253,7 +229,7 @@ module Tapioca
253
229
  FileUtils.remove_entry(dir)
254
230
  end
255
231
 
256
- sig { params(files: T::Set[Pathname]).void }
232
+ #: (Set[Pathname] files) -> void
257
233
  def purge_stale_dsl_rbi_files(files)
258
234
  if files.any?
259
235
  say("Removing stale RBI files...")
@@ -265,12 +241,12 @@ module Tapioca
265
241
  end
266
242
  end
267
243
 
268
- sig { params(constant_name: String).returns(Pathname) }
244
+ #: (String constant_name) -> Pathname
269
245
  def dsl_rbi_filename(constant_name)
270
246
  @outpath / "#{underscore(constant_name)}.rbi"
271
247
  end
272
248
 
273
- sig { params(tmp_dir: Pathname).returns(T::Hash[String, Symbol]) }
249
+ #: (tmp_dir: Pathname) -> Hash[String, Symbol]
274
250
  def verify_dsl_rbi(tmp_dir:)
275
251
  diff = {}
276
252
 
@@ -302,7 +278,7 @@ module Tapioca
302
278
  diff
303
279
  end
304
280
 
305
- sig { params(cause: Symbol, files: T::Array[String]).returns(String) }
281
+ #: (Symbol cause, Array[String] files) -> String
306
282
  def build_error_for_files(cause, files)
307
283
  filenames = files.map do |file|
308
284
  @outpath / file
@@ -311,7 +287,7 @@ module Tapioca
311
287
  " File(s) #{cause}:\n - #{filenames}"
312
288
  end
313
289
 
314
- sig { params(diff: T::Hash[String, Symbol], command: Symbol).void }
290
+ #: (Hash[String, Symbol] diff, Symbol command) -> void
315
291
  def report_diff_and_exit_if_out_of_date(diff, command)
316
292
  if diff.empty?
317
293
  say("Nothing to do, all RBIs are up-to-date.")
@@ -333,14 +309,14 @@ module Tapioca
333
309
  end
334
310
  end
335
311
 
336
- sig { params(path: Pathname).returns(T::Array[Pathname]) }
312
+ #: (Pathname path) -> Array[Pathname]
337
313
  def rbi_files_in(path)
338
314
  Pathname.glob(path / "**/*.rbi").map do |file|
339
315
  file.relative_path_from(path)
340
316
  end.sort
341
317
  end
342
318
 
343
- sig { params(class_name: String).returns(String) }
319
+ #: (String class_name) -> String
344
320
  def underscore(class_name)
345
321
  return class_name unless /[A-Z-]|::/.match?(class_name)
346
322
 
@@ -352,22 +328,20 @@ module Tapioca
352
328
  word
353
329
  end
354
330
 
355
- sig { params(constant: String).returns(String) }
331
+ #: (String constant) -> String
356
332
  def rbi_filename_for(constant)
357
333
  underscore(constant) + ".rbi"
358
334
  end
359
335
 
360
- sig { params(constant: String).returns(String) }
336
+ #: (String constant) -> String
361
337
  def generate_command_for(constant)
362
338
  default_command(:dsl, constant)
363
339
  end
364
340
 
365
- sig { returns(T::Array[String]) }
341
+ #: -> Array[String]
366
342
  def constants_from_requested_paths
367
- @constants_from_requested_paths ||= T.let(
368
- Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a,
369
- T.nilable(T::Array[String]),
370
- )
343
+ @constants_from_requested_paths ||=
344
+ Static::SymbolLoader.symbols_from_paths(@requested_paths).to_a #: Array[String]?
371
345
  end
372
346
  end
373
347
  end