From 69aae2037d5b56900112aa0a3b3d3c63fb1d1aa8 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 19 Aug 2024 18:44:52 +0300 Subject: [PATCH] Display default prompts more elaborately (#16471) Show them under `User` role instead of a `System` one, and insert them expanded. Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 29 ++++++++++++++++--- crates/assistant/src/context.rs | 4 +++ crates/assistant/src/context/context_tests.rs | 1 + crates/assistant/src/slash_command.rs | 2 ++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 9b4a8e2e2425ff56ac89188d6529377722eab812..8e6a7d364e8301c99239818c515b693a02c411b0 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -1808,7 +1808,7 @@ impl ContextEditor { }; this.update_message_headers(cx); this.update_image_blocks(cx); - this.insert_slash_command_output_sections(sections, cx); + this.insert_slash_command_output_sections(sections, false, cx); this } @@ -1821,7 +1821,7 @@ impl ContextEditor { let command = self.context.update(cx, |context, cx| { let first_message_id = context.messages(cx).next().unwrap().id; context.update_metadata(first_message_id, cx, |metadata| { - metadata.role = Role::System; + metadata.role = Role::User; }); context.reparse_slash_commands(cx); context.pending_slash_commands()[0].clone() @@ -1832,6 +1832,7 @@ impl ContextEditor { &command.name, &command.arguments, false, + true, self.workspace.clone(), cx, ); @@ -2098,6 +2099,7 @@ impl ContextEditor { &command.name, &command.arguments, true, + false, workspace.clone(), cx, ); @@ -2106,19 +2108,27 @@ impl ContextEditor { } } + #[allow(clippy::too_many_arguments)] pub fn run_command( &mut self, command_range: Range, name: &str, arguments: &[String], ensure_trailing_newline: bool, + expand_result: bool, workspace: WeakView, cx: &mut ViewContext, ) { if let Some(command) = SlashCommandRegistry::global(cx).command(name) { let output = command.run(arguments, workspace, self.lsp_adapter_delegate.clone(), cx); self.context.update(cx, |context, cx| { - context.insert_command_output(command_range, output, ensure_trailing_newline, cx) + context.insert_command_output( + command_range, + output, + ensure_trailing_newline, + expand_result, + cx, + ) }); } } @@ -2204,6 +2214,7 @@ impl ContextEditor { &command.name, &command.arguments, false, + false, workspace.clone(), cx, ); @@ -2300,8 +2311,13 @@ impl ContextEditor { output_range, sections, run_commands_in_output, + expand_result, } => { - self.insert_slash_command_output_sections(sections.iter().cloned(), cx); + self.insert_slash_command_output_sections( + sections.iter().cloned(), + *expand_result, + cx, + ); if *run_commands_in_output { let commands = self.context.update(cx, |context, cx| { @@ -2317,6 +2333,7 @@ impl ContextEditor { &command.name, &command.arguments, false, + false, self.workspace.clone(), cx, ); @@ -2333,6 +2350,7 @@ impl ContextEditor { fn insert_slash_command_output_sections( &mut self, sections: impl IntoIterator>, + expand_result: bool, cx: &mut ViewContext, ) { self.editor.update(cx, |editor, cx| { @@ -2387,6 +2405,9 @@ impl ContextEditor { editor.insert_creases(creases, cx); + if expand_result { + buffer_rows_to_fold.clear(); + } for buffer_row in buffer_rows_to_fold.into_iter().rev() { editor.fold_at(&FoldAt { buffer_row }, cx); } diff --git a/crates/assistant/src/context.rs b/crates/assistant/src/context.rs index 4608c5df4b25ff7bc51de7eea9bd12b11e4829d1..f68cdb53eb2e326504218902c251c914eb3e641d 100644 --- a/crates/assistant/src/context.rs +++ b/crates/assistant/src/context.rs @@ -295,6 +295,7 @@ pub enum ContextEvent { output_range: Range, sections: Vec>, run_commands_in_output: bool, + expand_result: bool, }, Operation(ContextOperation), } @@ -774,6 +775,7 @@ impl Context { cx.emit(ContextEvent::SlashCommandFinished { output_range, sections, + expand_result: false, run_commands_in_output: false, }); } @@ -1396,6 +1398,7 @@ impl Context { command_range: Range, output: Task>, ensure_trailing_newline: bool, + expand_result: bool, cx: &mut ModelContext, ) { self.reparse_slash_commands(cx); @@ -1469,6 +1472,7 @@ impl Context { output_range, sections, run_commands_in_output: output.run_commands_in_text, + expand_result, }, ) }); diff --git a/crates/assistant/src/context/context_tests.rs b/crates/assistant/src/context/context_tests.rs index 1f5b98c930666ab8f9b7041f0b4c65bb7176231a..4eb7b75a64e54ded5065b6a2bd92bc57d8189fd8 100644 --- a/crates/assistant/src/context/context_tests.rs +++ b/crates/assistant/src/context/context_tests.rs @@ -891,6 +891,7 @@ async fn test_random_context_collaboration(cx: &mut TestAppContext, mut rng: Std run_commands_in_text: false, })), true, + false, cx, ); }); diff --git a/crates/assistant/src/slash_command.rs b/crates/assistant/src/slash_command.rs index 667b11c7421dce6c06735399531c0e8f5b677efa..b1a97688b2b46a977654c6ddd6d6389f79638d7d 100644 --- a/crates/assistant/src/slash_command.rs +++ b/crates/assistant/src/slash_command.rs @@ -124,6 +124,7 @@ impl SlashCommandCompletionProvider { &command_name, &[], true, + false, workspace.clone(), cx, ); @@ -208,6 +209,7 @@ impl SlashCommandCompletionProvider { &command_name, &completed_arguments, true, + false, workspace.clone(), cx, );