@@ -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 {
@@ -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;
@@ -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<ContextStore>,
- ) -> Task<Result<()>> {
- 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,