Skip to content

Commit ebfb33d

Browse files
committed
Cleanup orphaned RBIs
1 parent 01f65db commit ebfb33d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lib/ruby_lsp/tapioca/addon.rb

+27-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def activate(global_state, outgoing_queue)
4747
@outgoing_queue << Notification.window_log_message("Activating Tapioca add-on v#{version}")
4848
@rails_runner_client.register_server_addon(File.expand_path("server_addon.rb", __dir__))
4949

50-
generate_gem_rbis if git_repo? && lockfile_changed?
50+
if git_repo?
51+
lockfile_changed? ? generate_gem_rbis : cleanup_orphaned_rbis
52+
end
5153
rescue IncompatibleApiError
5254
# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
5355
# changes
@@ -154,6 +156,30 @@ def generate_gem_rbis
154156
diff: T.must(@lockfile_diff),
155157
)
156158
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
157183
end
158184
end
159185
end

0 commit comments

Comments
 (0)