fix: make codegen not fail for "blob" columns
- was previously using "[]byte" as a single `ast.NewIdent`, which made comment+blank-line-insertion reparsing fail
This commit is contained in:
@@ -76,28 +76,35 @@ func FprintWithComments(w io.Writer, file *ast.File) error {
|
||||
return fmt.Errorf("re-parsing pretty-print: %w", err)
|
||||
}
|
||||
|
||||
// Convert the tree-of-nodes into a slice-of-nodes
|
||||
collectNodes := func(node ast.Node) []ast.Node {
|
||||
var nodes []ast.Node
|
||||
ast.Inspect(node, func(n ast.Node) bool {
|
||||
// Filter out comments, as they only appear in the
|
||||
switch n.(type) {
|
||||
case *ast.CommentGroup, *ast.Comment:
|
||||
return false
|
||||
}
|
||||
nodes = append(nodes, n)
|
||||
return true
|
||||
})
|
||||
return nodes
|
||||
}
|
||||
|
||||
// Parallel walk: apply TrailingComments from the side map.
|
||||
// Both trees have identical structure (the reparse is just a positioned copy),
|
||||
// so ast.Inspect visits nodes in the same order. We skip comment nodes to
|
||||
// avoid mismatches from Doc fields.
|
||||
if len(TrailingComments) > 0 {
|
||||
// Helper: convert the tree-of-nodes into a slice-of-nodes
|
||||
collectNodes := func(node ast.Node) []ast.Node {
|
||||
var nodes []ast.Node
|
||||
ast.Inspect(node, func(n ast.Node) bool {
|
||||
// Filter out comments, as they only appear in the
|
||||
switch n.(type) {
|
||||
case *ast.CommentGroup, *ast.Comment:
|
||||
return false
|
||||
}
|
||||
nodes = append(nodes, n)
|
||||
return true
|
||||
})
|
||||
return nodes
|
||||
}
|
||||
|
||||
origNodes := collectNodes(file)
|
||||
reparsedNodes := collectNodes(parsed)
|
||||
if len(origNodes) != len(reparsedNodes) {
|
||||
panic(fmt.Sprintf(
|
||||
"origNodes: %d; reparsedNodes: %d. The AST generator is likely generating an invalid AST",
|
||||
len(origNodes), len(reparsedNodes),
|
||||
))
|
||||
}
|
||||
|
||||
for i, orig := range origNodes {
|
||||
text, isOk := TrailingComments[orig]
|
||||
if !isOk {
|
||||
|
||||
Reference in New Issue
Block a user