From 351a2fb000a7c69a3f8af7edab0584b9706cc49b Mon Sep 17 00:00:00 2001 From: Alex Rocha Date: Wed, 20 Nov 2024 13:26:39 -0800 Subject: [PATCH] Skip gem RBI regeneration when lockfile clean Only regenerate RBIs when Gemfile.lock has uncommitted changes in git, which targets manual bundle updates. This improves performance by avoiding unnecessary regeneration during normal git operations. --- lib/ruby_lsp/tapioca/addon.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ruby_lsp/tapioca/addon.rb b/lib/ruby_lsp/tapioca/addon.rb index 6cdaca0c68..49a39b6593 100644 --- a/lib/ruby_lsp/tapioca/addon.rb +++ b/lib/ruby_lsp/tapioca/addon.rb @@ -47,7 +47,7 @@ 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__)) - check_gemfile_changes + handle_gemfile_changes rescue IncompatibleApiError # The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking # changes @@ -114,7 +114,17 @@ def workspace_did_change_watched_files(changes) private sig { void } - def check_gemfile_changes + def handle_gemfile_changes + return unless File.exist?(".git") + + gemfile_status = %x(git status --porcelain Gemfile.lock).strip + return if gemfile_status.empty? + + process_gemfile_changes + end + + sig { returns(T.nilable(Integer)) } + def process_gemfile_changes current_lockfile = File.read("Gemfile.lock") snapshot_lockfile = File.read(GEMFILE_LOCK_SNAPSHOT) if File.exist?(GEMFILE_LOCK_SNAPSHOT)