assistant: Restructure ambient context in preparation for adding more (#11822)

This PR restructures the ambient context in the `assistant` crate to
make it more amenable to adding more kinds of ambient context.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-05-14 17:03:39 -04:00 committed by GitHub
parent bf4478703b
commit ba4d4c8e1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 28 deletions

View file

@ -0,0 +1,8 @@
mod recent_buffers;
pub use recent_buffers::*;
#[derive(Default)]
pub struct AmbientContext {
pub recent_buffers: RecentBuffersContext,
}

View file

@ -0,0 +1,25 @@
use gpui::{Subscription, Task, WeakModel};
use language::Buffer;
pub struct RecentBuffersContext {
pub enabled: bool,
pub buffers: Vec<RecentBuffer>,
pub message: String,
pub pending_message: Option<Task<()>>,
}
pub struct RecentBuffer {
pub buffer: WeakModel<Buffer>,
pub _subscription: Subscription,
}
impl Default for RecentBuffersContext {
fn default() -> Self {
Self {
enabled: true,
buffers: Vec::new(),
message: String::new(),
pending_message: None,
}
}
}

View file

@ -1,3 +1,4 @@
mod ambient_context;
pub mod assistant_panel;
pub mod assistant_settings;
mod codegen;

View file

@ -1,3 +1,4 @@
use crate::ambient_context::{AmbientContext, RecentBuffer};
use crate::{
assistant_settings::{AssistantDockPosition, AssistantSettings, ZedDotDevModel},
codegen::{self, Codegen, CodegenKind},
@ -1367,34 +1368,6 @@ pub struct Conversation {
telemetry: Option<Arc<Telemetry>>,
}
#[derive(Default)]
struct AmbientContext {
recent_buffers: RecentBuffersContext,
}
struct RecentBuffersContext {
enabled: bool,
buffers: Vec<RecentBuffer>,
message: String,
pending_message: Option<Task<()>>,
}
struct RecentBuffer {
buffer: WeakModel<Buffer>,
_subscription: Subscription,
}
impl Default for RecentBuffersContext {
fn default() -> Self {
Self {
enabled: true,
buffers: Vec::new(),
message: String::new(),
pending_message: None,
}
}
}
impl EventEmitter<ConversationEvent> for Conversation {}
impl Conversation {