Skip to content

Don't delete RBI files for missing constants in LSP addon mode#2526

Draft
KaanOzkan wants to merge 1 commit intomainfrom
ko/dont-delete-rbis-in-addon-mode
Draft

Don't delete RBI files for missing constants in LSP addon mode#2526
KaanOzkan wants to merge 1 commit intomainfrom
ko/dont-delete-rbis-in-addon-mode

Conversation

@KaanOzkan
Copy link
Contributor

Summary

When the LSP addon requests DSL generation for a constant that can't be found (e.g., due to a failed reload or a mid-edit syntax error), the existing code:

  1. Deletes the RBI file for the missing constant
  2. Raises an error that aborts DSL generation for all remaining constants
  3. Purges "stale" files — any RBI that existed before but wasn't regenerated gets deleted

This is wrong in addon mode. The constant may be temporarily unavailable (user is mid-edit, reload failed, server has stale state). Deleting the RBI means Sorbet loses type information until the next successful generation.

Changes

Two deletion paths are fixed:

  • abstract_dsl.rb (constantize): Skip deleting RBI and skip raising error when @lsp_addon is true
  • dsl_generate.rb (execute): Skip purge_stale_dsl_rbi_files when @lsp_addon is true

Testing

End-to-end test with a real Rails runner client:

  1. Generate valid RBI for NotifyUserJob
  2. Hide the job file to simulate it becoming unloadable (e.g., syntax error after save)
  3. Trigger reload + request DSL for the now-missing constant
  4. RED (main): RBI deleted
  5. GREEN (this branch): RBI preserved

All 4 existing addon tests pass.

Related

When the LSP addon requests DSL generation for a constant that can't be
found (e.g., due to a failed reload or mid-edit syntax error), the
existing code deletes the RBI file and raises an error. This is wrong in
addon mode — the constant may be temporarily unavailable and its RBI
should be preserved.

Skip both deletion paths in addon mode:
- constantize: don't delete RBI or raise for unprocessable constants
- dsl_generate: don't purge "stale" RBI files

Fixes Shopify/team-ruby-dx#1711
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