Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
seren5240 committed Mar 13, 2024
1 parent 5cbd2e9 commit 8eb2d3e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crates/cli/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions crates/cli/src/commands/apply_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion crates/cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ pub(crate) async fn run_check(
let found_files: DashMap<String, Vec<RichPath>> = 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?;
Expand Down
11 changes: 7 additions & 4 deletions crates/cli/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,10 +785,13 @@ mod tests {
let cli_release_date = updater._get_app_release_date(SupportedApp::Cli)?;
assert_eq!(
cli_release_date,
DateTime::<Utc>::from_naive_utc_and_offset(NaiveDate::from_ymd_opt(2023, 7, 12)
.unwrap()
.and_hms_opt(5, 2, 9)
.unwrap(), Utc),
DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDate::from_ymd_opt(2023, 7, 12)
.unwrap()
.and_hms_opt(5, 2, 9)
.unwrap(),
Utc
),
);

Ok(())
Expand Down
6 changes: 5 additions & 1 deletion crates/cli/tests/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/pattern/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ pub struct AllDone {
#[serde(rename_all = "camelCase")]
pub enum AllDoneReason {
NoInputPaths,
AllPathsIgnored,
AllMatchesFound,
MaxResultsReached,
Aborted,
Expand Down
13 changes: 3 additions & 10 deletions crates/language/src/target_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,14 @@ fn is_file_ignored(path: &Path) -> Result<bool> {
return Ok(true);
}
}
println!(
"Is file ignored returning false for {}, grit ignores were {:?}",
path.display(),
grit_ignores
);
Ok(false)
}

#[cfg(feature = "finder")]
pub fn expand_paths(
start_paths: &[PathBuf],
target_languages: Option<&[PatternLanguage]>,
) -> Result<Walk, Error> {
use anyhow::bail;
) -> Result<Option<Walk>, Error> {
use ignore::overrides::OverrideBuilder;

let mut file_types = TypesBuilder::new();
Expand Down Expand Up @@ -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;
Expand All @@ -541,7 +534,7 @@ pub fn expand_paths(
.parents(true)
.hidden(false)
.build();
Ok(final_walker)
Ok(Some(final_walker))
}

#[derive(Debug, Clone)]
Expand Down
5 changes: 4 additions & 1 deletion crates/lsp/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ pub fn get_watched_files(root_uri: Url) -> Vec<String> {
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![];
}
Expand Down

0 comments on commit 8eb2d3e

Please sign in to comment.