From cc4dfabe3d71fd4299422ba77742a8867eb128c0 Mon Sep 17 00:00:00 2001 From: "Ifiok Jr." Date: Tue, 27 Aug 2024 07:03:46 +0100 Subject: [PATCH] feat(edgedb_codegen_core): add `prettyplease` format option output of `rustfmt` is dependent on the version of rust used and not good for tests. --- Cargo.lock | 1 + Cargo.toml | 1 + crates/edgedb_codegen_core/Cargo.toml | 1 + crates/edgedb_codegen_core/src/utils.rs | 6 ++++++ 4 files changed, 9 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index d437065..dac4a59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -575,6 +575,7 @@ dependencies = [ "edgedb-tokio", "heck", "log", + "prettyplease", "proc-macro2", "quote", "syn 2.0.76", diff --git a/Cargo.toml b/Cargo.toml index c048113..7f1c193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ insta = "1" log = "0.4" num-bigint = "0.4" num-traits = "0.2" +prettyplease = "0.2" proc-macro2 = "1" quote = "1" rstest = "0.22" diff --git a/crates/edgedb_codegen_core/Cargo.toml b/crates/edgedb_codegen_core/Cargo.toml index c463b9a..6d5d75c 100644 --- a/crates/edgedb_codegen_core/Cargo.toml +++ b/crates/edgedb_codegen_core/Cargo.toml @@ -19,6 +19,7 @@ edgedb-protocol = { workspace = true, features = ["all-types", "with-serde"] } edgedb-tokio = { workspace = true, features = ["unstable", "derive"] } heck = { workspace = true } log = { workspace = true } +prettyplease = { workspace = true } proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true } diff --git a/crates/edgedb_codegen_core/src/utils.rs b/crates/edgedb_codegen_core/src/utils.rs index 4992093..c79fb63 100644 --- a/crates/edgedb_codegen_core/src/utils.rs +++ b/crates/edgedb_codegen_core/src/utils.rs @@ -41,6 +41,7 @@ pub fn resolve_path(path: impl AsRef, error_span: Span) -> syn::Result std::io::Result { let mut process = Command::new("rustfmt") .args(["--emit", "stdout"]) @@ -57,3 +58,8 @@ pub async fn rustfmt(source: &str) -> std::io::Result { std::io::Error::new(std::io::ErrorKind::InvalidData, "Rustfmt output not UTF-8") }) } + +/// Will format the given source code using `prettyplease`. +pub fn prettify(source: &str) -> syn::Result { + Ok(prettyplease::unparse(&syn::parse_str(source)?)) +}