diff --git a/crates/assistant2/src/context_picker/fetch_context_picker.rs b/crates/assistant2/src/context_picker/fetch_context_picker.rs index 545de80a3c..dd23ed7c9f 100644 --- a/crates/assistant2/src/context_picker/fetch_context_picker.rs +++ b/crates/assistant2/src/context_picker/fetch_context_picker.rs @@ -204,9 +204,7 @@ impl PickerDelegate for FetchContextPickerDelegate { this.delegate .context_store .update(cx, |context_store, _cx| { - if context_store.includes_url(&url).is_none() { - context_store.insert_fetched_url(url, text); - } + context_store.add_fetched_url(url, text); })?; match confirm_behavior { diff --git a/crates/assistant2/src/context_store.rs b/crates/assistant2/src/context_store.rs index 74e84b1cd1..f6b2d5c38f 100644 --- a/crates/assistant2/src/context_store.rs +++ b/crates/assistant2/src/context_store.rs @@ -15,6 +15,7 @@ use crate::context::{ Context, ContextBuffer, ContextId, ContextSnapshot, DirectoryContext, FetchedUrlContext, FileContext, ThreadContext, }; +use crate::context_strip::SuggestedContext; use crate::thread::{Thread, ThreadId}; pub struct ContextStore { @@ -148,7 +149,7 @@ impl ContextStore { }) } - pub fn insert_file(&mut self, context_buffer: ContextBuffer) { + fn insert_file(&mut self, context_buffer: ContextBuffer) { let id = self.next_context_id.post_inc(); self.files.insert(context_buffer.id, id); self.context @@ -239,7 +240,7 @@ impl ContextStore { }) } - pub fn insert_directory(&mut self, path: &Path, context_buffers: Vec) { + fn insert_directory(&mut self, path: &Path, context_buffers: Vec) { let id = self.next_context_id.post_inc(); self.directories.insert(path.to_path_buf(), id); @@ -258,7 +259,7 @@ impl ContextStore { } } - pub fn insert_thread(&mut self, thread: Model, cx: &AppContext) { + fn insert_thread(&mut self, thread: Model, cx: &AppContext) { let id = self.next_context_id.post_inc(); let text = thread.read(cx).text().into(); @@ -267,7 +268,13 @@ impl ContextStore { .push(Context::Thread(ThreadContext { id, thread, text })); } - pub fn insert_fetched_url(&mut self, url: String, text: impl Into) { + pub fn add_fetched_url(&mut self, url: String, text: impl Into) { + if self.includes_url(&url).is_none() { + self.insert_fetched_url(url, text); + } + } + + fn insert_fetched_url(&mut self, url: String, text: impl Into) { let id = self.next_context_id.post_inc(); self.fetched_urls.insert(url.clone(), id); @@ -278,6 +285,30 @@ impl ContextStore { })); } + pub fn accept_suggested_context( + &mut self, + suggested: &SuggestedContext, + cx: &mut ModelContext, + ) -> Task> { + match suggested { + SuggestedContext::File { + buffer, + icon_path: _, + name: _, + } => { + if let Some(buffer) = buffer.upgrade() { + return self.add_file_from_buffer(buffer, cx); + }; + } + SuggestedContext::Thread { thread, name: _ } => { + if let Some(thread) = thread.upgrade() { + self.insert_thread(thread, cx); + }; + } + } + Task::ready(Ok(())) + } + pub fn remove_context(&mut self, id: ContextId) { let Some(ix) = self.context.iter().position(|context| context.id() == id) else { return; diff --git a/crates/assistant2/src/context_strip.rs b/crates/assistant2/src/context_strip.rs index 32a2ce2e11..10ac4edd7e 100644 --- a/crates/assistant2/src/context_strip.rs +++ b/crates/assistant2/src/context_strip.rs @@ -1,12 +1,10 @@ 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, + DismissEvent, EventEmitter, FocusHandle, Model, Subscription, View, WeakModel, WeakView, }; use itertools::Itertools; use language::Buffer; @@ -244,7 +242,7 @@ impl Render for ContextStrip { let context_store = self.context_store.clone(); Rc::new(cx.listener(move |this, _event, cx| { let task = context_store.update(cx, |context_store, cx| { - suggested.accept(context_store, cx) + context_store.accept_suggested_context(&suggested, cx) }); let workspace = this.workspace.clone(); @@ -339,30 +337,6 @@ impl SuggestedContext { } } - pub fn accept( - &self, - context_store: &mut ContextStore, - cx: &mut ModelContext, - ) -> Task> { - match self { - Self::File { - buffer, - icon_path: _, - name: _, - } => { - if let Some(buffer) = buffer.upgrade() { - return context_store.add_file_from_buffer(buffer, cx); - }; - } - Self::Thread { thread, name: _ } => { - if let Some(thread) = thread.upgrade() { - context_store.insert_thread(thread, cx); - }; - } - } - Task::ready(Ok(())) - } - pub fn kind(&self) -> ContextKind { match self { Self::File { .. } => ContextKind::File,