assistant2: Derive the Context
icon at render time instead of storing (#22397)
This PR is a follow up to #22385 that makes it so we treat the icon as derived state. Release Notes: - N/A
This commit is contained in:
parent
564936e1fe
commit
4c84600630
3 changed files with 10 additions and 22 deletions
|
@ -1,7 +1,6 @@
|
||||||
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)]
|
||||||
|
@ -20,10 +19,9 @@ 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, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum ContextKind {
|
pub enum ContextKind {
|
||||||
File,
|
File,
|
||||||
Directory,
|
Directory,
|
||||||
|
@ -31,17 +29,6 @@ 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,9 +36,8 @@ 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.clone(),
|
kind,
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
icon: kind.icon(),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::rc::Rc;
|
||||||
use gpui::ClickEvent;
|
use gpui::ClickEvent;
|
||||||
use ui::{prelude::*, IconButtonShape};
|
use ui::{prelude::*, IconButtonShape};
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::{Context, ContextKind};
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct ContextPill {
|
pub struct ContextPill {
|
||||||
|
@ -32,6 +32,12 @@ impl RenderOnce for ContextPill {
|
||||||
} else {
|
} else {
|
||||||
px(4.)
|
px(4.)
|
||||||
};
|
};
|
||||||
|
let icon = match self.context.kind {
|
||||||
|
ContextKind::File => IconName::File,
|
||||||
|
ContextKind::Directory => IconName::Folder,
|
||||||
|
ContextKind::FetchedUrl => IconName::Globe,
|
||||||
|
ContextKind::Thread => IconName::MessageCircle,
|
||||||
|
};
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
|
@ -42,11 +48,7 @@ impl RenderOnce for ContextPill {
|
||||||
.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(
|
.child(Icon::new(icon).size(IconSize::XSmall).color(Color::Muted))
|
||||||
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