Skip to content

Stop generation from writing to what it reads, and format with go/format - #147

Merged
crhntr merged 1 commit into
mainfrom
split/2-generation-fixes
Sep 16, 2026
Merged

crhntr merged 1 commit into
mainfrom
split/2-generation-fixes

Conversation

@crhntr

@crhntr crhntr commented Sep 14, 2026

Copy link
Copy Markdown
Member

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

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.

🟡 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.

Comment thread internal/muxt/call.go
@crhntr
crhntr force-pushed the split/1-load-package branch from 0f0c63b to ea47bd8 Compare September 16, 2026 01:36
@crhntr
crhntr force-pushed the split/2-generation-fixes branch from 9633986 to ec1fa6c Compare September 16, 2026 01:36
Base automatically changed from split/1-load-package to main September 16, 2026 06:05
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
crhntr force-pushed the split/2-generation-fixes branch from ec1fa6c to e8aca9e Compare September 16, 2026 06:07
@crhntr
crhntr merged commit 2f3f833 into main Sep 16, 2026
2 checks passed
@crhntr
crhntr deleted the split/2-generation-fixes branch September 16, 2026 06:20
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.

2 participants