From 37366ac90779643a3e16cc9abae54004b7159e2c Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:56:01 -0300 Subject: [PATCH] assistant: Improve UI feedback when inserting `/delta` without new changes (#20356) Closes https://github.com/zed-industries/zed/issues/18488 ### Before No feedback when inserting `/delta` without new changes. https://github.com/user-attachments/assets/4cc76ff4-419d-4a3f-a6a2-8712856b1aa8 ### After You now see an error within the `delta` crease. https://github.com/user-attachments/assets/c56654bb-776f-4dac-a499-db4625a4f1bd Release Notes: - Improve UI feedback when inserting `/delta` without new changes --- crates/assistant/src/slash_command/delta_command.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/assistant/src/slash_command/delta_command.rs b/crates/assistant/src/slash_command/delta_command.rs index 5c8bc2b02309d61cdd4393a44dce231c4f98a38a..f854bd5fdfb0c579fba0fd098bea1a355098ee24 100644 --- a/crates/assistant/src/slash_command/delta_command.rs +++ b/crates/assistant/src/slash_command/delta_command.rs @@ -58,6 +58,7 @@ impl SlashCommand for DeltaSlashCommand { let mut paths = HashSet::default(); let mut file_command_old_outputs = Vec::new(); let mut file_command_new_outputs = Vec::new(); + for section in context_slash_command_output_sections.iter().rev() { if let Some(metadata) = section .metadata @@ -84,6 +85,7 @@ impl SlashCommand for DeltaSlashCommand { cx.background_executor().spawn(async move { let mut output = SlashCommandOutput::default(); + let mut changes_detected = false; let file_command_new_outputs = future::join_all(file_command_new_outputs).await; for (old_text, new_output) in file_command_old_outputs @@ -96,6 +98,7 @@ impl SlashCommand for DeltaSlashCommand { if let Some(file_command_range) = new_output.sections.first() { let new_text = &new_output.text[file_command_range.range.clone()]; if old_text.chars().ne(new_text.chars()) { + changes_detected = true; output.sections.extend(new_output.sections.into_iter().map( |section| SlashCommandOutputSection { range: output.text.len() + section.range.start @@ -112,6 +115,10 @@ impl SlashCommand for DeltaSlashCommand { } } + if !changes_detected { + return Err(anyhow!("no new changes detected")); + } + Ok(output.to_event_stream()) }) }