@@ -47,7 +47,9 @@ def activate(global_state, outgoing_queue)
47
47
@outgoing_queue << Notification . window_log_message ( "Activating Tapioca add-on v#{ version } " )
48
48
@rails_runner_client . register_server_addon ( File . expand_path ( "server_addon.rb" , __dir__ ) )
49
49
50
- generate_gem_rbis if git_repo? && lockfile_changed?
50
+ if git_repo?
51
+ lockfile_changed? ? generate_gem_rbis : cleanup_orphaned_rbis
52
+ end
51
53
rescue IncompatibleApiError
52
54
# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
53
55
# changes
@@ -154,6 +156,30 @@ def generate_gem_rbis
154
156
diff : T . must ( @lockfile_diff ) ,
155
157
)
156
158
end
159
+
160
+ sig { void }
161
+ def cleanup_orphaned_rbis
162
+ untracked_files = %x(git ls-files --others --exclude-standard sorbet/rbi/gems/) . lines . map ( &:strip )
163
+ deleted_files = %x(git ls-files --deleted sorbet/rbi/gems/) . lines . map ( &:strip )
164
+
165
+ untracked_files . each do |file |
166
+ File . delete ( file )
167
+
168
+ T . must ( @outgoing_queue ) << Notification . window_log_message (
169
+ "Deleted untracked RBI: #{ file } " ,
170
+ type : Constant ::MessageType ::INFO ,
171
+ )
172
+ end
173
+
174
+ deleted_files . each do |file |
175
+ %x(git checkout -- #{ file } )
176
+
177
+ T . must ( @outgoing_queue ) << Notification . window_log_message (
178
+ "Restored deleted RBI: #{ file } " ,
179
+ type : Constant ::MessageType ::INFO ,
180
+ )
181
+ end
182
+ end
157
183
end
158
184
end
159
185
end
0 commit comments