From 6b214acbc4f3c02df6e02b2d009a0ce7e7edb9ad Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 4 Nov 2022 10:34:28 -0700 Subject: [PATCH] =?UTF-8?q?Got=20Zed=20compiling=20again=20=F0=9F=A5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/db/examples/serialize-pane.rs | 50 +++++++++++++--------------- crates/db/src/workspace.rs | 26 +++++++-------- crates/db/src/workspace/model.rs | 11 +++--- crates/db/src/workspace/pane.rs | 37 +++++++++----------- crates/sqlez/src/bindable.rs | 2 +- crates/workspace/src/workspace.rs | 8 ++--- 6 files changed, 64 insertions(+), 70 deletions(-) diff --git a/crates/db/examples/serialize-pane.rs b/crates/db/examples/serialize-pane.rs index ebe88037cd..2f362fb997 100644 --- a/crates/db/examples/serialize-pane.rs +++ b/crates/db/examples/serialize-pane.rs @@ -1,7 +1,5 @@ use std::{fs::File, path::Path}; -use db::{pane::SerializedDockPane, DockAnchor}; - const TEST_FILE: &'static str = "test-db.db"; fn main() -> anyhow::Result<()> { @@ -14,31 +12,31 @@ fn main() -> anyhow::Result<()> { let f = File::create(file)?; drop(f); - let workspace_1 = db.workspace_for_roots(&["/tmp"]); - let workspace_2 = db.workspace_for_roots(&["/tmp", "/tmp2"]); - let workspace_3 = db.workspace_for_roots(&["/tmp3", "/tmp2"]); + // let workspace_1 = db.workspace_for_roots(&["/tmp"]); + // let workspace_2 = db.workspace_for_roots(&["/tmp", "/tmp2"]); + // let workspace_3 = db.workspace_for_roots(&["/tmp3", "/tmp2"]); - db.save_dock_pane( - &workspace_1.workspace_id, - &SerializedDockPane { - anchor_position: DockAnchor::Expanded, - visible: true, - }, - ); - db.save_dock_pane( - &workspace_2.workspace_id, - &SerializedDockPane { - anchor_position: DockAnchor::Bottom, - visible: true, - }, - ); - db.save_dock_pane( - &workspace_3.workspace_id, - &SerializedDockPane { - anchor_position: DockAnchor::Right, - visible: false, - }, - ); + // db.save_dock_pane( + // &workspace_1.workspace_id, + // &SerializedDockPane { + // anchor_position: DockAnchor::Expanded, + // visible: true, + // }, + // ); + // db.save_dock_pane( + // &workspace_2.workspace_id, + // &SerializedDockPane { + // anchor_position: DockAnchor::Bottom, + // visible: true, + // }, + // ); + // db.save_dock_pane( + // &workspace_3.workspace_id, + // &SerializedDockPane { + // anchor_position: DockAnchor::Right, + // visible: false, + // }, + // ); db.write_to(file).ok(); diff --git a/crates/db/src/workspace.rs b/crates/db/src/workspace.rs index 5fc9e075e9..cf09bdd06e 100644 --- a/crates/db/src/workspace.rs +++ b/crates/db/src/workspace.rs @@ -2,7 +2,7 @@ mod items; pub mod model; pub(crate) mod pane; -use anyhow::{Context, Result}; +use anyhow::Context; use util::{iife, ResultExt}; use std::path::{Path, PathBuf}; @@ -10,9 +10,6 @@ use std::path::{Path, PathBuf}; use indoc::indoc; use sqlez::migrations::Migration; -// If you need to debug the worktree root code, change 'BLOB' here to 'TEXT' for easier debugging -// you might want to update some of the parsing code as well, I've left the variations in but commented -// out. This will panic if run on an existing db that has already been migrated pub(crate) const WORKSPACES_MIGRATION: Migration = Migration::new( "workspace", &[indoc! {" @@ -39,7 +36,9 @@ impl Db { ) -> Option { let workspace_id: WorkspaceId = worktree_roots.into(); - let (_, dock_anchor, dock_visible) = iife!({ + // Note that we re-assign the workspace_id here in case it's empty + // and we've grabbed the most recent workspace + let (workspace_id, dock_anchor, dock_visible) = iife!({ if worktree_roots.len() == 0 { self.prepare(indoc! {" SELECT workspace_id, dock_anchor, dock_visible @@ -51,7 +50,7 @@ impl Db { SELECT workspace_id, dock_anchor, dock_visible FROM workspaces WHERE workspace_id = ?"})? - .with_bindings(workspace_id)? + .with_bindings(&workspace_id)? .maybe_row::() } }) @@ -59,8 +58,8 @@ impl Db { .flatten()?; Some(SerializedWorkspace { - dock_pane: self.get_dock_pane(workspace_id)?, - center_group: self.get_center_group(workspace_id), + dock_pane: self.get_dock_pane(&workspace_id)?, + center_group: self.get_center_group(&workspace_id), dock_anchor, dock_visible, }) @@ -82,12 +81,12 @@ impl Db { self.prepare(indoc!{" DELETE FROM workspaces WHERE workspace_id = ?1; INSERT INTO workspaces(workspace_id, dock_anchor, dock_visible) VALUES (?1, ?, ?)"})? - .with_bindings((workspace_id, workspace.dock_anchor, workspace.dock_visible))? + .with_bindings((&workspace_id, workspace.dock_anchor, workspace.dock_visible))? .exec()?; // Save center pane group and dock pane - Self::save_center_group(workspace_id, &workspace.center_group, conn)?; - Self::save_dock_pane(workspace_id, &workspace.dock_pane, conn)?; + Self::save_center_group(&workspace_id, &workspace.center_group, conn)?; + Self::save_dock_pane(&workspace_id, &workspace.dock_pane, conn)?; Ok(()) }) @@ -98,11 +97,12 @@ impl Db { /// Returns the previous workspace ids sorted by last modified along with their opened worktree roots pub fn recent_workspaces(&self, limit: usize) -> Vec> { iife!({ - self.prepare("SELECT workspace_id FROM workspaces ORDER BY timestamp DESC LIMIT ?")? + Ok::<_, anyhow::Error>(self.prepare("SELECT workspace_id FROM workspaces ORDER BY timestamp DESC LIMIT ?")? .with_bindings(limit)? .rows::()? .into_iter().map(|id| id.0) - .collect() + .collect::>>()) + }).log_err().unwrap_or_default() } } diff --git a/crates/db/src/workspace/model.rs b/crates/db/src/workspace/model.rs index 37c353a47b..1a6b4ee41f 100644 --- a/crates/db/src/workspace/model.rs +++ b/crates/db/src/workspace/model.rs @@ -9,7 +9,7 @@ use sqlez::{ }; #[derive(Debug, PartialEq, Eq, Clone)] -pub(crate) struct WorkspaceId(Vec); +pub(crate) struct WorkspaceId(pub(crate) Vec); impl, T: IntoIterator> From for WorkspaceId { fn from(iterator: T) -> Self { @@ -22,7 +22,7 @@ impl, T: IntoIterator> From for WorkspaceId { } } -impl Bind for WorkspaceId { +impl Bind for &WorkspaceId { fn bind(&self, statement: &Statement, start_index: i32) -> Result { bincode::serialize(&self.0) .expect("Bincode serialization of paths should not fail") @@ -85,13 +85,16 @@ pub struct SerializedWorkspace { #[derive(Debug, PartialEq, Eq)] pub struct SerializedPaneGroup { axis: Axis, - children: Vec, + children: Vec, } +#[derive(Debug)] pub struct SerializedPane { - children: Vec, + _children: Vec, } +#[derive(Debug)] pub enum SerializedItemKind {} +#[derive(Debug)] pub enum SerializedItem {} diff --git a/crates/db/src/workspace/pane.rs b/crates/db/src/workspace/pane.rs index 4f263e496c..73306707cf 100644 --- a/crates/db/src/workspace/pane.rs +++ b/crates/db/src/workspace/pane.rs @@ -1,10 +1,11 @@ -use gpui::Axis; +use anyhow::Result; use indoc::indoc; use sqlez::{connection::Connection, migrations::Migration}; -use util::{iife, ResultExt}; + +use crate::model::SerializedPane; use super::{ - model::{PaneGroupId, PaneId, SerializedDockPane, SerializedPaneGroup, WorkspaceId}, + model::{SerializedPaneGroup, WorkspaceId}, Db, }; @@ -44,11 +45,11 @@ pub(crate) const PANE_MIGRATIONS: Migration = Migration::new( ); impl Db { - pub(crate) fn get_center_group(&self, _workspace: WorkspaceId) -> SerializedPaneGroup { + pub(crate) fn get_center_group(&self, _workspace: &WorkspaceId) -> SerializedPaneGroup { unimplemented!() } - pub fn get_pane_group(&self, _pane_group_id: PaneGroupId) -> SerializedPaneGroup { + pub(crate) fn _get_pane_group(&self, _workspace: &WorkspaceId) -> SerializedPaneGroup { unimplemented!() // let axis = self.get_pane_group_axis(pane_group_id); // let mut children: Vec<(usize, PaneGroupChild)> = Vec::new(); @@ -91,31 +92,22 @@ impl Db { _workspace: &WorkspaceId, _center_pane_group: &SerializedPaneGroup, _connection: &Connection, - ) { + ) -> Result<()> { // Delete the center pane group for this workspace and any of its children // Generate new pane group IDs as we go through // insert them + Ok(()) } - pub fn _get_pane(&self, _pane_id: PaneId) -> SerializedPane { - unimplemented!(); - } - - pub(crate) fn get_dock_pane(&self, workspace: WorkspaceId) -> Option { - iife!({ - self.prepare("SELECT anchor_position, visible FROM dock_panes WHERE workspace_id = ?")? - .with_bindings(workspace)? - .maybe_row::() - }) - .log_err() - .flatten() + pub(crate) fn get_dock_pane(&self, _workspace: &WorkspaceId) -> Option { + unimplemented!() } pub(crate) fn save_dock_pane( - workspace: &WorkspaceId, - dock_pane: &SerializedDockPane, - connection: &Connection, - ) { + _workspace: &WorkspaceId, + _dock_pane: &SerializedPane, + _connection: &Connection, + ) -> Result<()> { // iife!({ // self.prepare( // "INSERT INTO dock_panes (workspace_id, anchor_position, visible) VALUES (?, ?, ?);", @@ -124,6 +116,7 @@ impl Db { // .insert() // }) // .log_err(); + Ok(()) } } diff --git a/crates/sqlez/src/bindable.rs b/crates/sqlez/src/bindable.rs index a22363ae63..1ce350a550 100644 --- a/crates/sqlez/src/bindable.rs +++ b/crates/sqlez/src/bindable.rs @@ -1,5 +1,5 @@ use std::{ - ffi::{CString, OsStr}, + ffi::OsStr, os::unix::prelude::OsStrExt, path::{Path, PathBuf}, }; diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index a6ef7c6c01..d1dbc6982b 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -15,7 +15,7 @@ use anyhow::{anyhow, Context, Result}; use call::ActiveCall; use client::{proto, Client, PeerId, TypedEnvelope, UserStore}; use collections::{hash_map, HashMap, HashSet}; -use db::{Db, SerializedWorkspace, WorkspaceId}; +use db::{model::SerializedWorkspace, Db}; use dock::{DefaultItemFactory, Dock, ToggleDockButton}; use drag_and_drop::DragAndDrop; use fs::{self, Fs}; @@ -1073,7 +1073,7 @@ pub enum Event { pub struct Workspace { weak_self: WeakViewHandle, - _db_id: WorkspaceId, + // _db_id: WorkspaceId, client: Arc, user_store: ModelHandle, remote_entity_subscription: Option, @@ -1120,7 +1120,7 @@ enum FollowerItem { impl Workspace { pub fn new( - serialized_workspace: SerializedWorkspace, + _serialized_workspace: Option, project: ModelHandle, dock_default_factory: DefaultItemFactory, cx: &mut ViewContext, @@ -1217,7 +1217,7 @@ impl Workspace { let mut this = Workspace { modal: None, weak_self: weak_handle, - _db_id: serialized_workspace.workspace_id, + // _db_id: serialized_workspace.workspace_id, center: PaneGroup::new(center_pane.clone()), dock, // When removing an item, the last element remaining in this array