File context for assistant panel (#9712)

Introducing the Active File Context portion of #9705. When someone is in
the assistant panel it now includes the active file as a system message
on send while showing them a nice little display in the lower right:


![image](https://github.com/zed-industries/zed/assets/836375/9abc56e0-e8f2-45ee-9e7e-b83b28b483ea)

For this iteration, I'd love to see the following before we land this:

* [x] Toggle-able context - user should be able to disable sending this
context
* [x] Show nothing if there is no context coming in
* [x] Update token count as we change items
* [x] Listen for a more finely scoped event for when the active item
changes
* [x] Create a global for pulling a file icon based on a path. Zed's
main way to do this is nested within project panel's `FileAssociation`s.
* [x] Get the code fence name for a Language for the system prompt
* [x] Update the token count when the buffer content changes

I'm seeing this PR as the foundation for providing other kinds of
context -- diagnostic summaries, failing tests, additional files, etc.

Release Notes:

- Added file context to assistant chat panel
([#9705](https://github.com/zed-industries/zed/issues/9705)).

<img width="1558" alt="image"
src="https://github.com/zed-industries/zed/assets/836375/86eb7e50-3e28-4754-9c3f-895be588616d">

---------

Co-authored-by: Conrad Irwin <conrad@zed.dev>
Co-authored-by: Nathan <nathan@zed.dev>
Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Kyle Kelley 2024-03-29 13:55:01 -07:00 committed by GitHub
parent df3050dac1
commit d77e553466
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 377 additions and 49 deletions

View file

@ -517,6 +517,7 @@ impl DelayedDebouncedEditAction {
pub enum Event {
PaneAdded(View<Pane>),
ActiveItemChanged,
ContactRequestedJoin(u64),
WorkspaceCreated(WeakView<Workspace>),
SpawnTask(SpawnInTerminal),
@ -2377,6 +2378,7 @@ impl Workspace {
self.update_window_edited(cx);
}
pane::Event::RemoveItem { item_id } => {
cx.emit(Event::ActiveItemChanged);
self.update_window_edited(cx);
if let hash_map::Entry::Occupied(entry) = self.panes_by_item.entry(*item_id) {
if entry.get().entity_id() == pane.entity_id() {
@ -2747,10 +2749,12 @@ impl Workspace {
.any(|state| state.leader_id == peer_id)
}
fn active_item_path_changed(&mut self, cx: &mut WindowContext) {
fn active_item_path_changed(&mut self, cx: &mut ViewContext<Self>) {
cx.emit(Event::ActiveItemChanged);
let active_entry = self.active_project_path(cx);
self.project
.update(cx, |project, cx| project.set_active_path(active_entry, cx));
self.update_window_title(cx);
}