Skip to content

Commit

Permalink
Cleanup orphaned RBIs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrocha committed Nov 27, 2024
1 parent e843209 commit 21df7e6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/ruby_lsp/tapioca/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 @@ -154,6 +156,22 @@ def generate_gem_rbis
diff: T.must(@lockfile_diff),
)
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)
$stderr.puts "Deleted untracked RBI: #{file}"
end

deleted_files.each do |file|
%x(git checkout -- #{file})
$stderr.puts "Restored deleted RBI: #{file}"
end
end
end
end
end

0 comments on commit 21df7e6

Please sign in to comment.