Skip to content

Commit 0f5138c

Browse files
committed
WIP Skip RBI regeneration after git operations
If the Ruby LSP was stopped shortly after the last git checkout/pull operation, we don't need to regenerate RBIs since any Gemfile.lock changes were likely from version control, not from bundle install
1 parent 77d4f16 commit 0f5138c

File tree

5 files changed

+1001
-668
lines changed

5 files changed

+1001
-668
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ gem "irb"
1515
gem "rubocop-shopify"
1616
gem "rubocop-sorbet", ">= 0.4.1"
1717
gem "rubocop-rspec"
18-
gem "ruby-lsp", ">= 0.19.1"
18+
gem "ruby-lsp", ">= 0.19.1", git: "https://github.com/Shopify/ruby-lsp.git", branch: "ar/shutdown-timestamp"
1919
gem "ruby-lsp-rails", ">= 0.3.18"
2020

2121
group :deployment, :development do

Gemfile.lock

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
GIT
2+
remote: https://github.com/Shopify/ruby-lsp.git
3+
revision: 06602886c19cad7f44101b143bdbba9a5fc40a0d
4+
branch: ar/shutdown-timestamp
5+
specs:
6+
ruby-lsp (0.21.4)
7+
language_server-protocol (~> 3.17.0)
8+
prism (>= 1.2, < 2.0)
9+
rbs (>= 3, < 4)
10+
sorbet-runtime (>= 0.5.10782)
11+
112
GIT
213
remote: https://github.com/csfrancis/cityhash.git
314
revision: 3cfc7d01f333c01811d5e834f1495eaa29f87c36
@@ -303,13 +314,8 @@ GEM
303314
rubocop (~> 1.51)
304315
rubocop-sorbet (0.8.6)
305316
rubocop (>= 1)
306-
ruby-lsp (0.19.1)
307-
language_server-protocol (~> 3.17.0)
308-
prism (>= 1.1, < 2.0)
309-
rbs (>= 3, < 4)
310-
sorbet-runtime (>= 0.5.10782)
311-
ruby-lsp-rails (0.3.18)
312-
ruby-lsp (>= 0.19.0, < 0.20.0)
317+
ruby-lsp-rails (0.3.25)
318+
ruby-lsp (>= 0.21.2, < 0.22.0)
313319
ruby-progressbar (1.13.0)
314320
shopify-money (3.0.0)
315321
sidekiq (7.3.2)
@@ -394,7 +400,7 @@ DEPENDENCIES
394400
rubocop-rspec
395401
rubocop-shopify
396402
rubocop-sorbet (>= 0.4.1)
397-
ruby-lsp (>= 0.19.1)
403+
ruby-lsp (>= 0.19.1)!
398404
ruby-lsp-rails (>= 0.3.18)
399405
shopify-money
400406
sidekiq

lib/ruby_lsp/tapioca/addon.rb

+20-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def activate(global_state, outgoing_queue)
4747
outgoing_queue << Notification.window_log_message("Activating Tapioca add-on v#{version}")
4848
@rails_runner_client.register_server_addon(File.expand_path("server_addon.rb", __dir__))
4949

50-
check_gemfile_changes
50+
handle_gemfile_changes
5151
rescue IncompatibleApiError
5252
# The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
5353
# changes
@@ -114,14 +114,25 @@ def workspace_did_change_watched_files(changes)
114114
private
115115

116116
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
125136

126137
current_lockfile = File.read("Gemfile.lock")
127138
snapshot_lockfile = File.read(GEMFILE_LOCK_SNAPSHOT) if File.exist?(GEMFILE_LOCK_SNAPSHOT)

0 commit comments

Comments
 (0)