diff --git a/src/formatters/autopep8.rs b/src/formatters/autopep8.rs index 19987b8f..b8e3794a 100644 --- a/src/formatters/autopep8.rs +++ b/src/formatters/autopep8.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_autopep8( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("autopep8"); + let mut cmd = std::process::Command::new("autopep8"); cmd.arg("--in-place").arg(snippet_path); diff --git a/src/formatters/beautysh.rs b/src/formatters/beautysh.rs index 6595e58c..cab6f847 100644 --- a/src/formatters/beautysh.rs +++ b/src/formatters/beautysh.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_beautysh( file_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("beautysh"); + let mut cmd = std::process::Command::new("beautysh"); cmd.arg(file_path); diff --git a/src/formatters/biome.rs b/src/formatters/biome.rs index bc3388a6..6fe4a8c0 100644 --- a/src/formatters/biome.rs +++ b/src/formatters/biome.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -6,6 +9,8 @@ use super::execute_command; pub fn format_using_biome( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("biome"); + // NOTE: the biome docs recommend running biome using npx, and not directly let mut cmd = setup_npm_script(JavaScriptRuntime::default(), "@biomejs/biome"); diff --git a/src/formatters/black.rs b/src/formatters/black.rs index 3267fc42..cf73f2ad 100644 --- a/src/formatters/black.rs +++ b/src/formatters/black.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_black( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("black"); + let mut cmd = std::process::Command::new("black"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/blade_formatter.rs b/src/formatters/blade_formatter.rs index 9b9c22e2..74b82c36 100644 --- a/src/formatters/blade_formatter.rs +++ b/src/formatters/blade_formatter.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -21,6 +24,8 @@ fn invote_blade_formatter( pub fn format_using_blade_formatter( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("blade-formatter"); + invote_blade_formatter( setup_npm_script(JavaScriptRuntime::default(), "blade-formatter"), snippet_path, diff --git a/src/formatters/blue.rs b/src/formatters/blue.rs index 305fb8e5..6cbc2cbe 100644 --- a/src/formatters/blue.rs +++ b/src/formatters/blue.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_blue( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("blue"); + let mut cmd = std::process::Command::new("blue"); cmd.arg("--quiet").arg(snippet_path); diff --git a/src/formatters/buf.rs b/src/formatters/buf.rs index d34af37e..e9fe77bd 100644 --- a/src/formatters/buf.rs +++ b/src/formatters/buf.rs @@ -1,7 +1,11 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_buf(snippet_path: &std::path::Path) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("buf"); + let mut cmd = std::process::Command::new("buf"); cmd.arg("format").arg("--write").arg(snippet_path); diff --git a/src/formatters/clang_format.rs b/src/formatters/clang_format.rs index 1b370475..e76cc4cf 100644 --- a/src/formatters/clang_format.rs +++ b/src/formatters/clang_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_clang_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("clang-format"); + let mut cmd = std::process::Command::new("clang-format"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/cljstyle.rs b/src/formatters/cljstyle.rs index c78b7ff3..c4d8ea5a 100644 --- a/src/formatters/cljstyle.rs +++ b/src/formatters/cljstyle.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_cljstyle( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("cljstyle"); + let mut cmd = std::process::Command::new("cljstyle"); cmd.arg("fix").arg(snippet_path); diff --git a/src/formatters/crystal_format.rs b/src/formatters/crystal_format.rs index cf6ef569..a3be0c56 100644 --- a/src/formatters/crystal_format.rs +++ b/src/formatters/crystal_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_crystal_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("crystal"); + let mut cmd = std::process::Command::new("crystal"); cmd.arg("tool").arg("format").arg(snippet_path); diff --git a/src/formatters/csharpier.rs b/src/formatters/csharpier.rs index da191189..95074b76 100644 --- a/src/formatters/csharpier.rs +++ b/src/formatters/csharpier.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_csharpier( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("csharpier"); + let mut cmd = std::process::Command::new("dotnet"); cmd.arg("csharpier").arg(snippet_path); diff --git a/src/formatters/dart_format.rs b/src/formatters/dart_format.rs index 54ef2324..8f152a49 100644 --- a/src/formatters/dart_format.rs +++ b/src/formatters/dart_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_dart_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("dart_format"); + let mut cmd = std::process::Command::new("dart"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/deno_fmt.rs b/src/formatters/deno_fmt.rs index fab58be3..1a404257 100644 --- a/src/formatters/deno_fmt.rs +++ b/src/formatters/deno_fmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_deno_fmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("deno_fmt"); + let mut cmd = std::process::Command::new("deno"); cmd.arg("fmt").arg("--quiet").arg(snippet_path); diff --git a/src/formatters/efmt.rs b/src/formatters/efmt.rs index d7dc109b..7e6c64c2 100644 --- a/src/formatters/efmt.rs +++ b/src/formatters/efmt.rs @@ -1,7 +1,11 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_efmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("efmt"); + let mut cmd = std::process::Command::new("efmt"); cmd.arg("-w").arg(file_path); diff --git a/src/formatters/elm_format.rs b/src/formatters/elm_format.rs index 322ebc71..eaa99fb4 100644 --- a/src/formatters/elm_format.rs +++ b/src/formatters/elm_format.rs @@ -1,9 +1,14 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; #[inline] fn set_elm_format_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { + print_debug_formatter_info("elm_format"); + cmd.arg("--elm-version=0.19").arg("--yes").arg(snippet_path); } diff --git a/src/formatters/erlfmt.rs b/src/formatters/erlfmt.rs index 8c4a1c8c..d51a094a 100644 --- a/src/formatters/erlfmt.rs +++ b/src/formatters/erlfmt.rs @@ -1,7 +1,11 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_erlfmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("erlfmt"); + let mut cmd = std::process::Command::new("erlfmt"); cmd.arg("-w") diff --git a/src/formatters/fantomas.rs b/src/formatters/fantomas.rs index e9c4b56e..b8b41d22 100644 --- a/src/formatters/fantomas.rs +++ b/src/formatters/fantomas.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_fantomas( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("fantomas"); + let mut cmd = std::process::Command::new("fantomas"); cmd.arg(snippet_path); diff --git a/src/formatters/fourmolu.rs b/src/formatters/fourmolu.rs index 63fff3ac..b6376d20 100644 --- a/src/formatters/fourmolu.rs +++ b/src/formatters/fourmolu.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_fourmolu( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("fourmolu"); + let mut cmd = std::process::Command::new("fourmolu"); cmd.arg("-i").arg(snippet_path); @@ -22,8 +26,8 @@ mod test_fourmolu { fn it_should_format_haskell() { let input = " addNumbers::Int->Int->Int -addNumbers a b = do - a + b +addNumbers a b = do + a + b "; let expected_output = "addNumbers :: Int -> Int -> Int diff --git a/src/formatters/gleam_format.rs b/src/formatters/gleam_format.rs index a3940456..adcaf523 100644 --- a/src/formatters/gleam_format.rs +++ b/src/formatters/gleam_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_gleam_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("gleam_format"); + let mut cmd = std::process::Command::new("gleam"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/gofmt.rs b/src/formatters/gofmt.rs index 611063f9..bf7db30f 100644 --- a/src/formatters/gofmt.rs +++ b/src/formatters/gofmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_gofmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("gofmt"); + let mut cmd = std::process::Command::new("gofmt"); cmd.arg("-w").arg(snippet_path); diff --git a/src/formatters/gofumpt.rs b/src/formatters/gofumpt.rs index f95d10dc..93746d6d 100644 --- a/src/formatters/gofumpt.rs +++ b/src/formatters/gofumpt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_gofumpt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("gofumpt"); + let mut cmd = std::process::Command::new("gofumpt"); cmd.arg("-w").arg(snippet_path); @@ -18,10 +22,10 @@ mod test_gofumpt { #[test_with::executable(gofumpt)] #[test] fn it_should_format_go() { - let input = "package main + let input = "package main func add(a int , b int ) int { - return a + b + return a + b } "; diff --git a/src/formatters/goimports.rs b/src/formatters/goimports.rs index 1f63fe10..e276e435 100644 --- a/src/formatters/goimports.rs +++ b/src/formatters/goimports.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_goimports( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("goimports"); + let mut cmd = std::process::Command::new("goimports"); cmd.arg("-w").arg(snippet_path); diff --git a/src/formatters/google_java_format.rs b/src/formatters/google_java_format.rs index c6e474ed..5e8732a6 100644 --- a/src/formatters/google_java_format.rs +++ b/src/formatters/google_java_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_google_java_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("google-java-format"); + let mut cmd = std::process::Command::new("google-java-format"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/hindent.rs b/src/formatters/hindent.rs index a465586c..ffd0083f 100644 --- a/src/formatters/hindent.rs +++ b/src/formatters/hindent.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_hindent( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("hindent"); + let mut cmd = std::process::Command::new("hindent"); cmd.arg(snippet_path); @@ -22,8 +26,8 @@ mod test_hindent { fn it_should_format_haskell() { let input = " addNumbers::Int->Int->Int -addNumbers a b = do - a + b +addNumbers a b = do + a + b "; let expected_output = "addNumbers :: Int -> Int -> Int diff --git a/src/formatters/isort.rs b/src/formatters/isort.rs index 08f947dc..ac5ed6dc 100644 --- a/src/formatters/isort.rs +++ b/src/formatters/isort.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_isort( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("isort"); + let mut cmd = std::process::Command::new("isort"); cmd.arg("--quiet").arg(snippet_path); @@ -22,8 +26,8 @@ mod test_isort { fn it_should_format_python() { let input = "from q import d import b -import a -import c +import a +import c def add(a: int, b: int) -> int: diff --git a/src/formatters/just_fmt.rs b/src/formatters/just_fmt.rs index dba2a99b..5d1428c1 100644 --- a/src/formatters/just_fmt.rs +++ b/src/formatters/just_fmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_just_fmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("just_fmt"); + let mut cmd = std::process::Command::new("just"); cmd.arg("--fmt") diff --git a/src/formatters/ktfmt.rs b/src/formatters/ktfmt.rs index f8a313c1..3de5fe24 100644 --- a/src/formatters/ktfmt.rs +++ b/src/formatters/ktfmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_ktfmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("ktfmt"); + let mut cmd = std::process::Command::new("ktfmt"); cmd.arg("--format") diff --git a/src/formatters/ktlint.rs b/src/formatters/ktlint.rs index 843e1c1c..1324eec9 100644 --- a/src/formatters/ktlint.rs +++ b/src/formatters/ktlint.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_ktlint( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("ktlint"); + let mut cmd = std::process::Command::new("ktlint"); cmd.arg("--format") diff --git a/src/formatters/luaformatter.rs b/src/formatters/luaformatter.rs index 10452e18..2ab95a9e 100644 --- a/src/formatters/luaformatter.rs +++ b/src/formatters/luaformatter.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_luaformatter( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("luaformatter"); + let mut cmd = std::process::Command::new("lua-format"); cmd.arg("-i").arg(snippet_path); @@ -26,7 +30,7 @@ mod test_luaformatter { local function add ( a , b ) local c=a+b -return c +return c end diff --git a/src/formatters/mix_format.rs b/src/formatters/mix_format.rs index 51db9472..92432ef2 100644 --- a/src/formatters/mix_format.rs +++ b/src/formatters/mix_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_mix_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("mix_format"); + let mut cmd = std::process::Command::new("mix"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/nimpretty.rs b/src/formatters/nimpretty.rs index 8d4016a4..9d950286 100644 --- a/src/formatters/nimpretty.rs +++ b/src/formatters/nimpretty.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_nimpretty( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("nimpretty"); + let mut cmd = std::process::Command::new("nimpretty"); cmd.arg(snippet_path); diff --git a/src/formatters/npm_groovy_lint.rs b/src/formatters/npm_groovy_lint.rs index 180a00c3..48c0130f 100644 --- a/src/formatters/npm_groovy_lint.rs +++ b/src/formatters/npm_groovy_lint.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -22,6 +25,8 @@ fn invoke_npm_groovy_lint( pub fn format_using_npm_groovy_lint( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("npm-groovy-lint"); + let path_result = invoke_npm_groovy_lint(std::process::Command::new("npm-groovy-lint"), snippet_path)?; @@ -45,7 +50,7 @@ mod test_npm_groovy_lint { #[test] fn it_should_format_groovy() { let input = " def add(a, b) { - return a + b + return a + b } assert add(1,2) == 3 "; diff --git a/src/formatters/ocamlformat.rs b/src/formatters/ocamlformat.rs index b9b04805..66b8daf2 100644 --- a/src/formatters/ocamlformat.rs +++ b/src/formatters/ocamlformat.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_ocamlformat( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("ocamlformat"); + let mut cmd = std::process::Command::new("ocamlformat"); cmd.arg("--ignore-invalid-option") diff --git a/src/formatters/ormolu.rs b/src/formatters/ormolu.rs index 089b5338..fbec5387 100644 --- a/src/formatters/ormolu.rs +++ b/src/formatters/ormolu.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_ormolu( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("ormolu"); + let mut cmd = std::process::Command::new("ormolu"); cmd.arg("--mode").arg("inplace").arg(snippet_path); @@ -22,8 +26,8 @@ mod test_ormolu { fn it_should_format_haskell() { let input = " addNumbers::Int->Int->Int -addNumbers a b = do - a + b +addNumbers a b = do + a + b "; let expected_output = "addNumbers :: Int -> Int -> Int diff --git a/src/formatters/perltidy.rs b/src/formatters/perltidy.rs index 319115bd..84eb1b20 100644 --- a/src/formatters/perltidy.rs +++ b/src/formatters/perltidy.rs @@ -1,3 +1,5 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] @@ -20,6 +22,8 @@ fn invoke_perltidy( pub fn format_using_perltidy( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("perltidy"); + invoke_perltidy(std::process::Command::new("perltidy"), snippet_path) } diff --git a/src/formatters/prettier.rs b/src/formatters/prettier.rs index b09b9375..8efdf830 100644 --- a/src/formatters/prettier.rs +++ b/src/formatters/prettier.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -31,6 +34,8 @@ pub fn format_using_prettier( snippet_path: &std::path::Path, embedded_language_formatting: bool, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("prettier"); + // Local prettier let local_result = invoke_prettier( std::process::Command::new("node_modules/prettier/bin/prettier.cjs"), @@ -374,8 +379,8 @@ function add(a: number, b: number): number { #[test] fn it_should_format_graphql() { - let input = "{ hero { name - # Queries can have comments! + let input = "{ hero { name + # Queries can have comments! friends { name } } }"; let expected_output = "{ diff --git a/src/formatters/purs_tidy.rs b/src/formatters/purs_tidy.rs index 801cddf8..02327675 100644 --- a/src/formatters/purs_tidy.rs +++ b/src/formatters/purs_tidy.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -21,6 +24,8 @@ fn invoke_purs_tidy( pub fn format_using_purs_tidy( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("purs-tidy"); + invoke_purs_tidy( setup_npm_script(JavaScriptRuntime::default(), "purs-tidy"), snippet_path, diff --git a/src/formatters/rescript_format.rs b/src/formatters/rescript_format.rs index 748443af..e1843029 100644 --- a/src/formatters/rescript_format.rs +++ b/src/formatters/rescript_format.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -21,6 +24,8 @@ fn invote_rescript_format( pub fn format_using_rescript_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("rescript_format"); + invote_rescript_format( setup_npm_script(JavaScriptRuntime::default(), "rescript"), snippet_path, diff --git a/src/formatters/roc_format.rs b/src/formatters/roc_format.rs index 634fa02c..041da04b 100644 --- a/src/formatters/roc_format.rs +++ b/src/formatters/roc_format.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_roc_format( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("roc_format"); + let mut cmd = std::process::Command::new("roc"); cmd.arg("format").arg(snippet_path); diff --git a/src/formatters/rubocop.rs b/src/formatters/rubocop.rs index a8b03fd0..e1dce551 100644 --- a/src/formatters/rubocop.rs +++ b/src/formatters/rubocop.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_rubocop( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("rubocop"); + let mut cmd = std::process::Command::new("rubocop"); cmd.arg("--fix-layout") diff --git a/src/formatters/rubyfmt.rs b/src/formatters/rubyfmt.rs index d4ce114b..0883077e 100644 --- a/src/formatters/rubyfmt.rs +++ b/src/formatters/rubyfmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_rubyfmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("rubyfmt"); + let mut cmd = std::process::Command::new("rubyfmt"); cmd.arg("-i").arg(snippet_path); diff --git a/src/formatters/ruff.rs b/src/formatters/ruff.rs index d2d2c5bf..26b2705c 100644 --- a/src/formatters/ruff.rs +++ b/src/formatters/ruff.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_ruff( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("ruff"); + let mut cmd = std::process::Command::new("ruff"); cmd.arg("format"); diff --git a/src/formatters/rufo.rs b/src/formatters/rufo.rs index 5679e101..c9e52b6f 100644 --- a/src/formatters/rufo.rs +++ b/src/formatters/rufo.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_rufo( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("rufo"); + let mut cmd = std::process::Command::new("rufo"); cmd.arg("--simple-exit").arg(snippet_path); diff --git a/src/formatters/rustfmt.rs b/src/formatters/rustfmt.rs index 530b4d17..26ef8ad1 100644 --- a/src/formatters/rustfmt.rs +++ b/src/formatters/rustfmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_rustfmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("rustfmt"); + let mut cmd = std::process::Command::new("rustfmt"); // Needed for async diff --git a/src/formatters/scalafmt.rs b/src/formatters/scalafmt.rs index 9d355eda..59db94a7 100644 --- a/src/formatters/scalafmt.rs +++ b/src/formatters/scalafmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_scalafmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("scalafmt"); + let mut cmd = std::process::Command::new("scalafmt"); #[cfg(test)] @@ -30,10 +34,10 @@ mod test_scalafmt { #[test_with::executable(scalafmt)] #[test] fn it_should_format_scala() { - let input = "object Addition { + let input = "object Addition { def main() = { println(1 + 3) - } + } }"; let expected_output = "object Addition { def main() = { diff --git a/src/formatters/shfmt.rs b/src/formatters/shfmt.rs index eaa2ab1e..8d18f0b3 100644 --- a/src/formatters/shfmt.rs +++ b/src/formatters/shfmt.rs @@ -1,7 +1,11 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_shfmt(file_path: &std::path::Path) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("shfmt"); + let mut cmd = std::process::Command::new("shfmt"); cmd.arg("--write").arg(file_path); diff --git a/src/formatters/sql_formatter.rs b/src/formatters/sql_formatter.rs index 6a8f39d5..8c62f572 100644 --- a/src/formatters/sql_formatter.rs +++ b/src/formatters/sql_formatter.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -21,6 +24,8 @@ fn invote_sql_formatter( pub fn format_using_sql_formatter( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("sql-formatter"); + invote_sql_formatter( setup_npm_script(JavaScriptRuntime::default(), "sql-formatter"), snippet_path, diff --git a/src/formatters/sqlfluff.rs b/src/formatters/sqlfluff.rs index 4de17e89..9e52c75d 100644 --- a/src/formatters/sqlfluff.rs +++ b/src/formatters/sqlfluff.rs @@ -1,3 +1,5 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] @@ -23,6 +25,8 @@ fn invote_sqlfluff( pub fn format_using_sqlfluff( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("sqlfluff"); + invote_sqlfluff(std::process::Command::new("sqlfluff"), snippet_path) } @@ -33,7 +37,7 @@ mod test_sqlfluff { #[test_with::executable(sqlfluff)] #[test] fn it_should_format_sql() { - let input = "SELECT * FROM tbl + let input = "SELECT * FROM tbl WHERE foo = 'bar'; "; let expected_output = "SELECT * FROM tbl diff --git a/src/formatters/standardrb.rs b/src/formatters/standardrb.rs index 2c28ee20..cf87ecfc 100644 --- a/src/formatters/standardrb.rs +++ b/src/formatters/standardrb.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_standardrb( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("standardrb"); + let mut cmd = std::process::Command::new("standardrb"); cmd.arg("--fix").arg(snippet_path); diff --git a/src/formatters/stylua.rs b/src/formatters/stylua.rs index 17b08327..b752e5ba 100644 --- a/src/formatters/stylua.rs +++ b/src/formatters/stylua.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -22,6 +25,8 @@ fn invoke_stylua( pub fn format_using_stylua( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("stylua"); + let path_result = invoke_stylua(std::process::Command::new("stylua"), snippet_path)?; if !path_result.0 { diff --git a/src/formatters/swiftformat.rs b/src/formatters/swiftformat.rs index fb0ef929..82c9d424 100644 --- a/src/formatters/swiftformat.rs +++ b/src/formatters/swiftformat.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_swiftformat( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("swiftformat"); + let mut cmd = std::process::Command::new("swiftformat"); cmd.arg("--quiet").arg(snippet_path); @@ -21,7 +25,7 @@ mod test_swiftformat { #[test] fn it_should_format_swift() { let input = " func add(a:Int ,b:Int)->Int { - return a + b + return a + b }"; let expected_output = "func add(a: Int, b: Int) -> Int { diff --git a/src/formatters/taplo.rs b/src/formatters/taplo.rs index db291478..aa168523 100644 --- a/src/formatters/taplo.rs +++ b/src/formatters/taplo.rs @@ -1,4 +1,7 @@ -use crate::runners::{setup_npm_script, JavaScriptRuntime}; +use crate::{ + runners::{setup_npm_script, JavaScriptRuntime}, + terminal::print_debug_formatter_info, +}; use super::execute_command; @@ -22,6 +25,8 @@ fn invoke_taplo( pub fn format_using_taplo( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("taplo"); + let path_result = invoke_taplo(std::process::Command::new("taplo"), snippet_path)?; if !path_result.0 { diff --git a/src/formatters/usort.rs b/src/formatters/usort.rs index f1b4de23..4fb21121 100644 --- a/src/formatters/usort.rs +++ b/src/formatters/usort.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_usort( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("usort"); + let mut cmd = std::process::Command::new("usort"); cmd.arg("format").arg(snippet_path); @@ -22,8 +26,8 @@ mod test_usort { fn it_should_format_python() { let input = "from q import d import b -import a -import c +import a +import c def add(a: int, b: int) -> int: diff --git a/src/formatters/xmllint.rs b/src/formatters/xmllint.rs index c346e7f6..fa416bf4 100644 --- a/src/formatters/xmllint.rs +++ b/src/formatters/xmllint.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_xmllint( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("xmllint"); + let mut cmd = std::process::Command::new("xmllint"); cmd.arg("--format") diff --git a/src/formatters/yamlfmt.rs b/src/formatters/yamlfmt.rs index e4ce58d8..dd57a886 100644 --- a/src/formatters/yamlfmt.rs +++ b/src/formatters/yamlfmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_yamlfmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("yamlfmt"); + let mut cmd = std::process::Command::new("yamlfmt"); cmd.arg("-quiet").arg(snippet_path); diff --git a/src/formatters/yapf.rs b/src/formatters/yapf.rs index d16dc6a8..7bb817de 100644 --- a/src/formatters/yapf.rs +++ b/src/formatters/yapf.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_yapf( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("yapf"); + let mut cmd = std::process::Command::new("yapf"); cmd.arg("--in-place").arg(snippet_path); diff --git a/src/formatters/zigfmt.rs b/src/formatters/zigfmt.rs index cd493a41..a62285fc 100644 --- a/src/formatters/zigfmt.rs +++ b/src/formatters/zigfmt.rs @@ -1,9 +1,13 @@ +use crate::terminal::print_debug_formatter_info; + use super::execute_command; #[inline] pub fn format_using_zigfmt( snippet_path: &std::path::Path, ) -> std::io::Result<(bool, Option)> { + print_debug_formatter_info("zigfmt"); + let mut cmd = std::process::Command::new("zig"); cmd.arg("fmt"); diff --git a/src/languages/mod.rs b/src/languages/mod.rs index fde8b426..6ddfc547 100644 --- a/src/languages/mod.rs +++ b/src/languages/mod.rs @@ -2,12 +2,25 @@ use schemars::JsonSchema; use crate::formatters::MdsfFormatter; +#[derive(Clone, Copy)] pub enum JsonFlavor { Json, JsonC, Json5, } +impl core::fmt::Display for JsonFlavor { + #[inline] + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Json => f.write_str("json"), + Self::JsonC => f.write_str("jsonc"), + Self::Json5 => f.write_str("json5"), + } + } +} + +#[derive(Clone, Copy)] pub enum Language { Blade, C, @@ -64,6 +77,60 @@ pub enum Language { // TODO: R, } +impl core::fmt::Display for Language { + #[inline] + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Blade => f.write_str("blade"), + Self::C => f.write_str("c"), + Self::Clojure => f.write_str("clojure"), + Self::CSharp => f.write_str("c#"), + Self::Cpp => f.write_str("c++"), + Self::Crystal => f.write_str("crystal"), + Self::Css => f.write_str("css"), + Self::Dart => f.write_str("dart"), + Self::Elixir => f.write_str("elixir"), + Self::Elm => f.write_str("elm"), + Self::Erlang => f.write_str("erlang"), + Self::FSharp => f.write_str("f#"), + Self::Gleam => f.write_str("gleam"), + Self::Go => f.write_str("go"), + Self::GraphQL => f.write_str("graphql"), + Self::Groovy => f.write_str("groovy"), + Self::Haskell => f.write_str("haskell"), + Self::Html => f.write_str("html"), + Self::Java => f.write_str("java"), + Self::JavaScript => f.write_str("javascript"), + Self::Json(flavor) => flavor.fmt(f), + Self::Just => f.write_str("just"), + Self::Kotlin => f.write_str("kotlin"), + Self::Lua => f.write_str("lua"), + Self::Markdown => f.write_str("markdown"), + Self::Nim => f.write_str("nim"), + Self::OCaml => f.write_str("ocaml"), + Self::ObjectiveC => f.write_str("objective c"), + Self::Perl => f.write_str("perl"), + Self::Protobuf => f.write_str("protobuf"), + Self::PureScript => f.write_str("purescript"), + Self::Python => f.write_str("python"), + Self::ReScript => f.write_str("rescript"), + Self::Roc => f.write_str("roc"), + Self::Ruby => f.write_str("ruby"), + Self::Rust => f.write_str("rust"), + Self::Scala => f.write_str("scala"), + Self::Shell => f.write_str("shell"), + Self::Sql => f.write_str("sql"), + Self::Swift => f.write_str("swift"), + Self::Toml => f.write_str("toml"), + Self::TypeScript => f.write_str("typescript"), + Self::Vue => f.write_str("vue"), + Self::Xml => f.write_str("xml"), + Self::Yaml => f.write_str("yaml"), + Self::Zig => f.write_str("zig"), + } + } +} + pub mod blade; pub mod c; pub mod clojure; diff --git a/src/lib.rs b/src/lib.rs index 6746007c..bffc180f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,9 @@ use config::MdsfConfig; use error::MdsfError; use formatters::format_snippet; use languages::Language; +use terminal::{ + print_debug_file_info, print_debug_line_info, write_changed_line, write_unchanged_line, +}; pub mod cli; pub mod config; @@ -11,36 +14,13 @@ pub mod error; pub mod formatters; pub mod languages; mod runners; +pub mod terminal; #[cfg(test)] pub static DEBUG: AtomicBool = AtomicBool::new(true); #[cfg(not(test))] pub static DEBUG: AtomicBool = AtomicBool::new(false); -#[inline] -fn write_unchanged_line(path: &std::path::Path, dur: core::time::Duration) { - #[cfg(target_os = "windows")] - let pre = ""; - #[cfg(not(target_os = "windows"))] - let pre = "\u{1b}[2m"; - - #[cfg(target_os = "windows")] - let post = ""; - #[cfg(not(target_os = "windows"))] - let post = "\u{1b}[0m"; - - println!( - "{pre}{} {}ms (unchanged){post}", - path.display(), - dur.as_millis() - ); -} - -#[inline] -fn write_changed_line(path: &std::path::Path, dur: core::time::Duration) { - println!("{} {}ms", path.display(), dur.as_millis()); -} - #[inline] fn format_file(config: &MdsfConfig, input: &str) -> (bool, String) { let mut output = String::with_capacity(input.len() + 128); @@ -49,7 +29,7 @@ fn format_file(config: &MdsfConfig, input: &str) -> (bool, String) { let mut lines = input.lines().enumerate(); - while let Some((_, line)) = lines.next() { + while let Some((line_index, line)) = lines.next() { // TODO: implement support for code blocks with 4 ` if line.starts_with("```") { if let Some(language) = line.strip_prefix("```").and_then(Language::maybe_from_str) { @@ -57,7 +37,11 @@ fn format_file(config: &MdsfConfig, input: &str) -> (bool, String) { let mut is_snippet = false; + let mut snippet_lines = 0; + for (_, subline) in lines.by_ref() { + snippet_lines += 1; + if subline.trim_end() == "```" { is_snippet = true; break; @@ -69,6 +53,14 @@ fn format_file(config: &MdsfConfig, input: &str) -> (bool, String) { } if is_snippet { + if DEBUG.load(core::sync::atomic::Ordering::Relaxed) { + print_debug_line_info( + language, + line_index + 1, + line_index + snippet_lines + 1, + ); + } + let formatted = format_snippet(config, &language, &code_snippet); output.push_str(line); @@ -103,6 +95,8 @@ fn format_file(config: &MdsfConfig, input: &str) -> (bool, String) { #[inline] pub fn handle_file(config: &MdsfConfig, path: &std::path::Path) -> Result<(), MdsfError> { + print_debug_file_info(path); + let time = std::time::Instant::now(); let input = std::fs::read_to_string(path)?; diff --git a/src/main.rs b/src/main.rs index 0a51e082..701d2389 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use mdsf::{ config::MdsfConfig, error::MdsfError, handle_file, + terminal::print_file_not_found, }; fn format_command(args: FormatCommandArguments) -> Result<(), MdsfError> { @@ -28,20 +29,7 @@ fn format_command(args: FormatCommandArguments) -> Result<(), MdsfError> { } } } else { - #[cfg(target_os = "windows")] - let pre = ""; - #[cfg(not(target_os = "windows"))] - let pre = "\u{1b}[31m"; - - #[cfg(target_os = "windows")] - let post = ""; - #[cfg(not(target_os = "windows"))] - let post = "\u{1b}[0m"; - - println!( - "{pre}No file or directory with the name \"{}\" found{post}", - args.path.display(), - ); + print_file_not_found(&args.path); } Ok(()) diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs new file mode 100644 index 00000000..786e0502 --- /dev/null +++ b/src/terminal/mod.rs @@ -0,0 +1,67 @@ +use crate::{languages::Language, DEBUG}; + +#[cfg(target_os = "windows")] +const GREY_TEXT: &str = ""; +#[cfg(not(target_os = "windows"))] +const GREY_TEXT: &str = "\u{1b}[2m"; + +#[cfg(target_os = "windows")] +const DEBUG_TEXT_DECORATION: &str = ""; +#[cfg(not(target_os = "windows"))] +const DEBUG_TEXT_DECORATION: &str = "\u{1b}[33m"; + +#[cfg(target_os = "windows")] +const ERROR_TEXT_DECORATION: &str = ""; +#[cfg(not(target_os = "windows"))] +const ERROR_TEXT_DECORATION: &str = "\u{1b}[31m"; + +#[cfg(target_os = "windows")] +const TEXT_RESET: &str = ""; +#[cfg(not(target_os = "windows"))] +const TEXT_RESET: &str = "\u{1b}[0m"; + +#[inline] +pub fn print_debug_file_info(filename: &std::path::Path) { + if DEBUG.load(core::sync::atomic::Ordering::Relaxed) { + println!( + "{DEBUG_TEXT_DECORATION}Formatting '{}'{TEXT_RESET}", + filename.display() + ); + } +} + +#[inline] +pub fn print_debug_line_info(language: Language, start: usize, end: usize) { + if DEBUG.load(core::sync::atomic::Ordering::Relaxed) { + println!("{DEBUG_TEXT_DECORATION}Formatting '{language}' block from :{start} to :{end}{TEXT_RESET}"); + } +} + +#[inline] +pub fn print_debug_formatter_info(formatter: &str) { + if DEBUG.load(core::sync::atomic::Ordering::Relaxed) { + println!("{DEBUG_TEXT_DECORATION}Using formatter: '{formatter}'{TEXT_RESET}"); + } +} + +#[inline] +pub fn write_unchanged_line(path: &std::path::Path, dur: core::time::Duration) { + println!( + "{GREY_TEXT}{} {}ms (unchanged){TEXT_RESET}", + path.display(), + dur.as_millis() + ); +} + +#[inline] +pub fn write_changed_line(path: &std::path::Path, dur: core::time::Duration) { + println!("{} {}ms", path.display(), dur.as_millis()); +} + +#[inline] +pub fn print_file_not_found(path: &std::path::Path) { + println!( + "{ERROR_TEXT_DECORATION}No file or directory with the name \"{}\" found{TEXT_RESET}", + path.display(), + ); +}