@@ -47,7 +47,7 @@ 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
- check_gemfile_changes
50
+ handle_gemfile_changes
51
51
rescue IncompatibleApiError
52
52
# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
53
53
# changes
@@ -114,14 +114,25 @@ def workspace_did_change_watched_files(changes)
114
114
private
115
115
116
116
sig { void }
117
- def check_gemfile_changes
118
- gemfile_mtime = File . mtime ( "Gemfile" )
119
- lockfile_mtime = File . mtime ( "Gemfile.lock" )
120
-
121
- # If Gemfile is more recent than Gemfile.lock, bundle install hasn't been run yet
122
- # If Gemfile.lock was modified less than 1 second after Gemfile, it's likely a version control system operation
123
- return if gemfile_mtime > lockfile_mtime
124
- return if ( lockfile_mtime - gemfile_mtime ) <= 1.0
117
+ def handle_gemfile_changes
118
+ return unless File . exist? ( ".git" ) && File . exist? ( ".ruby-lsp/shutdown-timestamp" )
119
+
120
+ git_reflog_output = %x(git reflog --date=iso | grep -E "checkout|pull" | head -n 1) . strip
121
+ return if git_reflog_output . empty?
122
+
123
+ timestamp_string = T . must ( git_reflog_output . match ( /\{ (.*)\} / ) ) [ 1 ]
124
+ last_git_operation_time = Time . iso8601 ( T . must ( timestamp_string ) . sub ( " " , "T" ) . delete ( " " ) )
125
+
126
+ return if last_git_operation_time . nil?
127
+
128
+ ruby_lsp_stop_time = Time . iso8601 ( File . read ( ".ruby-lsp/shutdown-timestamp" ) )
129
+
130
+ $stderr. puts ( "ruby_lsp_stop_time: #{ ruby_lsp_stop_time } " ) # TODO: Remove
131
+ $stderr. puts ( "last_git_operation_time: #{ last_git_operation_time } " ) # TODO: Remove
132
+
133
+ # If the Ruby LSP was stopped shortly after the last git checkout/pull operation, we don't need to regenerate
134
+ # RBIs since any Gemfile.lock changes were likely from version control, not from running bundle install
135
+ return if ( ruby_lsp_stop_time - last_git_operation_time ) <= 15.0
125
136
126
137
current_lockfile = File . read ( "Gemfile.lock" )
127
138
snapshot_lockfile = File . read ( GEMFILE_LOCK_SNAPSHOT ) if File . exist? ( GEMFILE_LOCK_SNAPSHOT )
0 commit comments