diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-19 00:31:05 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-19 00:31:05 +0800 |
| commit | 532f4ceba2bddb1c84d2e0bdd69808a3ebd5ca4a (patch) | |
| tree | 043514a2aca670d8b2398726b17aab1066938ba1 /mingling_macros/src/lib.rs | |
| parent | ecc1329bbd31cd98fa9b4c2f25a3114f133987ae (diff) | |
Make async an optional feature
Diffstat (limited to 'mingling_macros/src/lib.rs')
| -rw-r--r-- | mingling_macros/src/lib.rs | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 5391dfd..4ae9e43 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -132,6 +132,36 @@ pub fn gen_program(input: TokenStream) -> TokenStream { pub fn program_gen_completion(input: TokenStream) -> TokenStream { let name = read_name(&input); + #[cfg(feature = "async")] + let fn_exec_comp = quote! { + #[::mingling::macros::chain(#name)] + pub async fn __exec_completion(prev: CompletionContext) -> NextProcess { + let read_ctx = ::mingling::ShellContext::try_from(prev.inner); + match read_ctx { + Ok(ctx) => { + let suggest = ::mingling::CompletionHelper::exec_completion::<#name>(&ctx); + CompletionSuggest::new((ctx, suggest)).to_render() + } + Err(_) => std::process::exit(1), + } + } + }; + + #[cfg(not(feature = "async"))] + let fn_exec_comp = quote! { + #[::mingling::macros::chain(#name)] + pub fn __exec_completion(prev: CompletionContext) -> NextProcess { + let read_ctx = ::mingling::ShellContext::try_from(prev.inner); + match read_ctx { + Ok(ctx) => { + let suggest = ::mingling::CompletionHelper::exec_completion::<#name>(&ctx); + CompletionSuggest::new((ctx, suggest)).to_render() + } + Err(_) => std::process::exit(1), + } + } + }; + let comp_dispatcher = quote! { #[allow(unused)] use __completion_gen::*; @@ -144,17 +174,7 @@ pub fn program_gen_completion(input: TokenStream) -> TokenStream { CompletionSuggest = (::mingling::ShellContext, ::mingling::Suggest) ); - #[::mingling::macros::chain(#name)] - pub async fn __exec_completion(prev: CompletionContext) -> NextProcess { - let read_ctx = ::mingling::ShellContext::try_from(prev.inner); - match read_ctx { - Ok(ctx) => { - let suggest = ::mingling::CompletionHelper::exec_completion::<#name>(&ctx); - CompletionSuggest::new((ctx, suggest)).to_render() - } - Err(_) => std::process::exit(1), - } - } + #fn_exec_comp ::mingling::macros::register_type!(CompletionContext); |
