From 884a131b613b2986fd1958b31e3dbf36ff8e63a0 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Sat, 28 Jan 2023 11:15:32 -0500 Subject: [PATCH] wip --- Cargo.lock | 1 - helix-core/.DS_Store | Bin 0 -> 8196 bytes helix-core/Cargo.toml | 1 - helix-core/src/history.rs | 46 ++++++++++++------ helix-core/tests/.DS_Store | Bin 0 -> 6148 bytes helix-view/.DS_Store | Bin 0 -> 8196 bytes helix-view/src/.DS_Store | Bin 0 -> 6148 bytes helix-view/src/editor.rs | 6 +-- helix-view/src/lib.rs | 2 +- helix-view/src/{session => workspace}/mod.rs | 9 +--- helix-view/src/{session => workspace}/undo.rs | 0 11 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 helix-core/.DS_Store create mode 100644 helix-core/tests/.DS_Store create mode 100644 helix-view/.DS_Store create mode 100644 helix-view/src/.DS_Store rename helix-view/src/{session => workspace}/mod.rs (93%) rename helix-view/src/{session => workspace}/undo.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index cfdc709d40921..7a530a20109cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1140,7 +1140,6 @@ dependencies = [ "unicode-general-category", "unicode-segmentation", "unicode-width", - "walkdir", ] [[package]] diff --git a/helix-core/.DS_Store b/helix-core/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a116e7215c8c51421a4a266f572302777f7dda3d GIT binary patch literal 8196 zcmeHMO>h)N6n<~=*E1n9$&e7FmaGIUj0waf{0nS;0Fh{b%`bn;?9NC=W@p0A>@E;v z<%AYmrIv+%SAV&1uu2QPfH$q;q7_lJ%8MShe+vkRrl-n`n~RX zufI3FJqrNXlQ$j#XaoR8l~c8vn!6M}&g&gT3MG|9k?g^nNZW3jxJ&7YJG3J~6oDuL zQ3Rq0L=lK0a4$rF&TL-TJm%5#aBKI8{y)A)OX9cy&+{TmgudlQ<~U zS9ynMJfw+`P76vSR8W`_6{Z+oF;JM3JRa&LLOLy|Fb51T9~iET;SB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Cargo.toml index 6ff8700b2a2f3..ca6cd51e354e7 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -32,7 +32,6 @@ regex = "1" bitflags = "1.3" ahash = "0.8.2" hashbrown = { version = "0.13.1", features = ["raw"] } -walkdir = "2.3" log = "0.4" serde = { version = "1.0", features = ["derive"] } diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index bab69b6318f0d..3e253a3c8f96b 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -71,30 +71,25 @@ struct Revision { const HEADER_TAG: &str = "Helix Undofile"; const CURRENT_VERSION: u8 = 1; -pub fn serialize_history(file: File, history: &History) -> std::io::Result<()> { - let mut writer = std::io::BufWriter::new(file); - - write_string(&mut writer, HEADER_TAG)?; - write_byte(&mut writer, CURRENT_VERSION)?; - write_usize(&mut writer, history.current)?; - write_vec(&mut writer, &history.revisions, serialize_revision)?; +pub fn serialize_history(writer: &mut W, history: &History) -> std::io::Result<()> { + write_string(writer, HEADER_TAG)?; + write_byte(writer, CURRENT_VERSION)?; + write_usize(writer, history.current)?; + write_vec(writer, &history.revisions, serialize_revision)?; Ok(()) } -pub fn deserialize_history(file: File) -> std::io::Result { - let mut reader = std::io::BufReader::new(file); - if HEADER_TAG != read_string(&mut reader)? { +pub fn deserialize_history(reader: &mut R) -> std::io::Result { + if HEADER_TAG != read_string(reader)? { Err(std::io::Error::new( std::io::ErrorKind::Other, "missing undofile header", )) } else { - let _version = read_byte(&mut reader)?; + let _version = read_byte(reader)?; let timestamp = Instant::now(); - let current = read_usize(&mut reader)?; - let revisions = read_vec(&mut reader, |reader| { - deserialize_revision(reader, timestamp) - })?; + let current = read_usize(reader)?; + let revisions = read_vec(reader, |reader| deserialize_revision(reader, timestamp))?; Ok(History { current, revisions }) } } @@ -446,6 +441,8 @@ impl std::str::FromStr for UndoKind { #[cfg(test)] mod test { + use quickcheck::quickcheck; + use super::*; use crate::Selection; @@ -690,4 +687,23 @@ mod test { Err("duration too large".to_string()) ); } + + quickcheck!( + fn serde_history(a: String, b: String) -> bool { + let old = Rope::from(a); + let new = Rope::from(b); + let transaction = crate::diff::compare_ropes(&old, &new); + + let mut buf = Vec::new(); + let mut history = History::default(); + let state = State { + doc: old, + selection: Selection::point(0), + }; + history.commit_revision(&transaction, &state); + serialize_history(&mut buf, &history).unwrap(); + deserialize_history(&mut buf.as_slice()).unwrap(); + true + } + ); } diff --git a/helix-core/tests/.DS_Store b/helix-core/tests/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T05wWP#=wnFK9e7cNS=Y7ekbUxyjsf&$;K^ zd(XMwnY(wEF@~Ok{sd!BC<0Lg?uQ7_ne7*TmvdkAMs*Z{C;|^;1pN0yoF1PhLOLyI@amu{xB?KZ zBymuvt@;h3@sK7$IxQ&mP=PQdDohbxF(AxI9uM^rA)OXfm@|Zz4}>!#yrCeNoyLy` z>I?}%qdJN}6oK0#;NRUVn9K4knsiLxKPBpLQHT*zw+$kl!v{!I@ z()oQpH|RK4rrb_vhE1cCQtNvi+e@3akq-<^-5{0yBc`o8r5>kX>uzA16dhdVa!PHS zoa|V=t~K7dx^t>EKDn-=y*1v|xn^og<_*oOHtb0qv2wO^S~!64CBWv*a_Hro-dJw2 zSA31AsLf0WZ@w#gBP%u9(6BN(YGxffX`V1r>U@{n*-q@Pyip`KMzW4o$k}d6t<9#b zY{5!}8%I>IV9P|9vUf0Qcy@6s%RST}M#~?kkX!Mabnb!Fu4NQ2ZW4psf-X+?c zXcvo?&&_R!Eq(Oy_SNg3>fN?u;L5y*=BrAbQa@5OT{B}DLnTx9#>dib*06QcKD?LW zWqamxrjeIx(JBwx>6~#zUAU-m@xz)nTf02UXdz=BEtuYMwV87$J#c z9o-*M4|=pFZ8_)re0gu)pjwEP6tE{h@BlvT3o%7aH}Q-x`V(#2I>9*R9ej4Nabt%s{$^Mn4x{b|=5m@w?}k`mfh&iA_G z>AW#eB1n}jp5Z*$G?M!!TXfTN@20AAF5l|4V|2BT)0Tpc56wlUM3sWw2LNz znD#8@vH` zuCX83&+Iq$2fL0cRD(lC9TuPg3(<^Lv|%OIqZfVHif!n}5QZ^|F&xBUjN^G6!BL#R zB&P5pPU2O(hS%{f-oyL&5Fg<@zQ9F%iA%VOYxoww;&)ufU-(<9mbj!yHPRBPNm?Pb zNh^g1QaMe=W_l!TCO%AhN|W%Ton+l9O=4TNDo_8fY4ZJCKQU_S7SuN^X2>Y9J^a0snvec@hiS|Q(TFuRRnjzE?Z9Q z9D=%FA8U!lREaW7uq#)^6t#l#M-FT|TZl!-tbI~Z)Jn=E(YH|}mW52Bn}+f8g8zGj zo@Jk~3+y7hL8AWo=UhUJ9Hc66W!XM3%jug z`)~j$97389Y9R+3B^)P|zCbuViBot9r||~P;4Qq3cLKbAjI*;4xP2x9@!3rT7L$3~ za_qw-@$nksvgmr2cYMOwNdTQ`8*%q40u^GQM*sf5^{=G1Jjs9IbPR}8F{Nn3P3mTYEHRD47@i+c3q;{NCeVar`rv)VmmH+%hK+cHH N|LFV=u=gNW{{S;Y6bk?V literal 0 HcmV?d00001 diff --git a/helix-view/src/.DS_Store b/helix-view/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c7a70ec6218a6dec2ebe5a1e5be6f844d002eb97 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO(;SS3Oz1(Em*A;#7n641&ruHr6#6mXv~(THHT8jSzpK}@p+ut z-HOtB6Ol3lGv9W8Hk~hJw*vs8JB{`M>Hy%N5|&&vD}>^tOH#6)GNRCXWH5pN?qLw- zOWExBj||Yeb0G%>V;I7h_m_>rM1>fA3r9(uOtDJodSP(TDB}M;1w4uI*YRVB*bq@ zX)D6d{y0rk`hd~J#+1pz3@`)Cz*;e24>+f`R$Xy3%m6d+8w}9-AW;cDi-kdbbfD2A z0AdB*T5wIX1l353p2fl-Mo@$)MKqA1ht z=^#9VY?%RO;5!2}`=Qk7{y+P9{?|!tm;q*BJsA*{p5NXPnSiF$`hLV1P3 l&k|hds~B_XDsG@^LBFI0qGz!%h#nOFBcN$u!wmc>10NHJRH^^~ literal 0 HcmV?d00001 diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 34dec0d09b923..199b1376c7c1a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -5,9 +5,9 @@ use crate::{ graphics::{CursorKind, Rect}, info::Info, input::KeyEvent, - session::Session, theme::{self, Theme}, tree::{self, Tree}, + workspace::Workspace, Align, Document, DocumentId, View, ViewId, }; use helix_vcs::DiffProviderRegistry; @@ -830,8 +830,8 @@ impl Editor { } } - pub fn session(&self) -> anyhow::Result { - Session::new(std::env::current_dir()?) + pub fn session(&self) -> anyhow::Result { + Workspace::new(std::env::current_dir()?) } /// Current editing mode for the [`Editor`]. diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index 59ac56fcb0437..ee6fe73de3de2 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -7,7 +7,7 @@ pub mod editor; pub mod env; pub mod graphics; pub mod gutter; -pub mod session; +pub mod workspace; pub mod handlers { pub mod dap; pub mod lsp; diff --git a/helix-view/src/session/mod.rs b/helix-view/src/workspace/mod.rs similarity index 93% rename from helix-view/src/session/mod.rs rename to helix-view/src/workspace/mod.rs index c25aca958ec5e..cdc5648014992 100644 --- a/helix-view/src/session/mod.rs +++ b/helix-view/src/workspace/mod.rs @@ -13,7 +13,7 @@ pub struct Workspace { lock: Option, } -pub fn path_as_bytes(path: PathBuf) -> Vec { +fn path_as_bytes(path: PathBuf) -> Vec { #[cfg(windows)] return path.to_str().unwrap().into(); @@ -26,7 +26,7 @@ impl Workspace { pub fn new(path: PathBuf) -> Result { let bytes = path_as_bytes(path); let hash = Sha1::from(bytes).digest().to_string(); - let path = helix_loader::cache_dir().join("sessions").join(hash); + let path = helix_loader::cache_dir().join("workspaces").join(hash); Ok(Self { path, lock: None }) } @@ -48,7 +48,6 @@ impl Workspace { .context("failed to open file") } - // TODO: Return a FileLockGuard instead. pub fn get_mut(&mut self, filename: &str) -> Result { if self.lock.is_none() { let lock = FileLock::exclusive(self.path.join(".helix.lock"))?; @@ -141,10 +140,6 @@ mod sys { minwinbase::LOCKFILE_EXCLUSIVE_LOCK, }; - pub(super) fn path_as_bytes(path: &Path) -> &[u8] { - path.to_str().unwrap().as_bytes() - } - /// Blocks until the lock is acquired. pub(super) fn lock(file: &File, shared: bool) -> anyhow::Result<()> { let flag = if shared { 0 } else { LOCKFILE_EXCLUSIVE_LOCK }; diff --git a/helix-view/src/session/undo.rs b/helix-view/src/workspace/undo.rs similarity index 100% rename from helix-view/src/session/undo.rs rename to helix-view/src/workspace/undo.rs