mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 10:29:35 +03:00
WIP, incorporating type parsing using new sqlez patterns
This commit is contained in:
parent
3c1b747f64
commit
c8face33fa
@ -1,7 +1,9 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use gpui::Axis;
|
||||
use indoc::indoc;
|
||||
use sqlez::migrations::Migration;
|
||||
use sqlez::{migrations::Migration, bindable::{Bind, Column}, connection::Connection, statement::Statement};
|
||||
|
||||
|
||||
use crate::{items::ItemId, workspace::WorkspaceId};
|
||||
@ -138,7 +140,6 @@ pub struct SerializedPane {
|
||||
|
||||
//********* CURRENTLY IN USE TYPES: *********
|
||||
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub enum DockAnchor {
|
||||
#[default]
|
||||
@ -147,6 +148,29 @@ pub enum DockAnchor {
|
||||
Expanded,
|
||||
}
|
||||
|
||||
impl ToString for DockAnchor {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
DockAnchor::Bottom => "Bottom".to_string(),
|
||||
DockAnchor::Right => "Right".to_string(),
|
||||
DockAnchor::Expanded => "Expanded".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for DockAnchor {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> anyhow::Result<Self> {
|
||||
match s {
|
||||
"Bottom" => Ok(DockAnchor::Bottom),
|
||||
"Right" => Ok(DockAnchor::Right),
|
||||
"Expanded" => Ok(DockAnchor::Expanded),
|
||||
_ => anyhow::bail!("Not a valid dock anchor")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub struct SerializedDockPane {
|
||||
pub anchor_position: DockAnchor,
|
||||
@ -159,6 +183,7 @@ impl SerializedDockPane {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct DockRow {
|
||||
workspace_id: WorkspaceId,
|
||||
@ -172,6 +197,21 @@ impl DockRow {
|
||||
}
|
||||
}
|
||||
|
||||
impl Bind for DockRow {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> anyhow::Result<i32> {
|
||||
statement.bind((self.workspace_id, self.anchor_position.to_string(), self.visible), start_index)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for DockRow {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> anyhow::Result<(Self, i32)> {
|
||||
<(WorkspaceId, &str, bool) as Column>::column(statement, start_index)
|
||||
.map(|((workspace_id, anchor_position, visible), next_index)| {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Db {
|
||||
pub fn get_pane_group(&self, pane_group_id: PaneGroupId) -> SerializedPaneGroup {
|
||||
let axis = self.get_pane_group_axis(pane_group_id);
|
||||
@ -229,7 +269,10 @@ impl Db {
|
||||
pub fn get_dock_pane(&self, workspace: WorkspaceId) -> Option<SerializedDockPane> {
|
||||
fn logic(conn: &Connection, workspace: WorkspaceId) -> anyhow::Result<Option<SerializedDockPane>> {
|
||||
|
||||
let mut stmt = conn.prepare("SELECT workspace_id, anchor_position, visible FROM dock_panes WHERE workspace_id = ?")?;
|
||||
let mut stmt = conn.prepare("SELECT workspace_id, anchor_position, visible FROM dock_panes WHERE workspace_id = ?")?
|
||||
.maybe_row()
|
||||
.map(|row| DockRow::col);
|
||||
|
||||
|
||||
let dock_panes = stmt.query_row([workspace.raw_id()], |row_ref| from_row::<DockRow>).optional();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use anyhow::{Result, anyhow};
|
||||
|
||||
use std::{
|
||||
ffi::OsStr,
|
||||
@ -10,7 +10,7 @@ use std::{
|
||||
|
||||
use indoc::indoc;
|
||||
use sqlez::{
|
||||
connection::Connection, migrations::Migration,
|
||||
connection::Connection, migrations::Migration, bindable::{Column, Bind},
|
||||
};
|
||||
|
||||
use crate::pane::SerializedDockPane;
|
||||
@ -45,6 +45,18 @@ impl WorkspaceId {
|
||||
}
|
||||
}
|
||||
|
||||
impl Bind for WorkspaceId {
|
||||
fn bind(&self, statement: &sqlez::statement::Statement, start_index: i32) -> Result<i32> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for WorkspaceId {
|
||||
fn column(statement: &mut sqlez::statement::Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct SerializedWorkspace {
|
||||
pub workspace_id: WorkspaceId,
|
||||
|
@ -10,6 +10,18 @@ pub trait Column: Sized {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)>;
|
||||
}
|
||||
|
||||
impl Bind for bool {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||
statement.bind(self.then_some(1).unwrap_or(0), start_index)
|
||||
}
|
||||
}
|
||||
|
||||
impl Column for bool {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||
i32::column(statement, start_index).map(|(i, next_index)| (i != 0, next_index))
|
||||
}
|
||||
}
|
||||
|
||||
impl Bind for &[u8] {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||
statement.bind_blob(start_index, self)?;
|
||||
|
@ -114,7 +114,7 @@ impl<'a> Statement<'a> {
|
||||
|
||||
unsafe {
|
||||
sqlite3_bind_int(self.raw_statement, index, int);
|
||||
}
|
||||
};
|
||||
self.connection.last_error()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user