From 7d5cf1811b21131eed36235414188c9bb98a0180 Mon Sep 17 00:00:00 2001 From: Jane Lewis Date: Tue, 11 Jun 2024 11:50:01 -0700 Subject: [PATCH] `ruff server`: Improve error message when a command is run on an unavailable document (#11823) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes #11744. We now show a distinct popup message when we fail to get a document snapshot during command execution. This message more clearly communicates the issue to the user, instead of a generic "ruff encountered an error" message. ## Test Plan Try running `Fix all auto-fixable problems` on an incompatible file (for example: `settings.json`). You should see the following popup message: Screenshot 2024-06-11 at 11 47 16 AM --- .../src/server/api/requests/execute_command.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ruff_server/src/server/api/requests/execute_command.rs b/crates/ruff_server/src/server/api/requests/execute_command.rs index 570b16cba0..4f27b9e756 100644 --- a/crates/ruff_server/src/server/api/requests/execute_command.rs +++ b/crates/ruff_server/src/server/api/requests/execute_command.rs @@ -68,10 +68,11 @@ impl super::SyncRequestHandler for ExecuteCommand { let mut edit_tracker = WorkspaceEditTracker::new(session.resolved_client_capabilities()); for Argument { uri, version } in arguments { - let snapshot = session - .take_snapshot(uri.clone()) - .ok_or(anyhow::anyhow!("Document snapshot not available for {uri}",)) - .with_failure_code(ErrorCode::InternalError)?; + let Some(snapshot) = session.take_snapshot(uri.clone()) else { + tracing::error!("Document at {uri} could not be opened"); + show_err_msg!("Ruff does not recognize this file"); + return Ok(None); + }; match command { Command::FixAll => { let fixes = super::code_action_resolve::fix_all_edit(