Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bincode = "1.3.3"
dirs = "6.0"
num_cpus = "1.15"
ureq = { version = "2.9" }
rayon = "1.10.0"

[build-dependencies]
winres = "0.1.12"
Expand Down
18 changes: 10 additions & 8 deletions cli/src/commands/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//! Formats TechScript source code files recursively in the specified path.

use crate::exit_code::ExitCode;
use rayon::prelude::*;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};

pub fn execute(path_str: Option<&str>) -> ExitCode {
let current_dir = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
Expand Down Expand Up @@ -41,11 +43,11 @@ pub fn execute(path_str: Option<&str>) -> ExitCode {
files_to_format.push(target_path);
}

let formatter = techscript_formatter::DocumentFormatter::new(4);
let mut formatted_count = 0;
let formatted_count = AtomicUsize::new(0);

for file in files_to_format {
match std::fs::read_to_string(&file) {
files_to_format.par_iter().for_each(|file| {
let formatter = techscript_formatter::DocumentFormatter::new(4);
match std::fs::read_to_string(file) {
Ok(content) => {
let formatted = formatter.format_source(&content);
// In skeletal phase, if format_source returns empty, we just skip writing to avoid wiping out files.
Expand All @@ -55,20 +57,20 @@ pub fn execute(path_str: Option<&str>) -> ExitCode {
&& !formatted.contains("<stmt>")
&& !formatted.contains("<pat>")
{
if let Err(e) = std::fs::write(&file, formatted) {
if let Err(e) = std::fs::write(file, formatted) {
eprintln!("Error writing formatted file {:?}: {}", file, e);
} else {
println!("Formatted: {:?}", file);
formatted_count += 1;
formatted_count.fetch_add(1, Ordering::Relaxed);
}
}
}
Err(e) => {
eprintln!("Error reading file {:?}: {}", file, e);
}
}
}
});

println!("Formatted {} files.", formatted_count);
println!("Formatted {} files.", formatted_count.into_inner());
ExitCode::Success
}
Loading