// use std::path::Path; use crate::model::{Config, Line, Marker, Markers}; use anyhow::Result; use ignore::Walk; pub fn find_markers(config: &Config) -> Result { let mut markers = Markers::default(); for file in Walk::new(config.fs().base()).flatten() { let path = file.path(); if config.fs().path_is_file(path)? { scan_file(path, config, &mut markers)?; } } Ok(markers) } fn scan_file(file: &Path, config: &Config, found_markers: &mut Markers) -> Result<()> { let relative_path = file.strip_prefix(config.fs().base())?.to_path_buf(); config .fs() .file_read_to_string(file)? .lines() .enumerate() .map(|(n, line)| { Line::builder() .file(file.to_path_buf()) .relative_path(relative_path.clone()) .num(n) .value(line.to_owned()) .build() }) .filter_map(|line| line.into_marker().ok()) .filter(|marker| !matches!(marker, Marker::Unmarked)) .for_each(|marker| found_markers.add_marker(marker)); Ok(()) }