dfinity / dfinity/candid

didc bind --target mo: emit PascalCase type names (Motoko convention)

Open
#733 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
301
Forks
85
Avg merge
1h 4m
Merged PRs (30d)
4

Description

Problem

didc bind --target mo emits snake_case type names, but the Motoko convention for types is PascalCase. This means generated bindings are not idiomatic Motoko and require a post-processing step to be usable in practice.

Example — current output:

public type canister_status_args = { canister_id : canister_id };
public type canister_status_result = { ... };

Expected idiomatic output:

public type CanisterStatusArgs = { canister_id : CanisterId };
public type CanisterStatusResult = { ... };

Note: record field labels and method names should stay snake_case — they are Candid identifiers, not Motoko identifiers. Only the type definition names and their references as types should be converted.

Context

This was discovered while maintaining caffeinelabs/mops-ic, the Motoko bindings package for the IC management canister. The initial generation in that repo was done with an undocumented post-processing step (snake→PascalCase); a follow-up PR (caffeinelabs/mops-ic#11) formalised this as scripts/pascal_types.py.

The Rust binding generator in didc already converts to PascalCase for struct/enum names (following Rust conventions). The Motoko generator should do the same.

Proposed fix

In rust/candid_parser/src/bindings/motoko.rs, convert type definition names (and their references) from snake_case to PascalCase when generating the public type declarations. Field labels (Label::Named) and method names should remain unchanged.

The conversion is straightforward: split on _, capitalise each word, join. The scripts/pascal_types.py in caffeinelabs/mops-ic#11 demonstrates the exact logic.

Additional note

didc 0.6.1 (current main) also fixes the float32 not supported in Motoko panic present in the released 0.5.4 binary — a release with both fixes would be very welcome.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in rust/candid_parser/src/bindings/motoko.rs and trace how type declarations and type references are emitted. Use the conversion logic described in the issue as a reference, while preserving snake_case for record field labels and method names. Done means Motoko type names and their references use PascalCase without changing Candid labels or methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.