diff --git a/src/command/format.rs b/src/command/format.rs index fb9eff36..29ad5e3b 100644 --- a/src/command/format.rs +++ b/src/command/format.rs @@ -6,7 +6,7 @@ use directories::ProjectDirs; use std::fs; use std::path::PathBuf; -pub fn format_cmd(work_dir: &PathBuf, paths: &[PathBuf]) -> anyhow::Result<()> { +pub fn format_cmd(work_dir: &PathBuf, paths: &[PathBuf], clear_cache: bool) -> anyhow::Result<()> { let proj_dirs = match ProjectDirs::from("com", "NumTide", "treefmt") { Some(x) => x, None => { @@ -41,7 +41,7 @@ pub fn format_cmd(work_dir: &PathBuf, paths: &[PathBuf]) -> anyhow::Result<()> { )); // Finally run the main formatter logic from the engine. - run_treefmt(&work_dir, &cache_dir, &config_file, &paths)?; + run_treefmt(&work_dir, &cache_dir, &config_file, &paths, clear_cache)?; Ok(()) } diff --git a/src/command/mod.rs b/src/command/mod.rs index a582d07d..90927c53 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -26,6 +26,10 @@ pub struct Cli { #[structopt(long = "init")] pub init: bool, + /// Clear the evaluation cache. Use in case the cache is not precise enough. + #[structopt(long = "clear-cache")] + pub clear_cache: bool, + /// Log verbosity is based off the number of v used #[structopt(long = "verbose", short = "v", parse(from_occurrences))] pub verbosity: u8, @@ -63,7 +67,7 @@ pub fn run_cli(cli: &Cli) -> anyhow::Result<()> { if cli.init { init_cmd(&cli.work_dir)? } else { - format_cmd(&cli.work_dir, &cli.paths)? + format_cmd(&cli.work_dir, &cli.paths, cli.clear_cache)? } Ok(()) diff --git a/src/engine.rs b/src/engine.rs index ed7addf2..0b6a316f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -13,6 +13,7 @@ pub fn run_treefmt( cache_dir: &PathBuf, treefmt_toml: &PathBuf, paths: &[PathBuf], + clear_cache: bool, ) -> anyhow::Result<()> { assert!(work_dir.is_absolute()); assert!(cache_dir.is_absolute()); @@ -78,7 +79,12 @@ pub fn run_treefmt( )); // Load the eval cache - let cache = CacheManifest::load(&cache_dir, &treefmt_toml); + let cache = if clear_cache { + // Start with an empty cache + CacheManifest::default() + } else { + CacheManifest::load(&cache_dir, &treefmt_toml) + }; CLOG.debug(&format!("load cache: {}", start_time.elapsed().as_millis())); // Insert the new formatter configs let cache = cache.update_formatters(formatters.clone());