Skip to content

Commit

Permalink
feat(edgedb_codegen_core): add prettyplease format option
Browse files Browse the repository at this point in the history
output of `rustfmt` is dependent on the version of rust used and not good for tests.
  • Loading branch information
ifiokjr committed Aug 27, 2024
1 parent cec890a commit cc4dfab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions crates/edgedb_codegen_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 6 additions & 0 deletions crates/edgedb_codegen_core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn resolve_path(path: impl AsRef<Path>, error_span: Span) -> syn::Result<Pat
Ok(base_dir_path.join(path))
}

/// Will format the given source code using `rustfmt`.
pub async fn rustfmt(source: &str) -> std::io::Result<String> {
let mut process = Command::new("rustfmt")
.args(["--emit", "stdout"])
Expand All @@ -57,3 +58,8 @@ pub async fn rustfmt(source: &str) -> std::io::Result<String> {
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<String> {
Ok(prettyplease::unparse(&syn::parse_str(source)?))
}

0 comments on commit cc4dfab

Please sign in to comment.