Refactor operations.ts - #5185
Conversation
|
All changed packages have been documented.
Show changes
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the TypeSpec Go emitter’s operation-generation implementation by extracting request/response handler generation into dedicated modules and introducing barrel (index.ts) exports for clearer API surfaces. The intent is improved readability/maintainability with no intended functional change, but I found a real behavioral bug introduced/retained in the new response-handler implementation.
Changes:
- Split request/response handler generation out of
core/operations.tsintocore/request-handler.tsandcore/response-handler.ts. - Added barrel exports for
core/*andfake/*and updated the main emitter to import through them. - Moved shared helpers (e.g.,
fixUpMethodName,getClientReceiverDefinition, media/time helpers) intocore/helpers.tsand updated call sites.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typespec-go/src/codegen/fake/servers.ts | Switches fixUpMethodName usage to helpers.fixUpMethodName after helper relocation. |
| packages/typespec-go/src/codegen/fake/index.ts | New barrel exporting fake server generators. |
| packages/typespec-go/src/codegen/emitter.ts | Refactors imports to use core/index.ts + fake/index.ts barrels. |
| packages/typespec-go/src/codegen/core/response-handler.ts | New extracted response-handler generator (contains a confirmed unmarshal target bug). |
| packages/typespec-go/src/codegen/core/request-handler.ts | New extracted request-handler generator (large move of existing logic). |
| packages/typespec-go/src/codegen/core/operations.ts | Integrates new request/response handler modules and removes inlined implementations. |
| packages/typespec-go/src/codegen/core/index.ts | New barrel exporting core generators used by the emitter. |
| packages/typespec-go/src/codegen/core/helpers.ts | Adds/moves shared helper APIs (method naming, receiver formatting, media/time helpers). |
| packages/typespec-go/src/codegen/core/example.ts | Updates example generation to use helpers.fixUpMethodName. |
| .chronus/changes/go-op-refactor-2026-7-6-15-44-32.md | Adds internal changelog entry for the refactor. |
Suppressed comments (2)
packages/typespec-go/src/codegen/core/response-handler.ts:160
- generateResponseUnmarshaller() assigns array-of-datetime results to
result.<field>instead of the providedunmarshalTarget, so callers that unmarshal into a temp var (e.g.valin the anyResult switch) won't work correctly.
unmarshallerText += `${indent.get()}result.${helpers.getResultFieldName(method)} = cp\n`;
packages/typespec-go/src/codegen/core/response-handler.ts:173
- generateResponseUnmarshaller() assigns map-of-datetime results to
result.<field>instead of the providedunmarshalTarget, which will generate incorrect code when the unmarshaller is used with a local variable target.
unmarshallerText += `${indent.get()}result.${helpers.getResultFieldName(method)} = cp\n`;
📦 Package size report2 packages changed size compared to the base branch.
43 unchanged package(s)
Packed = gzipped |
commit: |
|
You can try these changes here
|
Split monolithic file into three files so it's easier to reason about. Added barrel files to clarify external APIs used by the emitter. Moved shared functions to helpers.ts. Simplified a few bits of code to avoid more shared helpers.
169c46c to
3013ad9
Compare
Split monolithic file into three files so it's easier to reason about. Added barrel files to clarify external APIs used by the emitter. Moved shared functions to helpers.ts.
Simplified a few bits of code to avoid more shared helpers.
No functional changes.