Stop generation from writing to what it reads, and format with go/format - #147
Merged
Merged
Conversation
This was referenced Sep 14, 2026
There was a problem hiding this comment.
🟡 Changes recommended
The path-parameter guard can leave valid typed route parameters generated as string.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR refactors route generation to avoid mutating resolved calls and replaces goimports with per-file import tracking and go/format.
Changes:
- Resolves path parameter types during call resolution.
- Clones calls before generation and isolates file imports.
- Adds custom formatting and formatter tests.
- Updates fake-server and AST formatting.
File summaries
| File | Summary |
|---|---|
internal/muxt/unmarshal.go |
Adds shared string-assignability logic. |
internal/muxt/definition.go |
Exposes resolved argument types. |
internal/muxt/call.go |
Records resolved path parameter types; a guard can skip valid names such as signals or sseID. |
internal/generate/sse.go |
Generates SSE handlers from cloned calls. |
internal/generate/routes.go |
Clones calls and manages per-file imports. |
internal/generate/html.go |
Generates handlers from cloned calls. |
internal/generate/format.go |
Formats generated files and imports. |
internal/generate/format_test.go |
Tests import formatting. |
internal/generate/file.go |
Adds independent sibling file registries. |
internal/fakeserver/fakeserver.go |
Uses go/format. |
internal/astgen/format.go |
Removes goimports-based formatting. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
crhntr
force-pushed
the
split/1-load-package
branch
from
September 16, 2026 01:36
0f0c63b to
ea47bd8
Compare
crhntr
force-pushed
the
split/2-generation-fixes
branch
from
September 16, 2026 01:36
9633986 to
ec1fa6c
Compare
Three generation fixes. Every generated file in the integration suite is unchanged. Path parameter types are resolved before handlers are generated. A route path helper takes each path parameter as the type the handler parses it into, and that type was only known once the handler had been generated: argument parsing wrote it onto the definition as it went, and the route path helpers, generated afterwards, read it back. Resolution records it now, by the rule parsing followed: the first place the call passes a parameter, depth first in argument order, decides -- its parameter type, unless a string is assignable to it. Argument parsing also rewrote the definition's call expression in place, so generating a handler twice read the first run's rewrites; it rewrites a copy now. Both are stated by unit tests two changes on, once resolution runs against a mock checker; here the integration suite holds them. Each generated file has imports of its own. One import registry was shared by every file a run writes, so with --output-multiple-files each file declared every package any of them had registered, and goimports dropped the extras. The routes file also took its import list before building TemplateData, so goimports found and added the fmt, errors, io and strings those declarations use -- by walking the module cache. Each file now gets its own registry, and the import declaration is filled in after the declarations that register into it. With exactly the imports it uses, a file only needs its import block laid out: formatFile groups it as goimports does (a path whose first element has a dot after those that have none) and formats with go/format. TestFormatFileImports states the layout. generate no longer links golang.org/x/tools/imports; the fake server's main.go is formatted the same way. Assisted-by: Claude:claude-opus-5 gofumpt
crhntr
force-pushed
the
split/2-generation-fixes
branch
from
September 16, 2026 06:07
ec1fa6c to
e8aca9e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolution records path parameter types, and handler generation works on a copy of the call instead of rewriting the route. Each generated file has its own import registry and fills its import block last, so files are formatted with go/format and goimports is gone. Generated output is unchanged.
Part 2 of 8, stacked on #146. Replaces #145.
🤖 Generated with Claude Code
https://claude.ai/code/session_01UjkpA4fvZ7xQAsY65Beprp