assistant2: Add icons to the context pill (#22385)
This PR adds an icon field to the `ContextKind` enum, which means that icons will now display on context pills, both on the message editor and on the active thread. <img width="800" alt="Screenshot 2024-12-24 at 12 23 17 AM" src="https://github.com/user-attachments/assets/f00e540b-30fe-49ac-b3df-7c7a5dc86d65" /> Release Notes: - N/A
This commit is contained in:
parent
44a46e3713
commit
3d4e0780c4
3 changed files with 28 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
use gpui::SharedString;
|
use gpui::SharedString;
|
||||||
use language_model::{LanguageModelRequestMessage, MessageContent};
|
use language_model::{LanguageModelRequestMessage, MessageContent};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use ui::prelude::*;
|
||||||
use util::post_inc;
|
use util::post_inc;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize, Deserialize)]
|
||||||
|
@ -19,6 +20,7 @@ pub struct Context {
|
||||||
pub name: SharedString,
|
pub name: SharedString,
|
||||||
pub kind: ContextKind,
|
pub kind: ContextKind,
|
||||||
pub text: SharedString,
|
pub text: SharedString,
|
||||||
|
pub icon: IconName,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -29,6 +31,17 @@ pub enum ContextKind {
|
||||||
Thread,
|
Thread,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ContextKind {
|
||||||
|
pub fn icon(&self) -> IconName {
|
||||||
|
match self {
|
||||||
|
ContextKind::File => IconName::File,
|
||||||
|
ContextKind::Directory => IconName::Folder,
|
||||||
|
ContextKind::FetchedUrl => IconName::Globe,
|
||||||
|
ContextKind::Thread => IconName::MessageCircle,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn attach_context_to_message(
|
pub fn attach_context_to_message(
|
||||||
message: &mut LanguageModelRequestMessage,
|
message: &mut LanguageModelRequestMessage,
|
||||||
context: impl IntoIterator<Item = Context>,
|
context: impl IntoIterator<Item = Context>,
|
||||||
|
|
|
@ -36,8 +36,9 @@ impl ContextStore {
|
||||||
self.context.push(Context {
|
self.context.push(Context {
|
||||||
id: self.next_context_id.post_inc(),
|
id: self.next_context_id.post_inc(),
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
kind,
|
kind: kind.clone(),
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
|
icon: kind.icon(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,15 +27,26 @@ impl ContextPill {
|
||||||
|
|
||||||
impl RenderOnce for ContextPill {
|
impl RenderOnce for ContextPill {
|
||||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
|
let padding_right = if self.on_remove.is_some() {
|
||||||
|
px(2.)
|
||||||
|
} else {
|
||||||
|
px(4.)
|
||||||
|
};
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.pl_1p5()
|
.pl_1()
|
||||||
.pr_0p5()
|
.pr(padding_right)
|
||||||
.pb(px(1.))
|
.pb(px(1.))
|
||||||
.border_1()
|
.border_1()
|
||||||
.border_color(cx.theme().colors().border.opacity(0.5))
|
.border_color(cx.theme().colors().border.opacity(0.5))
|
||||||
.bg(cx.theme().colors().element_background)
|
.bg(cx.theme().colors().element_background)
|
||||||
.rounded_md()
|
.rounded_md()
|
||||||
|
.child(
|
||||||
|
Icon::new(self.context.icon)
|
||||||
|
.size(IconSize::XSmall)
|
||||||
|
.color(Color::Muted),
|
||||||
|
)
|
||||||
.child(Label::new(self.context.name.clone()).size(LabelSize::Small))
|
.child(Label::new(self.context.name.clone()).size(LabelSize::Small))
|
||||||
.when_some(self.on_remove, |parent, on_remove| {
|
.when_some(self.on_remove, |parent, on_remove| {
|
||||||
parent.child(
|
parent.child(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue