Introduce recent files ambient context for assistant (#11791)

<img width="1637" alt="image"
src="https://github.com/zed-industries/zed/assets/482957/5aaec657-3499-42c9-9528-c83728f2a7a1">

Release Notes:

- Added a new ambient context feature that allows showing the model up
to three buffers (along with their diagnostics) that the user interacted
with recently.

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-05-14 13:48:36 +02:00 committed by GitHub
parent e4c95b25bf
commit a13a92fbbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 522 additions and 411 deletions

View file

@ -191,7 +191,8 @@ pub struct Pane {
),
focus_handle: FocusHandle,
items: Vec<Box<dyn ItemHandle>>,
activation_history: Vec<EntityId>,
activation_history: Vec<ActivationHistoryEntry>,
next_activation_timestamp: Arc<AtomicUsize>,
zoomed: bool,
was_focused: bool,
active_item_index: usize,
@ -219,6 +220,11 @@ pub struct Pane {
double_click_dispatch_action: Box<dyn Action>,
}
pub struct ActivationHistoryEntry {
pub entity_id: EntityId,
pub timestamp: usize,
}
pub struct ItemNavHistory {
history: NavHistory,
item: Arc<dyn WeakItemHandle>,
@ -296,6 +302,7 @@ impl Pane {
focus_handle,
items: Vec::new(),
activation_history: Vec::new(),
next_activation_timestamp: next_timestamp.clone(),
was_focused: false,
zoomed: false,
active_item_index: 0,
@ -506,7 +513,7 @@ impl Pane {
self.active_item_index
}
pub fn activation_history(&self) -> &Vec<EntityId> {
pub fn activation_history(&self) -> &[ActivationHistoryEntry] {
&self.activation_history
}
@ -892,10 +899,13 @@ impl Pane {
if let Some(newly_active_item) = self.items.get(index) {
self.activation_history
.retain(|&previously_active_item_id| {
previously_active_item_id != newly_active_item.item_id()
});
self.activation_history.push(newly_active_item.item_id());
.retain(|entry| entry.entity_id != newly_active_item.item_id());
self.activation_history.push(ActivationHistoryEntry {
entity_id: newly_active_item.item_id(),
timestamp: self
.next_activation_timestamp
.fetch_add(1, Ordering::SeqCst),
});
}
self.update_toolbar(cx);
@ -1211,7 +1221,7 @@ impl Pane {
cx: &mut ViewContext<Self>,
) {
self.activation_history
.retain(|&history_entry| history_entry != self.items[item_index].item_id());
.retain(|entry| entry.entity_id != self.items[item_index].item_id());
if item_index == self.active_item_index {
let index_to_activate = self
@ -1219,7 +1229,7 @@ impl Pane {
.pop()
.and_then(|last_activated_item| {
self.items.iter().enumerate().find_map(|(index, item)| {
(item.item_id() == last_activated_item).then_some(index)
(item.item_id() == last_activated_item.entity_id).then_some(index)
})
})
// We didn't have a valid activation history entry, so fallback

View file

@ -532,6 +532,9 @@ impl DelayedDebouncedEditAction {
pub enum Event {
PaneAdded(View<Pane>),
PaneRemoved,
ItemAdded,
ItemRemoved,
ActiveItemChanged,
ContactRequestedJoin(u64),
WorkspaceCreated(WeakView<Workspace>),
@ -2513,7 +2516,10 @@ impl Workspace {
cx: &mut ViewContext<Self>,
) {
match event {
pane::Event::AddItem { item } => item.added_to_pane(self, pane, cx),
pane::Event::AddItem { item } => {
item.added_to_pane(self, pane, cx);
cx.emit(Event::ItemAdded);
}
pane::Event::Split(direction) => {
self.split_and_clone(pane, *direction, cx);
}
@ -2696,6 +2702,7 @@ impl Workspace {
} else {
self.active_item_path_changed(cx);
}
cx.emit(Event::PaneRemoved);
}
pub fn panes(&self) -> &[View<Pane>] {