mirror of https://github.com/helix-editor/helix
wip only show coverage if it is newer than doc
parent
79b85030b2
commit
a9f2ec3eea
|
@ -3,6 +3,7 @@ use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
pub struct Coverage {
|
pub struct Coverage {
|
||||||
pub files: HashMap<std::path::PathBuf, FileCoverage>,
|
pub files: HashMap<std::path::PathBuf, FileCoverage>,
|
||||||
|
@ -10,6 +11,7 @@ pub struct Coverage {
|
||||||
|
|
||||||
pub struct FileCoverage {
|
pub struct FileCoverage {
|
||||||
pub lines: HashMap<u32, bool>,
|
pub lines: HashMap<u32, bool>,
|
||||||
|
pub modified_time: Option<SystemTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -18,6 +20,7 @@ struct RawCoverage {
|
||||||
version: String,
|
version: String,
|
||||||
sources: Sources,
|
sources: Sources,
|
||||||
packages: Packages,
|
packages: Packages,
|
||||||
|
modified_time: Option<SystemTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -72,8 +75,10 @@ struct Line {
|
||||||
|
|
||||||
pub fn parse(path: std::path::PathBuf) -> Option<Coverage> {
|
pub fn parse(path: std::path::PathBuf) -> Option<Coverage> {
|
||||||
let file = File::open(path).ok()?;
|
let file = File::open(path).ok()?;
|
||||||
|
let metadata = file.metadata().ok()?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
let tmp: RawCoverage = from_reader(reader).ok()?;
|
let mut tmp: RawCoverage = from_reader(reader).ok()?;
|
||||||
|
tmp.modified_time = metadata.modified().ok();
|
||||||
Some(tmp.into())
|
Some(tmp.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +94,13 @@ impl From<RawCoverage> for Coverage {
|
||||||
for source in &coverage.sources.source {
|
for source in &coverage.sources.source {
|
||||||
let path: std::path::PathBuf = [&source.name, &class.filename].iter().collect();
|
let path: std::path::PathBuf = [&source.name, &class.filename].iter().collect();
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
files.insert(path, FileCoverage { lines });
|
files.insert(
|
||||||
|
path,
|
||||||
|
FileCoverage {
|
||||||
|
lines,
|
||||||
|
modified_time: coverage.modified_time,
|
||||||
|
},
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
last_saved_time: SystemTime,
|
pub last_saved_time: SystemTime,
|
||||||
|
|
||||||
last_saved_revision: usize,
|
last_saved_revision: usize,
|
||||||
version: i32, // should be usize?
|
version: i32, // should be usize?
|
||||||
|
|
|
@ -159,9 +159,15 @@ pub fn coverage<'doc>(
|
||||||
path = tmp.into();
|
path = tmp.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(file) = cov.files.get(&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 {
|
let this_file = coverage::FileCoverage {
|
||||||
lines: file.lines.clone(),
|
lines: file_coverage.lines.clone(),
|
||||||
|
modified_time: file_coverage.modified_time,
|
||||||
};
|
};
|
||||||
return Box::new(
|
return Box::new(
|
||||||
move |line: usize,
|
move |line: usize,
|
||||||
|
@ -185,6 +191,7 @@ pub fn coverage<'doc>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Box::new(move |_, _, _, _| None);
|
return Box::new(move |_, _, _, _| None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue