Skip to content

Commit

Permalink
refactor(vm): fix Reagent code gen
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Sep 17, 2024
1 parent 08c42a2 commit 6e80f21
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 92 deletions.
70 changes: 42 additions & 28 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion rust-analyzer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rust-analyzer.cargo.features": [
"tsify"
"tsify",
"prefab_database"
]
}
18 changes: 12 additions & 6 deletions xtask/src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::eyre;
use color_eyre::eyre::{self, Context};
use quote::ToTokens;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -98,16 +98,22 @@ fn format_rust(content: impl ToTokens) -> color_eyre::Result<String> {
Ok(prettyplease::unparse(&content))
}

fn prepend_generated_comment_and_format(file_path: &std::path::Path, module: &str) -> color_eyre::Result<()> {
fn prepend_generated_comment_and_format(
file_path: &std::path::Path,
module: &str,
) -> color_eyre::Result<()> {
use std::io::Write;
let tmp_path = file_path.with_extension("rs.tmp");
{
let mut tmp = std::fs::File::create(&tmp_path)?;
let src = syn::parse_file(&std::fs::read_to_string(file_path)?)?;
let src = syn::parse_file(&std::fs::read_to_string(file_path)?)
.with_context(|| format!("Error parsing file {}", file_path.display()))?;

let formated = format_rust(src)?;
let formatted = format_rust(src)?;

write!(&mut tmp, "\
write!(
&mut tmp,
"\
// =================================================\n\
// !! <-----> DO NOT MODIFY <-----> !!\n\
//\n\
Expand All @@ -122,7 +128,7 @@ fn prepend_generated_comment_and_format(file_path: &std::path::Path, module: &st
//\n\
// =================================================\n\
\n\
{formated}\
{formatted}\
"
)?;
}
Expand Down
Loading

0 comments on commit 6e80f21

Please sign in to comment.