From 42545b29a4e5fed4c341cc4477da442fdaaadaba Mon Sep 17 00:00:00 2001 From: Kaan Ozkan Date: Fri, 6 Mar 2026 15:28:35 -0500 Subject: [PATCH] Don't delete RBI files for missing constants in LSP addon mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/Shopify/team-ruby-dx/issues/1711 --- lib/tapioca/commands/abstract_dsl.rb | 11 ++++++++--- lib/tapioca/commands/dsl_generate.rb | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/tapioca/commands/abstract_dsl.rb b/lib/tapioca/commands/abstract_dsl.rb index 72320c46c..d177ea152 100644 --- a/lib/tapioca/commands/abstract_dsl.rb +++ b/lib/tapioca/commands/abstract_dsl.rb @@ -175,11 +175,16 @@ def constantize(constant_names, ignore_missing: false) unless unprocessable_constants.empty? || ignore_missing unprocessable_constants.each do |name, _| say("Error: Cannot find constant '#{name}'", :red) - filename = dsl_rbi_filename(name) - remove_file(filename) if File.file?(filename) + + unless @lsp_addon + filename = dsl_rbi_filename(name) + remove_file(filename) if File.file?(filename) + end end - raise Tapioca::Error, "" + unless @lsp_addon + raise Tapioca::Error, "" + end end processable_constants diff --git a/lib/tapioca/commands/dsl_generate.rb b/lib/tapioca/commands/dsl_generate.rb index 3114bebd6..433fa72ed 100644 --- a/lib/tapioca/commands/dsl_generate.rb +++ b/lib/tapioca/commands/dsl_generate.rb @@ -17,7 +17,7 @@ def execute rbi_files_to_purge = generate_dsl_rbi_files(@outpath, quiet: @quiet && !@verbose) say("") - purge_stale_dsl_rbi_files(rbi_files_to_purge) + purge_stale_dsl_rbi_files(rbi_files_to_purge) unless @lsp_addon say("Done", :green) if @auto_strictness && !@lsp_addon