From 8eb2d3e078418c96a7f8cefbc440fe7f767c6dcb Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Wed, 13 Mar 2024 11:19:49 +0000 Subject: [PATCH] build --- crates/cli/src/analyze.rs | 4 ++-- crates/cli/src/commands/apply_pattern.rs | 13 +++++++++++++ crates/cli/src/commands/check.rs | 5 ++++- crates/cli/src/updater.rs | 11 +++++++---- crates/cli/tests/plumbing.rs | 6 +++++- crates/core/src/pattern/api.rs | 1 + crates/language/src/target_language.rs | 13 +++---------- crates/lsp/src/watcher.rs | 5 ++++- 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/crates/cli/src/analyze.rs b/crates/cli/src/analyze.rs index b04645c95..9f8d48e92 100644 --- a/crates/cli/src/analyze.rs +++ b/crates/cli/src/analyze.rs @@ -13,13 +13,13 @@ use grit_cache::paths::cache_for_cwd; use ignore::Walk; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; +#[allow(unused_imports)] +use marzano_core::pattern::built_in_functions::BuiltIns; use marzano_core::pattern::{ api::{AnalysisLog, DoneFile, MatchResult}, compiler::CompilationResult, Problem, }; -#[allow(unused_imports)] -use marzano_core::pattern::built_in_functions::BuiltIns; use marzano_language::target_language::PatternLanguage; use marzano_util::cache::GritCache; use marzano_util::position::Position; diff --git a/crates/cli/src/commands/apply_pattern.rs b/crates/cli/src/commands/apply_pattern.rs index 386ddf77f..4246dca6b 100644 --- a/crates/cli/src/commands/apply_pattern.rs +++ b/crates/cli/src/commands/apply_pattern.rs @@ -374,6 +374,19 @@ pub(crate) async fn run_apply_pattern( expand_paths(&my_input.paths, Some(&[(&compiled.language).into()])) ); + if file_walker.is_none() { + let all_done = MatchResult::AllDone(AllDone { + processed: 0, + found: 0, + reason: AllDoneReason::AllPathsIgnored, + }); + emitter.emit(&all_done, min_level).unwrap(); + emitter.flush().await?; + + return Ok(()); + } + let file_walker = file_walker.unwrap(); + let processed = AtomicI32::new(0); let mut emitter = par_apply_pattern( diff --git a/crates/cli/src/commands/check.rs b/crates/cli/src/commands/check.rs index 407f5ed7b..80786a6c6 100644 --- a/crates/cli/src/commands/check.rs +++ b/crates/cli/src/commands/check.rs @@ -153,7 +153,10 @@ pub(crate) async fn run_check( let found_files: DashMap> = DashMap::new(); for language in target_languages { - let file_walker = expand_paths(&paths, Some(&[language]))?; + let file_walker = match expand_paths(&paths, Some(&[language]))? { + Some(walker) => walker, + None => continue, + }; let mut language_paths = Vec::new(); for file in file_walker { let file = file?; diff --git a/crates/cli/src/updater.rs b/crates/cli/src/updater.rs index 48f1a65e9..5b21b9abc 100644 --- a/crates/cli/src/updater.rs +++ b/crates/cli/src/updater.rs @@ -785,10 +785,13 @@ mod tests { let cli_release_date = updater._get_app_release_date(SupportedApp::Cli)?; assert_eq!( cli_release_date, - DateTime::::from_naive_utc_and_offset(NaiveDate::from_ymd_opt(2023, 7, 12) - .unwrap() - .and_hms_opt(5, 2, 9) - .unwrap(), Utc), + DateTime::::from_naive_utc_and_offset( + NaiveDate::from_ymd_opt(2023, 7, 12) + .unwrap() + .and_hms_opt(5, 2, 9) + .unwrap(), + Utc + ), ); Ok(()) diff --git a/crates/cli/tests/plumbing.rs b/crates/cli/tests/plumbing.rs index 6a66a9d04..53851662d 100644 --- a/crates/cli/tests/plumbing.rs +++ b/crates/cli/tests/plumbing.rs @@ -103,7 +103,11 @@ fn returns_check_results_for_level() -> Result<()> { let input = format!(r#"{{ "paths" : [{:?}] }}"#, "check.ts"); - cmd.arg("plumbing").arg("check").arg("--level").arg("error").current_dir(fixtures_root); + cmd.arg("plumbing") + .arg("check") + .arg("--level") + .arg("error") + .current_dir(fixtures_root); cmd.write_stdin(input); let output = cmd.output()?; diff --git a/crates/core/src/pattern/api.rs b/crates/core/src/pattern/api.rs index 40f156a29..60b3a303f 100644 --- a/crates/core/src/pattern/api.rs +++ b/crates/core/src/pattern/api.rs @@ -555,6 +555,7 @@ pub struct AllDone { #[serde(rename_all = "camelCase")] pub enum AllDoneReason { NoInputPaths, + AllPathsIgnored, AllMatchesFound, MaxResultsReached, Aborted, diff --git a/crates/language/src/target_language.rs b/crates/language/src/target_language.rs index 1a12d1830..7f5e52623 100644 --- a/crates/language/src/target_language.rs +++ b/crates/language/src/target_language.rs @@ -419,11 +419,6 @@ fn is_file_ignored(path: &Path) -> Result { return Ok(true); } } - println!( - "Is file ignored returning false for {}, grit ignores were {:?}", - path.display(), - grit_ignores - ); Ok(false) } @@ -431,8 +426,7 @@ fn is_file_ignored(path: &Path) -> Result { pub fn expand_paths( start_paths: &[PathBuf], target_languages: Option<&[PatternLanguage]>, -) -> Result { - use anyhow::bail; +) -> Result, Error> { use ignore::overrides::OverrideBuilder; let mut file_types = TypesBuilder::new(); @@ -518,13 +512,12 @@ pub fn expand_paths( .position(|path| !is_file_ignored(path).unwrap_or(false)) { Some(index) => index, - None => bail!("All selected paths are ignored"), + None => return Ok(None), }; let mut file_walker = WalkBuilder::new(start_paths[first_whitelisted_index].clone()); file_walker.types(file_types.build()?); for path in start_paths.iter().skip(first_whitelisted_index) { - println!("Path {} is file: {}", path.display(), path.is_file()); // This is necessary because ignore does not check directly added WalkBuilder paths against ignore files if path.is_file() && is_file_ignored(path)? { continue; @@ -541,7 +534,7 @@ pub fn expand_paths( .parents(true) .hidden(false) .build(); - Ok(final_walker) + Ok(Some(final_walker)) } #[derive(Debug, Clone)] diff --git a/crates/lsp/src/watcher.rs b/crates/lsp/src/watcher.rs index 282d8a15e..74fe3812a 100644 --- a/crates/lsp/src/watcher.rs +++ b/crates/lsp/src/watcher.rs @@ -12,7 +12,10 @@ pub fn get_watched_files(root_uri: Url) -> Vec { let paths = vec![root]; let languages = PatternLanguage::enumerate(); let walker = match expand_paths(&paths, Some(&languages)) { - Ok(walker) => walker, + Ok(Some(walker)) => walker, + Ok(None) => { + return vec![]; + } Err(_) => { return vec![]; }