aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_macros/src/completion.rs')
-rw-r--r--mingling_macros/src/completion.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/mingling_macros/src/completion.rs b/mingling_macros/src/completion.rs
index ea57f06..cd4a9ad 100644
--- a/mingling_macros/src/completion.rs
+++ b/mingling_macros/src/completion.rs
@@ -1,6 +1,7 @@
use proc_macro::TokenStream;
use quote::quote;
-use syn::{Ident, ItemFn, parse_macro_input};
+use syn::spanned::Spanned;
+use syn::{FnArg, Ident, ItemFn, PatType, Type, parse_macro_input};
#[cfg(feature = "comp")]
pub fn completion_attr(attr: TokenStream, item: TokenStream) -> TokenStream {
@@ -45,6 +46,23 @@ pub fn completion_attr(attr: TokenStream, item: TokenStream) -> TokenStream {
.into();
}
+ // Check that the function parameter type is a single-segment type path (no `::`)
+ if let Some(arg) = inputs.first()
+ && let FnArg::Typed(PatType { ty, .. }) = arg
+ && let Type::Path(type_path) = &**ty
+ && type_path.path.segments.len() > 1
+ {
+ return syn::Error::new(
+ type_path.span(),
+ format!(
+ "The type `{}` in #[completion] function must be a simple single-segment type, e.g. `HelloEntry` instead of `other::HelloEntry`. Qualified paths with `::` are not allowed here.",
+ quote! { #type_path }
+ ),
+ )
+ .to_compile_error()
+ .into();
+ }
+
// Get the function body
let fn_body = &input_fn.block;