Skip to content

Replace manual AST type stitching with go/types - #7

Merged
chenyanchen merged 1 commit into
mainfrom
refactor/use-go-types
Feb 20, 2026
Merged

chenyanchen merged 1 commit into
mainfrom
refactor/use-go-types

Conversation

@chenyanchen

Copy link
Copy Markdown
Owner

Summary

  • Replace ~110 lines of hand-rolled AST type formatters (identName, ellipsisName, selectorExprName, starExprName, arrayTypeName, mapTypeName) with go/types.TypeString() and Scope().Lookup()
  • Simplify packages.Config mode from NeedName|NeedTypes|NeedTypesInfo|NeedSyntax to NeedName|NeedTypes
  • Remove dead code: toLowerCamelCase and unreachable len(interfaces) == 0 check

This fixes several limitations of the manual approach:

  • Missing support for interface{}, func, chan types
  • Incomplete basic type list (missing any, uintptr, complex64/128)
  • Multi-name parameters (a, b int) only capturing the first name
  • Embedded interface methods not being extracted

Test plan

  • go build . passes
  • go vet . passes
  • go test -v . passes (TestTemplateValidationPipeline — parse, generate_and_go_fix, final_build)

The interface extraction logic manually traversed AST nodes to rebuild
type strings, which missed interface{}, func, chan types and multi-name
parameters. Replace ~110 lines of hand-rolled type formatters with
go/types' TypeString and Scope().Lookup(), simplify packages.Config to
only NeedName|NeedTypes, and remove dead helper functions.
@chenyanchen
chenyanchen merged commit 04dabec into main Feb 20, 2026
2 checks passed
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.

1 participant