assistant: Support retrying empty workflow step (#16301)
Co-Authored-by: Nathan <nathan@zed.dev> Co-Authored-by: Kirill <kirill@zed.dev> Release Notes: - N/A Co-authored-by: Nathan <nathan@zed.dev> Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
parent
7434b56e68
commit
0b3e5b2649
1 changed files with 58 additions and 38 deletions
|
@ -1387,8 +1387,10 @@ struct WorkflowStep {
|
||||||
impl WorkflowStep {
|
impl WorkflowStep {
|
||||||
fn status(&self, cx: &AppContext) -> WorkflowStepStatus {
|
fn status(&self, cx: &AppContext) -> WorkflowStepStatus {
|
||||||
match self.resolved_step.as_ref() {
|
match self.resolved_step.as_ref() {
|
||||||
Some(Ok(_)) => {
|
Some(Ok(step)) => {
|
||||||
if let Some(assist) = self.assist.as_ref() {
|
if step.suggestions.is_empty() {
|
||||||
|
WorkflowStepStatus::Empty
|
||||||
|
} else if let Some(assist) = self.assist.as_ref() {
|
||||||
let assistant = InlineAssistant::global(cx);
|
let assistant = InlineAssistant::global(cx);
|
||||||
if assist
|
if assist
|
||||||
.assist_ids
|
.assist_ids
|
||||||
|
@ -1424,6 +1426,7 @@ impl WorkflowStep {
|
||||||
enum WorkflowStepStatus {
|
enum WorkflowStepStatus {
|
||||||
Resolving,
|
Resolving,
|
||||||
Error(Arc<anyhow::Error>),
|
Error(Arc<anyhow::Error>),
|
||||||
|
Empty,
|
||||||
Idle,
|
Idle,
|
||||||
Pending,
|
Pending,
|
||||||
Done,
|
Done,
|
||||||
|
@ -1435,6 +1438,45 @@ impl WorkflowStepStatus {
|
||||||
matches!(self, Self::Confirmed)
|
matches!(self, Self::Confirmed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_workflow_step_error(
|
||||||
|
id: EntityId,
|
||||||
|
editor: WeakView<ContextEditor>,
|
||||||
|
step_range: Range<language::Anchor>,
|
||||||
|
error: String,
|
||||||
|
) -> AnyElement {
|
||||||
|
h_flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("step-resolution-failure")
|
||||||
|
.child(
|
||||||
|
Label::new("Step Resolution Failed")
|
||||||
|
.size(LabelSize::Small)
|
||||||
|
.color(Color::Error),
|
||||||
|
)
|
||||||
|
.tooltip(move |cx| Tooltip::text(error.clone(), cx)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new(("transform", id), "Retry")
|
||||||
|
.icon(IconName::Update)
|
||||||
|
.icon_position(IconPosition::Start)
|
||||||
|
.icon_size(IconSize::Small)
|
||||||
|
.label_size(LabelSize::Small)
|
||||||
|
.on_click({
|
||||||
|
let editor = editor.clone();
|
||||||
|
let step_range = step_range.clone();
|
||||||
|
move |_, cx| {
|
||||||
|
editor
|
||||||
|
.update(cx, |this, cx| {
|
||||||
|
this.resolve_workflow_step(step_range.clone(), cx)
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.into_any()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn into_element(
|
pub(crate) fn into_element(
|
||||||
&self,
|
&self,
|
||||||
step_range: Range<language::Anchor>,
|
step_range: Range<language::Anchor>,
|
||||||
|
@ -1469,40 +1511,18 @@ impl WorkflowStepStatus {
|
||||||
|label, delta| label.alpha(delta),
|
|label, delta| label.alpha(delta),
|
||||||
)
|
)
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
WorkflowStepStatus::Error(error) => {
|
WorkflowStepStatus::Error(error) => Self::render_workflow_step_error(
|
||||||
let error = error.clone();
|
id,
|
||||||
h_flex()
|
editor.clone(),
|
||||||
.gap_2()
|
step_range.clone(),
|
||||||
.child(
|
error.to_string(),
|
||||||
div()
|
),
|
||||||
.id("step-resolution-failure")
|
WorkflowStepStatus::Empty => Self::render_workflow_step_error(
|
||||||
.child(
|
id,
|
||||||
Label::new("Step Resolution Failed")
|
editor.clone(),
|
||||||
.size(LabelSize::Small)
|
step_range.clone(),
|
||||||
.color(Color::Error),
|
"Model was unable to locate the code to edit".to_string(),
|
||||||
)
|
),
|
||||||
.tooltip(move |cx| Tooltip::text(error.to_string(), cx)),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new(("transform", id), "Retry")
|
|
||||||
.icon(IconName::Update)
|
|
||||||
.icon_position(IconPosition::Start)
|
|
||||||
.icon_size(IconSize::Small)
|
|
||||||
.label_size(LabelSize::Small)
|
|
||||||
.on_click({
|
|
||||||
let editor = editor.clone();
|
|
||||||
let step_range = step_range.clone();
|
|
||||||
move |_, cx| {
|
|
||||||
editor
|
|
||||||
.update(cx, |this, cx| {
|
|
||||||
this.resolve_workflow_step(step_range.clone(), cx)
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.into_any()
|
|
||||||
}
|
|
||||||
WorkflowStepStatus::Idle => Button::new(("transform", id), "Transform")
|
WorkflowStepStatus::Idle => Button::new(("transform", id), "Transform")
|
||||||
.icon(IconName::SparkleAlt)
|
.icon(IconName::SparkleAlt)
|
||||||
.icon_position(IconPosition::Start)
|
.icon_position(IconPosition::Start)
|
||||||
|
@ -1871,7 +1891,7 @@ impl ContextEditor {
|
||||||
self.confirm_workflow_step(range, cx);
|
self.confirm_workflow_step(range, cx);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
WorkflowStepStatus::Error(_) => {
|
WorkflowStepStatus::Error(_) | WorkflowStepStatus::Empty => {
|
||||||
self.resolve_workflow_step(range, cx);
|
self.resolve_workflow_step(range, cx);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -3545,7 +3565,7 @@ impl ContextEditor {
|
||||||
let button_text = match self.active_workflow_step() {
|
let button_text = match self.active_workflow_step() {
|
||||||
Some(step) => match step.status(cx) {
|
Some(step) => match step.status(cx) {
|
||||||
WorkflowStepStatus::Resolving => "Resolving Step...",
|
WorkflowStepStatus::Resolving => "Resolving Step...",
|
||||||
WorkflowStepStatus::Error(_) => "Retry Step Resolution",
|
WorkflowStepStatus::Empty | WorkflowStepStatus::Error(_) => "Retry Step Resolution",
|
||||||
WorkflowStepStatus::Idle => "Transform",
|
WorkflowStepStatus::Idle => "Transform",
|
||||||
WorkflowStepStatus::Pending => "Transforming...",
|
WorkflowStepStatus::Pending => "Transforming...",
|
||||||
WorkflowStepStatus::Done => "Accept Transformation",
|
WorkflowStepStatus::Done => "Accept Transformation",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue