Added UUID based, stable workspace ID for caching on item startup. Completed first sketch of terminal persistence. Still need to debug it though....

This commit is contained in:
Mikayla Maki 2022-11-20 22:41:10 -08:00
parent e659823e6c
commit a47f2ca445
20 changed files with 501 additions and 364 deletions

View file

@ -83,7 +83,7 @@ use theme::{DiagnosticStyle, Theme};
use util::{post_inc, ResultExt, TryFutureExt};
use workspace::{ItemNavHistory, Workspace};
use crate::{git::diff_hunk_to_display, persistence::DB};
use crate::git::diff_hunk_to_display;
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
const SCROLLBAR_SHOW_INTERVAL: Duration = Duration::from_secs(1);
@ -1137,30 +1137,30 @@ impl Editor {
cx: &mut ViewContext<Self>,
) -> Self {
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
if let Some(project) = project.as_ref() {
if let Some(file) = buffer
.read(cx)
.as_singleton()
.and_then(|buffer| buffer.read(cx).file())
.and_then(|file| file.as_local())
{
let item_id = cx.weak_handle().id();
let workspace_id = project
.read(cx)
.visible_worktrees(cx)
.map(|worktree| worktree.read(cx).abs_path())
.collect::<Vec<_>>()
.into();
let path = file.abs_path(cx);
dbg!(&path);
// if let Some(project) = project.as_ref() {
// if let Some(file) = buffer
// .read(cx)
// .as_singleton()
// .and_then(|buffer| buffer.read(cx).file())
// .and_then(|file| file.as_local())
// {
// // let item_id = cx.weak_handle().id();
// // let workspace_id = project
// // .read(cx)
// // .visible_worktrees(cx)
// // .map(|worktree| worktree.read(cx).abs_path())
// // .collect::<Vec<_>>()
// // .into();
// let path = file.abs_path(cx);
// dbg!(&path);
cx.background()
.spawn(async move {
DB.save_path(item_id, workspace_id, path).log_err();
})
.detach();
}
}
// // cx.background()
// // .spawn(async move {
// // DB.save_path(item_id, workspace_id, path).log_err();
// // })
// // .detach();
// }
// }
Self::new(EditorMode::Full, buffer, project, None, cx)
}

View file

@ -368,7 +368,7 @@ impl Item for Editor {
self.buffer.read(cx).is_singleton()
}
fn clone_on_split(&self, cx: &mut ViewContext<Self>) -> Option<Self>
fn clone_on_split(&self, _workspace_id: WorkspaceId, cx: &mut ViewContext<Self>) -> Option<Self>
where
Self: Sized,
{
@ -561,14 +561,13 @@ impl Item for Editor {
fn deserialize(
project: ModelHandle<Project>,
_workspace: WeakViewHandle<Workspace>,
workspace_id: WorkspaceId,
workspace_id: workspace::WorkspaceId,
item_id: ItemId,
cx: &mut ViewContext<Pane>,
) -> Task<Result<ViewHandle<Self>>> {
if let Some(project_item) = project.update(cx, |project, cx| {
// Look up the path with this key associated, create a self with that path
let path = DB.get_path(item_id, workspace_id).ok()?;
dbg!(&path);
let (worktree, path) = project.find_local_worktree(&path, cx)?;
let project_path = ProjectPath {
worktree_id: worktree.read(cx).id(),

View file

@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use db::connection;
use db::{connection, exec_method};
use indoc::indoc;
use sqlez::domain::Domain;
use workspace::{ItemId, Workspace, WorkspaceId};
@ -35,18 +35,12 @@ impl EditorDb {
pub fn get_path(&self, item_id: ItemId, workspace_id: WorkspaceId) -> Result<PathBuf> {
self.select_row_bound(indoc! {"
SELECT path FROM editors
WHERE item_id = ? AND workspace_id = ?"})?((item_id, &workspace_id))?
WHERE item_id = ? AND workspace_id = ?"})?((item_id, workspace_id))?
.context("Path not found for serialized editor")
}
pub fn save_path(
&self,
item_id: ItemId,
workspace_id: WorkspaceId,
path: PathBuf,
) -> Result<()> {
self.exec_bound::<(ItemId, &WorkspaceId, &Path)>(indoc! {"
INSERT OR REPLACE INTO editors(item_id, workspace_id, path)
VALUES (?, ?, ?)"})?((item_id, &workspace_id, &path))
}
exec_method!(save_path(item_id: ItemId, workspace_id: WorkspaceId, path: &Path):
"INSERT OR REPLACE INTO editors(item_id, workspace_id, path)
VALUES (?, ?, ?)"
);
}