Skip to content

Commit

Permalink
Polish streaming slash commands (#20345)
Browse files Browse the repository at this point in the history
This improves the experience in a few ways:

- It avoids merging slash command output sections that are adjacent.
- When hitting cmd-z, all the output from a command is undone at once.
- When deleting a pending command, it stops the command and prevents new
output from flowing in.

Release Notes:

- N/A
  • Loading branch information
as-cii authored Nov 7, 2024
1 parent e62d60c commit 16cbff9
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 106 deletions.
46 changes: 10 additions & 36 deletions crates/assistant/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ use text::SelectionGoal;
use ui::{
prelude::*,
utils::{format_distance_from_now, DateTimeType},
Avatar, ButtonLike, ContextMenu, Disclosure, ElevationIndex, IconButtonShape, KeyBinding,
ListItem, ListItemSpacing, PopoverMenu, PopoverMenuHandle, TintColor, Tooltip,
Avatar, ButtonLike, ContextMenu, Disclosure, ElevationIndex, KeyBinding, ListItem,
ListItemSpacing, PopoverMenu, PopoverMenuHandle, TintColor, Tooltip,
};
use util::{maybe, ResultExt};
use workspace::{
Expand Down Expand Up @@ -2111,7 +2111,6 @@ impl ContextEditor {
command_id: SlashCommandId,
cx: &mut ViewContext<Self>,
) {
let context_editor = cx.view().downgrade();
self.editor.update(cx, |editor, cx| {
if let Some(invoked_slash_command) =
self.context.read(cx).invoked_slash_command(&command_id)
Expand Down Expand Up @@ -2152,7 +2151,7 @@ impl ContextEditor {
.anchor_in_excerpt(excerpt_id, invoked_slash_command.range.end)
.unwrap();
let fold_placeholder =
invoked_slash_command_fold_placeholder(command_id, context, context_editor);
invoked_slash_command_fold_placeholder(command_id, context);
let crease_ids = editor.insert_creases(
[Crease::new(
crease_start..crease_end,
Expand Down Expand Up @@ -2352,6 +2351,7 @@ impl ContextEditor {
section.icon,
section.label.clone(),
),
merge_adjacent: false,
..Default::default()
},
render_slash_command_output_toggle,
Expand Down Expand Up @@ -4963,6 +4963,7 @@ fn quote_selection_fold_placeholder(title: String, editor: WeakView<Editor>) ->
.into_any_element()
}
}),
merge_adjacent: false,
..Default::default()
}
}
Expand Down Expand Up @@ -5096,7 +5097,6 @@ enum PendingSlashCommand {}
fn invoked_slash_command_fold_placeholder(
command_id: SlashCommandId,
context: WeakModel<Context>,
context_editor: WeakView<ContextEditor>,
) -> FoldPlaceholder {
FoldPlaceholder {
constrain_width: false,
Expand Down Expand Up @@ -5126,37 +5126,11 @@ fn invoked_slash_command_fold_placeholder(
|icon, delta| icon.transform(Transformation::rotate(percentage(delta))),
))
}
InvokedSlashCommandStatus::Error(message) => parent
.child(
Label::new(format!("error: {message}"))
.single_line()
.color(Color::Error),
)
.child(
IconButton::new("dismiss-error", IconName::Close)
.shape(IconButtonShape::Square)
.icon_size(IconSize::XSmall)
.icon_color(Color::Muted)
.on_click({
let context_editor = context_editor.clone();
move |_event, cx| {
context_editor
.update(cx, |context_editor, cx| {
context_editor.editor.update(cx, |editor, cx| {
editor.remove_creases(
HashSet::from_iter(
context_editor
.invoked_slash_command_creases
.remove(&command_id),
),
cx,
);
})
})
.log_err();
}
}),
),
InvokedSlashCommandStatus::Error(message) => parent.child(
Label::new(format!("error: {message}"))
.single_line()
.color(Color::Error),
),
InvokedSlashCommandStatus::Finished => parent,
})
.into_any_element()
Expand Down
Loading

0 comments on commit 16cbff9

Please sign in to comment.