assistant2: Wire up context picker with inline assist (#22106)

This PR wire up the context picker with the inline assist.

UI is not finalized.

Release Notes:

- N/A

---------

Co-authored-by: Richard <richard@zed.dev>
Co-authored-by: Agus <agus@zed.dev>
This commit is contained in:
Marshall Bowers 2024-12-16 15:46:28 -05:00 committed by GitHub
parent 082469e173
commit 4bf005ef52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 391 additions and 241 deletions

View file

@ -16,7 +16,7 @@ use workspace::Workspace;
use crate::context_picker::fetch_context_picker::FetchContextPicker;
use crate::context_picker::file_context_picker::FileContextPicker;
use crate::context_picker::thread_context_picker::ThreadContextPicker;
use crate::context_strip::ContextStrip;
use crate::context_store::ContextStore;
use crate::thread_store::ThreadStore;
#[derive(Debug, Clone)]
@ -35,37 +35,42 @@ pub(super) struct ContextPicker {
impl ContextPicker {
pub fn new(
workspace: WeakView<Workspace>,
thread_store: WeakModel<ThreadStore>,
context_strip: WeakView<ContextStrip>,
thread_store: Option<WeakModel<ThreadStore>>,
context_store: WeakModel<ContextStore>,
cx: &mut ViewContext<Self>,
) -> Self {
let mut entries = vec![
ContextPickerEntry {
name: "directory".into(),
description: "Insert any directory".into(),
icon: IconName::Folder,
},
ContextPickerEntry {
name: "file".into(),
description: "Insert any file".into(),
icon: IconName::File,
},
ContextPickerEntry {
name: "fetch".into(),
description: "Fetch content from URL".into(),
icon: IconName::Globe,
},
];
if thread_store.is_some() {
entries.push(ContextPickerEntry {
name: "thread".into(),
description: "Insert any thread".into(),
icon: IconName::MessageBubbles,
});
}
let delegate = ContextPickerDelegate {
context_picker: cx.view().downgrade(),
workspace,
thread_store,
context_strip,
entries: vec![
ContextPickerEntry {
name: "directory".into(),
description: "Insert any directory".into(),
icon: IconName::Folder,
},
ContextPickerEntry {
name: "file".into(),
description: "Insert any file".into(),
icon: IconName::File,
},
ContextPickerEntry {
name: "fetch".into(),
description: "Fetch content from URL".into(),
icon: IconName::Globe,
},
ContextPickerEntry {
name: "thread".into(),
description: "Insert any thread".into(),
icon: IconName::MessageBubbles,
},
],
context_store,
entries,
selected_ix: 0,
};
@ -121,8 +126,8 @@ struct ContextPickerEntry {
pub(crate) struct ContextPickerDelegate {
context_picker: WeakView<ContextPicker>,
workspace: WeakView<Workspace>,
thread_store: WeakModel<ThreadStore>,
context_strip: WeakView<ContextStrip>,
thread_store: Option<WeakModel<ThreadStore>>,
context_store: WeakModel<ContextStore>,
entries: Vec<ContextPickerEntry>,
selected_ix: usize,
}
@ -161,7 +166,7 @@ impl PickerDelegate for ContextPickerDelegate {
FileContextPicker::new(
self.context_picker.clone(),
self.workspace.clone(),
self.context_strip.clone(),
self.context_store.clone(),
cx,
)
}));
@ -171,20 +176,22 @@ impl PickerDelegate for ContextPickerDelegate {
FetchContextPicker::new(
self.context_picker.clone(),
self.workspace.clone(),
self.context_strip.clone(),
self.context_store.clone(),
cx,
)
}));
}
"thread" => {
this.mode = ContextPickerMode::Thread(cx.new_view(|cx| {
ThreadContextPicker::new(
self.thread_store.clone(),
self.context_picker.clone(),
self.context_strip.clone(),
cx,
)
}));
if let Some(thread_store) = self.thread_store.as_ref() {
this.mode = ContextPickerMode::Thread(cx.new_view(|cx| {
ThreadContextPicker::new(
thread_store.clone(),
self.context_picker.clone(),
self.context_store.clone(),
cx,
)
}));
}
}
_ => {}
}