assistant2: Show file icons for context entries (#22928)

https://github.com/user-attachments/assets/d3d6f5f1-23ec-449b-a762-9869b9d4b5a5


Release Notes:

- N/A

---------

Co-authored-by: Nathan <nathan@zed.dev>
Co-authored-by: Michael <michael@zed.dev>
This commit is contained in:
Agus Zubiaga 2025-01-10 00:01:42 -03:00 committed by GitHub
parent c9008fb8c1
commit ec4c6744d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 78 additions and 17 deletions

View file

@ -2,11 +2,13 @@ use std::path::Path;
use std::rc::Rc;
use std::sync::Arc;
use file_icons::FileIcons;
use gpui::{AppContext, Model, SharedString};
use language::Buffer;
use language_model::{LanguageModelRequestMessage, MessageContent};
use serde::{Deserialize, Serialize};
use text::BufferId;
use ui::IconName;
use util::post_inc;
use crate::thread::Thread;
@ -27,6 +29,7 @@ pub struct ContextSnapshot {
pub name: SharedString,
pub parent: Option<SharedString>,
pub tooltip: Option<SharedString>,
pub icon_path: Option<SharedString>,
pub kind: ContextKind,
/// Concatenating these strings yields text to send to the model. Not refreshed by `snapshot`.
pub text: Box<[SharedString]>,
@ -40,6 +43,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,
}
}
}
#[derive(Debug)]
pub enum Context {
File(FileContext),
@ -138,11 +152,14 @@ impl FileContext {
.and_then(|p| p.file_name())
.map(|p| p.to_string_lossy().into_owned().into());
let icon_path = FileIcons::get_icon(&path, cx);
Some(ContextSnapshot {
id: self.id,
name,
parent,
tooltip: Some(full_path),
icon_path,
kind: ContextKind::File,
text: Box::new([self.buffer.text.clone()]),
})
@ -162,6 +179,7 @@ impl FetchedUrlContext {
name: self.url.clone(),
parent: None,
tooltip: None,
icon_path: None,
kind: ContextKind::FetchedUrl,
text: Box::new([self.text.clone()]),
}
@ -176,6 +194,7 @@ impl ThreadContext {
name: thread.summary().unwrap_or("New thread".into()),
parent: None,
tooltip: None,
icon_path: None,
kind: ContextKind::Thread,
text: Box::new([self.text.clone()]),
}