Skip to content

Commit

Permalink
Cleanup orphaned RBIs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrocha committed Dec 18, 2024
1 parent 180f3a1 commit bd835cd
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/ruby_lsp/tapioca/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def activate(global_state, outgoing_queue)
@outgoing_queue << Notification.window_log_message("Activating Tapioca add-on v#{version}")
@rails_runner_client.register_server_addon(File.expand_path("server_addon.rb", __dir__))

generate_gem_rbis if git_repo? && lockfile_changed?
if git_repo?
lockfile_changed? ? generate_gem_rbis : cleanup_orphaned_rbis
end
rescue IncompatibleApiError
# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
# changes
Expand Down Expand Up @@ -182,6 +184,30 @@ def generate_gem_rbis
)
end
end

sig { void }
def cleanup_orphaned_rbis
untracked_files = %x(git ls-files --others --exclude-standard sorbet/rbi/gems/).lines.map(&:strip)
deleted_files = %x(git ls-files --deleted sorbet/rbi/gems/).lines.map(&:strip)

untracked_files.each do |file|
File.delete(file)

T.must(@outgoing_queue) << Notification.window_log_message(
"Deleted untracked RBI: #{file}",
type: Constant::MessageType::INFO,
)
end

deleted_files.each do |file|
%x(git checkout -- #{file})

T.must(@outgoing_queue) << Notification.window_log_message(
"Restored deleted RBI: #{file}",
type: Constant::MessageType::INFO,
)
end
end
end
end
end

0 comments on commit bd835cd

Please sign in to comment.