fix: syntax hallucinations

This commit is contained in:
2025-01-05 22:50:45 +07:00
parent 0aba4f6e69
commit 21f40f5873

View File

@@ -217,6 +217,7 @@ func MethodCodeToDeclaration(methodCode string) (ast.FuncDecl, error) {
methodDecl = *funcDecl
return false
})
return methodDecl, nil
}
@@ -282,6 +283,21 @@ func ImplementMethod(file *ast.File, methodDecl *ast.FuncDecl, reimplement bool)
file.Decls = append(decls, methodDecl)
}
// Reload AST: fix issues with syntax 'hallucinations'
// Write AST
var buf bytes.Buffer
if err := printer.Fprint(&buf, token.NewFileSet(), file); err != nil {
return err
}
// Load AST
formattedFile, err := parser.ParseFile(token.NewFileSet(), "", buf.String(), parser.ParseComments)
if err != nil {
return err
}
*file = *formattedFile
return nil
}