use doc path for modification time

pull/10758/head
Dustin Lagoy 2024-05-09 10:19:39 -07:00 committed by Dustin Lagoy
parent a9f2ec3eea
commit b01329eb10
2 changed files with 40 additions and 27 deletions

View File

@ -185,7 +185,7 @@ pub struct Document {
// Last time we wrote to the file. This will carry the time the file was last opened if there // Last time we wrote to the file. This will carry the time the file was last opened if there
// were no saves. // were no saves.
pub last_saved_time: SystemTime, last_saved_time: SystemTime,
last_saved_revision: usize, last_saved_revision: usize,
version: i32, // should be usize? version: i32, // should be usize?

View File

@ -152,46 +152,59 @@ pub fn coverage<'doc>(
let covered = theme.get("diff.plus.gutter"); let covered = theme.get("diff.plus.gutter");
let not_covered = theme.get("diff.minus.gutter"); let not_covered = theme.get("diff.minus.gutter");
if let Ok(coverage_path) = std::env::var("HELIX_COVERAGE_FILE") { if let Ok(coverage_path) = std::env::var("HELIX_COVERAGE_FILE") {
log::debug!("coverage file is {}", coverage_path);
if let Some(cov) = coverage::parse(PathBuf::from(coverage_path)) { if let Some(cov) = coverage::parse(PathBuf::from(coverage_path)) {
log::debug!("coverage is valid");
if let Some(mut path) = doc.path.clone() { if let Some(mut path) = doc.path.clone() {
log::debug!("full document path: {:?}", path);
if let Ok(cwd) = std::env::current_dir() { if let Ok(cwd) = std::env::current_dir() {
if let Ok(tmp) = path.strip_prefix(cwd) { if let Ok(tmp) = path.strip_prefix(cwd) {
path = tmp.into(); path = tmp.into();
} }
} }
log::debug!("relative document path: {:?}", path);
if let Some(file_coverage) = cov.files.get(&path) { if let Some(file_coverage) = cov.files.get(&path) {
if file_coverage log::debug!(
.modified_time "coverage time: {:?} document time: {:?}",
.is_some_and(|x| x > doc.last_saved_time) file_coverage.modified_time,
{ path.metadata().map(|meta| meta.modified())
// clone file coverage so it can be moved into the closure );
let this_file = coverage::FileCoverage { if let Some(coverage_time) = file_coverage.modified_time {
lines: file_coverage.lines.clone(), if path.metadata().is_ok_and(|meta| {
modified_time: file_coverage.modified_time, meta.modified().is_ok_and(|time| time < coverage_time)
}; }) {
return Box::new( // clone file coverage so it can be moved into the closure
move |line: usize, let this_file = coverage::FileCoverage {
_selected: bool, lines: file_coverage.lines.clone(),
_first_visual_line: bool, modified_time: file_coverage.modified_time,
out: &mut String| { };
if let Some(line_coverage) = this_file.lines.get(&(line as u32)) { log::debug!("return valid coverage gutter");
let (icon, style) = if *line_coverage { return Box::new(
("", covered) move |line: usize,
_selected: bool,
_first_visual_line: bool,
out: &mut String| {
if let Some(line_coverage) = this_file.lines.get(&(line as u32))
{
let (icon, style) = if *line_coverage {
("", covered)
} else {
("", not_covered)
};
write!(out, "{}", icon).unwrap();
Some(style)
} else { } else {
("", not_covered) None
}; }
write!(out, "{}", icon).unwrap(); },
Some(style) );
} else { }
None
}
},
);
} }
} }
} }
} }
} }
log::debug!("return empty coverage gutter");
return Box::new(move |_, _, _, _| None); return Box::new(move |_, _, _, _| None);
} }