assistant2: Make ContextStore::insert_* methods private (#22989)

This PR makes the `insert_*` methods on the `ContextStore` private, to
reduce confusion with the public `add_*` methods.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-01-10 17:50:33 -05:00 committed by GitHub
parent 1fcc9b36ba
commit 40ecc38dd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 35 deletions

View file

@ -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<ContextBuffer>) {
fn insert_directory(&mut self, path: &Path, context_buffers: Vec<ContextBuffer>) {
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<Thread>, cx: &AppContext) {
fn insert_thread(&mut self, thread: Model<Thread>, 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<SharedString>) {
pub fn add_fetched_url(&mut self, url: String, text: impl Into<SharedString>) {
if self.includes_url(&url).is_none() {
self.insert_fetched_url(url, text);
}
}
fn insert_fetched_url(&mut self, url: String, text: impl Into<SharedString>) {
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<ContextStore>,
) -> Task<Result<()>> {
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;