diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/_zh_CN/pages/1-getting-started.md | 4 | ||||
| -rw-r--r-- | docs/dev-docs/README.md | 15 | ||||
| -rw-r--r-- | docs/dev-docs/pages/abouts/.name | 1 | ||||
| -rw-r--r-- | docs/dev-docs/pages/issues/.name | 1 | ||||
| -rw-r--r-- | docs/dev-docs/pages/templates/.name | 0 | ||||
| -rw-r--r-- | docs/dev/README.md | 21 | ||||
| -rw-r--r-- | docs/dev/_sidebar.md (renamed from docs/dev-docs/_sidebar.md) | 11 | ||||
| -rw-r--r-- | docs/dev/index.html (renamed from docs/dev-docs/index.html) | 0 | ||||
| -rw-r--r-- | docs/dev/pages/abouts/.name | 1 | ||||
| -rw-r--r-- | docs/dev/pages/abouts/ai-translation-rule.md (renamed from docs/dev-docs/pages/abouts/ai-translation-rule.md) | 0 | ||||
| -rw-r--r-- | docs/dev/pages/abouts/code-verify-system.md (renamed from docs/dev-docs/pages/abouts/code-verify-system.md) | 0 | ||||
| -rw-r--r-- | docs/dev/pages/issues/.name | 1 | ||||
| -rw-r--r-- | docs/dev/pages/issues/remove-r-print-macro.md | 97 | ||||
| -rw-r--r-- | docs/dev/pages/issues/the-mod-pathfinder.md (renamed from docs/dev-docs/pages/issues/the-mod-pathfinder.md) | 0 | ||||
| -rw-r--r-- | docs/dev/pages/issues/the-shit-time.md (renamed from docs/dev-docs/pages/issues/the-shit-time.md) | 10 | ||||
| -rw-r--r-- | docs/dev/pages/templates/.name | 1 | ||||
| -rw-r--r-- | docs/dev/pages/templates/doc.md (renamed from docs/dev-docs/pages/templates/doc.md) | 0 | ||||
| -rw-r--r-- | docs/pages/1-getting-started.md | 4 | ||||
| -rw-r--r-- | docs/res/guide.txt | 2 |
19 files changed, 142 insertions, 27 deletions
diff --git a/docs/_zh_CN/pages/1-getting-started.md b/docs/_zh_CN/pages/1-getting-started.md index 0a872c2..6dd1dea 100644 --- a/docs/_zh_CN/pages/1-getting-started.md +++ b/docs/_zh_CN/pages/1-getting-started.md @@ -13,7 +13,7 @@ cd my-cli ```toml [dependencies.mingling] -version = "0.2.1" +version = "0.2.2" features = [] ``` @@ -25,7 +25,7 @@ features = [] ```toml [dependencies.mingling] -version = "0.2.1" +version = "0.2.2" features = [ "parser", "comp", diff --git a/docs/dev-docs/README.md b/docs/dev-docs/README.md deleted file mode 100644 index a2eede9..0000000 --- a/docs/dev-docs/README.md +++ /dev/null @@ -1,15 +0,0 @@ -<h1 align="center">Mingling Dev Docs</h1> - -<p align="center"> - Internal development documentation for the <b>Mingling</b> codebase — design notes, issue discussions, and architectural decisions. -</p> - -This site is separate from the [main helpdoc](https://mingling-rs.github.io/mingling/docs/doc.html). The helpdoc is user-facing: tutorials, feature guides, and how-to content for developers _using_ Mingling to build CLI applications. This dev-docs site is for developers _working on_ Mingling itself — understanding internal mechanisms, tracking unresolved problems, and recording design rationale. - -## What's here - -- **Issues** — Collected notes on known pain points, unresolved trade-offs, and feature gaps in the current implementation. - -## How this is different from GitHub Issues - -Mingling is hosted on [GitHub](https://github.com/mingling-rs/mingling), and the [Issues page](https://github.com/mingling-rs/mingling/issues) there is primarily for discussion. In contrast, an issue in this document exists only when it is being planned or actively worked on. diff --git a/docs/dev-docs/pages/abouts/.name b/docs/dev-docs/pages/abouts/.name deleted file mode 100644 index d5a4a33..0000000 --- a/docs/dev-docs/pages/abouts/.name +++ /dev/null @@ -1 +0,0 @@ -Abouts diff --git a/docs/dev-docs/pages/issues/.name b/docs/dev-docs/pages/issues/.name deleted file mode 100644 index f99478d..0000000 --- a/docs/dev-docs/pages/issues/.name +++ /dev/null @@ -1 +0,0 @@ -Issues diff --git a/docs/dev-docs/pages/templates/.name b/docs/dev-docs/pages/templates/.name deleted file mode 100644 index e69de29..0000000 --- a/docs/dev-docs/pages/templates/.name +++ /dev/null diff --git a/docs/dev/README.md b/docs/dev/README.md new file mode 100644 index 0000000..9289fcf --- /dev/null +++ b/docs/dev/README.md @@ -0,0 +1,21 @@ +<h1 align="center">Mingling Dev Docs</h1> + +<p align="center"> + Internal development documentation for the <b>Mingling</b> codebase — design notes, issue discussions, and architectural decisions. +</p> + +This site is separate from the [Helpdoc](https://mingling-rs.github.io/mingling/docs/doc.html). + +The helpdoc is user-facing: `tutorials`, `feature guides`, and `how-to content` for developers _using_ Mingling to build CLI applications. + +This dev-docs site is for developers **working on** Mingling itself — understanding internal mechanisms, tracking unresolved problems, and recording design rationale. + +## What's here + +- **Issues** — Collected notes on known pain points, unresolved trade-offs, and feature gaps in the current implementation. + +## How this is different from GitHub Issues + +Mingling is hosted on [GitHub](https://github.com/mingling-rs/mingling), and the [Issues page](https://github.com/mingling-rs/mingling/issues) there is primarily for discussion. + +In contrast, an issue in this document exists only when it is being planned or actively worked on. diff --git a/docs/dev-docs/_sidebar.md b/docs/dev/_sidebar.md index acdb46f..5182676 100644 --- a/docs/dev-docs/_sidebar.md +++ b/docs/dev/_sidebar.md @@ -1,9 +1,10 @@ - [Welcome!](README) -* Abouts - * [AI Translation Rule](pages/abouts/ai-translation-rule) - * [Markdown Code Verification System](pages/abouts/code-verify-system) -* Issues +* ❓ Issues + * [Remove r_print! and r_println! Macros](pages/issues/remove-r-print-macro) * [The Mod Pathfinder](pages/issues/the-mod-pathfinder) * [Some Situations Where You'd Be Like "Shit!"](pages/issues/the-shit-time) -* templates +* 💡 Abouts + * [AI Translation Rule](pages/abouts/ai-translation-rule) + * [Markdown Code Verification System](pages/abouts/code-verify-system) +* 📄 Templates * [Helpdoc Template](pages/templates/doc) diff --git a/docs/dev-docs/index.html b/docs/dev/index.html index e62268d..e62268d 100644 --- a/docs/dev-docs/index.html +++ b/docs/dev/index.html diff --git a/docs/dev/pages/abouts/.name b/docs/dev/pages/abouts/.name new file mode 100644 index 0000000..f2b936c --- /dev/null +++ b/docs/dev/pages/abouts/.name @@ -0,0 +1 @@ +💡 Abouts diff --git a/docs/dev-docs/pages/abouts/ai-translation-rule.md b/docs/dev/pages/abouts/ai-translation-rule.md index b1f93f6..b1f93f6 100644 --- a/docs/dev-docs/pages/abouts/ai-translation-rule.md +++ b/docs/dev/pages/abouts/ai-translation-rule.md diff --git a/docs/dev-docs/pages/abouts/code-verify-system.md b/docs/dev/pages/abouts/code-verify-system.md index 61b66e8..61b66e8 100644 --- a/docs/dev-docs/pages/abouts/code-verify-system.md +++ b/docs/dev/pages/abouts/code-verify-system.md diff --git a/docs/dev/pages/issues/.name b/docs/dev/pages/issues/.name new file mode 100644 index 0000000..b207fb4 --- /dev/null +++ b/docs/dev/pages/issues/.name @@ -0,0 +1 @@ +❓ Issues diff --git a/docs/dev/pages/issues/remove-r-print-macro.md b/docs/dev/pages/issues/remove-r-print-macro.md new file mode 100644 index 0000000..96f99ef --- /dev/null +++ b/docs/dev/pages/issues/remove-r-print-macro.md @@ -0,0 +1,97 @@ +<h1 align="center">Remove r_print! and r_println! Macros</h1> + +`r_print!` and `r_println!` are important macros in Mingling for use inside `#[help]` and `#[renderer]` functions, but their implementation is not clean: they implicitly introduce a `__renderer_inner_result` field. While this might look elegant at the API level, it is **incorrect** and even **objectionable**. + +## Why **Objectionable**? + +Because you can't define declarative macros with `macro_rules` that wrap them. + +This is because `r_println!` depends on the implicit variable `__renderer_inner_result` injected by the `#[renderer]` proc macro into the function body. However, when a `macro_rules` declarative macro expands, **its internal code is placed in the caller's context**, which does not contain `__renderer_inner_result` — that variable only exists within the direct scope of the function body processed by `#[renderer]`. + +Let's look at some code to see why: + +```rust +// Suppose you want to write a wrapper macro: +macro_rules! my_println { + ($($arg:tt)*) => { + // When expanded here, the context is the call site of my_println!, + // not the location where the renderer function's injected variables live. + // So __renderer_inner_result is NOT visible here! + r_println!("Custom: {}", format!($($arg)*)); + }; +} + +#[renderer] +fn render_something(_p: ResultSomething) { + // Although this function body has __renderer_inner_result injected, + // the code from my_println! does NOT expand "inside this function body" — + // macro_rules expansion is essentially text replacement. The replaced code + // lives at the line where my_println! is called, and any variables referenced + // inside that macro must resolve to identifiers accessible at the call site. + // __renderer_inner_result is not a public, path-accessible variable; + // it's a hygienic local variable generated by the `#[renderer]` macro, + // and external macros cannot directly access it by name. + my_println!("{}", box_val); // Compile error: cannot find __renderer_inner_result +} +``` + +## Deeper Issues + +I have to admit, this is an early design flaw. After re-examining the code, I found the problem goes beyond "can't be wrapped". + +This isn't just a "can't wrap" issue — it reflects that `r_println!`'s design fundamentally violates Rust's macro hygiene principles: + +- **Implicit dependency**: Users of the macro must know that a variable named `__renderer_inner_result` exists — but this variable is neither part of the public API nor explicitly documented anywhere. +- **Scope leakage**: Variables injected by a proc macro should be confined to the scope processed by that macro. But `r_println!` attempts to make that variable accessible across macro calls, which effectively breaks Rust's identifier hygiene. +- **Non-composable**: Any attempt to wrap `r_println!` will fail, because declarative macros cannot "pass through" access to implicit variables. Even using a proc macro to wrap it would encounter similar hygiene issues. + +## Desired New Syntax + +I've designed two alternative approaches and will choose based on actual needs. + +### Option 1: Explicit Return + +```rust +#[renderer] +fn render_something(prev: ResultSomething) -> RenderResult { + let mut result = RenderResult::new(); + result.println(prev.to_string()); + // or + write!(result, "{}", prev.to_string()); + + result // return here +} +``` + +Clear boundaries — the entire rendering process is confined within the function body decorated by `#[help]` or `#[renderer]`, without introducing extra out-of-scope dependencies. The trade-off is slightly more boilerplate compared to the original approach. + +### Option 2: Resource Injection + +```rust +#[renderer] +fn render_something(prev: ResultSomething, result: &mut ResRenderResult) { + result.println(prev.to_string()); + // or + write!(result, "{}", prev.to_string()); + + result // return here +} +``` + +More flexible, but blurs the boundary between logic functions like `#[chain]` and rendering functions like `#[help]`. + +### Preferred Direction + +I lean toward **Option 1 (Explicit Return)**. There's no need to turn `RenderResult` into `ResRenderResult` as a global resource. + +As for rendering in logic functions like `#[chain]`, that should be handled by a separate system — not discussed here. + +## 🕘 Progress + +- [ ] In Progress + - [ ] Remove `r_println!` and `r_print!` macros + - [ ] Modify `#[renderer]` and `#[help]` macros, remove implicit injection + - [ ] Provide **no-return-value mode** and **RenderResult return value mode** for `#[renderer]` and `#[help]` macros + - [ ] Add new simplified syntax + - [ ] Update documentation and test cases, ensure **all pass** +- [ ] Complete diff --git a/docs/dev-docs/pages/issues/the-mod-pathfinder.md b/docs/dev/pages/issues/the-mod-pathfinder.md index 676251d..676251d 100644 --- a/docs/dev-docs/pages/issues/the-mod-pathfinder.md +++ b/docs/dev/pages/issues/the-mod-pathfinder.md diff --git a/docs/dev-docs/pages/issues/the-shit-time.md b/docs/dev/pages/issues/the-shit-time.md index f524f42..9d6c429 100644 --- a/docs/dev-docs/pages/issues/the-shit-time.md +++ b/docs/dev/pages/issues/the-shit-time.md @@ -83,6 +83,16 @@ fn desc_add() -> String { t!("cmd.add.desc") } +// Or + +#[completion(CMDAdd)] +fn desc_add(_ctx: &ShellContext) -> Suggest { + // If using rust_i18n + suggest{ + t!("cmd.add.desc") + } +} + // Collected and generated by `gen_program!()` // Generate something like get_dispatcher_desc(id: &ThisProgram) -> String // Match the corresponding function using enum values inside ThisProgram diff --git a/docs/dev/pages/templates/.name b/docs/dev/pages/templates/.name new file mode 100644 index 0000000..9e73889 --- /dev/null +++ b/docs/dev/pages/templates/.name @@ -0,0 +1 @@ +📄 Templates diff --git a/docs/dev-docs/pages/templates/doc.md b/docs/dev/pages/templates/doc.md index e8a9308..e8a9308 100644 --- a/docs/dev-docs/pages/templates/doc.md +++ b/docs/dev/pages/templates/doc.md diff --git a/docs/pages/1-getting-started.md b/docs/pages/1-getting-started.md index a701d7a..796c6bb 100644 --- a/docs/pages/1-getting-started.md +++ b/docs/pages/1-getting-started.md @@ -13,7 +13,7 @@ Add the following to `Cargo.toml`: ```toml [dependencies.mingling] -version = "0.2.1" +version = "0.2.2" features = [] ``` @@ -25,7 +25,7 @@ Some features **directly affect the entire lifecycle behavior**, so you need to ```toml [dependencies.mingling] -version = "0.2.1" +version = "0.2.2" features = [ "parser", "comp", diff --git a/docs/res/guide.txt b/docs/res/guide.txt index 19d99ff..f0d7652 100644 --- a/docs/res/guide.txt +++ b/docs/res/guide.txt @@ -5,5 +5,5 @@ │ > cargo add mingling │ │ │ │ Or add this to your Cargo.toml │ - │ > mingling = "0.2.1" │ + │ > mingling = "0.2.2" │ └────────────────────────────────────┘ |
