@@ -20,6 +20,7 @@ class Addon < ::RubyLsp::Addon
20
20
extend T ::Sig
21
21
22
22
GEMFILE_LOCK_SNAPSHOT = "tmp/tapioca/.gemfile_lock_snapshot"
23
+ GIT_OPERATION_THRESHOLD = 15.0 # seconds
23
24
24
25
sig { void }
25
26
def initialize
@@ -117,23 +118,32 @@ def workspace_did_change_watched_files(changes)
117
118
def handle_gemfile_changes
118
119
return unless File . exist? ( ".git" ) && File . exist? ( ".ruby-lsp/shutdown-timestamp" )
119
120
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?
121
+ git_timestamp = fetch_last_git_operation_time
122
+ return unless git_timestamp
127
123
128
124
ruby_lsp_stop_time = Time . iso8601 ( File . read ( ".ruby-lsp/shutdown-timestamp" ) )
129
125
130
126
$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
127
+ $stderr. puts ( "git_timestamp : #{ git_timestamp } " ) # TODO: Remove
132
128
133
129
# If the Ruby LSP was stopped shortly after the last git checkout/pull operation, we don't need to regenerate
134
130
# 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
131
+ return if ( ruby_lsp_stop_time - git_timestamp ) <= GIT_OPERATION_THRESHOLD
132
+
133
+ process_gemfile_changes
134
+ end
135
+
136
+ sig { returns ( T . nilable ( Time ) ) }
137
+ def fetch_last_git_operation_time
138
+ git_reflog_output = %x(git reflog --date=iso | grep -E "checkout|pull" | head -n 1) . strip
139
+ return if git_reflog_output . empty?
140
+
141
+ timestamp_string = T . must ( git_reflog_output . match ( /\{ (.*)\} / ) ) [ 1 ]
142
+ Time . iso8601 ( T . must ( timestamp_string ) . sub ( " " , "T" ) . delete ( " " ) )
143
+ end
136
144
145
+ sig { returns ( T . nilable ( Integer ) ) }
146
+ def process_gemfile_changes
137
147
current_lockfile = File . read ( "Gemfile.lock" )
138
148
snapshot_lockfile = File . read ( GEMFILE_LOCK_SNAPSHOT ) if File . exist? ( GEMFILE_LOCK_SNAPSHOT )
139
149
0 commit comments