Skip to content

Skip DSL generation on branch switch by detecting git HEAD changes#2525

Draft
KaanOzkan wants to merge 1 commit intomainfrom
ko/skip-dsl-on-branch-switch
Draft

Skip DSL generation on branch switch by detecting git HEAD changes#2525
KaanOzkan wants to merge 1 commit intomainfrom
ko/skip-dsl-on-branch-switch

Conversation

@KaanOzkan
Copy link
Contributor

Summary

When switching branches (especially in large repos like world), VS Code sends hundreds of didChangeWatchedFiles notifications. Previously, each notification triggered trigger_reload + DSL generation, causing:

  • Hundreds of parallel reload + DSL generation requests
  • Incorrect RBIs generated against stale server state
  • Valid RBI files deleted for constants that are temporarily unavailable

This PR detects branch switches by reading .git/HEAD on each file change event. If HEAD changed since the last check, we skip DSL generation entirely (only reload). Normal user edits don't change HEAD, so they continue to trigger DSL generation as before.

How it works

  • read_git_head reads .git/HEAD directly (no shelling out to git — just a file read)
  • git_head_changed? compares current HEAD to the last known value
  • On branch switch: reload fires but DSL generation is skipped
  • On normal file edit: HEAD unchanged, DSL generation proceeds as before

Testing

  • RED: Original code fires DSL generation during branch switch (1 DSL call)
  • GREEN: With fix, 0 DSL calls during branch switch
  • Simulated world branch switch (14,672 Ruby files, 147 batches): 318 server requests → 4 (reload only)
  • All 4 existing addon tests pass (normal edits still trigger DSL)

Related

When switching branches, VS Code sends hundreds of file change
notifications that trigger parallel reload + DSL generation requests.
This causes incorrect RBIs and deleted valid files due to stale server
state.

Detect branch switches by reading .git/HEAD on each file change event.
If HEAD changed since last check, skip DSL generation (only reload).
Normal user edits don't change HEAD, so they continue to trigger DSL
generation as before.

Fixes Shopify/team-ruby-dx#1429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant