diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-25 13:29:08 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-25 13:29:08 +0800 |
| commit | 757b1e412c8617cacd8ba0e428554e7f44e9d0e8 (patch) | |
| tree | 976691ec144d3e3adbb88b337a4eeac63de76197 | |
| parent | 85e5792e2d0b0c75eb4044c0450d60c07370afa4 (diff) | |
fix(dispatch_tree): use proper snake_case for dispatcher static names
Fix the static name generation for dispatch tree nodes to use a correct
snake_case conversion instead of a simple `.` to `_` replacement. Also
correct the `__comp` completion dispatcher name from triple underscore
to double underscore, resolving a mismatch between
`register_dispatcher!`
and `program_comp_gen`
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | mingling_macros/src/dispatch_tree_gen.rs | 3 | ||||
| -rw-r--r-- | mingling_macros/src/dispatcher.rs | 4 | ||||
| -rw-r--r-- | mingling_macros/src/lib.rs | 2 |
4 files changed, 8 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 47b6448..314bedc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ - `help_attr` (via `#[help]`) + `register_help` — checks `HELP_REQUESTS`; `register_help` also serves as a public escape hatch for manual help registration, automatically skipping the duplicate check when the exact same entry was pre-inserted by `#[help]` - `completion_attr` (via `#[completion]`) — checks `COMPLETIONS` set +7. **\[macros:dispatch_tree\]** Fixed the static name generation for dispatch tree nodes to use `snake_case` conversion instead of simple `.` → `_` replacement, and fixed the `__comp` completion dispatcher static name from `__internal_dispatcher___comp` (triple underscore) to `__internal_dispatcher_comp` (double underscore), resolving a mismatch between the name generated by `register_dispatcher!` and the name used in `program_comp_gen`. + #### Optimizations: 1. **\[core:flag\]** Refactored the `special_argument!` and `special_arguments!` macros to replace index‑based `while` loops with iterator `position` and `drain`, improving both performance and readability. diff --git a/mingling_macros/src/dispatch_tree_gen.rs b/mingling_macros/src/dispatch_tree_gen.rs index 66fb6e7..6b3efb9 100644 --- a/mingling_macros/src/dispatch_tree_gen.rs +++ b/mingling_macros/src/dispatch_tree_gen.rs @@ -1,3 +1,4 @@ +use just_fmt::snake_case; use proc_macro2::TokenStream; use quote::quote; use std::collections::BTreeMap; @@ -7,7 +8,7 @@ pub fn gen_get_nodes(entries: &[(String, String, String)]) -> TokenStream { let mut node_entries = Vec::new(); for (node_name, _disp_type, _entry_name) in entries { - let static_name_str = format!("__internal_dispatcher_{}", node_name.replace('.', "_")); + let static_name_str = format!("__internal_dispatcher_{}", snake_case!(node_name)); let static_ident = syn::Ident::new(&static_name_str, proc_macro2::Span::call_site()); let node_display_name = node_name.replace('.', " "); diff --git a/mingling_macros/src/dispatcher.rs b/mingling_macros/src/dispatcher.rs index 51dce95..36bdf31 100644 --- a/mingling_macros/src/dispatcher.rs +++ b/mingling_macros/src/dispatcher.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "dispatch_tree")] +use just_fmt::snake_case; use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; @@ -215,7 +217,7 @@ pub fn register_dispatcher(input: TokenStream) -> TokenStream { } = syn::parse_macro_input!(input as RegisterDispatcherInput); let node_name_str = node_name.value(); - let static_name = format!("__internal_dispatcher_{}", node_name_str.replace('.', "_")); + let static_name = format!("__internal_dispatcher_{}", snake_case!(node_name_str.clone())); let static_ident = Ident::new(&static_name, proc_macro2::Span::call_site()); // Register node info in the global collection at compile time diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 2622af0..d08e129 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -1458,7 +1458,7 @@ pub fn program_comp_gen(_input: TokenStream) -> TokenStream { #[cfg(feature = "dispatch_tree")] let internal_dispatcher_comp = quote! { - use __internal_completion_mod::__internal_dispatcher___comp; + use __internal_completion_mod::__internal_dispatcher_comp; }; #[cfg(not(feature = "dispatch_tree"))] |
