mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
agent_ui: Save the Delta clone of thread and terminal folders
Saved threads and terminals keep the clone of each Delta folder in a new `delta_clones` column, so a row can be labelled after its checkout while the checkout is closed. Thread import from another release channel falls back to a query without the column. `change_worktree_paths` no longer writes or notifies for rows that the change leaves as they are.
This commit is contained in:
@@ -154,6 +154,11 @@ fn terminal_program_to_report(
|
||||
pub struct TerminalId(uuid::Uuid);
|
||||
|
||||
impl TerminalId {
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn test_new() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(uuid::Uuid::new_v4())
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ use ui::{App, Context, SharedString};
|
||||
use util::ResultExt as _;
|
||||
use workspace::PathList;
|
||||
|
||||
use crate::{TerminalId, thread_metadata_store::WorktreePaths};
|
||||
use crate::{
|
||||
TerminalId,
|
||||
thread_metadata_store::{WorktreePaths, worktree_paths_from_columns},
|
||||
};
|
||||
|
||||
pub fn init(cx: &mut App) {
|
||||
TerminalThreadMetadataStore::init_global(cx);
|
||||
@@ -160,6 +163,7 @@ pub struct TerminalThreadMetadataStore {
|
||||
terminals_by_paths: HashMap<PathList, HashSet<TerminalId>>,
|
||||
terminals_by_main_paths: HashMap<PathList, HashSet<TerminalId>>,
|
||||
reload_task: Option<Shared<Task<()>>>,
|
||||
is_loaded: bool,
|
||||
pending_terminal_ops_tx: async_channel::Sender<DbOperation>,
|
||||
_db_operations_task: Task<()>,
|
||||
}
|
||||
@@ -222,6 +226,10 @@ impl TerminalThreadMetadataStore {
|
||||
.unwrap_or_else(|| Task::ready(()).shared())
|
||||
}
|
||||
|
||||
pub fn is_loaded(&self) -> bool {
|
||||
self.is_loaded
|
||||
}
|
||||
|
||||
pub fn entries_for_path<'a>(
|
||||
&'a self,
|
||||
path_list: &PathList,
|
||||
@@ -317,18 +325,22 @@ impl TerminalThreadMetadataStore {
|
||||
.copied()
|
||||
.collect();
|
||||
|
||||
if terminal_ids.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut changed = false;
|
||||
for terminal_id in terminal_ids {
|
||||
if let Some(mut terminal) = self.terminals.get(&terminal_id).cloned() {
|
||||
let worktree_paths = terminal.worktree_paths.clone();
|
||||
mutate(&mut terminal.worktree_paths);
|
||||
if terminal.worktree_paths == worktree_paths {
|
||||
continue;
|
||||
}
|
||||
changed = true;
|
||||
self.save_internal(terminal);
|
||||
}
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
if changed {
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
fn save_internal(&mut self, metadata: TerminalThreadMetadata) {
|
||||
@@ -421,6 +433,7 @@ impl TerminalThreadMetadataStore {
|
||||
terminals_by_paths: HashMap::default(),
|
||||
terminals_by_main_paths: HashMap::default(),
|
||||
reload_task: None,
|
||||
is_loaded: false,
|
||||
pending_terminal_ops_tx: tx,
|
||||
_db_operations_task,
|
||||
};
|
||||
@@ -449,10 +462,12 @@ impl TerminalThreadMetadataStore {
|
||||
.context("Failed to fetch terminal thread metadata")
|
||||
})
|
||||
.await
|
||||
.log_err()
|
||||
.unwrap_or_default();
|
||||
.log_err();
|
||||
let is_loaded = rows.is_some();
|
||||
let rows = rows.unwrap_or_default();
|
||||
|
||||
this.update(cx, |this, cx| {
|
||||
this.is_loaded = is_loaded;
|
||||
this.terminals.clear();
|
||||
this.terminals_by_paths.clear();
|
||||
this.terminals_by_main_paths.clear();
|
||||
@@ -475,7 +490,8 @@ struct TerminalThreadMetadataDb(ThreadSafeConnection);
|
||||
impl Domain for TerminalThreadMetadataDb {
|
||||
const NAME: &str = stringify!(TerminalThreadMetadataDb);
|
||||
|
||||
const MIGRATIONS: &[&str] = &[sql!(
|
||||
const MIGRATIONS: &[&str] = &[
|
||||
sql!(
|
||||
CREATE TABLE IF NOT EXISTS sidebar_terminal_threads(
|
||||
terminal_id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
@@ -488,7 +504,11 @@ impl Domain for TerminalThreadMetadataDb {
|
||||
main_worktree_paths_order TEXT,
|
||||
remote_connection TEXT
|
||||
) STRICT;
|
||||
)];
|
||||
),
|
||||
sql!(
|
||||
ALTER TABLE sidebar_terminal_threads ADD COLUMN delta_clones TEXT;
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
db::static_connection!(TerminalThreadMetadataDb, []);
|
||||
@@ -498,7 +518,7 @@ impl TerminalThreadMetadataDb {
|
||||
self.select::<TerminalThreadMetadata>(
|
||||
"SELECT terminal_id, title, custom_title, created_at, \
|
||||
working_directory, folder_paths, folder_paths_order, main_worktree_paths, \
|
||||
main_worktree_paths_order, remote_connection \
|
||||
main_worktree_paths_order, remote_connection, delta_clones \
|
||||
FROM sidebar_terminal_threads \
|
||||
ORDER BY created_at DESC",
|
||||
)?()
|
||||
@@ -532,10 +552,11 @@ impl TerminalThreadMetadataDb {
|
||||
.map(serde_json::to_string)
|
||||
.transpose()
|
||||
.context("serialize terminal thread remote connection")?;
|
||||
let delta_clones = row.worktree_paths.serialized_delta_clones();
|
||||
|
||||
self.write(move |conn| {
|
||||
let sql = "INSERT INTO sidebar_terminal_threads(terminal_id, title, custom_title, created_at, working_directory, folder_paths, folder_paths_order, main_worktree_paths, main_worktree_paths_order, remote_connection) \
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10) \
|
||||
let sql = "INSERT INTO sidebar_terminal_threads(terminal_id, title, custom_title, created_at, working_directory, folder_paths, folder_paths_order, main_worktree_paths, main_worktree_paths_order, remote_connection, delta_clones) \
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11) \
|
||||
ON CONFLICT(terminal_id) DO UPDATE SET \
|
||||
title = excluded.title, \
|
||||
custom_title = excluded.custom_title, \
|
||||
@@ -545,7 +566,8 @@ impl TerminalThreadMetadataDb {
|
||||
folder_paths_order = excluded.folder_paths_order, \
|
||||
main_worktree_paths = excluded.main_worktree_paths, \
|
||||
main_worktree_paths_order = excluded.main_worktree_paths_order, \
|
||||
remote_connection = excluded.remote_connection";
|
||||
remote_connection = excluded.remote_connection, \
|
||||
delta_clones = excluded.delta_clones";
|
||||
let mut stmt = Statement::prepare(conn, sql)?;
|
||||
let mut i = stmt.bind(&terminal_id, 1)?;
|
||||
i = stmt.bind(&title, i)?;
|
||||
@@ -556,7 +578,8 @@ impl TerminalThreadMetadataDb {
|
||||
i = stmt.bind(&folder_paths_order, i)?;
|
||||
i = stmt.bind(&main_worktree_paths, i)?;
|
||||
i = stmt.bind(&main_worktree_paths_order, i)?;
|
||||
stmt.bind(&remote_connection, i)?;
|
||||
i = stmt.bind(&remote_connection, i)?;
|
||||
stmt.bind(&delta_clones, i)?;
|
||||
stmt.exec()
|
||||
})
|
||||
.await
|
||||
@@ -592,24 +615,7 @@ impl Column for TerminalThreadMetadata {
|
||||
Column::column(statement, next)?;
|
||||
let (remote_connection_json, next): (Option<String>, i32) =
|
||||
Column::column(statement, next)?;
|
||||
|
||||
let folder_paths = folder_paths_str
|
||||
.map(|paths| {
|
||||
PathList::deserialize(&util::path_list::SerializedPathList {
|
||||
paths,
|
||||
order: folder_paths_order_str.unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let main_worktree_paths = main_worktree_paths_str
|
||||
.map(|paths| {
|
||||
PathList::deserialize(&util::path_list::SerializedPathList {
|
||||
paths,
|
||||
order: main_worktree_paths_order_str.unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let (delta_clones, next): (Option<String>, i32) = Column::column(statement, next)?;
|
||||
|
||||
let remote_connection = remote_connection_json
|
||||
.as_deref()
|
||||
@@ -617,8 +623,13 @@ impl Column for TerminalThreadMetadata {
|
||||
.transpose()
|
||||
.context("deserialize terminal thread remote connection")?;
|
||||
|
||||
let worktree_paths = WorktreePaths::from_path_lists(main_worktree_paths, folder_paths)
|
||||
.unwrap_or_else(|_| WorktreePaths::default());
|
||||
let worktree_paths = worktree_paths_from_columns((
|
||||
folder_paths_str,
|
||||
folder_paths_order_str,
|
||||
main_worktree_paths_str,
|
||||
main_worktree_paths_order_str,
|
||||
delta_clones,
|
||||
));
|
||||
|
||||
Ok((
|
||||
TerminalThreadMetadata {
|
||||
@@ -641,7 +652,11 @@ impl Column for TerminalThreadMetadata {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use gpui::TestAppContext;
|
||||
use std::path::Path;
|
||||
use std::{
|
||||
cell::Cell,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
fn init_test(cx: &mut TestAppContext) {
|
||||
cx.update(|cx| {
|
||||
@@ -730,6 +745,55 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_change_worktree_paths_skips_unchanged_terminals(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
let store = cx.update(|cx| TerminalThreadMetadataStore::global(cx));
|
||||
let folder_paths = PathList::new(&[Path::new("/projects/checkout")]);
|
||||
let metadata = metadata(
|
||||
"Dev Server",
|
||||
WorktreePaths::from_folder_paths(&folder_paths),
|
||||
);
|
||||
let terminal_id = metadata.terminal_id;
|
||||
store.update(cx, |store, cx| store.save(metadata, cx));
|
||||
cx.run_until_parked();
|
||||
|
||||
let notification_count = Rc::new(Cell::new(0));
|
||||
let _subscription = cx.update(|cx| {
|
||||
let notification_count = notification_count.clone();
|
||||
cx.observe(&store, move |_, _| {
|
||||
notification_count.set(notification_count.get() + 1);
|
||||
})
|
||||
});
|
||||
let mut main_paths = Vec::new();
|
||||
for _ in 0..2 {
|
||||
store.update(cx, |store, cx| {
|
||||
store.change_worktree_paths(
|
||||
&folder_paths,
|
||||
None,
|
||||
|paths| {
|
||||
paths.add_path(
|
||||
Path::new("/projects/source"),
|
||||
Path::new("/projects/checkout"),
|
||||
)
|
||||
},
|
||||
cx,
|
||||
);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
main_paths.push(store.read_with(cx, |store, _| {
|
||||
store
|
||||
.entry(terminal_id)
|
||||
.map(|terminal| terminal.main_worktree_paths().paths().to_vec())
|
||||
}));
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
(main_paths, notification_count.get()),
|
||||
(vec![Some(vec![PathBuf::from("/projects/source")]); 2], 1)
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_change_worktree_paths_reindexes_terminal_metadata(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
|
||||
@@ -22,7 +22,7 @@ use fs::Fs;
|
||||
use futures::{FutureExt, future::Shared};
|
||||
use gpui::{AppContext as _, Entity, Global, Subscription, Task, TaskExt};
|
||||
pub use project::WorktreePaths;
|
||||
use project::{AgentId, linked_worktree_short_name};
|
||||
use project::{AgentId, delta_checkout_short_name, linked_worktree_short_name};
|
||||
use remote::RemoteConnectionOptions;
|
||||
use ui::{App, Context, SharedString, ThreadItemWorktreeInfo, WorktreeKind};
|
||||
use util::{ResultExt as _, paths::PathStyle};
|
||||
@@ -67,7 +67,12 @@ const THREAD_ID_MIGRATION_KEY: &str = "thread-metadata-thread-id-backfill";
|
||||
pub(crate) fn list_thread_metadata_from_connection(
|
||||
connection: &db::sqlez::connection::Connection,
|
||||
) -> anyhow::Result<Vec<ThreadMetadata>> {
|
||||
connection.select::<ThreadMetadata>(ThreadMetadataDb::LIST_QUERY)?()
|
||||
match connection.select::<ThreadMetadata>(ThreadMetadataDb::LIST_QUERY) {
|
||||
Ok(mut list_thread_metadata) => list_thread_metadata(),
|
||||
Err(_) => connection
|
||||
.select::<ThreadMetadata>(ThreadMetadataDb::LIST_QUERY_WITHOUT_DELTA_CLONES)?(
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the `ThreadMetadataDb` migrations on a raw connection.
|
||||
@@ -189,6 +194,41 @@ fn migrate_thread_metadata(cx: &mut App) -> Task<anyhow::Result<()>> {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) type WorktreePathColumns = (
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
);
|
||||
|
||||
pub(crate) fn worktree_paths_from_columns(
|
||||
(
|
||||
folder_paths,
|
||||
folder_paths_order,
|
||||
main_worktree_paths,
|
||||
main_worktree_paths_order,
|
||||
delta_clones,
|
||||
): WorktreePathColumns,
|
||||
) -> WorktreePaths {
|
||||
let path_list = |paths: Option<String>, order: Option<String>| {
|
||||
paths
|
||||
.map(|paths| {
|
||||
PathList::deserialize(&util::path_list::SerializedPathList {
|
||||
paths,
|
||||
order: order.unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default()
|
||||
};
|
||||
WorktreePaths::from_path_lists(
|
||||
path_list(main_worktree_paths, main_worktree_paths_order),
|
||||
path_list(folder_paths, folder_paths_order),
|
||||
)
|
||||
.unwrap_or_else(|_| WorktreePaths::default())
|
||||
.with_serialized_delta_clones(delta_clones.as_deref())
|
||||
}
|
||||
|
||||
fn migrate_thread_remote_connections(cx: &mut App, migration_task: Task<anyhow::Result<()>>) {
|
||||
let store = ThreadMetadataStore::global(cx);
|
||||
let db = store.read(cx).db.clone();
|
||||
@@ -385,7 +425,10 @@ pub fn worktree_info_from_thread_paths<S: std::hash::BuildHasher>(
|
||||
let is_linked = main_path != folder_path;
|
||||
|
||||
if is_linked {
|
||||
let short_name = linked_worktree_short_name(main_path, folder_path, PathStyle::local())
|
||||
let short_name = worktree_paths
|
||||
.delta_clone(folder_path)
|
||||
.and_then(|clone| delta_checkout_short_name(clone, folder_path, PathStyle::local()))
|
||||
.or_else(|| linked_worktree_short_name(main_path, folder_path, PathStyle::local()))
|
||||
.unwrap_or_default();
|
||||
let project_name = main_path
|
||||
.file_name()
|
||||
@@ -506,6 +549,7 @@ pub struct ThreadMetadataStore {
|
||||
threads_by_main_paths: HashMap<PathList, HashSet<ThreadId>>,
|
||||
threads_by_session: HashMap<acp::SessionId, ThreadId>,
|
||||
reload_task: Option<Shared<Task<()>>>,
|
||||
is_loaded: bool,
|
||||
conversation_subscriptions: HashMap<gpui::EntityId, Subscription>,
|
||||
pending_thread_ops_tx: async_channel::Sender<DbOperation>,
|
||||
in_flight_archives: HashMap<ThreadId, (Task<()>, async_channel::Sender<()>)>,
|
||||
@@ -609,6 +653,10 @@ impl ThreadMetadataStore {
|
||||
.unwrap_or_else(|| Task::ready(()).shared())
|
||||
}
|
||||
|
||||
pub fn is_loaded(&self) -> bool {
|
||||
self.is_loaded
|
||||
}
|
||||
|
||||
/// Returns all archived threads.
|
||||
pub fn archived_entries(&self) -> impl Iterator<Item = &ThreadMetadata> + '_ {
|
||||
self.entries().filter(|t| t.archived)
|
||||
@@ -678,6 +726,7 @@ impl ThreadMetadataStore {
|
||||
for row in rows {
|
||||
this.cache_thread_metadata(row);
|
||||
}
|
||||
this.is_loaded = true;
|
||||
|
||||
cx.notify();
|
||||
})
|
||||
@@ -804,7 +853,8 @@ impl ThreadMetadataStore {
|
||||
thread.main_worktree_paths().clone(),
|
||||
work_dirs.clone(),
|
||||
)
|
||||
.unwrap_or_else(|_| WorktreePaths::from_folder_paths(&work_dirs)),
|
||||
.unwrap_or_else(|_| WorktreePaths::from_folder_paths(&work_dirs))
|
||||
.with_delta_clones(thread.worktree_paths.delta_clones().clone()),
|
||||
..thread.clone()
|
||||
});
|
||||
cx.notify();
|
||||
@@ -938,7 +988,8 @@ impl ThreadMetadataStore {
|
||||
thread.main_worktree_paths().clone(),
|
||||
new_folder_paths.clone(),
|
||||
)
|
||||
.unwrap_or_else(|_| WorktreePaths::from_folder_paths(&new_folder_paths)),
|
||||
.unwrap_or_else(|_| WorktreePaths::from_folder_paths(&new_folder_paths))
|
||||
.with_delta_clones(thread.worktree_paths.delta_clones().clone()),
|
||||
..thread
|
||||
});
|
||||
cx.notify();
|
||||
@@ -966,7 +1017,8 @@ impl ThreadMetadataStore {
|
||||
thread.main_worktree_paths().clone(),
|
||||
new_folder_paths.clone(),
|
||||
)
|
||||
.unwrap_or_else(|_| WorktreePaths::from_folder_paths(&new_folder_paths)),
|
||||
.unwrap_or_else(|_| WorktreePaths::from_folder_paths(&new_folder_paths))
|
||||
.with_delta_clones(thread.worktree_paths.delta_clones().clone()),
|
||||
..thread
|
||||
});
|
||||
cx.notify();
|
||||
@@ -1010,8 +1062,16 @@ impl ThreadMetadataStore {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut changed = false;
|
||||
for thread_id in thread_ids {
|
||||
if let Some(thread) = self.threads.get_mut(thread_id) {
|
||||
let mut worktree_paths = thread.worktree_paths.clone();
|
||||
mutate(&mut worktree_paths);
|
||||
if worktree_paths == thread.worktree_paths {
|
||||
continue;
|
||||
}
|
||||
changed = true;
|
||||
|
||||
if let Some(ids) = self
|
||||
.threads_by_main_paths
|
||||
.get_mut(thread.main_worktree_paths())
|
||||
@@ -1022,7 +1082,7 @@ impl ThreadMetadataStore {
|
||||
ids.remove(thread_id);
|
||||
}
|
||||
|
||||
mutate(&mut thread.worktree_paths);
|
||||
thread.worktree_paths = worktree_paths;
|
||||
|
||||
self.threads_by_main_paths
|
||||
.entry(thread.main_worktree_paths().clone())
|
||||
@@ -1039,7 +1099,9 @@ impl ThreadMetadataStore {
|
||||
}
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
if changed {
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_archived_worktree(
|
||||
@@ -1240,6 +1302,7 @@ impl ThreadMetadataStore {
|
||||
threads_by_main_paths: HashMap::default(),
|
||||
threads_by_session: HashMap::default(),
|
||||
reload_task: None,
|
||||
is_loaded: false,
|
||||
conversation_subscriptions: HashMap::default(),
|
||||
pending_thread_ops_tx: tx,
|
||||
in_flight_archives: HashMap::default(),
|
||||
@@ -1460,6 +1523,9 @@ impl Domain for ThreadMetadataDb {
|
||||
sql!(
|
||||
ALTER TABLE sidebar_threads ADD COLUMN title_override TEXT;
|
||||
),
|
||||
sql!(
|
||||
ALTER TABLE sidebar_threads ADD COLUMN delta_clones TEXT;
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1476,7 +1542,13 @@ impl ThreadMetadataDb {
|
||||
|
||||
const LIST_QUERY: &str = "SELECT thread_id, session_id, agent_id, title, updated_at, \
|
||||
created_at, interacted_at, folder_paths, folder_paths_order, archived, main_worktree_paths, \
|
||||
main_worktree_paths_order, remote_connection, title_override \
|
||||
main_worktree_paths_order, remote_connection, title_override, delta_clones \
|
||||
FROM sidebar_threads \
|
||||
ORDER BY updated_at DESC";
|
||||
|
||||
const LIST_QUERY_WITHOUT_DELTA_CLONES: &str = "SELECT thread_id, session_id, agent_id, \
|
||||
title, updated_at, created_at, interacted_at, folder_paths, folder_paths_order, archived, \
|
||||
main_worktree_paths, main_worktree_paths_order, remote_connection, title_override, NULL \
|
||||
FROM sidebar_threads \
|
||||
ORDER BY updated_at DESC";
|
||||
|
||||
@@ -1527,12 +1599,13 @@ impl ThreadMetadataDb {
|
||||
.transpose()
|
||||
.context("serialize thread metadata remote connection")?;
|
||||
let title_override = row.title_override.as_ref().map(|t| t.to_string());
|
||||
let delta_clones = row.worktree_paths.serialized_delta_clones();
|
||||
let thread_id = row.thread_id;
|
||||
let archived = row.archived;
|
||||
|
||||
self.write(move |conn| {
|
||||
let sql = "INSERT INTO sidebar_threads(thread_id, session_id, agent_id, title, updated_at, created_at, interacted_at, folder_paths, folder_paths_order, archived, main_worktree_paths, main_worktree_paths_order, remote_connection, title_override) \
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14) \
|
||||
let sql = "INSERT INTO sidebar_threads(thread_id, session_id, agent_id, title, updated_at, created_at, interacted_at, folder_paths, folder_paths_order, archived, main_worktree_paths, main_worktree_paths_order, remote_connection, title_override, delta_clones) \
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15) \
|
||||
ON CONFLICT(thread_id) DO UPDATE SET \
|
||||
session_id = excluded.session_id, \
|
||||
agent_id = excluded.agent_id, \
|
||||
@@ -1546,7 +1619,8 @@ impl ThreadMetadataDb {
|
||||
main_worktree_paths = excluded.main_worktree_paths, \
|
||||
main_worktree_paths_order = excluded.main_worktree_paths_order, \
|
||||
remote_connection = excluded.remote_connection, \
|
||||
title_override = excluded.title_override";
|
||||
title_override = excluded.title_override, \
|
||||
delta_clones = excluded.delta_clones";
|
||||
let mut stmt = Statement::prepare(conn, sql)?;
|
||||
let mut i = stmt.bind(&thread_id, 1)?;
|
||||
i = stmt.bind(&session_id, i)?;
|
||||
@@ -1561,7 +1635,8 @@ impl ThreadMetadataDb {
|
||||
i = stmt.bind(&main_worktree_paths, i)?;
|
||||
i = stmt.bind(&main_worktree_paths_order, i)?;
|
||||
i = stmt.bind(&remote_connection, i)?;
|
||||
stmt.bind(&title_override, i)?;
|
||||
i = stmt.bind(&title_override, i)?;
|
||||
stmt.bind(&delta_clones, i)?;
|
||||
stmt.exec()
|
||||
})
|
||||
.await
|
||||
@@ -1719,6 +1794,7 @@ impl Column for ThreadMetadata {
|
||||
let (remote_connection_json, next): (Option<String>, i32) =
|
||||
Column::column(statement, next)?;
|
||||
let (title_override, next): (Option<String>, i32) = Column::column(statement, next)?;
|
||||
let (delta_clones, next): (Option<String>, i32) = Column::column(statement, next)?;
|
||||
|
||||
let agent_id = agent_id
|
||||
.map(|id| AgentId::new(id))
|
||||
@@ -1737,32 +1813,19 @@ impl Column for ThreadMetadata {
|
||||
.transpose()?
|
||||
.map(|dt| dt.with_timezone(&Utc));
|
||||
|
||||
let folder_paths = folder_paths_str
|
||||
.map(|paths| {
|
||||
PathList::deserialize(&util::path_list::SerializedPathList {
|
||||
paths,
|
||||
order: folder_paths_order_str.unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let main_worktree_paths = main_worktree_paths_str
|
||||
.map(|paths| {
|
||||
PathList::deserialize(&util::path_list::SerializedPathList {
|
||||
paths,
|
||||
order: main_worktree_paths_order_str.unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let remote_connection = remote_connection_json
|
||||
.as_deref()
|
||||
.map(serde_json::from_str::<RemoteConnectionOptions>)
|
||||
.transpose()
|
||||
.context("deserialize thread metadata remote connection")?;
|
||||
|
||||
let worktree_paths = WorktreePaths::from_path_lists(main_worktree_paths, folder_paths)
|
||||
.unwrap_or_else(|_| WorktreePaths::default());
|
||||
let worktree_paths = worktree_paths_from_columns((
|
||||
folder_paths_str,
|
||||
folder_paths_order_str,
|
||||
main_worktree_paths_str,
|
||||
main_worktree_paths_order_str,
|
||||
delta_clones,
|
||||
));
|
||||
|
||||
let thread_id = ThreadId(thread_id_uuid);
|
||||
|
||||
@@ -1883,6 +1946,7 @@ mod tests {
|
||||
cx.update(|cx| {
|
||||
let settings_store = settings::SettingsStore::test(cx);
|
||||
cx.set_global(settings_store);
|
||||
cx.set_global(db::AppDatabase::test_new());
|
||||
theme_settings::init(theme::LoadThemes::JustBase, cx);
|
||||
editor::init(cx);
|
||||
release_channel::init("0.0.0".parse().unwrap(), cx);
|
||||
@@ -3716,6 +3780,88 @@ mod tests {
|
||||
assert!(!paths.contains(&PathBuf::from("/should/not/appear")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_reads_database_saved_before_delta_clones() {
|
||||
let connection = db::sqlez::connection::Connection::open_memory(Some(
|
||||
"test_list_reads_database_saved_before_delta_clones",
|
||||
));
|
||||
connection
|
||||
.migrate(
|
||||
ThreadMetadataDb::NAME,
|
||||
&ThreadMetadataDb::MIGRATIONS[..ThreadMetadataDb::MIGRATIONS.len() - 1],
|
||||
&mut |_, _, _| false,
|
||||
)
|
||||
.unwrap();
|
||||
connection
|
||||
.exec_bound::<(uuid::Uuid, &str, &str, &str)>(
|
||||
"INSERT INTO sidebar_threads (thread_id, session_id, title, updated_at) \
|
||||
VALUES (?1, ?2, ?3, ?4)",
|
||||
)
|
||||
.unwrap()((
|
||||
uuid::Uuid::new_v4(),
|
||||
"session",
|
||||
"Saved by an older build",
|
||||
"2024-01-01T00:00:00Z",
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let titles = list_thread_metadata_from_connection(&connection)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|thread| thread.title())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(titles, [Some("Saved by an older build".into())]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_change_worktree_paths_skips_unchanged_threads(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
let store = cx.update(|cx| ThreadMetadataStore::global(cx));
|
||||
let folder_paths = PathList::new(&[Path::new("/projects/checkout")]);
|
||||
let metadata = make_metadata("session", "Thread", Utc::now(), folder_paths.clone());
|
||||
let thread_id = metadata.thread_id;
|
||||
store.update(cx, |store, cx| {
|
||||
store.save(metadata, cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
let notification_count = Rc::new(std::cell::Cell::new(0));
|
||||
let _subscription = cx.update(|cx| {
|
||||
let notification_count = notification_count.clone();
|
||||
cx.observe(&store, move |_, _| {
|
||||
notification_count.set(notification_count.get() + 1);
|
||||
})
|
||||
});
|
||||
let mut main_paths = Vec::new();
|
||||
for _ in 0..2 {
|
||||
store.update(cx, |store, cx| {
|
||||
store.change_worktree_paths(
|
||||
&folder_paths,
|
||||
None,
|
||||
|paths| {
|
||||
paths.add_path(
|
||||
Path::new("/projects/source"),
|
||||
Path::new("/projects/checkout"),
|
||||
)
|
||||
},
|
||||
cx,
|
||||
);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
main_paths.push(store.read_with(cx, |store, _| {
|
||||
store
|
||||
.entry(thread_id)
|
||||
.map(|thread| thread.main_worktree_paths().paths().to_vec())
|
||||
}));
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
(main_paths, notification_count.get()),
|
||||
(vec![Some(vec![PathBuf::from("/projects/source")]); 2], 1)
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_multiple_archived_worktrees_per_thread(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
@@ -4002,6 +4148,33 @@ mod tests {
|
||||
assert_eq!(paths.ordered_pairs().count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_thread_worktree_paths_add_replaces_main_path_of_existing_folder() {
|
||||
let mut paths = make_worktree_paths(&[
|
||||
("/projects/zed", "/worktrees/selectric/zed"),
|
||||
("/projects/cloud", "/projects/cloud"),
|
||||
]);
|
||||
|
||||
paths.add_path(
|
||||
Path::new("/projects/zed-renamed"),
|
||||
Path::new("/worktrees/selectric/zed"),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
paths
|
||||
.ordered_pairs()
|
||||
.map(|(main_path, folder_path)| (main_path.as_path(), folder_path.as_path()))
|
||||
.collect::<Vec<_>>(),
|
||||
[
|
||||
(
|
||||
Path::new("/projects/zed-renamed"),
|
||||
Path::new("/worktrees/selectric/zed")
|
||||
),
|
||||
(Path::new("/projects/cloud"), Path::new("/projects/cloud")),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_thread_worktree_paths_remove_nonexistent_is_noop() {
|
||||
let mut paths = make_worktree_paths(&[("/projects/zed", "/worktrees/selectric/zed")]);
|
||||
|
||||
Reference in New Issue
Block a user