forked from helix-editor/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minimal implementation of shada currently only writes the header when closing disable writing shada in integration tests will probably need a sophisticated way of handling this eventually for testing shada behaviour, but for now this is fine switch from rmp-serde to bincode rename shada to session switch to multi-file approach, implement persisting command history read command history from file handle NotFound error when reading histfile before it has been created persist and load search history move session.rs from helix-term to helix-loader persist file history load file history It was necessary make pos in file args an option to prevent it from overwriting the file positions loaded from persistence. Alignment is not quite right... I think we need to persist selections instead of view positions, or disable center aligning encode register history with bincode, and merge logic with file history encoding was found to be necessary because registers can contain line endings, which breaks the previous lines-of-text format avoid exposing internals of register.rs rename session to persistence promote type/implementation-specific persistence logic to helix-view store ViewPosition and Selection directly in FileHistoryEntry fix quirky file persistence behaviour fix integration tests save cloning by passing by ref to persistence functions persist clipboard add on/off config options for persistence fix bug: writes on untruncated histfiles trim persistence files add config option to exclude files form old_file_locs add trim config options for persistence add command to reload history fix rebase breakage add .*/COMMIT_EDITMSG to persistent file exclusions useful in the case of bare git repos, where the git dir is not always named .git, and so the previous exclusion wouldn't catch it. default to <cache dir>/helix/state if state dir is None run docgen split persistence config options into own struct add documentation for persistent state only trim persistent state files if persistent state is enabled add integration test for persistent state avoid repeated loading of config to check persistence config in startup address hanging TODOs fix line feed handling in integration test for windows
- Loading branch information
Showing
24 changed files
with
785 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use bincode::{deserialize_from, serialize_into}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
fs::{File, OpenOptions}, | ||
io::{self, BufReader}, | ||
path::PathBuf, | ||
}; | ||
|
||
pub fn write_history<T: Serialize>(filepath: PathBuf, entries: &Vec<T>) { | ||
let file = OpenOptions::new() | ||
.write(true) | ||
.create(true) | ||
.truncate(true) | ||
.open(filepath) | ||
.unwrap(); | ||
|
||
for entry in entries { | ||
serialize_into(&file, &entry).unwrap(); | ||
} | ||
} | ||
|
||
pub fn push_history<T: Serialize>(filepath: PathBuf, entry: &T) { | ||
let file = OpenOptions::new() | ||
.append(true) | ||
.create(true) | ||
.open(filepath) | ||
.unwrap(); | ||
|
||
serialize_into(file, entry).unwrap(); | ||
} | ||
|
||
pub fn read_history<T: for<'a> Deserialize<'a>>(filepath: &PathBuf) -> Vec<T> { | ||
match File::open(filepath) { | ||
Ok(file) => { | ||
let mut read = BufReader::new(file); | ||
let mut entries = Vec::new(); | ||
// FIXME: Can we do better error handling here? It's unfortunate that bincode doesn't | ||
// distinguish an empty reader from an actual error. | ||
// | ||
// Perhaps we could use the underlying bufreader to check for emptiness in the while | ||
// condition, then we could know any errors from bincode should be surfaced or logged. | ||
// BufRead has a method `has_data_left` that would work for this, but at the time of | ||
// writing it is nightly-only and experimental :( | ||
while let Ok(entry) = deserialize_from(&mut read) { | ||
entries.push(entry); | ||
} | ||
entries | ||
} | ||
Err(e) => match e.kind() { | ||
io::ErrorKind::NotFound => Vec::new(), | ||
// Going through the potential errors listed from the docs: | ||
// - `InvalidInput` can't happen since we aren't setting options | ||
// - `AlreadyExists` can't happen since we aren't setting `create_new` | ||
// - `PermissionDenied` could happen if someone really borked their file permissions | ||
// in `~/.local`, but helix already panics in that case, and I think a panic is | ||
// acceptable. | ||
_ => unreachable!(), | ||
}, | ||
} | ||
} | ||
|
||
pub fn trim_history<T: Clone + Serialize + for<'a> Deserialize<'a>>( | ||
filepath: PathBuf, | ||
limit: usize, | ||
) { | ||
let history: Vec<T> = read_history(&filepath); | ||
if history.len() > limit { | ||
let trim_start = history.len() - limit; | ||
let trimmed_history = history[trim_start..].to_vec(); | ||
write_history(filepath, &trimmed_history); | ||
} | ||
} |
Oops, something went wrong.