replace worktree roots table with serialized worktree roots list
This commit is contained in:
committed by
Mikayla Maki
parent
eb0598dac2
commit
d419f27d75
@@ -1,3 +1,5 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use gpui::Axis;
|
||||
@@ -6,18 +8,32 @@ use sqlez::{
|
||||
statement::Statement,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
|
||||
pub(crate) struct WorkspaceId(pub(crate) i64);
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub(crate) struct WorkspaceId(Vec<PathBuf>);
|
||||
|
||||
impl<P: AsRef<Path>, T: IntoIterator<Item = P>> From<T> for WorkspaceId {
|
||||
fn from(iterator: T) -> Self {
|
||||
let mut roots = iterator
|
||||
.into_iter()
|
||||
.map(|p| p.as_ref().to_path_buf())
|
||||
.collect::<Vec<_>>();
|
||||
roots.sort();
|
||||
Self(roots)
|
||||
}
|
||||
}
|
||||
|
||||
impl Bind for WorkspaceId {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||
self.0.bind(statement, start_index)
|
||||
bincode::serialize(&self.0)
|
||||
.expect("Bincode serialization of paths should not fail")
|
||||
.bind(statement, start_index)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for WorkspaceId {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||
i64::column(statement, start_index).map(|(id, next_index)| (Self(id), next_index))
|
||||
let blob = statement.column_blob(start_index)?;
|
||||
Ok((WorkspaceId(bincode::deserialize(blob)?), start_index + 1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,116 +74,24 @@ impl Column for DockAnchor {
|
||||
|
||||
pub(crate) type WorkspaceRow = (WorkspaceId, DockAnchor, bool);
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct SerializedWorkspace {
|
||||
pub center_group: SerializedPaneGroup,
|
||||
pub dock_anchor: DockAnchor,
|
||||
pub dock_visible: bool,
|
||||
pub dock_pane: SerializedDockPane,
|
||||
pub center_group: SerializedPaneGroup,
|
||||
pub dock_pane: SerializedPane,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub struct PaneId {
|
||||
workspace_id: WorkspaceId,
|
||||
pane_id: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub struct PaneGroupId {
|
||||
workspace_id: WorkspaceId,
|
||||
}
|
||||
|
||||
impl PaneGroupId {
|
||||
pub fn root(workspace_id: WorkspaceId) -> Self {
|
||||
Self {
|
||||
workspace_id,
|
||||
// group_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Default)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct SerializedPaneGroup {
|
||||
axis: Axis,
|
||||
children: Vec<PaneGroupChild>,
|
||||
}
|
||||
|
||||
impl SerializedPaneGroup {
|
||||
pub(crate) fn empty_root(_workspace_id: WorkspaceId) -> Self {
|
||||
Self {
|
||||
// group_id: PaneGroupId::root(workspace_id),
|
||||
axis: Default::default(),
|
||||
children: Default::default(),
|
||||
}
|
||||
}
|
||||
pub struct SerializedPane {
|
||||
children: Vec<SerializedItem>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub struct SerializedDockPane {
|
||||
pub anchor_position: DockAnchor,
|
||||
pub visible: bool,
|
||||
}
|
||||
pub enum SerializedItemKind {}
|
||||
|
||||
impl SerializedDockPane {
|
||||
fn to_row(&self, workspace: &WorkspaceId) -> DockRow {
|
||||
DockRow {
|
||||
workspace_id: *workspace,
|
||||
anchor_position: self.anchor_position,
|
||||
visible: self.visible,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for SerializedDockPane {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> anyhow::Result<(Self, i32)> {
|
||||
<(DockAnchor, bool) as Column>::column(statement, start_index).map(
|
||||
|((anchor_position, visible), next_index)| {
|
||||
(
|
||||
SerializedDockPane {
|
||||
anchor_position,
|
||||
visible,
|
||||
},
|
||||
next_index,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct DockRow {
|
||||
workspace_id: WorkspaceId,
|
||||
anchor_position: DockAnchor,
|
||||
visible: bool,
|
||||
}
|
||||
|
||||
impl Bind for DockRow {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
||||
statement.bind(
|
||||
(self.workspace_id, self.anchor_position, self.visible),
|
||||
start_index,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for DockRow {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> anyhow::Result<(Self, i32)> {
|
||||
<(WorkspaceId, DockAnchor, bool) as Column>::column(statement, start_index).map(
|
||||
|((workspace_id, anchor_position, visible), next_index)| {
|
||||
(
|
||||
DockRow {
|
||||
workspace_id,
|
||||
anchor_position,
|
||||
visible,
|
||||
},
|
||||
next_index,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct ItemId {
|
||||
pub item_id: usize,
|
||||
}
|
||||
pub enum SerializedItem {}
|
||||
|
||||
Reference in New Issue
Block a user