Skip to content

Commit

Permalink
dev: handle module name error
Browse files Browse the repository at this point in the history
  • Loading branch information
shramee committed Oct 26, 2023
1 parent fa0d8a6 commit db7ee10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions crates/dojo-lang/src/inline_macros/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ impl InlineMacroExprPlugin for GetMacro {
));

let mut system_reads = SYSTEM_READS.lock().unwrap();
let mut module_name = "".to_string();

let module_syntax_node =
parent_of_kind(db, &syntax.as_syntax_node(), SyntaxKind::ItemModule);
if let Some(module_syntax_node) = &module_syntax_node {
let module_name = if let Some(module_syntax_node) = &module_syntax_node {
let mod_ast = ItemModule::from_syntax_node(db, module_syntax_node.clone());
module_name = mod_ast.name(db).as_syntax_node().get_text_without_trivia(db);
}
mod_ast.name(db).as_syntax_node().get_text_without_trivia(db)
} else {
eprintln!("Error: Couldn't get the module name.");
"".into()
};

for model in &models {
if !module_name.is_empty() {
Expand Down
10 changes: 6 additions & 4 deletions crates/dojo-lang/src/inline_macros/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ impl InlineMacroExprPlugin for SetMacro {
};
}

let mut module_name = "".to_string();
let module_syntax_node =
parent_of_kind(db, &syntax.as_syntax_node(), SyntaxKind::ItemModule);
if let Some(module_syntax_node) = &module_syntax_node {
let module_name = if let Some(module_syntax_node) = &module_syntax_node {
let mod_ast = ItemModule::from_syntax_node(db, module_syntax_node.clone());
module_name = mod_ast.name(db).as_syntax_node().get_text_without_trivia(db);
}
mod_ast.name(db).as_syntax_node().get_text_without_trivia(db)
} else {
eprintln!("Error: Couldn't get the module name.");
"".into()
};

let fn_syntax_node =
parent_of_kind(db, &syntax.as_syntax_node(), SyntaxKind::FunctionWithBody);
Expand Down

0 comments on commit db7ee10

Please sign in to comment.