Skip to content

Commit

Permalink
fix: adjust imports to look in the parent module
Browse files Browse the repository at this point in the history
For now, all imports are for external schemas only and those are
expected to be placed next to the module where these imports are
declared. Therefore, the generated Rust code should look in the parent
module instead of in its own modules.
  • Loading branch information
dnaka91 committed Nov 5, 2023
1 parent 7ec3e09 commit ca222db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion crates/stef-build/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ fn compile_import(Import { segments, element }: &Import<'_>) -> TokenStream {
});

quote! {
use #(#segments)*#element;
#[allow(unused_imports)]
use super::#(#segments)*#element;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ input_file: crates/stef-parser/tests/inputs/import_basic.stef
---
#[allow(unused_imports)]
use ::stef::buf::{Decode, Encode};
use other::schema::Sample;
use second::submodule;
#[allow(unused_imports)]
use super::other::schema::Sample;
#[allow(unused_imports)]
use super::second::submodule;

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ input_file: crates/stef-build/tests/inputs_extra/import.stef
---
#[allow(unused_imports)]
use ::stef::buf::{Decode, Encode};
use other::module;
use other::module::Type;
#[allow(unused_imports)]
use super::other::module;
#[allow(unused_imports)]
use super::other::module::Type;

15 changes: 11 additions & 4 deletions crates/stef-playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ mod schemas {
stef::include!("enum_min_ws");
}

// TODO: implement imports
// mod import_basic {
// stef::include!("import_basic");
// }
mod import_basic {
stef::include!("import_basic");
}

mod other {
stef::include!("other");
}

mod second {
stef::include!("second");
}

mod module_basic {
stef::include!("module_basic");
Expand Down

0 comments on commit ca222db

Please sign in to comment.