Skip to content

✨ zlink-macros: Support rename_all_arguments on the proxy macro - #299

Merged
zeenix merged 1 commit into
mainfrom
copilot/add-attribute-rename-method-arguments
Jul 19, 2026
Merged

✨ zlink-macros: Support rename_all_arguments on the proxy macro#299
zeenix merged 1 commit into
mainfrom
copilot/add-attribute-rename-method-arguments

Conversation

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

systemd's Varlink APIs use camelCase for method arguments per their Varlink API style guide, with PascalCase where a name mirrors a documented option name (the Varlink spec itself mandates no case convention; its own examples are snake_case). Rust arguments are snake_case, so today each argument of a proxy for such a service must be individually annotated with #[zlink(rename = "...")] — see the machined mock in zlink/tests/mock_machined_service.rs, which hand-renames every argument. This adds rename_all_arguments to the #[proxy] macro so a single attribute converts all argument names automatically. The attribute is deliberately not called rename_all: the explicit name makes it obvious it renames the method arguments, not the methods.

#[proxy(interface = "org.example.Config", rename_all_arguments = "camelCase")]
trait ConfigProxy {
    async fn set_config(
        &mut self,
        dry_run: bool,        // serialized as "dryRun"
        config_value: String, // serialized as "configValue"
    ) -> zlink::Result<Result<(), Error>>;
}

Per-argument #[zlink(rename = "...")] takes precedence over rename_all_arguments, which irregular names (e.g. machined's OSRelease, UIDShift) still need. The convention is applied to the unraw'd ident (r#type under PascalCase maps to Type, not R#type), and every produced name is validated against the Varlink field grammar — matching what the derives and the service macro already guarantee since #296 — so e.g. kebab-case on a multi-word argument is a compile error, not an invalid wire name.

Fixes #170.

Changes

  • naming.rs: Widen RenameAll::parse to pub(crate), make its unknown-value error attribute-neutral
  • proxy.rs: Parse rename_all_arguments from proxy attributes, thread it to all three code generators
  • proxy/utils.rs: New resolve_serialized_name helper holding the precedence rule, the unrawing, and the grammar validation in one place
  • method_impl.rs / chain_extension.rs / chain_method.rs: Resolve argument wire names through the shared helper
  • lib.rs: Document rename_all_arguments in the supported-attributes list, including the systemd camelCase guidance and the grammar constraint (with a compile_fail doctest)
  • tests/proxy/rename.rs: Tests for PascalCase, camelCase, explicit-override precedence, chain methods, and raw identifiers (plain and chained)

Copilot AI changed the title [WIP] Add attribute to rename method arguments from camelCase to PascalCase feat(proxy): add rename_all attribute for method parameter renaming Jul 18, 2026
Copilot AI requested a review from zeenix July 18, 2026 19:54
Copilot AI force-pushed the copilot/add-attribute-rename-method-arguments branch from 2425123 to 811d084 Compare July 18, 2026 20:25
Copilot AI force-pushed the copilot/add-attribute-rename-method-arguments branch from 811d084 to 35a629d Compare July 18, 2026 20:27
Copilot AI force-pushed the copilot/add-attribute-rename-method-arguments branch from 35a629d to ccda498 Compare July 18, 2026 20:36
@zeenix zeenix changed the title feat(proxy): add rename_all attribute for method parameter renaming ✨ zlink-macros: Support rename_all on the proxy macro Jul 18, 2026
@zeenix
zeenix marked this pull request as ready for review July 18, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the #[proxy] macro in zlink-macros to support a rename_all = "...“ attribute, allowing proxy method parameter names to be case-converted automatically (with per-parameter #[zlink(rename = "...")] still taking precedence). This fits the macros crate’s role of generating client-side Varlink proxy code with correct wire-format naming.

Changes:

  • Parse rename_all from #[proxy(...)] attributes and thread it through proxy method / chain method code generation.
  • Apply RenameAll::apply_to_field to parameters that do not have an explicit #[zlink(rename = "...")].
  • Add/extend tests and documentation to cover rename_all usage and precedence.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
