fix(derive): keep missing-generation diagnostics author-facing
Replace OUT_DIR/path-shaped proc-macro errors with generated slhx file/module language while preserving the build.rs fix hint. req: dx/005 req: component/004
This commit is contained in:
+9
-13
@@ -12,7 +12,7 @@ pub fn handler(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let name = function.sig.ident.to_string();
|
||||
|
||||
let Some(syms_path) = syms_path() else {
|
||||
let message = "#[slhx::handler] requires OUT_DIR; run inside a Cargo crate with slhx_build::app() in build.rs";
|
||||
let message = "#[slhx::handler] requires generated slhx files; add slhx_build::app().run()? to build.rs or run inside a Cargo crate";
|
||||
return quote!(
|
||||
#function
|
||||
compile_error!(#message);
|
||||
@@ -20,10 +20,7 @@ pub fn handler(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
.into();
|
||||
};
|
||||
if !syms_path.exists() {
|
||||
let message = format!(
|
||||
"#[slhx::handler] could not find {}; add slhx_build::app().run()? to build.rs or check template generation",
|
||||
syms_path.display()
|
||||
);
|
||||
let message = "#[slhx::handler] could not find generated slhx symbols; add slhx_build::app().run()? to build.rs or check template generation";
|
||||
return quote!(
|
||||
#function
|
||||
compile_error!(#message);
|
||||
@@ -89,7 +86,7 @@ pub fn form(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let form_name = parse_macro_input!(attr as LitStr).value();
|
||||
let form_struct = parse_macro_input!(item as ItemStruct);
|
||||
let Some(syms_path) = syms_path() else {
|
||||
let message = "#[slhx::form] requires OUT_DIR; run inside a Cargo crate with slhx_build::app() in build.rs";
|
||||
let message = "#[slhx::form] requires generated slhx files; add slhx_build::app().run()? to build.rs or run inside a Cargo crate";
|
||||
return quote!(
|
||||
#form_struct
|
||||
compile_error!(#message);
|
||||
@@ -183,7 +180,7 @@ fn surface_include() -> String {
|
||||
let Some(path) = generated_path("slhx.generated.rs") else {
|
||||
return format!(
|
||||
" compile_error!({:?}); ",
|
||||
"#[slhx::surface] requires OUT_DIR; run inside a Cargo crate with slhx_build::app() in build.rs"
|
||||
"#[slhx::surface] requires generated slhx files; add slhx_build::app().run()? to build.rs or run inside a Cargo crate"
|
||||
);
|
||||
};
|
||||
|
||||
@@ -193,8 +190,7 @@ fn surface_include() -> String {
|
||||
format!(
|
||||
" compile_error!({:?}); ",
|
||||
format!(
|
||||
"#[slhx::surface] could not find {}; add slhx_build::app().run()? to build.rs or check template generation",
|
||||
path.display()
|
||||
"#[slhx::surface] could not find generated slhx module; add slhx_build::app().run()? to build.rs or check template generation"
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -301,10 +297,10 @@ struct GeneratedFormField {
|
||||
|
||||
fn form_contract_errors(syms_path: &PathBuf, form_name: &str, form_struct: &ItemStruct) -> Vec<String> {
|
||||
if !syms_path.exists() {
|
||||
return vec![format!(
|
||||
"#[slhx::form] could not find {}; add slhx_build::app().run()? to build.rs or check template generation",
|
||||
syms_path.display()
|
||||
)];
|
||||
return vec![
|
||||
"#[slhx::form] could not find generated slhx symbols; add slhx_build::app().run()? to build.rs or check template generation"
|
||||
.to_owned(),
|
||||
];
|
||||
}
|
||||
let expected = form_fields(syms_path, form_name);
|
||||
if expected.is_empty() {
|
||||
|
||||
@@ -218,6 +218,10 @@ fn create() -> impl slhx::IntoEffect {
|
||||
stderr.contains("add slhx_build::app().run()? to build.rs"),
|
||||
"missing build.rs hint in stderr:\n{stderr}"
|
||||
);
|
||||
assert!(
|
||||
!stderr.contains("OUT_DIR"),
|
||||
"diagnostic should not teach Cargo internals:\n{stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -810,6 +814,10 @@ pub mod ui {}
|
||||
stderr.contains("add slhx_build::app().run()? to build.rs"),
|
||||
"missing build.rs hint in stderr:\n{stderr}"
|
||||
);
|
||||
assert!(
|
||||
!stderr.contains("OUT_DIR"),
|
||||
"diagnostic should not teach Cargo internals:\n{stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user