Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cairo file metadata for contracts and models #2175

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,25 @@
contract_basename: &str,
contract_tag: &str,
) -> anyhow::Result<()> {
if let Ok(file_id) = db.module_main_file(module_id) {
if let Ok(files) = db.module_files(module_id) {
let contract_name = naming::get_name_from_tag(contract_tag);

// search among all the module files (real and virtual), the one named with
// the contract/model name. This is the file containing the Cairo code generated
// from Dojo plugins.
let res = files.iter().filter(|f| f.file_name(db).eq(&contract_name)).collect::<Vec<_>>();

let file_id = if res.is_empty() {
// if there is no virtual file with the name of the contract/model, just use the main
// module file
match db.module_main_file(module_id) {
Ok(f) => f,
Err(_) => return Err(anyhow!("failed to get source file: {contract_tag}")),

Check warning on line 569 in crates/dojo-lang/src/compiler.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-lang/src/compiler.rs#L569

Added line #L569 was not covered by tests
}
} else {
*res[0]
};

if let Some(file_content) = db.file_content(file_id) {
let src_file_name = format!("{contract_basename}.cairo");

Expand Down
Loading