Preserve sections generated by slash commands when reloading a context (#13199)

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-06-18 14:49:53 +02:00 committed by GitHub
parent 195a270e18
commit e4ba336971
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 250 additions and 348 deletions

View file

@ -5,7 +5,7 @@ use assistant_slash_command::SlashCommandOutputSection;
use gpui::{AppContext, Task, WeakView};
use language::LspAdapterDelegate;
use std::sync::{atomic::AtomicBool, Arc};
use ui::{prelude::*, ButtonLike, ElevationIndex};
use ui::prelude::*;
use workspace::Workspace;
pub(crate) struct PromptSlashCommand;
@ -78,36 +78,11 @@ impl SlashCommand for PromptSlashCommand {
text: prompt,
sections: vec![SlashCommandOutputSection {
range,
render_placeholder: Arc::new(move |id, unfold, _cx| {
PromptPlaceholder {
id,
unfold,
title: title.clone(),
}
.into_any_element()
}),
icon: IconName::Library,
label: title,
}],
run_commands_in_text: true,
})
})
}
}
#[derive(IntoElement)]
pub struct PromptPlaceholder {
pub title: SharedString,
pub id: ElementId,
pub unfold: Arc<dyn Fn(&mut WindowContext)>,
}
impl RenderOnce for PromptPlaceholder {
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
let unfold = self.unfold;
ButtonLike::new(self.id)
.style(ButtonStyle::Filled)
.layer(ElevationIndex::ElevatedSurface)
.child(Icon::new(IconName::Library))
.child(Label::new(self.title))
.on_click(move |_, cx| unfold(cx))
}
}