From 8430197df0ffde444c5f4286fc7c22875368709c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 8 Aug 2025 15:56:07 +0200 Subject: [PATCH] Restore accidentally deleted `EditFileTool::still_streaming_ui_text` (#35871) This was accidentally removed in #35844. Release Notes: - N/A Co-authored-by: Ben Brandt --- crates/assistant_tools/src/edit_file_tool.rs | 85 ++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/crates/assistant_tools/src/edit_file_tool.rs b/crates/assistant_tools/src/edit_file_tool.rs index 311521019d1be69a269a459d62af844e4123cde3..dce9f49abdde7e0ea00d976a4d9f029f98f7a067 100644 --- a/crates/assistant_tools/src/edit_file_tool.rs +++ b/crates/assistant_tools/src/edit_file_tool.rs @@ -120,6 +120,8 @@ struct PartialInput { display_description: String, } +const DEFAULT_UI_TEXT: &str = "Editing file"; + impl Tool for EditFileTool { fn name(&self) -> String { "edit_file".into() @@ -209,6 +211,22 @@ impl Tool for EditFileTool { } } + fn still_streaming_ui_text(&self, input: &serde_json::Value) -> String { + if let Some(input) = serde_json::from_value::(input.clone()).ok() { + let description = input.display_description.trim(); + if !description.is_empty() { + return description.to_string(); + } + + let path = input.path.trim(); + if !path.is_empty() { + return path.to_string(); + } + } + + DEFAULT_UI_TEXT.to_string() + } + fn run( self: Arc, input: serde_json::Value, @@ -1352,6 +1370,73 @@ mod tests { assert_eq!(actual, expected); } + #[test] + fn still_streaming_ui_text_with_path() { + let input = json!({ + "path": "src/main.rs", + "display_description": "", + "old_string": "old code", + "new_string": "new code" + }); + + assert_eq!(EditFileTool.still_streaming_ui_text(&input), "src/main.rs"); + } + + #[test] + fn still_streaming_ui_text_with_description() { + let input = json!({ + "path": "", + "display_description": "Fix error handling", + "old_string": "old code", + "new_string": "new code" + }); + + assert_eq!( + EditFileTool.still_streaming_ui_text(&input), + "Fix error handling", + ); + } + + #[test] + fn still_streaming_ui_text_with_path_and_description() { + let input = json!({ + "path": "src/main.rs", + "display_description": "Fix error handling", + "old_string": "old code", + "new_string": "new code" + }); + + assert_eq!( + EditFileTool.still_streaming_ui_text(&input), + "Fix error handling", + ); + } + + #[test] + fn still_streaming_ui_text_no_path_or_description() { + let input = json!({ + "path": "", + "display_description": "", + "old_string": "old code", + "new_string": "new code" + }); + + assert_eq!( + EditFileTool.still_streaming_ui_text(&input), + DEFAULT_UI_TEXT, + ); + } + + #[test] + fn still_streaming_ui_text_with_null() { + let input = serde_json::Value::Null; + + assert_eq!( + EditFileTool.still_streaming_ui_text(&input), + DEFAULT_UI_TEXT, + ); + } + fn init_test(cx: &mut TestAppContext) { cx.update(|cx| { let settings_store = SettingsStore::test(cx);