zlink-macros/src/naming.rs Exposes RenameAll::parse to allow proxy macro parsing.
zlink-macros/src/proxy.rs Parses rename_all from proxy attributes and passes it into generators.
zlink-macros/src/proxy/method_impl.rs Applies rename_all when generating serde parameter structs (method impl path).
zlink-macros/src/proxy/chain_method.rs Applies rename_all for chain methods’ parameter serialization.
zlink-macros/src/proxy/chain_extension.rs Applies rename_all for chain extension methods’ parameter serialization.
zlink-macros/src/lib.rs Documents rename_all as a supported #[proxy] attribute and lists accepted values.
zlink-macros/tests/proxy/rename.rs Adds tests for rename_all (PascalCase/camelCase), explicit override precedence, and chain methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread zlink-macros/src/proxy/method_impl.rs Outdated
Comment thread zlink-macros/src/proxy/chain_method.rs Outdated
Comment thread zlink-macros/src/proxy/chain_extension.rs Outdated
Comment thread zlink-macros/tests/proxy/rename.rs
@codspeed-hq

codspeed-hq Bot commented Jul 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks


Comparing copilot/add-attribute-rename-method-arguments (798aa8f) with main (27552b9)

Open in CodSpeed

@zeenix zeenix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on top of the existing comments (not repeating them). The raw-identifier issue already flagged in three files is real; two additional findings inline: (1) rename_all-produced names are never validated against the Varlink field grammar, so documented values like kebab-case silently emit wire names Varlink cannot express — the opposite of what #298 established for the derives; (2) the resolution logic is triplicated across the three codegen files, which is why the raw-ident bug appears three times — it should be a single shared helper. Fixes for all comments follow on claude/zlink-pr-299-review-r18v2c.


Generated by Claude Code

Comment thread zlink-macros/src/proxy.rs
Comment thread zlink-macros/src/proxy/method_impl.rs Outdated
@zeenix
zeenix force-pushed the copilot/add-attribute-rename-method-arguments branch 2 times, most recently from bcff004 to 4d60ddb Compare July 19, 2026 11:10
@zeenix zeenix changed the title ✨ zlink-macros: Support rename_all on the proxy macro ✨ zlink-macros: Support rename_all_arguments on the proxy macro Jul 19, 2026
systemd's Varlink APIs use camelCase for method arguments per their
Varlink API style guide, with PascalCase where a name mirrors a
documented option name (the Varlink spec itself mandates no case
convention; its own examples are snake_case). Rust arguments are
snake_case, so today each argument of a proxy for such a service must
be individually annotated with `#[zlink(rename = "...")]`. This adds
`rename_all_arguments` to the `#[proxy]` macro so a single attribute
converts all argument names automatically. Per-argument
`#[zlink(rename = "...")]` takes precedence over `rename_all_arguments`,
which irregular names (e.g. machined's `OSRelease`) still need.

The attribute is named `rename_all_arguments`, not `rename_all`, so it
is obvious it renames the method arguments and not the methods.

The resolution lives in a single helper shared by the three code
generators (regular, chain and chain-extension methods), so the
precedence rule cannot drift between them. The convention is applied to
the unraw'd ident -- `r#` is Rust syntax, never part of the name, so
`r#type` under `PascalCase` maps to `Type`, not `R#type`. Every name the
convention produces is validated against the Varlink field grammar,
matching what the derives and the service macro already guarantee since
the fix for #296: `kebab-case` turning `dry_run` into `dry-run` is a
compile error on the argument, not a wire name the peer rejects.

Tests cover PascalCase and camelCase conversion, explicit-override
precedence, chain methods, raw identifiers (plain and chained), and the
grammar rejection (as a compile_fail doctest and helper unit tests).

Fixes #170.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2pHFDxsBxrrYAVKeCosGy
@zeenix
zeenix force-pushed the copilot/add-attribute-rename-method-arguments branch from 4d60ddb to 798aa8f Compare July 19, 2026 12:25
@zeenix
zeenix merged commit 4d9c3f5 into main Jul 19, 2026
18 of 19 checks passed
@zeenix
zeenix deleted the copilot/add-attribute-rename-method-arguments branch July 19, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[proxy macro]: Add attribute to rename all method arguments from camelCase to PascalCase

3 participants