You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Verify compliance with project patterns (pooling, race safety)
Provide comprehensive feedback
Code Review Summary
This PR implements comment preservation during SQL parsing and formatting. The implementation is well-architected and follows the project's established patterns. Here's my detailed analysis:
✅ Strengths
Clean Architecture: The comment preservation follows a clear pipeline: tokenizer captures → AST stores → formatter emits
Proper Object Pooling: Comments are correctly handled in the AST pool with proper cleanup in ReleaseAST() pkg/sql/ast/pool.go:357-359
Comprehensive Coverage: Supports both line (--) and block (/* */) comments with proper position tracking
Round-trip Preservation: Comments survive parse→format cycles, which is essential for code formatters
Non-breaking: Implementation is additive and doesn't change existing APIs
The Comments field on Tokenizer struct is not properly isolated. Multiple goroutines could access the same tokenizer instance if pooling patterns are misused.
Recommendation: Add a defensive copy in the tokenizer pool reset:
// In Reset() method (tokenizer.go:165-168)ifcap(t.Comments) >0 {
t.Comments=t.Comments[:0]
} else {
t.Comments=make([]models.Comment, 0, 4) // Initialize with reasonable capacity
}
This is a well-implemented feature that adds significant value. The core implementation is solid and follows project conventions. With the recommended fixes for the race condition and bounds checking, this PR is ready for merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #275
Changes
models.Commenttype for representing SQL comments with position info--) and block (/* */) comments during tokenization