From 89334a678df3f90261b885765fa87ac0577ac92d Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Sun, 26 Jan 2025 18:56:46 -0600 Subject: [PATCH 01/17] add format test case --- crates/cli/src/commands/format.rs | 48 ++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index de6fa1160..0145109a6 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -24,25 +24,27 @@ pub async fn run_format(arg: &FormatArgs) -> Result<()> { let (resolved, _) = resolve_from_cwd(&Source::Local).await?; let file_path_to_resolved = group_resolved_patterns_by_group(resolved); - let mut results = file_path_to_resolved + + println!("Formtting {} files", file_path_to_resolved.len()); + + let _ = file_path_to_resolved .into_par_iter() .map(|(file_path, resolved_patterns)| { let result = format_file_resolved_patterns(&file_path, resolved_patterns, arg.clone()); (file_path, result) - }) - .collect::>(); + }); // sort outputs to ensure consistent stdout output // also avoid using sort_by_key to prevent additional cloning of file_path - results.sort_by(|(file_path, _), (other_file_path, _)| file_path.cmp(other_file_path)); + // results.sort_by(|(file_path, _), (other_file_path, _)| file_path.cmp(other_file_path)); - for (file_path, result) in results { - match result { - Err(error) => eprintln!("couldn't format '{}': {error:?}", file_path), - Ok(Some(diff)) => println!("{}:\n{}", file_path.bold(), diff), - Ok(None) => (), // `args.write` is true or file is already formated - } - } + // for (file_path, result) in results { + // match result { + // Err(error) => eprintln!("couldn't format '{}': {error:?}", file_path), + // Ok(Some(diff)) => println!("{}:\n{}", file_path.bold(), diff), + // Ok(None) => (), // `args.write` is true or file is already formated + // } + // } Ok(()) } @@ -236,3 +238,27 @@ fn apply_hunk_changes(input: &str, mut hunks: Vec) -> String { } buffer } + +#[cfg(test)] +mod tests { + use super::*; + use std::path::PathBuf; + + #[tokio::test] + async fn test_format_fixtures() -> Result<()> { + // Change to the fixtures directory relative to the project root + let fixtures_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .join("cli_bin") + .join("fixtures"); + + println!("fixtures_path: {:?}", fixtures_path); + std::env::set_current_dir(&fixtures_path)?; + + let args = FormatArgs { write: false }; + run_format(&args).await?; + + Ok(()) + } +} From fd2a8b9cccc26cc500427682400c9c5d7d77ab59 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Sun, 26 Jan 2025 21:13:37 -0600 Subject: [PATCH 02/17] [skip ci] yolo --- crates/cli/Cargo.toml | 6 +- crates/cli/src/commands/format.rs | 246 ++++++++++++++++++------------ crates/cli/src/commands/mod.rs | 6 +- crates/core/src/api.rs | 9 ++ 4 files changed, 161 insertions(+), 106 deletions(-) diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index e5131567a..7aed19b30 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -87,8 +87,10 @@ tracing-subscriber = { version = "0.3", default-features = false, optional = tru tracing-log = { version = "0.2.0", optional = true } fs-err = { version = "2.11.0" } -biome_grit_parser = { git = "https://github.com/biomejs/biome" } -biome_grit_formatter = { git = "https://github.com/biomejs/biome" } +# biome_grit_parser = { git = "https://github.com/biomejs/biome" } +# biome_grit_formatter = { git = "https://github.com/biomejs/biome" } +biome_grit_parser = { path = "../../../../../../biome/crates/biome_grit_parser" } +biome_grit_formatter = { path = "../../../../../../biome/crates/biome_grit_formatter" } [target.'cfg(not(windows))'.dependencies] openssl = { version = "0.10", features = ["vendored"] } diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 0145109a6..00139f242 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -1,75 +1,79 @@ use crate::{ + flags::GlobalFormatFlags, + messenger_variant::{create_emitter, MessengerVariant}, resolver::{resolve_from_cwd, GritModuleResolver, Source}, ux::{format_diff, DiffString}, }; use anyhow::{anyhow, bail, ensure, Context, Result}; use biome_grit_formatter::context::GritFormatOptions; +use biome_grit_parser::GritParse; use clap::Args; use colored::Colorize; -use marzano_core::api::MatchResult; +use marzano_core::api::{EntireFile, MatchResult, Rewrite}; use marzano_gritmodule::{config::ResolvedGritDefinition, parser::PatternFileExt}; +use marzano_messenger::{emit::Messager, output_mode::OutputMode}; use marzano_util::{rich_path::RichFile, runtime::ExecutionContext}; -use rayon::iter::{IntoParallelIterator, ParallelIterator}; +use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator as _, ParallelIterator}; use serde::Serialize; -use std::collections::BTreeMap; +use std::fmt::Write; +use std::{collections::BTreeMap, panic::set_hook, sync::mpsc}; #[derive(Args, Debug, Serialize, Clone)] -pub struct FormatArgs { +pub struct FormatGritArgs { /// Write formats to file instead of just showing them #[clap(long)] pub write: bool, } -pub async fn run_format(arg: &FormatArgs) -> Result<()> { +pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Result<()> { let (resolved, _) = resolve_from_cwd(&Source::Local).await?; let file_path_to_resolved = group_resolved_patterns_by_group(resolved); - println!("Formtting {} files", file_path_to_resolved.len()); - - let _ = file_path_to_resolved - .into_par_iter() - .map(|(file_path, resolved_patterns)| { - let result = format_file_resolved_patterns(&file_path, resolved_patterns, arg.clone()); - (file_path, result) - }); - - // sort outputs to ensure consistent stdout output - // also avoid using sort_by_key to prevent additional cloning of file_path - // results.sort_by(|(file_path, _), (other_file_path, _)| file_path.cmp(other_file_path)); - - // for (file_path, result) in results { - // match result { - // Err(error) => eprintln!("couldn't format '{}': {error:?}", file_path), - // Ok(Some(diff)) => println!("{}:\n{}", file_path.bold(), diff), - // Ok(None) => (), // `args.write` is true or file is already formated - // } - // } + println!("Formatting {} files", file_path_to_resolved.len()); + + // Create an emitter for formatting results + let mut emitter = create_emitter( + &crate::flags::OutputFormat::from(flags), + OutputMode::default(), + None, + false, + None, + None, + marzano_messenger::emit::VisibilityLevels::default(), + ) + .await?; + + for (file_path, resolved_patterns) in file_path_to_resolved { + let results = format_file_resolved_patterns(&file_path, resolved_patterns); + if let Ok(results) = results { + emitter.emit(&results).unwrap(); + } + } + Ok(()) } fn group_resolved_patterns_by_group( resolved: Vec, ) -> Vec<(String, Vec)> { - resolved.into_iter().fold(Vec::new(), |mut acc, resolved| { - let file_path = &resolved.config.path; - if let Some((_, resolved_patterns)) = acc - .iter_mut() - .find(|(resolv_file_path, _)| resolv_file_path == file_path) - { - resolved_patterns.push(resolved); - } else { - acc.push((file_path.clone(), vec![resolved])); - } - acc - }) + let mut map = BTreeMap::new(); + + // Group into map + for resolved in resolved { + map.entry(resolved.config.path.clone()) + .or_insert_with(Vec::new) + .push(resolved); + } + + // Convert to Vec + map.into_iter().collect() } fn format_file_resolved_patterns( file_path: &str, patterns: Vec, - arg: FormatArgs, -) -> Result> { +) -> Result> { let first_pattern = patterns .first() .ok_or_else(|| anyhow!("patterns is empty"))?; @@ -80,28 +84,36 @@ fn format_file_resolved_patterns( .ok_or_else(|| anyhow!("pattern doesn't have raw data"))?; let old_file_content = &first_pattern_raw_data.content; - let new_file_content = match first_pattern_raw_data.format { - PatternFileExt::Yaml => format_yaml_file(&patterns, old_file_content)?, + println!("Parsing {:?}", file_path); + + let (mut results, new_file_content) = match first_pattern_raw_data.format { + PatternFileExt::Yaml => { + // println!("format_yaml_file not implemented"); + (vec![], old_file_content.to_owned()) + } PatternFileExt::Grit => format_grit_code(old_file_content)?, PatternFileExt::Md => { - let hunks = patterns - .iter() - .map(format_pattern_as_hunk_changes) - .collect::>>()?; - apply_hunk_changes(old_file_content, hunks) + // println!("format_md_file not implemented"); + // let hunks = patterns + // .iter() + // .map(format_pattern_as_hunk_changes) + // .collect::>>()?; + // apply_hunk_changes(old_file_content, hunks) + (vec![], old_file_content.to_owned()) } }; if &new_file_content == old_file_content { - return Ok(None); + return Ok(results); } - if arg.write { - std::fs::write(file_path, new_file_content).with_context(|| "could not write to file")?; - Ok(None) - } else { - Ok(Some(format_diff(old_file_content, &new_file_content))) - } + results.push(MatchResult::Rewrite(Rewrite::for_file( + file_path, + old_file_content, + &new_file_content, + ))); + + Ok(results) } /// bubble clause that finds a grit pattern with name "\" in yaml and @@ -121,22 +133,22 @@ const YAML_REPLACE_BODY_PATERN: &str = r#" "#; /// format each pattern and use gritql pattern to match and rewrite -fn format_yaml_file(patterns: &[ResolvedGritDefinition], file_content: &str) -> Result { - let bubbles = patterns - .iter() - .map(|pattern| { - let formatted_body = format_grit_code(&pattern.body) - .with_context(|| format!("could not format '{}'", pattern.name()))?; - let bubble = YAML_REPLACE_BODY_PATERN - .replace("", pattern.name()) - .replace("", &format_yaml_body_code(&formatted_body)); - Ok(bubble) - }) - .collect::>>()? - .join(",\n"); - let pattern_body = format!("language yaml\nsequential{{ {bubbles} }}"); - apply_grit_rewrite(file_content, &pattern_body) -} +// fn format_yaml_file(patterns: &[ResolvedGritDefinition], file_content: &str) -> Result { +// let bubbles = patterns +// .iter() +// .map(|pattern| { +// let formatted_body = format_grit_code(&pattern.body) +// .with_context(|| format!("could not format '{}'", pattern.name()))?; +// let bubble = YAML_REPLACE_BODY_PATERN +// .replace("", pattern.name()) +// .replace("", &format_yaml_body_code(&formatted_body)); +// Ok(bubble) +// }) +// .collect::>>()? +// .join(",\n"); +// let pattern_body = format!("language yaml\nsequential{{ {bubbles} }}"); +// apply_grit_rewrite(file_content, &pattern_body) +// } fn format_yaml_body_code(input: &str) -> String { // yaml body still needs two indentation to look good @@ -184,37 +196,65 @@ fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { bail!("no rewrite result after applying grit pattern") } -fn format_pattern_as_hunk_changes(pattern: &ResolvedGritDefinition) -> Result { - let formatted_grit_code = format_grit_code(&pattern.body)?; - let body_range = pattern - .config - .range - .ok_or_else(|| anyhow!("pattern doesn't have config range"))?; - Ok(HunkChange { - starting_byte: body_range.start_byte as usize, - ending_byte: body_range.end_byte as usize, - new_content: formatted_grit_code, - }) -} - /// format grit code using `biome` -fn format_grit_code(source: &str) -> Result { +fn format_grit_code(source: &str) -> Result<(Vec, String)> { + // Biome might panic when parsing, so we need to catch it + set_hook(Box::new(panic_handler)); + let parsed = biome_grit_parser::parse_grit(source); - ensure!( - parsed.diagnostics().is_empty(), - "biome couldn't parse: {}", - parsed - .diagnostics() - .iter() - .map(|diag| diag.message.to_string()) - .collect::>() - .join("\n") - ); + + // TODO: restore this part + // ensure!( + // parsed.diagnostics().is_empty(), + // "biome couldn't parse: {}", + // parsed + // .diagnostics() + // .iter() + // .map(|diag| diag.message.to_string()) + // .collect::>() + // .join("\n") + // ); let options = GritFormatOptions::default(); let doc = biome_grit_formatter::format_node(options, &parsed.syntax()) .with_context(|| "biome couldn't format")?; - Ok(doc.print()?.into_code()) + Ok((vec![], doc.print()?.into_code())) +} + +fn panic_handler(info: &std::panic::PanicHookInfo) { + // Buffer the error message to a string before printing it at once + // to prevent it from getting mixed with other errors if multiple threads + // panic at the same time + let mut error = String::new(); + + writeln!(error, "Biome encountered an unexpected error").unwrap(); + writeln!(error).unwrap(); + + writeln!(error, "This is a bug in Biome, not an error in your code, and we would appreciate it if you could report it to https://github.com/biomejs/biome/issues/ along with the following information to help us fixing the issue:").unwrap(); + writeln!(error).unwrap(); + + if let Some(location) = info.location() { + writeln!(error, "Source Location: {location}").unwrap(); + } + + if let Some(thread) = std::thread::current().name() { + writeln!(error, "Thread Name: {thread}").unwrap(); + } + + let payload = info.payload(); + if let Some(msg) = payload.downcast_ref::<&'static str>() { + writeln!(error, "Message: {msg}").unwrap(); + } else if let Some(msg) = payload.downcast_ref::() { + writeln!(error, "Message: {msg}").unwrap(); + } + + // Write the panic to stderr + eprintln!("{error}"); + + // Write the panic to the log file, this is done last since the `tracing` + // infrastructure could panic a second time and abort the process, so we + // want to ensure the error has at least been logged to stderr beforehand + tracing::error!("{error}"); } /// Represent a hunk of text that needs to be changed @@ -247,17 +287,21 @@ mod tests { #[tokio::test] async fn test_format_fixtures() -> Result<()> { // Change to the fixtures directory relative to the project root - let fixtures_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .parent() - .unwrap() - .join("cli_bin") - .join("fixtures"); + // let fixtures_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + // .parent() + // .unwrap() + // .join("cli_bin") + // .join("fixtures"); + + let fixtures_path = PathBuf::from("/Users/morgante/code/grit/stdlib"); println!("fixtures_path: {:?}", fixtures_path); std::env::set_current_dir(&fixtures_path)?; - let args = FormatArgs { write: false }; - run_format(&args).await?; + let args = FormatGritArgs { write: false }; + run_format(&args, &GlobalFormatFlags::default()).await?; + + println!("done"); Ok(()) } diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index 845bcddd5..228d5d4b7 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -83,7 +83,7 @@ use check::CheckArg; use clap::Parser; use clap::Subcommand; use doctor::DoctorArgs; -use format::{run_format, FormatArgs}; +use format::{run_format, FormatGritArgs}; use indicatif::MultiProgress; use indicatif_log_bridge::LogWrapper; use init::InitArgs; @@ -174,7 +174,7 @@ pub enum Commands { /// Display version information about the CLI and agents Version(VersionArgs), /// Format grit files under current directory - Format(FormatArgs), + Format(FormatGritArgs), /// Generate documentation for the Grit CLI (internal use only) #[cfg(feature = "docgen")] #[clap(hide = true)] @@ -463,7 +463,7 @@ async fn run_command(_use_tracing: bool) -> Result<()> { run_plumbing(arg, multi, &mut apply_details, app.format_flags).await } Commands::Version(arg) => run_version(arg).await, - Commands::Format(arg) => run_format(&arg).await, + Commands::Format(arg) => run_format(&arg, &app.format_flags).await, #[cfg(feature = "docgen")] Commands::Docgen(arg) => run_docgen(arg).await, #[cfg(feature = "server")] diff --git a/crates/core/src/api.rs b/crates/core/src/api.rs index 153d2024c..1558e1fa7 100644 --- a/crates/core/src/api.rs +++ b/crates/core/src/api.rs @@ -510,6 +510,15 @@ impl Rewrite { let rewritten = EntireFile::from_file(rewritten_file)?; Ok(Rewrite::new(original, rewritten, None)) } + + pub fn for_file(path: &str, old_content: &str, new_content: &str) -> Self { + Self { + original: EntireFile::file_to_entire_file(path, old_content, None), + rewritten: EntireFile::file_to_entire_file(path, new_content, None), + reason: None, + id: Uuid::new_v4(), + } + } } impl FileMatchResult for Rewrite { From 40990b428d3529440b13ccd344169e7ce6de7b50 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Sun, 26 Jan 2025 21:34:32 -0600 Subject: [PATCH 03/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 98 +++++++++++-------------------- 1 file changed, 34 insertions(+), 64 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 00139f242..2d4403ea4 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -47,7 +47,9 @@ pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Resu for (file_path, resolved_patterns) in file_path_to_resolved { let results = format_file_resolved_patterns(&file_path, resolved_patterns); if let Ok(results) = results { - emitter.emit(&results).unwrap(); + for result in results { + emitter.emit(&result).unwrap(); + } } } @@ -91,7 +93,10 @@ fn format_file_resolved_patterns( // println!("format_yaml_file not implemented"); (vec![], old_file_content.to_owned()) } - PatternFileExt::Grit => format_grit_code(old_file_content)?, + PatternFileExt::Grit => { + format_grit_code(old_file_content)?; + (vec![], old_file_content.to_owned()) + } PatternFileExt::Md => { // println!("format_md_file not implemented"); // let hunks = patterns @@ -103,15 +108,17 @@ fn format_file_resolved_patterns( } }; + println!("parsed file:\n{}", new_file_content); + if &new_file_content == old_file_content { return Ok(results); } - results.push(MatchResult::Rewrite(Rewrite::for_file( - file_path, - old_file_content, - &new_file_content, - ))); + // results.push(MatchResult::Rewrite(Rewrite::for_file( + // file_path, + // old_file_content, + // &new_file_content, + // ))); Ok(results) } @@ -198,11 +205,10 @@ fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { /// format grit code using `biome` fn format_grit_code(source: &str) -> Result<(Vec, String)> { - // Biome might panic when parsing, so we need to catch it - set_hook(Box::new(panic_handler)); - let parsed = biome_grit_parser::parse_grit(source); + println!("parsed: {:?}", parsed); + // TODO: restore this part // ensure!( // parsed.diagnostics().is_empty(), @@ -215,46 +221,12 @@ fn format_grit_code(source: &str) -> Result<(Vec, String)> { // .join("\n") // ); - let options = GritFormatOptions::default(); - let doc = biome_grit_formatter::format_node(options, &parsed.syntax()) - .with_context(|| "biome couldn't format")?; - Ok((vec![], doc.print()?.into_code())) -} - -fn panic_handler(info: &std::panic::PanicHookInfo) { - // Buffer the error message to a string before printing it at once - // to prevent it from getting mixed with other errors if multiple threads - // panic at the same time - let mut error = String::new(); - - writeln!(error, "Biome encountered an unexpected error").unwrap(); - writeln!(error).unwrap(); - - writeln!(error, "This is a bug in Biome, not an error in your code, and we would appreciate it if you could report it to https://github.com/biomejs/biome/issues/ along with the following information to help us fixing the issue:").unwrap(); - writeln!(error).unwrap(); - - if let Some(location) = info.location() { - writeln!(error, "Source Location: {location}").unwrap(); - } - - if let Some(thread) = std::thread::current().name() { - writeln!(error, "Thread Name: {thread}").unwrap(); - } - - let payload = info.payload(); - if let Some(msg) = payload.downcast_ref::<&'static str>() { - writeln!(error, "Message: {msg}").unwrap(); - } else if let Some(msg) = payload.downcast_ref::() { - writeln!(error, "Message: {msg}").unwrap(); - } - - // Write the panic to stderr - eprintln!("{error}"); - - // Write the panic to the log file, this is done last since the `tracing` - // infrastructure could panic a second time and abort the process, so we - // want to ensure the error has at least been logged to stderr beforehand - tracing::error!("{error}"); + // let options = GritFormatOptions::default(); + // let doc = biome_grit_formatter::format_node(options, &parsed.syntax()) + // .with_context(|| "biome couldn't format")?; + // println!("formatted file:\n{}", doc.print()?.into_code()); + // Ok((vec![], doc.print()?.into_code())) + Ok((vec![], source.to_owned())) } /// Represent a hunk of text that needs to be changed @@ -285,23 +257,21 @@ mod tests { use std::path::PathBuf; #[tokio::test] - async fn test_format_fixtures() -> Result<()> { - // Change to the fixtures directory relative to the project root - // let fixtures_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - // .parent() - // .unwrap() - // .join("cli_bin") - // .join("fixtures"); - - let fixtures_path = PathBuf::from("/Users/morgante/code/grit/stdlib"); + async fn test_format_go_imports() -> Result<()> { + // This somehow has a massive memory leak but only in --release mode - println!("fixtures_path: {:?}", fixtures_path); - std::env::set_current_dir(&fixtures_path)?; + let fixtures_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .join("cli_bin") + .join("fixtures") + .join("go") + .join("imports.grit"); - let args = FormatGritArgs { write: false }; - run_format(&args, &GlobalFormatFlags::default()).await?; + let input = std::fs::read_to_string(&fixtures_path)?; + let result = format_grit_code(&input); - println!("done"); + println!("done: {:?}", result); Ok(()) } From b56fd41ecfb9de105abfe20f5438ba76a0186037 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Tue, 4 Feb 2025 23:08:46 -0600 Subject: [PATCH 04/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 48 ++++++++++++------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 2d4403ea4..ea89d6c83 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -108,17 +108,15 @@ fn format_file_resolved_patterns( } }; - println!("parsed file:\n{}", new_file_content); - if &new_file_content == old_file_content { return Ok(results); } - // results.push(MatchResult::Rewrite(Rewrite::for_file( - // file_path, - // old_file_content, - // &new_file_content, - // ))); + results.push(MatchResult::Rewrite(Rewrite::for_file( + file_path, + old_file_content, + &new_file_content, + ))); Ok(results) } @@ -205,28 +203,20 @@ fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { /// format grit code using `biome` fn format_grit_code(source: &str) -> Result<(Vec, String)> { - let parsed = biome_grit_parser::parse_grit(source); - - println!("parsed: {:?}", parsed); - - // TODO: restore this part - // ensure!( - // parsed.diagnostics().is_empty(), - // "biome couldn't parse: {}", - // parsed - // .diagnostics() - // .iter() - // .map(|diag| diag.message.to_string()) - // .collect::>() - // .join("\n") - // ); - - // let options = GritFormatOptions::default(); - // let doc = biome_grit_formatter::format_node(options, &parsed.syntax()) - // .with_context(|| "biome couldn't format")?; - // println!("formatted file:\n{}", doc.print()?.into_code()); - // Ok((vec![], doc.print()?.into_code())) - Ok((vec![], source.to_owned())) + let result = std::panic::catch_unwind(|| { + let parsed = biome_grit_parser::parse_grit(source); + parsed + }); + + let Ok(parsed) = result else { + return Err(anyhow!("Syntax error in grit code, parsing failed")); + }; + + let options = GritFormatOptions::default(); + let doc = biome_grit_formatter::format_node(options, &parsed.syntax()) + .with_context(|| "biome couldn't format")?; + let formatted = doc.print()?.into_code(); + Ok((vec![], formatted)) } /// Represent a hunk of text that needs to be changed From f0a8b196f3d134e17dfe9144ac9e218c1c2787dc Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Tue, 4 Feb 2025 23:47:39 -0600 Subject: [PATCH 05/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 84 +++++++++++++----------- crates/cli/src/commands/patterns_test.rs | 22 ++++--- 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index ea89d6c83..f96b16de1 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -1,4 +1,5 @@ use crate::{ + commands::patterns_test::filter_patterns_by_regex, flags::GlobalFormatFlags, messenger_variant::{create_emitter, MessengerVariant}, resolver::{resolve_from_cwd, GritModuleResolver, Source}, @@ -9,7 +10,7 @@ use biome_grit_formatter::context::GritFormatOptions; use biome_grit_parser::GritParse; use clap::Args; use colored::Colorize; -use marzano_core::api::{EntireFile, MatchResult, Rewrite}; +use marzano_core::api::{DoneFile, EntireFile, MatchResult, Rewrite}; use marzano_gritmodule::{config::ResolvedGritDefinition, parser::PatternFileExt}; use marzano_messenger::{emit::Messager, output_mode::OutputMode}; use marzano_util::{rich_path::RichFile, runtime::ExecutionContext}; @@ -23,10 +24,23 @@ pub struct FormatGritArgs { /// Write formats to file instead of just showing them #[clap(long)] pub write: bool, + // Level of detail to show for results + #[clap( + long = "output", + default_value_t = OutputMode::Standard, + )] + output: OutputMode, + /// Regex of a specific pattern to test + #[clap(long = "filter")] + pub filter: Option, } pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Result<()> { - let (resolved, _) = resolve_from_cwd(&Source::Local).await?; + let (mut resolved, _) = resolve_from_cwd(&Source::Local).await?; + + if let Some(filter) = &arg.filter { + resolved = filter_patterns_by_regex(resolved, filter)?; + } let file_path_to_resolved = group_resolved_patterns_by_group(resolved); @@ -35,7 +49,7 @@ pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Resu // Create an emitter for formatting results let mut emitter = create_emitter( &crate::flags::OutputFormat::from(flags), - OutputMode::default(), + arg.output.clone(), None, false, None, @@ -76,6 +90,10 @@ fn format_file_resolved_patterns( file_path: &str, patterns: Vec, ) -> Result> { + // Apply patterns in reverse order to avoid conflicts + let mut patterns = patterns; + patterns.sort_by_key(|p| p.config.range.map_or(0, |r| r.start_byte)); + let first_pattern = patterns .first() .ok_or_else(|| anyhow!("patterns is empty"))?; @@ -84,30 +102,44 @@ fn format_file_resolved_patterns( .raw .as_ref() .ok_or_else(|| anyhow!("pattern doesn't have raw data"))?; + + let format = first_pattern_raw_data.format; let old_file_content = &first_pattern_raw_data.content; - println!("Parsing {:?}", file_path); + let mut results = vec![]; - let (mut results, new_file_content) = match first_pattern_raw_data.format { + let new_file_content = match format { PatternFileExt::Yaml => { // println!("format_yaml_file not implemented"); - (vec![], old_file_content.to_owned()) + // (vec![], old_file_content.to_owned()) + old_file_content.to_owned() } PatternFileExt::Grit => { - format_grit_code(old_file_content)?; - (vec![], old_file_content.to_owned()) + let (this_results, new_file_content) = format_grit_code(old_file_content)?; + results.extend(this_results); + new_file_content } PatternFileExt::Md => { - // println!("format_md_file not implemented"); - // let hunks = patterns - // .iter() - // .map(format_pattern_as_hunk_changes) - // .collect::>>()?; - // apply_hunk_changes(old_file_content, hunks) - (vec![], old_file_content.to_owned()) + let mut new_file_content = old_file_content.clone(); + for pattern in &patterns { + if let Some(range) = pattern.config.range { + let (this_results, formatted_pattern) = format_grit_code(&pattern.body) + .with_context(|| format!("could not format '{}'", pattern.name()))?; + results.extend(this_results); + new_file_content.replace_range( + range.start_byte as usize..range.end_byte as usize, + formatted_pattern.as_str(), + ); + } else { + println!("pattern {} has no range", pattern.name()); + } + } + new_file_content } }; + results.push(MatchResult::DoneFile(DoneFile::new(file_path.to_owned()))); + if &new_file_content == old_file_content { return Ok(results); } @@ -219,28 +251,6 @@ fn format_grit_code(source: &str) -> Result<(Vec, String)> { Ok((vec![], formatted)) } -/// Represent a hunk of text that needs to be changed -#[derive(Debug)] -struct HunkChange { - starting_byte: usize, - ending_byte: usize, - new_content: String, -} - -/// returns a new string that applies hunk changes -fn apply_hunk_changes(input: &str, mut hunks: Vec) -> String { - if hunks.is_empty() { - return input.to_string(); - } - hunks.sort_by_key(|hunk| -(hunk.starting_byte as isize)); - let mut buffer = input.to_owned(); - for hunk in hunks { - let hunk_range = hunk.starting_byte..hunk.ending_byte; - buffer.replace_range(hunk_range, &hunk.new_content); - } - buffer -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/cli/src/commands/patterns_test.rs b/crates/cli/src/commands/patterns_test.rs index 40bf0a8c6..00075c10b 100644 --- a/crates/cli/src/commands/patterns_test.rs +++ b/crates/cli/src/commands/patterns_test.rs @@ -4,7 +4,7 @@ use log::{debug, info}; use marzano_core::analysis::get_dependents_of_target_patterns_by_traversal_from_src; use marzano_core::api::MatchResult; -use marzano_gritmodule::config::{GritPatternSample, GritPatternTestInfo}; +use marzano_gritmodule::config::{GritPatternSample, GritPatternTestInfo, ResolvedGritDefinition}; use marzano_gritmodule::formatting::format_rich_files; use marzano_gritmodule::markdown::replace_sample_in_md_file; use marzano_gritmodule::patterns_directory::PatternsDirectory; @@ -255,6 +255,17 @@ pub async fn get_marzano_pattern_test_results( Ok(AggregatedTestResult::AllPassed) } +pub(crate) fn filter_patterns_by_regex( + patterns: Vec, + filter: &String, +) -> Result> { + let regex = regex::Regex::new(filter.as_str())?; + Ok(patterns + .into_iter() + .filter(|p| regex.is_match(&p.local_name)) + .collect()) +} + pub(crate) async fn run_patterns_test( arg: PatternsTestArgs, flags: GlobalFormatFlags, @@ -262,13 +273,8 @@ pub(crate) async fn run_patterns_test( let (mut patterns, _) = resolve_from_cwd(&Source::Local).await?; let libs = get_grit_files_from_flags_or_cwd(&flags).await?; - if arg.filter.is_some() { - let filter = arg.filter.as_ref().unwrap(); - let regex = regex::Regex::new(filter)?; - patterns = patterns - .into_iter() - .filter(|p| regex.is_match(&p.local_name)) - .collect::>() + if let Some(filter) = &arg.filter { + patterns = filter_patterns_by_regex(patterns, filter)?; } if !arg.exclude.is_empty() { From fdf86b160c27423516fcb75fafb2d7f73b07e70a Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:04:49 -0600 Subject: [PATCH 06/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 143 +++++++++++++++++++----------- 1 file changed, 93 insertions(+), 50 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index f96b16de1..6c5e9eb31 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -12,7 +12,11 @@ use clap::Args; use colored::Colorize; use marzano_core::api::{DoneFile, EntireFile, MatchResult, Rewrite}; use marzano_gritmodule::{config::ResolvedGritDefinition, parser::PatternFileExt}; -use marzano_messenger::{emit::Messager, output_mode::OutputMode}; +use marzano_language::{markdown_block::MarkdownBlock, target_language::TargetLanguage}; +use marzano_messenger::{ + emit::{ApplyDetails, Messager}, + output_mode::OutputMode, +}; use marzano_util::{rich_path::RichFile, runtime::ExecutionContext}; use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator as _, ParallelIterator}; use serde::Serialize; @@ -44,7 +48,15 @@ pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Resu let file_path_to_resolved = group_resolved_patterns_by_group(resolved); - println!("Formatting {} files", file_path_to_resolved.len()); + println!( + "Formatting {} {}", + format!("{}", file_path_to_resolved.len()).bold().yellow(), + if file_path_to_resolved.len() == 1 { + "pattern" + } else { + "patterns" + } + ); // Create an emitter for formatting results let mut emitter = create_emitter( @@ -58,15 +70,40 @@ pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Resu ) .await?; + let mut details = ApplyDetails { + matched: 0, + rewritten: 0, + named_pattern: None, + }; + let dry_run = !arg.write; + for (file_path, resolved_patterns) in file_path_to_resolved { let results = format_file_resolved_patterns(&file_path, resolved_patterns); if let Ok(results) = results { - for result in results { - emitter.emit(&result).unwrap(); - } + emitter.handle_results( + results, + &mut details, + dry_run, + false, + &mut false, + None, + None, + None, + &TargetLanguage::MarkdownBlock(MarkdownBlock::new(None)), + ); } } + println!( + "Modified {} {}", + format!("{}", details.rewritten).bold().yellow(), + if details.rewritten == 1 { + "file" + } else { + "files" + } + ); + Ok(()) } @@ -110,8 +147,14 @@ fn format_file_resolved_patterns( let new_file_content = match format { PatternFileExt::Yaml => { - // println!("format_yaml_file not implemented"); - // (vec![], old_file_content.to_owned()) + let mut new_file_content = old_file_content.clone(); + for pattern in &patterns { + if let Some(range) = pattern.config.range { + let (this_results, formatted_pattern) = format_grit_code(&pattern.body) + .with_context(|| format!("could not format '{}'", pattern.name()))?; + results.extend(this_results); + } + } old_file_content.to_owned() } PatternFileExt::Grit => { @@ -187,51 +230,51 @@ const YAML_REPLACE_BODY_PATERN: &str = r#" // apply_grit_rewrite(file_content, &pattern_body) // } -fn format_yaml_body_code(input: &str) -> String { - // yaml body still needs two indentation to look good - let body_with_prefix = prefix_lines(input, &" ".repeat(2)); - let escaped_body = body_with_prefix.replace("\"", "\\\""); - // body: | - // escaped_body - format!("|\n{escaped_body}") -} +// fn format_yaml_body_code(input: &str) -> String { +// // yaml body still needs two indentation to look good +// let body_with_prefix = prefix_lines(input, &" ".repeat(2)); +// let escaped_body = body_with_prefix.replace("\"", "\\\""); +// // body: | +// // escaped_body +// format!("|\n{escaped_body}") +// } -fn prefix_lines(input: &str, prefix: &str) -> String { - input - .lines() - .map(|line| { - if line.is_empty() { - line.to_owned() - } else { - format!("{prefix}{line}") - } - }) - .collect::>() - .join("\n") -} +// fn prefix_lines(input: &str, prefix: &str) -> String { +// input +// .lines() +// .map(|line| { +// if line.is_empty() { +// line.to_owned() +// } else { +// format!("{prefix}{line}") +// } +// }) +// .collect::>() +// .join("\n") +// } -fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { - let resolver = GritModuleResolver::new(); - let rich_pattern = resolver.make_pattern(pattern, None)?; - - let compiled = rich_pattern - .compile(&BTreeMap::new(), None, None, None) - .map(|cr| cr.problem) - .with_context(|| "could not compile pattern")?; - - let rich_file = RichFile::new(String::new(), input.to_owned()); - let runtime = ExecutionContext::default(); - for result in compiled.execute_file(&rich_file, &runtime) { - if let MatchResult::Rewrite(rewrite) = result { - let content = rewrite - .rewritten - .content - .ok_or_else(|| anyhow!("rewritten content is empty"))?; - return Ok(content); - } - } - bail!("no rewrite result after applying grit pattern") -} +// fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { +// let resolver = GritModuleResolver::new(); +// let rich_pattern = resolver.make_pattern(pattern, None)?; + +// let compiled = rich_pattern +// .compile(&BTreeMap::new(), None, None, None) +// .map(|cr| cr.problem) +// .with_context(|| "could not compile pattern")?; + +// let rich_file = RichFile::new(String::new(), input.to_owned()); +// let runtime = ExecutionContext::default(); +// for result in compiled.execute_file(&rich_file, &runtime) { +// if let MatchResult::Rewrite(rewrite) = result { +// let content = rewrite +// .rewritten +// .content +// .ok_or_else(|| anyhow!("rewritten content is empty"))?; +// return Ok(content); +// } +// } +// bail!("no rewrite result after applying grit pattern") +// } /// format grit code using `biome` fn format_grit_code(source: &str) -> Result<(Vec, String)> { From b337c48cbcf27a991eb135a37c113ca51815daac Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:21:33 -0600 Subject: [PATCH 07/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 181 +++++++++++++++++------------- 1 file changed, 100 insertions(+), 81 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 6c5e9eb31..7dd963bf2 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -129,7 +129,7 @@ fn format_file_resolved_patterns( ) -> Result> { // Apply patterns in reverse order to avoid conflicts let mut patterns = patterns; - patterns.sort_by_key(|p| p.config.range.map_or(0, |r| r.start_byte)); + patterns.sort_by_key(|p| std::cmp::Reverse(p.config.range.map_or(0, |r| r.start_byte))); let first_pattern = patterns .first() @@ -196,86 +196,6 @@ fn format_file_resolved_patterns( Ok(results) } -/// bubble clause that finds a grit pattern with name "\" in yaml and -/// replaces it's body to "\", `format_yaml_file` uses this pattern to replace -/// pattern bodies with formatted ones -const YAML_REPLACE_BODY_PATERN: &str = r#" - bubble file($body) where { - $body <: contains block_mapping(items=$items) where { - $items <: within `patterns: $_`, - $items <: contains `name: $name`, - $name <: "", - $items <: contains `body: $yaml_body`, - $new_body = "", - $yaml_body => $new_body - }, - } -"#; - -/// format each pattern and use gritql pattern to match and rewrite -// fn format_yaml_file(patterns: &[ResolvedGritDefinition], file_content: &str) -> Result { -// let bubbles = patterns -// .iter() -// .map(|pattern| { -// let formatted_body = format_grit_code(&pattern.body) -// .with_context(|| format!("could not format '{}'", pattern.name()))?; -// let bubble = YAML_REPLACE_BODY_PATERN -// .replace("", pattern.name()) -// .replace("", &format_yaml_body_code(&formatted_body)); -// Ok(bubble) -// }) -// .collect::>>()? -// .join(",\n"); -// let pattern_body = format!("language yaml\nsequential{{ {bubbles} }}"); -// apply_grit_rewrite(file_content, &pattern_body) -// } - -// fn format_yaml_body_code(input: &str) -> String { -// // yaml body still needs two indentation to look good -// let body_with_prefix = prefix_lines(input, &" ".repeat(2)); -// let escaped_body = body_with_prefix.replace("\"", "\\\""); -// // body: | -// // escaped_body -// format!("|\n{escaped_body}") -// } - -// fn prefix_lines(input: &str, prefix: &str) -> String { -// input -// .lines() -// .map(|line| { -// if line.is_empty() { -// line.to_owned() -// } else { -// format!("{prefix}{line}") -// } -// }) -// .collect::>() -// .join("\n") -// } - -// fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { -// let resolver = GritModuleResolver::new(); -// let rich_pattern = resolver.make_pattern(pattern, None)?; - -// let compiled = rich_pattern -// .compile(&BTreeMap::new(), None, None, None) -// .map(|cr| cr.problem) -// .with_context(|| "could not compile pattern")?; - -// let rich_file = RichFile::new(String::new(), input.to_owned()); -// let runtime = ExecutionContext::default(); -// for result in compiled.execute_file(&rich_file, &runtime) { -// if let MatchResult::Rewrite(rewrite) = result { -// let content = rewrite -// .rewritten -// .content -// .ok_or_else(|| anyhow!("rewritten content is empty"))?; -// return Ok(content); -// } -// } -// bail!("no rewrite result after applying grit pattern") -// } - /// format grit code using `biome` fn format_grit_code(source: &str) -> Result<(Vec, String)> { let result = std::panic::catch_unwind(|| { @@ -294,6 +214,105 @@ fn format_grit_code(source: &str) -> Result<(Vec, String)> { Ok((vec![], formatted)) } +mod yaml { + use std::collections::BTreeMap; + + use anyhow::{anyhow, bail, Context, Result}; + use marzano_core::api::MatchResult; + use marzano_gritmodule::config::ResolvedGritDefinition; + use marzano_util::{rich_path::RichFile, runtime::ExecutionContext}; + + use crate::resolver::GritModuleResolver; + + use super::format_grit_code; + + /// bubble clause that finds a grit pattern with name "\" in yaml and + /// replaces it's body to "\", `format_yaml_file` uses this pattern to replace + /// pattern bodies with formatted ones + const YAML_REPLACE_BODY_PATERN: &str = r#" + bubble file($body) where { + $body <: contains block_mapping(items=$items) where { + $items <: within `patterns: $_`, + $items <: contains `name: $name`, + $name <: "", + $items <: contains `body: $yaml_body`, + $new_body = "", + $yaml_body => $new_body + }, + } +"#; + + /// format each pattern and use gritql pattern to match and rewrite + fn apply_yaml_rewrites( + patterns: &[ResolvedGritDefinition], + file_content: &str, + ) -> Result<(Vec, String)> { + let mut results = vec![]; + let bubbles = patterns + .iter() + .map(|pattern| { + let (this_results, formatted_body) = format_grit_code(&pattern.body) + .with_context(|| format!("could not format '{}'", pattern.name()))?; + results.extend(this_results); + let bubble = YAML_REPLACE_BODY_PATERN + .replace("", pattern.name()) + .replace("", &format_yaml_body_code(&formatted_body)); + Ok(bubble) + }) + .collect::>>()? + .join(",\n"); + let pattern_body = format!("language yaml\nsequential{{ {bubbles} }}"); + let rewritten = apply_grit_rewrite(file_content, &pattern_body)?; + Ok((results, rewritten)) + } + + fn format_yaml_body_code(input: &str) -> String { + // yaml body still needs two indentation to look good + let body_with_prefix = prefix_lines(input, &" ".repeat(2)); + let escaped_body = body_with_prefix.replace("\"", "\\\""); + // body: | + // escaped_body + format!("|\n{escaped_body}") + } + + fn prefix_lines(input: &str, prefix: &str) -> String { + input + .lines() + .map(|line| { + if line.is_empty() { + line.to_owned() + } else { + format!("{prefix}{line}") + } + }) + .collect::>() + .join("\n") + } + + fn apply_grit_rewrite(input: &str, pattern: &str) -> Result { + let resolver = GritModuleResolver::new(); + let rich_pattern = resolver.make_pattern(pattern, None)?; + + let compiled = rich_pattern + .compile(&BTreeMap::new(), None, None, None) + .map(|cr| cr.problem) + .with_context(|| "could not compile pattern")?; + + let rich_file = RichFile::new(String::new(), input.to_owned()); + let runtime = ExecutionContext::default(); + for result in compiled.execute_file(&rich_file, &runtime) { + if let MatchResult::Rewrite(rewrite) = result { + let content = rewrite + .rewritten + .content + .ok_or_else(|| anyhow!("rewritten content is empty"))?; + return Ok(content); + } + } + bail!("no rewrite result after applying grit pattern") + } +} + #[cfg(test)] mod tests { use super::*; From 2eb233a0767adab354af3a1bf11d7fdb6830aa92 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:22:56 -0600 Subject: [PATCH 08/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 7dd963bf2..85370cb87 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -147,15 +147,10 @@ fn format_file_resolved_patterns( let new_file_content = match format { PatternFileExt::Yaml => { - let mut new_file_content = old_file_content.clone(); - for pattern in &patterns { - if let Some(range) = pattern.config.range { - let (this_results, formatted_pattern) = format_grit_code(&pattern.body) - .with_context(|| format!("could not format '{}'", pattern.name()))?; - results.extend(this_results); - } - } - old_file_content.to_owned() + let (this_results, new_file_content) = + yaml::apply_yaml_rewrites(&patterns, old_file_content)?; + results.extend(this_results); + new_file_content } PatternFileExt::Grit => { let (this_results, new_file_content) = format_grit_code(old_file_content)?; @@ -243,7 +238,7 @@ mod yaml { "#; /// format each pattern and use gritql pattern to match and rewrite - fn apply_yaml_rewrites( + pub(crate) fn apply_yaml_rewrites( patterns: &[ResolvedGritDefinition], file_content: &str, ) -> Result<(Vec, String)> { From 1c7363c691bbf25df18458e21dfeb2d606c76b03 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:30:46 -0600 Subject: [PATCH 09/17] stdout --- Cargo.lock | 200 +++++---------------------------- crates/cli_bin/tests/format.rs | 3 +- 2 files changed, 31 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94281572b..8587b1664 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -323,11 +323,9 @@ dependencies = [ [[package]] name = "biome_console" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_markup", "biome_text_size", - "schemars", "serde", "termcolor", "unicode-segmentation", @@ -337,23 +335,18 @@ dependencies = [ [[package]] name = "biome_deserialize" version = "0.6.0" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_console", - "biome_deserialize_macros", "biome_diagnostics", "biome_json_parser", "biome_json_syntax", "biome_rowan", "enumflags2", - "indexmap 2.7.1", - "serde", ] [[package]] name = "biome_deserialize_macros" version = "0.6.0" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_string_case", "proc-macro-error", @@ -365,7 +358,6 @@ dependencies = [ [[package]] name = "biome_diagnostics" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "backtrace", "biome_console", @@ -374,20 +366,17 @@ dependencies = [ "biome_rowan", "biome_text_edit", "biome_text_size", - "bpaf", "enumflags2", - "oxc_resolver", "serde", - "serde_ini", "serde_json", "termcolor", + "terminal_size", "unicode-width", ] [[package]] name = "biome_diagnostics_categories" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "quote", "serde", @@ -396,7 +385,6 @@ dependencies = [ [[package]] name = "biome_diagnostics_macros" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "proc-macro-error", "proc-macro2", @@ -407,7 +395,6 @@ dependencies = [ [[package]] name = "biome_formatter" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_console", "biome_deserialize", @@ -415,6 +402,7 @@ dependencies = [ "biome_diagnostics", "biome_rowan", "biome_string_case", + "camino", "cfg-if", "countme", "drop_bomb", @@ -427,7 +415,6 @@ dependencies = [ [[package]] name = "biome_grit_factory" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_grit_syntax", "biome_rowan", @@ -436,7 +423,6 @@ dependencies = [ [[package]] name = "biome_grit_formatter" version = "0.0.0" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_formatter", "biome_grit_syntax", @@ -446,7 +432,6 @@ dependencies = [ [[package]] name = "biome_grit_parser" version = "0.1.0" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_console", "biome_diagnostics", @@ -464,17 +449,16 @@ dependencies = [ [[package]] name = "biome_grit_syntax" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_rowan", "biome_string_case", + "camino", "serde", ] [[package]] name = "biome_json_factory" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_json_syntax", "biome_rowan", @@ -483,7 +467,6 @@ dependencies = [ [[package]] name = "biome_json_parser" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_console", "biome_diagnostics", @@ -499,17 +482,16 @@ dependencies = [ [[package]] name = "biome_json_syntax" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_rowan", "biome_string_case", + "camino", "serde", ] [[package]] name = "biome_markup" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "proc-macro-error", "proc-macro2", @@ -519,7 +501,6 @@ dependencies = [ [[package]] name = "biome_parser" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_console", "biome_diagnostics", @@ -533,7 +514,6 @@ dependencies = [ [[package]] name = "biome_rowan" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_text_edit", "biome_text_size", @@ -541,18 +521,15 @@ dependencies = [ "hashbrown 0.14.5", "rustc-hash 2.1.0", "serde", - "tracing", ] [[package]] name = "biome_string_case" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" [[package]] name = "biome_text_edit" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ "biome_text_size", "serde", @@ -562,16 +539,13 @@ dependencies = [ [[package]] name = "biome_text_size" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" dependencies = [ - "schemars", "serde", ] [[package]] name = "biome_unicode_table" version = "0.5.7" -source = "git+https://github.com/biomejs/biome#92d3fbe59f48530b833af7fce5c4ee0940b7f5f6" [[package]] name = "bitflags" @@ -594,26 +568,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bpaf" -version = "0.9.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "913d667d4716acd286a0dc58824a4c0ec8ce58eeca95cfb58172d17a9ec01035" -dependencies = [ - "bpaf_derive", -] - -[[package]] -name = "bpaf_derive" -version = "0.5.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d8a24f809c4cda0832689019daa067d0ae927d801429196b238a3e8cb0cd3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.96", -] - [[package]] name = "bstr" version = "1.9.1" @@ -657,9 +611,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "camino" -version = "1.1.6" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" dependencies = [ "serde", ] @@ -1152,20 +1106,6 @@ dependencies = [ "parking_lot_core", ] -[[package]] -name = "dashmap" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "debugid" version = "0.8.0" @@ -1287,12 +1227,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1" -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - [[package]] name = "either" version = "1.10.0" @@ -1347,6 +1281,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba2f4b465f5318854c6f8dd686ede6c0a9dc67d4b1ac241cf0eb51521a309147" dependencies = [ "enumflags2_derive", + "serde", ] [[package]] @@ -2359,15 +2294,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "json-strip-comments" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b271732a960335e715b6b2ae66a086f115c74eb97360e996d2bd809bfc063bba" -dependencies = [ - "memchr", -] - [[package]] name = "kqueue" version = "1.0.8" @@ -2427,7 +2353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -2570,7 +2496,7 @@ dependencies = [ "cli_server", "colored", "console", - "dashmap 5.5.3", + "dashmap", "dialoguer", "env_logger", "flate2", @@ -2735,7 +2661,7 @@ version = "0.1.0" dependencies = [ "ai_builtins", "anyhow", - "dashmap 5.5.3", + "dashmap", "grit-util", "grit_cache", "marzano-core", @@ -3295,25 +3221,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "oxc_resolver" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bed381b6ab4bbfebfc7a011ad43b110ace8d201d02a39c0e09855f16b8f3f741" -dependencies = [ - "cfg-if", - "dashmap 6.1.0", - "indexmap 2.7.1", - "json-strip-comments", - "once_cell", - "rustc-hash 2.1.0", - "serde", - "serde_json", - "simdutf8", - "thiserror", - "tracing", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -3867,12 +3774,6 @@ dependencies = [ "winreg 0.52.0", ] -[[package]] -name = "result" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" - [[package]] name = "ring" version = "0.17.8" @@ -4037,32 +3938,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "schemars" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" -dependencies = [ - "dyn-clone", - "indexmap 2.7.1", - "schemars_derive", - "serde", - "serde_json", - "smallvec", -] - -[[package]] -name = "schemars_derive" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 2.0.96", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -4135,28 +4010,6 @@ dependencies = [ "syn 2.0.96", ] -[[package]] -name = "serde_derive_internals" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.96", -] - -[[package]] -name = "serde_ini" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb236687e2bb073a7521c021949be944641e671b8505a94069ca37b656c81139" -dependencies = [ - "result", - "serde", - "void", -] - [[package]] name = "serde_json" version = "1.0.137" @@ -4259,12 +4112,6 @@ dependencies = [ "libc", ] -[[package]] -name = "simdutf8" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" - [[package]] name = "similar" version = "2.7.0" @@ -4443,6 +4290,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5352447f921fda68cf61b4101566c0bdb5104eff6804d0678e5227580ab6a4e9" +dependencies = [ + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "termtree" version = "0.4.1" @@ -4697,7 +4554,7 @@ dependencies = [ "async-trait", "auto_impl", "bytes", - "dashmap 5.5.3", + "dashmap", "futures", "httparse", "lsp-types", @@ -5161,12 +5018,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "wait-timeout" version = "0.2.0" @@ -5966,6 +5817,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/crates/cli_bin/tests/format.rs b/crates/cli_bin/tests/format.rs index 67081ad4a..155d6a278 100644 --- a/crates/cli_bin/tests/format.rs +++ b/crates/cli_bin/tests/format.rs @@ -18,12 +18,11 @@ fn format_patterns_with_rewrite() -> Result<()> { println!("stderr: {}", String::from_utf8(output.stderr.clone())?); println!("stdout: {}", String::from_utf8(output.stdout.clone())?); - assert!(output.stdout.is_empty()); assert!( output.status.success(), "Command didn't finish successfully" ); - assert_eq!(output.stderr, b"couldn't format '.grit/patterns/not_parsable.grit': biome couldn't parse: Expected a predicate here.\n"); + assert!(output.stderr.is_empty()); let yaml_file_content = std::fs::read_to_string(grit_dir.join(".grit/grit.yaml"))?; let test_move_import_file_content = From b4292259d4bbdb6b13700afc74f3f977fe0ffdb8 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:32:49 -0600 Subject: [PATCH 10/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 85370cb87..0fd09c87b 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -48,6 +48,11 @@ pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Resu let file_path_to_resolved = group_resolved_patterns_by_group(resolved); + if file_path_to_resolved.is_empty() { + println!("No patterns to format"); + return Ok(()); + } + println!( "Formatting {} {}", format!("{}", file_path_to_resolved.len()).bold().yellow(), From 3a671664c9588836fd99a75e7779c268d562f05b Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:35:55 -0600 Subject: [PATCH 11/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 3 +-- crates/cli/src/result_formatting.rs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 0fd09c87b..d2ed59d96 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -49,8 +49,7 @@ pub async fn run_format(arg: &FormatGritArgs, flags: &GlobalFormatFlags) -> Resu let file_path_to_resolved = group_resolved_patterns_by_group(resolved); if file_path_to_resolved.is_empty() { - println!("No patterns to format"); - return Ok(()); + return Err(anyhow!("No patterns found to format")); } println!( diff --git a/crates/cli/src/result_formatting.rs b/crates/cli/src/result_formatting.rs index b4ec672ff..ce33c10d3 100644 --- a/crates/cli/src/result_formatting.rs +++ b/crates/cli/src/result_formatting.rs @@ -179,6 +179,7 @@ impl fmt::Display for FormattedResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { FormattedResult::Compact(result) => { + eprintln!("Compact result: {:?}", result); match result { MatchResult::AnalysisLog(log) => { print_error_log(log, f)?; From b9223950a178e399cd55ef263d61c3f93706deea Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:39:18 -0600 Subject: [PATCH 12/17] [skip ci] yolo --- crates/cli/src/commands/format.rs | 23 ++++++++--------------- crates/cli/src/result_formatting.rs | 23 +++++++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index d2ed59d96..00dc059ba 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -1,27 +1,23 @@ use crate::{ commands::patterns_test::filter_patterns_by_regex, flags::GlobalFormatFlags, - messenger_variant::{create_emitter, MessengerVariant}, - resolver::{resolve_from_cwd, GritModuleResolver, Source}, - ux::{format_diff, DiffString}, + messenger_variant::create_emitter, + resolver::{resolve_from_cwd, Source}, }; -use anyhow::{anyhow, bail, ensure, Context, Result}; +use anyhow::{anyhow, Context, Result}; use biome_grit_formatter::context::GritFormatOptions; -use biome_grit_parser::GritParse; use clap::Args; use colored::Colorize; -use marzano_core::api::{DoneFile, EntireFile, MatchResult, Rewrite}; +use marzano_core::api::{DoneFile, MatchResult, Rewrite}; use marzano_gritmodule::{config::ResolvedGritDefinition, parser::PatternFileExt}; use marzano_language::{markdown_block::MarkdownBlock, target_language::TargetLanguage}; use marzano_messenger::{ emit::{ApplyDetails, Messager}, output_mode::OutputMode, }; -use marzano_util::{rich_path::RichFile, runtime::ExecutionContext}; -use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator as _, ParallelIterator}; +use rayon::iter::ParallelIterator; use serde::Serialize; -use std::fmt::Write; -use std::{collections::BTreeMap, panic::set_hook, sync::mpsc}; +use std::collections::BTreeMap; #[derive(Args, Debug, Serialize, Clone)] pub struct FormatGritArgs { @@ -31,7 +27,7 @@ pub struct FormatGritArgs { // Level of detail to show for results #[clap( long = "output", - default_value_t = OutputMode::Standard, + default_value_t = OutputMode::Compact, )] output: OutputMode, /// Regex of a specific pattern to test @@ -197,10 +193,7 @@ fn format_file_resolved_patterns( /// format grit code using `biome` fn format_grit_code(source: &str) -> Result<(Vec, String)> { - let result = std::panic::catch_unwind(|| { - let parsed = biome_grit_parser::parse_grit(source); - parsed - }); + let result = std::panic::catch_unwind(|| biome_grit_parser::parse_grit(source)); let Ok(parsed) = result else { return Err(anyhow!("Syntax error in grit code, parsing failed")); diff --git a/crates/cli/src/result_formatting.rs b/crates/cli/src/result_formatting.rs index ce33c10d3..2c0ac351a 100644 --- a/crates/cli/src/result_formatting.rs +++ b/crates/cli/src/result_formatting.rs @@ -57,15 +57,19 @@ impl FormattedResult { fn print_file_ranges(item: &mut T, f: &mut fmt::Formatter<'_>) -> fmt::Result { let name = item.file_name().bold(); - for range in item.ranges() { - writeln!( - f, - "{}:{}:{} - {}", - name, - range.start.line, - range.start.column, - T::action() - )?; + if item.ranges().is_empty() { + writeln!(f, "{}", name)?; + } else { + for range in item.ranges() { + writeln!( + f, + "{}:{}:{} - {}", + name, + range.start.line, + range.start.column, + T::action() + )?; + } } Ok(()) } @@ -179,7 +183,6 @@ impl fmt::Display for FormattedResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { FormattedResult::Compact(result) => { - eprintln!("Compact result: {:?}", result); match result { MatchResult::AnalysisLog(log) => { print_error_log(log, f)?; From 030c98b0e3cf8f4506b02c5b8cff5bc964e18f94 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:40:31 -0600 Subject: [PATCH 13/17] run the tests --- crates/cli/src/commands/format.rs | 1 - crates/cli/src/commands/patterns_test.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index 00dc059ba..b3835ca10 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -15,7 +15,6 @@ use marzano_messenger::{ emit::{ApplyDetails, Messager}, output_mode::OutputMode, }; -use rayon::iter::ParallelIterator; use serde::Serialize; use std::collections::BTreeMap; diff --git a/crates/cli/src/commands/patterns_test.rs b/crates/cli/src/commands/patterns_test.rs index 00075c10b..395f94ad4 100644 --- a/crates/cli/src/commands/patterns_test.rs +++ b/crates/cli/src/commands/patterns_test.rs @@ -257,9 +257,9 @@ pub async fn get_marzano_pattern_test_results( pub(crate) fn filter_patterns_by_regex( patterns: Vec, - filter: &String, + filter: &str, ) -> Result> { - let regex = regex::Regex::new(filter.as_str())?; + let regex = regex::Regex::new(filter)?; Ok(patterns .into_iter() .filter(|p| regex.is_match(&p.local_name)) From 0a6a2921a8fd4bf581e7b2ca2a4e24ab6f7cde62 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:46:17 -0600 Subject: [PATCH 14/17] run the tests --- crates/cli/src/result_formatting.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/result_formatting.rs b/crates/cli/src/result_formatting.rs index 2c0ac351a..2e4ebc77a 100644 --- a/crates/cli/src/result_formatting.rs +++ b/crates/cli/src/result_formatting.rs @@ -58,7 +58,8 @@ impl FormattedResult { fn print_file_ranges(item: &mut T, f: &mut fmt::Formatter<'_>) -> fmt::Result { let name = item.file_name().bold(); if item.ranges().is_empty() { - writeln!(f, "{}", name)?; + // Not we only print the file name if there are no ranges, the newline is handled by the caller + write!(f, "{}", name)?; } else { for range in item.ranges() { writeln!( From 978efccf46e1f658b8b2785299253b817a6f8177 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:48:12 -0600 Subject: [PATCH 15/17] see https://github.com/biomejs/biome/issues/5032 --- crates/cli/src/commands/format.rs | 1 + crates/cli_bin/fixtures/go/imports.grit | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 crates/cli_bin/fixtures/go/imports.grit diff --git a/crates/cli/src/commands/format.rs b/crates/cli/src/commands/format.rs index b3835ca10..7a93a0ffd 100644 --- a/crates/cli/src/commands/format.rs +++ b/crates/cli/src/commands/format.rs @@ -312,6 +312,7 @@ mod tests { #[tokio::test] async fn test_format_go_imports() -> Result<()> { // This somehow has a massive memory leak but only in --release mode + // See https://github.com/biomejs/biome/issues/5032 let fixtures_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .parent() diff --git a/crates/cli_bin/fixtures/go/imports.grit b/crates/cli_bin/fixtures/go/imports.grit new file mode 100644 index 000000000..922b19509 --- /dev/null +++ b/crates/cli_bin/fixtures/go/imports.grit @@ -0,0 +1,18 @@ +language go + +// All core stdlib functions can be done here +private pattern before_each_file_stdlib() { + before_each_file_prep_imports() +} + +private pattern after_each_file_stdlib() { + after_each_file_handle_imports() +} + +pattern before_each_file() { + before_each_file_stdlib() +} + +pattern after_each_file() { + after_each_file_stdlib() +} From ca76cf39aca7ede3431a0e0cc7590ebd59921bfd Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 00:52:07 -0600 Subject: [PATCH 16/17] run the tests --- crates/cli/src/result_formatting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/src/result_formatting.rs b/crates/cli/src/result_formatting.rs index 2e4ebc77a..72d0f8062 100644 --- a/crates/cli/src/result_formatting.rs +++ b/crates/cli/src/result_formatting.rs @@ -58,7 +58,7 @@ impl FormattedResult { fn print_file_ranges(item: &mut T, f: &mut fmt::Formatter<'_>) -> fmt::Result { let name = item.file_name().bold(); if item.ranges().is_empty() { - // Not we only print the file name if there are no ranges, the newline is handled by the caller + // Note we only print the file name if there are no ranges, the newline is handled by the caller write!(f, "{}", name)?; } else { for range in item.ranges() { From ffaf63d845a19d1e16f04387c04584c97b588648 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Wed, 5 Feb 2025 12:39:18 -0600 Subject: [PATCH 17/17] pin biome version --- Cargo.lock | 21 +++++++++++++++++++++ crates/cli/Cargo.toml | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8587b1664..5d18704be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -323,6 +323,7 @@ dependencies = [ [[package]] name = "biome_console" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_markup", "biome_text_size", @@ -335,6 +336,7 @@ dependencies = [ [[package]] name = "biome_deserialize" version = "0.6.0" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_console", "biome_diagnostics", @@ -347,6 +349,7 @@ dependencies = [ [[package]] name = "biome_deserialize_macros" version = "0.6.0" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_string_case", "proc-macro-error", @@ -358,6 +361,7 @@ dependencies = [ [[package]] name = "biome_diagnostics" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "backtrace", "biome_console", @@ -377,6 +381,7 @@ dependencies = [ [[package]] name = "biome_diagnostics_categories" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "quote", "serde", @@ -385,6 +390,7 @@ dependencies = [ [[package]] name = "biome_diagnostics_macros" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "proc-macro-error", "proc-macro2", @@ -395,6 +401,7 @@ dependencies = [ [[package]] name = "biome_formatter" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_console", "biome_deserialize", @@ -415,6 +422,7 @@ dependencies = [ [[package]] name = "biome_grit_factory" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_grit_syntax", "biome_rowan", @@ -423,6 +431,7 @@ dependencies = [ [[package]] name = "biome_grit_formatter" version = "0.0.0" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_formatter", "biome_grit_syntax", @@ -432,6 +441,7 @@ dependencies = [ [[package]] name = "biome_grit_parser" version = "0.1.0" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_console", "biome_diagnostics", @@ -449,6 +459,7 @@ dependencies = [ [[package]] name = "biome_grit_syntax" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_rowan", "biome_string_case", @@ -459,6 +470,7 @@ dependencies = [ [[package]] name = "biome_json_factory" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_json_syntax", "biome_rowan", @@ -467,6 +479,7 @@ dependencies = [ [[package]] name = "biome_json_parser" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_console", "biome_diagnostics", @@ -482,6 +495,7 @@ dependencies = [ [[package]] name = "biome_json_syntax" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_rowan", "biome_string_case", @@ -492,6 +506,7 @@ dependencies = [ [[package]] name = "biome_markup" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "proc-macro-error", "proc-macro2", @@ -501,6 +516,7 @@ dependencies = [ [[package]] name = "biome_parser" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_console", "biome_diagnostics", @@ -514,6 +530,7 @@ dependencies = [ [[package]] name = "biome_rowan" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_text_edit", "biome_text_size", @@ -526,10 +543,12 @@ dependencies = [ [[package]] name = "biome_string_case" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" [[package]] name = "biome_text_edit" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "biome_text_size", "serde", @@ -539,6 +558,7 @@ dependencies = [ [[package]] name = "biome_text_size" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" dependencies = [ "serde", ] @@ -546,6 +566,7 @@ dependencies = [ [[package]] name = "biome_unicode_table" version = "0.5.7" +source = "git+https://github.com/biomejs/biome?rev=71c825e65e58fc1937b55b4f26edafdd183a50f3#71c825e65e58fc1937b55b4f26edafdd183a50f3" [[package]] name = "bitflags" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 7aed19b30..8030f9516 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -87,10 +87,10 @@ tracing-subscriber = { version = "0.3", default-features = false, optional = tru tracing-log = { version = "0.2.0", optional = true } fs-err = { version = "2.11.0" } -# biome_grit_parser = { git = "https://github.com/biomejs/biome" } -# biome_grit_formatter = { git = "https://github.com/biomejs/biome" } -biome_grit_parser = { path = "../../../../../../biome/crates/biome_grit_parser" } -biome_grit_formatter = { path = "../../../../../../biome/crates/biome_grit_formatter" } +biome_grit_parser = { git = "https://github.com/biomejs/biome", rev = "71c825e65e58fc1937b55b4f26edafdd183a50f3" } +biome_grit_formatter = { git = "https://github.com/biomejs/biome", rev = "71c825e65e58fc1937b55b4f26edafdd183a50f3" } +# biome_grit_parser = { path = "../../../../../../biome/crates/biome_grit_parser" } +# biome_grit_formatter = { path = "../../../../../../biome/crates/biome_grit_formatter" } [target.'cfg(not(windows))'.dependencies] openssl = { version = "0.10", features = ["vendored"] }