|
|
|
@ -1,39 +1,36 @@
|
|
|
|
|
use bincode::{encode_into_std_write, Decode, Encode};
|
|
|
|
|
use helix_loader::{shada_file, VERSION_AND_GIT_HASH};
|
|
|
|
|
use helix_view::view::ViewPosition;
|
|
|
|
|
use rmp_serde::Serializer;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
// use helix_view::view::ViewPosition;
|
|
|
|
|
use std::{
|
|
|
|
|
fs::File,
|
|
|
|
|
time::{SystemTime, UNIX_EPOCH},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: should this be non-exhaustive?
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
|
|
|
#[serde(rename = "H")]
|
|
|
|
|
#[derive(Debug, Encode, Decode)]
|
|
|
|
|
struct Header {
|
|
|
|
|
generator: String,
|
|
|
|
|
version: String,
|
|
|
|
|
encoding: String,
|
|
|
|
|
max_kbyte: u32,
|
|
|
|
|
pid: u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: should this be non-exhaustive?
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
|
|
|
#[derive(Debug, Encode, Decode)]
|
|
|
|
|
struct FilePosition {
|
|
|
|
|
path: String,
|
|
|
|
|
position: ViewPosition,
|
|
|
|
|
// position: ViewPosition,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: should this be non-exhaustive?
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
|
|
|
#[derive(Debug, Encode, Decode)]
|
|
|
|
|
enum EntryData {
|
|
|
|
|
Header(Header),
|
|
|
|
|
FilePosition(FilePosition),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: should this be non-exhaustive?
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
|
|
|
#[derive(Debug, Encode, Decode)]
|
|
|
|
|
struct Entry {
|
|
|
|
|
timestamp: u64,
|
|
|
|
|
data: EntryData,
|
|
|
|
@ -52,9 +49,6 @@ fn generate_header() -> Entry {
|
|
|
|
|
data: EntryData::Header(Header {
|
|
|
|
|
generator: "helix".to_string(),
|
|
|
|
|
version: VERSION_AND_GIT_HASH.to_string(),
|
|
|
|
|
// TODO: is this necessary? helix doesn't seem to expose an option
|
|
|
|
|
// for internal encoding like nvim does
|
|
|
|
|
encoding: "utf-8".to_string(),
|
|
|
|
|
max_kbyte: 100,
|
|
|
|
|
pid: std::process::id(),
|
|
|
|
|
}),
|
|
|
|
@ -65,11 +59,10 @@ pub fn write_shada_file() {
|
|
|
|
|
// TODO: merge existing file if exists
|
|
|
|
|
|
|
|
|
|
// TODO: do something about this unwrap
|
|
|
|
|
let shada_file = File::create(shada_file()).unwrap();
|
|
|
|
|
let mut serializer = Serializer::new(shada_file);
|
|
|
|
|
let mut shada_file = File::create(shada_file()).unwrap();
|
|
|
|
|
|
|
|
|
|
let header = generate_header();
|
|
|
|
|
|
|
|
|
|
// TODO: do something about this unwrap
|
|
|
|
|
header.serialize(&mut serializer).unwrap();
|
|
|
|
|
encode_into_std_write(&header, &mut shada_file, bincode::config::standard()).unwrap();
|
|
|
|
|
}
|
|
|
|
|