Restore recent history
Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
parent
f66e10f965
commit
219c3bfde8
4 changed files with 72 additions and 36 deletions
|
@ -6,7 +6,7 @@ use std::sync::atomic::AtomicBool;
|
||||||
use acp_thread::MentionUri;
|
use acp_thread::MentionUri;
|
||||||
use agent::context_store::ContextStore;
|
use agent::context_store::ContextStore;
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use collections::HashMap;
|
use collections::{HashMap, HashSet};
|
||||||
use editor::display_map::CreaseId;
|
use editor::display_map::CreaseId;
|
||||||
use editor::{CompletionProvider, Editor, ExcerptId};
|
use editor::{CompletionProvider, Editor, ExcerptId};
|
||||||
use file_icons::FileIcons;
|
use file_icons::FileIcons;
|
||||||
|
@ -309,7 +309,6 @@ pub struct ContextPickerCompletionProvider {
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
||||||
editor: WeakEntity<Editor>,
|
editor: WeakEntity<Editor>,
|
||||||
excluded_buffer: Option<WeakEntity<Buffer>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextPickerCompletionProvider {
|
impl ContextPickerCompletionProvider {
|
||||||
|
@ -319,7 +318,6 @@ impl ContextPickerCompletionProvider {
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
||||||
editor: WeakEntity<Editor>,
|
editor: WeakEntity<Editor>,
|
||||||
exclude_buffer: Option<WeakEntity<Buffer>>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
mention_set,
|
mention_set,
|
||||||
|
@ -327,7 +325,6 @@ impl ContextPickerCompletionProvider {
|
||||||
thread_store,
|
thread_store,
|
||||||
text_thread_store,
|
text_thread_store,
|
||||||
editor,
|
editor,
|
||||||
excluded_buffer: exclude_buffer,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,21 +769,35 @@ impl CompletionProvider for ContextPickerCompletionProvider {
|
||||||
let MentionCompletion { mode, argument, .. } = state;
|
let MentionCompletion { mode, argument, .. } = state;
|
||||||
let query = argument.unwrap_or_else(|| "".to_string());
|
let query = argument.unwrap_or_else(|| "".to_string());
|
||||||
|
|
||||||
let excluded_path = self
|
let (exclude_paths, exclude_threads) = {
|
||||||
.excluded_buffer
|
let mention_set = self.mention_set.lock();
|
||||||
.as_ref()
|
|
||||||
.and_then(WeakEntity::upgrade)
|
|
||||||
.and_then(|b| b.read(cx).file())
|
|
||||||
.map(|file| ProjectPath::from_file(file.as_ref(), cx));
|
|
||||||
|
|
||||||
// let recent_entries = recent_context_picker_entries(
|
let mut excluded_paths = HashSet::default();
|
||||||
// context_store.clone(),
|
let mut excluded_threads = HashSet::default();
|
||||||
// thread_store.clone(),
|
|
||||||
// text_thread_store.clone(),
|
for uri in mention_set.uri_by_crease_id.values() {
|
||||||
// workspace.clone(),
|
match uri {
|
||||||
// excluded_path.clone(),
|
MentionUri::File(path) => {
|
||||||
// cx,
|
excluded_paths.insert(path.clone());
|
||||||
// );
|
}
|
||||||
|
MentionUri::Thread(thread) => {
|
||||||
|
excluded_threads.insert(thread.0.as_ref().into());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(excluded_paths, excluded_threads)
|
||||||
|
};
|
||||||
|
|
||||||
|
let recent_entries = recent_context_picker_entries(
|
||||||
|
thread_store.clone(),
|
||||||
|
text_thread_store.clone(),
|
||||||
|
workspace.clone(),
|
||||||
|
&exclude_paths,
|
||||||
|
&exclude_threads,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
let prompt_store = thread_store.as_ref().and_then(|thread_store| {
|
let prompt_store = thread_store.as_ref().and_then(|thread_store| {
|
||||||
thread_store
|
thread_store
|
||||||
|
@ -799,9 +810,7 @@ impl CompletionProvider for ContextPickerCompletionProvider {
|
||||||
mode,
|
mode,
|
||||||
query,
|
query,
|
||||||
Arc::<AtomicBool>::default(),
|
Arc::<AtomicBool>::default(),
|
||||||
// todo!
|
recent_entries,
|
||||||
// recent_entries,
|
|
||||||
vec![],
|
|
||||||
prompt_store,
|
prompt_store,
|
||||||
thread_store.clone(),
|
thread_store.clone(),
|
||||||
text_thread_store.clone(),
|
text_thread_store.clone(),
|
||||||
|
@ -827,10 +836,6 @@ impl CompletionProvider for ContextPickerCompletionProvider {
|
||||||
path: mat.path.clone(),
|
path: mat.path.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if excluded_path.as_ref() == Some(&project_path) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Self::completion_for_path(
|
Self::completion_for_path(
|
||||||
project_path,
|
project_path,
|
||||||
&mat.path_prefix,
|
&mat.path_prefix,
|
||||||
|
|
|
@ -145,7 +145,7 @@ impl AcpThreadView {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
cx.weak_entity(),
|
cx.weak_entity(),
|
||||||
None,
|
// None,
|
||||||
))));
|
))));
|
||||||
editor.set_context_menu_options(ContextMenuOptions {
|
editor.set_context_menu_options(ContextMenuOptions {
|
||||||
min_entries_visible: 12,
|
min_entries_visible: 12,
|
||||||
|
|
|
@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
|
use collections::HashSet;
|
||||||
pub use completion_provider::ContextPickerCompletionProvider;
|
pub use completion_provider::ContextPickerCompletionProvider;
|
||||||
use editor::display_map::{Crease, CreaseId, CreaseMetadata, FoldId};
|
use editor::display_map::{Crease, CreaseId, CreaseMetadata, FoldId};
|
||||||
use editor::{Anchor, AnchorRangeExt as _, Editor, ExcerptId, FoldPlaceholder, ToOffset};
|
use editor::{Anchor, AnchorRangeExt as _, Editor, ExcerptId, FoldPlaceholder, ToOffset};
|
||||||
|
@ -531,7 +532,7 @@ impl ContextPicker {
|
||||||
return vec![];
|
return vec![];
|
||||||
};
|
};
|
||||||
|
|
||||||
recent_context_picker_entries(
|
recent_context_picker_entries_with_store(
|
||||||
context_store,
|
context_store,
|
||||||
self.thread_store.clone(),
|
self.thread_store.clone(),
|
||||||
self.text_thread_store.clone(),
|
self.text_thread_store.clone(),
|
||||||
|
@ -631,24 +632,56 @@ pub(crate) fn available_context_picker_entries(
|
||||||
entries
|
entries
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn recent_context_picker_entries(
|
fn recent_context_picker_entries_with_store(
|
||||||
context_store: Entity<ContextStore>,
|
context_store: Entity<ContextStore>,
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
||||||
workspace: Entity<Workspace>,
|
workspace: Entity<Workspace>,
|
||||||
exclude_path: Option<ProjectPath>,
|
exclude_path: Option<ProjectPath>,
|
||||||
cx: &App,
|
cx: &App,
|
||||||
|
) -> Vec<RecentEntry> {
|
||||||
|
let project = workspace.read(cx).project();
|
||||||
|
|
||||||
|
let mut exclude_paths = context_store.read(cx).file_paths(cx);
|
||||||
|
exclude_paths.extend(exclude_path);
|
||||||
|
|
||||||
|
let exclude_paths = exclude_paths
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|project_path| project.read(cx).absolute_path(&project_path, cx))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let exclude_threads = context_store.read(cx).thread_ids();
|
||||||
|
|
||||||
|
recent_context_picker_entries(
|
||||||
|
thread_store,
|
||||||
|
text_thread_store,
|
||||||
|
workspace,
|
||||||
|
&exclude_paths,
|
||||||
|
exclude_threads,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn recent_context_picker_entries(
|
||||||
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
|
text_thread_store: Option<WeakEntity<TextThreadStore>>,
|
||||||
|
workspace: Entity<Workspace>,
|
||||||
|
exclude_paths: &HashSet<PathBuf>,
|
||||||
|
exclude_threads: &HashSet<ThreadId>,
|
||||||
|
cx: &App,
|
||||||
) -> Vec<RecentEntry> {
|
) -> Vec<RecentEntry> {
|
||||||
let mut recent = Vec::with_capacity(6);
|
let mut recent = Vec::with_capacity(6);
|
||||||
let mut current_files = context_store.read(cx).file_paths(cx);
|
|
||||||
current_files.extend(exclude_path);
|
|
||||||
let workspace = workspace.read(cx);
|
let workspace = workspace.read(cx);
|
||||||
let project = workspace.project().read(cx);
|
let project = workspace.project().read(cx);
|
||||||
|
|
||||||
recent.extend(
|
recent.extend(
|
||||||
workspace
|
workspace
|
||||||
.recent_navigation_history_iter(cx)
|
.recent_navigation_history_iter(cx)
|
||||||
.filter(|(path, _)| !current_files.contains(path))
|
.filter(|(_, abs_path)| {
|
||||||
|
abs_path
|
||||||
|
.as_ref()
|
||||||
|
.map_or(true, |path| !exclude_paths.contains(path.as_path()))
|
||||||
|
})
|
||||||
.take(4)
|
.take(4)
|
||||||
.filter_map(|(project_path, _)| {
|
.filter_map(|(project_path, _)| {
|
||||||
project
|
project
|
||||||
|
@ -660,8 +693,6 @@ pub(crate) fn recent_context_picker_entries(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let current_threads = context_store.read(cx).thread_ids();
|
|
||||||
|
|
||||||
let active_thread_id = workspace
|
let active_thread_id = workspace
|
||||||
.panel::<AgentPanel>(cx)
|
.panel::<AgentPanel>(cx)
|
||||||
.and_then(|panel| Some(panel.read(cx).active_thread(cx)?.read(cx).id()));
|
.and_then(|panel| Some(panel.read(cx).active_thread(cx)?.read(cx).id()));
|
||||||
|
@ -673,7 +704,7 @@ pub(crate) fn recent_context_picker_entries(
|
||||||
let mut threads = unordered_thread_entries(thread_store, text_thread_store, cx)
|
let mut threads = unordered_thread_entries(thread_store, text_thread_store, cx)
|
||||||
.filter(|(_, thread)| match thread {
|
.filter(|(_, thread)| match thread {
|
||||||
ThreadContextEntry::Thread { id, .. } => {
|
ThreadContextEntry::Thread { id, .. } => {
|
||||||
Some(id) != active_thread_id && !current_threads.contains(id)
|
Some(id) != active_thread_id && !exclude_threads.contains(id)
|
||||||
}
|
}
|
||||||
ThreadContextEntry::Context { .. } => true,
|
ThreadContextEntry::Context { .. } => true,
|
||||||
})
|
})
|
||||||
|
|
|
@ -35,7 +35,7 @@ use super::symbol_context_picker::search_symbols;
|
||||||
use super::thread_context_picker::{ThreadContextEntry, ThreadMatch, search_threads};
|
use super::thread_context_picker::{ThreadContextEntry, ThreadMatch, search_threads};
|
||||||
use super::{
|
use super::{
|
||||||
ContextPickerAction, ContextPickerEntry, ContextPickerMode, MentionLink, RecentEntry,
|
ContextPickerAction, ContextPickerEntry, ContextPickerMode, MentionLink, RecentEntry,
|
||||||
available_context_picker_entries, recent_context_picker_entries, selection_ranges,
|
available_context_picker_entries, recent_context_picker_entries_with_store, selection_ranges,
|
||||||
};
|
};
|
||||||
use crate::message_editor::ContextCreasesAddon;
|
use crate::message_editor::ContextCreasesAddon;
|
||||||
|
|
||||||
|
@ -787,7 +787,7 @@ impl CompletionProvider for ContextPickerCompletionProvider {
|
||||||
.and_then(|b| b.read(cx).file())
|
.and_then(|b| b.read(cx).file())
|
||||||
.map(|file| ProjectPath::from_file(file.as_ref(), cx));
|
.map(|file| ProjectPath::from_file(file.as_ref(), cx));
|
||||||
|
|
||||||
let recent_entries = recent_context_picker_entries(
|
let recent_entries = recent_context_picker_entries_with_store(
|
||||||
context_store.clone(),
|
context_store.clone(),
|
||||||
thread_store.clone(),
|
thread_store.clone(),
|
||||||
text_thread_store.clone(),
|
text_thread_store.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue