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:
Danilo Leal 2024-12-24 01:26:09 -03:00 committed by GitHub
parent 44a46e3713
commit 3d4e0780c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 3 deletions

View file

@ -1,6 +1,7 @@
use gpui::SharedString;
use language_model::{LanguageModelRequestMessage, MessageContent};
use serde::{Deserialize, Serialize};
use ui::prelude::*;
use util::post_inc;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize, Deserialize)]
@ -19,6 +20,7 @@ pub struct Context {
pub name: SharedString,
pub kind: ContextKind,
pub text: SharedString,
pub icon: IconName,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -29,6 +31,17 @@ pub enum ContextKind {
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(
message: &mut LanguageModelRequestMessage,
context: impl IntoIterator<Item = Context>,