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
// were no saves.
pub last_saved_time: SystemTime,
last_saved_time: SystemTime,
last_saved_revision: usize,
version: i32, // should be usize?

View File

@ -152,46 +152,59 @@ pub fn coverage<'doc>(
let covered = theme.get("diff.plus.gutter");
let not_covered = theme.get("diff.minus.gutter");
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)) {
log::debug!("coverage is valid");
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(tmp) = path.strip_prefix(cwd) {
path = tmp.into();
}
}
log::debug!("relative document path: {:?}", path);
if let Some(file_coverage) = cov.files.get(&path) {
if file_coverage
.modified_time
.is_some_and(|x| x > doc.last_saved_time)
{
// clone file coverage so it can be moved into the closure
let this_file = coverage::FileCoverage {
lines: file_coverage.lines.clone(),
modified_time: file_coverage.modified_time,
};
return Box::new(
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)
log::debug!(
"coverage time: {:?} document time: {:?}",
file_coverage.modified_time,
path.metadata().map(|meta| meta.modified())
);
if let Some(coverage_time) = file_coverage.modified_time {
if path.metadata().is_ok_and(|meta| {
meta.modified().is_ok_and(|time| time < coverage_time)
}) {
// clone file coverage so it can be moved into the closure
let this_file = coverage::FileCoverage {
lines: file_coverage.lines.clone(),
modified_time: file_coverage.modified_time,
};
log::debug!("return valid coverage gutter");
return Box::new(
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 {
("", not_covered)
};
write!(out, "{}", icon).unwrap();
Some(style)
} else {
None
}
},
);
None
}
},
);
}
}
}
}
}
}
log::debug!("return empty coverage gutter");
return Box::new(move |_, _, _, _| None);
}