From ca222db151cc115d135caf45e7424ac4aadadbf2 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Sun, 5 Nov 2023 12:45:44 +0900 Subject: [PATCH] fix: adjust imports to look in the parent module 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. --- crates/stef-build/src/definition.rs | 3 ++- .../compiler__compile@import_basic.stef.snap | 6 ++++-- .../compiler__compile_extra@import.stef.snap | 6 ++++-- crates/stef-playground/src/lib.rs | 15 +++++++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/crates/stef-build/src/definition.rs b/crates/stef-build/src/definition.rs index af8bdb8..377a7ad 100644 --- a/crates/stef-build/src/definition.rs +++ b/crates/stef-build/src/definition.rs @@ -199,7 +199,8 @@ fn compile_import(Import { segments, element }: &Import<'_>) -> TokenStream { }); quote! { - use #(#segments)*#element; + #[allow(unused_imports)] + use super::#(#segments)*#element; } } diff --git a/crates/stef-build/tests/snapshots/compiler__compile@import_basic.stef.snap b/crates/stef-build/tests/snapshots/compiler__compile@import_basic.stef.snap index 6c4c5bf..bd18da8 100644 --- a/crates/stef-build/tests/snapshots/compiler__compile@import_basic.stef.snap +++ b/crates/stef-build/tests/snapshots/compiler__compile@import_basic.stef.snap @@ -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; diff --git a/crates/stef-build/tests/snapshots/compiler__compile_extra@import.stef.snap b/crates/stef-build/tests/snapshots/compiler__compile_extra@import.stef.snap index 1c31158..f556eb3 100644 --- a/crates/stef-build/tests/snapshots/compiler__compile_extra@import.stef.snap +++ b/crates/stef-build/tests/snapshots/compiler__compile_extra@import.stef.snap @@ -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; diff --git a/crates/stef-playground/src/lib.rs b/crates/stef-playground/src/lib.rs index 3677ae5..6c54085 100644 --- a/crates/stef-playground/src/lib.rs +++ b/crates/stef-playground/src/lib.rs @@ -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");