From 1ed3903fb68e3cb3aaedfa40f8f92ca6ecae5076 Mon Sep 17 00:00:00 2001 From: Kariy Date: Wed, 25 Oct 2023 10:28:06 +0900 Subject: [PATCH] rebase main --- crates/dojo-lang/src/compiler.rs | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/crates/dojo-lang/src/compiler.rs b/crates/dojo-lang/src/compiler.rs index c98ae96d84..1d178ef399 100644 --- a/crates/dojo-lang/src/compiler.rs +++ b/crates/dojo-lang/src/compiler.rs @@ -104,18 +104,30 @@ impl Compiler for DojoCompiler { let contract_name = decl.submodule_id.name(db.upcast_mut()); let contract_name_snake = contract_name.to_case(Case::Snake); - let is_model = match class.abi.clone() { - Some(abii) => abii.items.iter().any(|i| match i { - abi::Item::Struct(s) => s.name == "dojo::database::schema::Struct", - _ => false, - }), - None => false, - }; - - let separator = if is_model { "model" } else { "contract" }; - let file_name = format!("{target_name}-{separator}-{contract_name_snake}.json"); - - let mut file = target_dir.open_rw(file_name.clone(), "output file", ws.config())?; + println!("{}", target_name); + println!("{}", contract_name); + println!("{}", contract_name_snake); + + if let Ok(Some(ModuleItemId::Struct(_))) = + db.module_item_by_name(decl.module_id(), contract_name.clone()) + { + println!("is a model?"); + } + + // let is_model = match &class.abi { + // Some(abi) => abi.items.iter().any(|i| match i { + // abi::Item::Struct(s) => s.name == "dojo::database::schema::Struct", + // _ => false, + // }), + + // None => false, + // }; + + // let separator = if is_model { "model" } else { "contract" }; + // let file_name = format!("{target_name}-{separator}-{contract_name_snake}.json"); + + let mut file = + target_dir.open_rw(contract_name_snake.clone(), "output file", ws.config())?; serde_json::to_writer_pretty(file.deref_mut(), &class) .with_context(|| format!("failed to serialize contract: {contract_name}"))?;