feat: upgrade gogen and use custom go printer output & fix some newline before decl#641
Conversation
Summary of ChangesHello @luoliwoshang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where generated Go ASTs, particularly those derived from C outputs, sometimes lacked per-node source positions. This deficiency, exacerbated by an upgrade to Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a fix for unstable Go printer output when AST nodes lack position information. The main change is the new internal/gowrite package, which implements a synthetic-position pass before formatting the Go code. This ensures stable comment placement. The change is adopted in gogensig and gengo tools. Additionally, the comment parser is updated to not force a trailing newline, and test expectations are updated accordingly. The gogen dependency is also bumped. The changes look solid and well-implemented. I have one suggestion for improving idiomatic error handling in the new gowrite package.
|
Clean approach to stabilizing Notable: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #641 +/- ##
==========================================
+ Coverage 84.77% 85.30% +0.52%
==========================================
Files 27 28 +1
Lines 2318 2415 +97
==========================================
+ Hits 1965 2060 +95
- Misses 310 311 +1
- Partials 43 44 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ment' into fix/issue-635-gowrite-parser-comment
…ment' into fix/issue-635-gowrite-parser-comment
025dbbe to
713b743
Compare
Summary
github.com/goplus/gogentov1.20.2internal/gowriteas the custom Go output path (go/formatwith a controlled synthetictoken.FileSet)tool/gengoandcmd/gogensigto useinternal/gowriteast.Comment.Textentry inCommentGroup.Listconst ()Why not use gogen's built-in print path?
This change needs full control of the
token.FileSetused during printing.llcppgoften generates AST nodes without full original source positions. To keep output stable on newergo/printer, we assign synthetic anchors and line table entries in a specificFileSet. If the final print path does not use the same controllableFileSet, then even with assignedPosvalues, comment/declaration spacing can still collapse or drift.gogen's default print path does not let this PR choose and manage the exactFileSetlifecycle required by that strategy, so this PR uses a custom writer path.Parser comment behavior
For Go AST/printer compatibility, a multiline block comment should be represented as a single
ast.Comment.Text(for example one/* ... */text), not split into multiple plain lines.So in parser output we now keep such multiline comments as one
CommentGroup.Listitem. This keepsgo/printerbehavior correct and stable.Future refinement: multiline
//runs can be split into multipleComment.Textentries when/if needed.Context
Validation
go test ./internal/gowrite -count=1go test ./cl/internal/convert -count=1cd _xtool/internal/parser && llgo test .