feat(protobuf): add opt-in enum value prefixes - #12103
Cameron Taggart (cataggar) wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
|
You can try these changes here
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 3
Open (4)
The collision index is keyed only by@packagenamespaces, and entries are only recorded when… · New The collision index is keyed only by@packagenamespaces, and entries are only recorded when… · New The collision index is keyed only by@packagenamespaces, and entries are only recorded when… · New This diagnostic message doesn’t provide enough context to quickly resolve collisions in larger… · New
What changed in this PR
Adds an opt-in Protobuf emitter option to prefix enum value names with their enum name (UPPER_SNAKE_CASE) to avoid package-scope collisions, and documents/tests the new behavior.
Changes:
- Add
enum-value-prefix: enum-nameemitter option + schema/diagnostic support. - Implement enum value prefixing + collision detection in the transform pipeline.
- Add docs (guide/reference/README) and a dedicated test suite for the option.
| File | Description |
|---|---|
| website/src/content/docs/docs/emitters/protobuf/reference/emitter.md | Documents the new enum-value-prefix option in the reference page. |
| website/src/content/docs/docs/emitters/protobuf/guide.md | Adds a guide section explaining enum emission and the new prefixing option. |
| packages/protobuf/test/enum-prefix.test.ts | Adds tests covering prefixing, normalization, and collision diagnostics. |
| packages/protobuf/src/transform/index.ts | Implements enum value prefixing and collision checking across a Protobuf package. |
| packages/protobuf/src/lib.ts | Extends emitter options + JSON schema and introduces a new collision diagnostic. |
| packages/protobuf/package.json | Adds change-case dependency for name normalization/prefixing. |
| packages/protobuf/README.md | Documents the new emitter option for package consumers. |
| .chronus/changes/protobuf-enum-value-prefix-2026-10-02.md | Adds a feature changelog entry describing the new option. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
All changed packages have been documented.
Show changes
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the linked feature requirements and includes appropriate tests, documentation, dependency updates, and changelog coverage.
Review effort: Balanced
Findings: None
Resolved since last review (4)
The collision index is keyed only by@packagenamespaces, and entries are only recorded when… The collision index is keyed only by@packagenamespaces, and entries are only recorded when… The collision index is keyed only by@packagenamespaces, and entries are only recorded when… This diagnostic message doesn’t provide enough context to quickly resolve collisions in larger…
Files not reviewed (1)
- pnpm-lock.yaml: Generated file


Summary
Fixes #12102.
Add the opt-in
enum-value-prefix: enum-nameoption to@typespec/protobuf. Every enum value is prefixed with its enum name inUPPER_SNAKE_CASE, so TypeSpec can use short member names without package-scope collisions.enum-value-prefix: none).Unspecifiedmember is synthesized.change-casedependency and update the lockfile's protobuf importer only.This follows AIP-126 and the Protobuf style guide, which recommends:
Explicit
@encodedNamesupport and automatic numbering/member synthesis are outside this change.Validation
pnpm build— full workspace build passed.pnpm --filter @typespec/protobuf test— 63 tests passed, including 22 prefix-option cases and all existing scenarios.pnpm exec oxlint packages/protobuf --type-aware --deny-warnings— passed.pnpm format:check— passed.pnpm chronus verify --since microsoft/main— passed.Unspecifiedmembers, then compiled the emitted.protowithprotoc36.2.Local lint limitation after a full build:
pnpm lintandpnpm lint:fixfail in the unchanged compiler configuration:packages/compiler/tsconfig.jsonattempts to emitdist/src/server/tmlanguage.d.tsover an input declaration imported by its generation script. The protobuf package's type-aware lint passes; no unrelated compiler changes are included.