From d3b9d9c756eb4e00442b09f34d3e751180491ccd Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Sat, 28 Jan 2023 12:05:36 -0500 Subject: [PATCH] wip --- helix-core/.DS_Store | Bin 8196 -> 0 bytes helix-core/src/history.rs | 11 ++++------- helix-core/src/parse.rs | 8 +++++--- helix-core/tests/.DS_Store | Bin 6148 -> 0 bytes helix-view/.DS_Store | Bin 8196 -> 0 bytes helix-view/src/.DS_Store | Bin 6148 -> 0 bytes helix-view/src/editor.rs | 5 +++++ 7 files changed, 14 insertions(+), 10 deletions(-) delete mode 100644 helix-core/.DS_Store delete mode 100644 helix-core/tests/.DS_Store delete mode 100644 helix-view/.DS_Store delete mode 100644 helix-view/src/.DS_Store diff --git a/helix-core/.DS_Store b/helix-core/.DS_Store deleted file mode 100644 index a116e7215c8c51421a4a266f572302777f7dda3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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|Y)oK2CpbnT2 zG-{&=L=m_%0{re?1|H-flP=zVf442qZ*RYbQdxOLWfiMp)$B-e+$|=3-OqbHdhQVC z23^-qm->2o*fNVLbxE)5_`2noxxm0OOj0>KVmXFe>~Zss;RUuyF~DRdr_{#D$&U4# zTH~GTJEvOXlbbu*TjO1w8>XgYR^PmC>w(k>JL|aTgaa791fXV)LoeL&#`X%m;%h`% zZF)j@^KHo+S*g~BhLzD#E8{vz>x`LF7klK+9%A?9%mTSFl5y>P*6~tmZAP~-bCq6Tam--msbTh&CtM#Y4*% z7uCmBKKO9^`YqdgckdmTskv{lT3e?n2PrO&Z#`w1xuK$E_~T=`moXi~a*mG_EYC{Y z=Affz&01__@=Q&`(#B=?YubFOqxrOTGH>~()n>+K)cY3KC{5Y}vicD_Y|ukK;Tn7; zBN)+|wAG9q;_}{{Nv#koYqSakE)+(i5_T*2C1#*-^f5zwY@16Q)yoq=dGMv4h^Yo-+rE z1gVn6#+fwu@&2JEpEYH?89BS8~bqxhjA3g@F*U~aeNw2;7L4#lQ@OX z;#qtNU&dGPEqoi_!T0ce{1`9e75ogZ;@5Z$zrkPdH@ty=;$Kpg#3V(kmR3kj(i*8v zS}Qz|N@+4S+aqZQ@nOQe@65F{;dF)?Jlk1DZ#8^_lqIpeQ$A+ytZo)^P ztpu>!fg50T7QzFp20J_#XF&!nS7Jj1X7kj1iKJFh!pUrgYd6J}m|8(_7woFl#8wj2 z1^ZA-ET&47VS-(|E~cnuls|G{+u1@ahRnuIilUZNCdo6)mNqsh%VXPRrb3{Y=%#6S zUa)_T&b_-;DtE|+%p@2 z_~|VK7Lqx~cAeuS;dre8A51!seDMAw2hwdG&GB`1P!^mk6Dv0I`~S}QzyB}zb43eA z5r`tNa1p@rzGPnytylWJFn4Kw*N#&?MwJ(?H!WyjLd~oX0mR?@!;t!MQsp*@kWLFq Y5-JP+As}l;=YMqmFW`mr-aP;R22DqRq5uE@ diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 3e253a3c8f96b..a5867948019bb 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -2,7 +2,6 @@ use crate::parse::*; use crate::{Assoc, ChangeSet, Range, Rope, Selection, Transaction}; use once_cell::sync::Lazy; use regex::Regex; -use std::fs::File; use std::io::{Read, Write}; use std::num::NonZeroUsize; use std::time::{Duration, Instant}; @@ -68,25 +67,23 @@ struct Revision { timestamp: Instant, } -const HEADER_TAG: &str = "Helix Undofile"; -const CURRENT_VERSION: u8 = 1; +const HEADER_TAG: &str = "Helix Undofile 1\n"; 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(reader: &mut R) -> std::io::Result { - if HEADER_TAG != read_string(reader)? { + let header = read_string(reader)?; + if HEADER_TAG != header { Err(std::io::Error::new( std::io::ErrorKind::Other, - "missing undofile header", + format!("missing undofile header"), )) } else { - let _version = read_byte(reader)?; let timestamp = Instant::now(); let current = read_usize(reader)?; let revisions = read_vec(reader, |reader| deserialize_revision(reader, timestamp))?; diff --git a/helix-core/src/parse.rs b/helix-core/src/parse.rs index ce8ef6665c042..f97700c19e31b 100644 --- a/helix-core/src/parse.rs +++ b/helix-core/src/parse.rs @@ -88,9 +88,11 @@ pub fn read_usize(reader: &mut R) -> Result { pub fn read_string(reader: &mut R) -> Result { let len = read_usize(reader)?; - let mut buf = String::with_capacity(len); - reader.read_to_string(&mut buf)?; - Ok(buf) + let mut buf = vec![0; len]; + reader.read_exact(&mut buf)?; + + let res = String::from_utf8(buf).map_err(|e| Error::new(ErrorKind::InvalidData, e))?; + Ok(res) } pub fn read_vec(reader: &mut R, f: impl Fn(&mut R) -> Result) -> Result> { diff --git a/helix-core/tests/.DS_Store b/helix-core/tests/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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_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!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 diff --git a/helix-view/src/.DS_Store b/helix-view/src/.DS_Store deleted file mode 100644 index c7a70ec6218a6dec2ebe5a1e5be6f844d002eb97..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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^^~ diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 199b1376c7c1a..861a0666fbac1 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -830,6 +830,11 @@ impl Editor { } } + pub fn save_workspace(&self) -> anyhow::Result<()> { + let mut workspace = Workspace::new(std::env::current_dir()?)?; + Ok(()) + } + pub fn session(&self) -> anyhow::Result { Workspace::new(std::env::current_dir()?) }