aboutsummaryrefslogtreecommitdiff
path: root/CHANGELOG.md
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-22 20:41:00 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-22 20:41:00 +0800
commit5169b9a462a7a3854b8320c8d9e78985a34c5f15 (patch)
treeb0c029bb7dbf4e0cb39794f43c3b3166d539e24b /CHANGELOG.md
parentd7c9ad94113cca2f782666e37a0aa4fb7b8d7d86 (diff)
Support resource injection in #[help] and #[completion
Diffstat (limited to 'CHANGELOG.md')
-rw-r--r--CHANGELOG.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a0f5b5..5384b45 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -195,6 +195,26 @@ group!(std::io::Error);
This macro is only available with the `extra_macros` feature.
+11. **\[macros\]** `#[help]` and `#[completion]` now support resource injection parameters, consistent with `#[chain]` and `#[renderer]`. Specific changes:
+
+- `#[help]`: Removed the restriction of "must have exactly one parameter". The first parameter still serves as the entry type, while subsequent parameters are treated as resource injections. The internal implementation was changed from a nested `help_wrapper` function to an inline body (consistent with the renderer), making resource variables visible within the scope.
+- `#[completion]`: Removed the restriction of "must have exactly one parameter". The first parameter `ctx: &ShellContext` is used for the `Completion::comp` trait method signature, while subsequent parameters are treated as resource injections. Within the `comp` method body, resource bindings are injected via `::mingling::this::<P>().res_or_default::<T>()` and `modify_res`.
+
+```rust
+#[help]
+fn help_my_entry(prev: EntryMyEntry, res: &ResA) {
+ r_println!("res: {:?}", *res);
+}
+
+#[completion(EntryMyEntry)]
+fn comp_my_entry(ctx: &ShellContext, res: &mut ResA) -> Suggest {
+ // res is injected from the program's global resources
+ suggest! {}
+}
+```
+
+For mutable resources (`&mut T`), both macros use `Program::modify_res` (with constraint `Return: Default`) instead of `#[chain]`'s dedicated `__modify_res_and_return_route` (with constraint `Return: Into<ChainProcess>`), because the return types of help/completion are `()` and `Suggest` respectively.
+
#### **BREAKING CHANGES** (API CHANGES):
---