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

@ -3,6 +3,7 @@ use std::rc::Rc;
use anyhow::Result;
use collections::HashSet;
use editor::Editor;
use file_icons::FileIcons;
use gpui::{
DismissEvent, EventEmitter, FocusHandle, Model, ModelContext, Subscription, Task, View,
WeakModel, WeakView,
@ -95,9 +96,12 @@ impl ContextStrip {
None => path.to_string_lossy().into_owned().into(),
};
let icon_path = FileIcons::get_icon(path, cx);
Some(SuggestedContext::File {
name,
buffer: active_buffer_model.downgrade(),
icon_path,
})
}
@ -228,6 +232,7 @@ impl Render for ContextStrip {
.when_some(suggested_context, |el, suggested| {
el.child(ContextPill::new_suggested(
suggested.name().clone(),
suggested.icon_path(),
suggested.kind(),
{
let context_store = self.context_store.clone();
@ -304,6 +309,7 @@ pub enum SuggestContextKind {
pub enum SuggestedContext {
File {
name: SharedString,
icon_path: Option<SharedString>,
buffer: WeakModel<Buffer>,
},
Thread {
@ -320,13 +326,24 @@ impl SuggestedContext {
}
}
pub fn icon_path(&self) -> Option<SharedString> {
match self {
Self::File { icon_path, .. } => icon_path.clone(),
Self::Thread { .. } => None,
}
}
pub fn accept(
&self,
context_store: &mut ContextStore,
cx: &mut ModelContext<ContextStore>,
) -> Task<Result<()>> {
match self {
Self::File { buffer, name: _ } => {
Self::File {
buffer,
icon_path: _,
name: _,
} => {
if let Some(buffer) = buffer.upgrade() {
return context_store.add_file_from_buffer(buffer, cx);
};