feat(#20): --@swell.<attr> comment hints on analyzed-single-truth - #34
Open
wokalski wants to merge 1 commit into
Open
feat(#20): --@swell.<attr> comment hints on analyzed-single-truth#34wokalski wants to merge 1 commit into
wokalski wants to merge 1 commit into
Conversation
Closes #20 on top of analyzed-single-truth. `pg_query::scan` exposes every `--` / `/* */` as a token with byte positions; `pg_query::parse` exposes `ResTarget.location` per target-list entry. A comment attaches to the column whose `ResTarget.location` is the largest one less-or-equal to the comment's start. String literals + dollar-quoted bodies are naturally excluded by the scanner. Attributes supported (case-insensitive): - `nullable` — force `nullable: true` - `nonnullable` / `nonnull` / `notnull` — force `nullable: false` - `type=T` or `type: T` — verbatim TS type Stacking is allowed (multiple comments on one column, or comma-separated attrs in a single comment). Works on SELECT target lists and DML RETURNING lists. Hints take precedence over the SQLx-style `col!` / `col?` markers and over the inferred verdict. When any hint applies the analyzer drops the base-column `table_ref`, so the override shows verbatim in the emitted TS instead of being masked by an indexed-access (`Table["col"]`) lookup. 11 unit tests in `comment_hints.rs` and 7 corpus tests in `billing.md` covering both forms, attribution to the preceding column, stacking, RETURNING, and string-literal isolation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #20 on top of #32 (
analyzed-single-truth).A clean reimplementation of #23 using the new internals — the AST-driven
Analyzedpipeline +pg_utilhelpers already had everything we needed.How it works
pg_query::scanreturns every--//* */as a token with byte positions;pg_query::parseexposesResTarget.locationper target-list entry. A comment attaches to the column whoseResTarget.locationis the largest one less-or-equal to the comment's start. String literals + dollar-quoted bodies are naturally excluded by the scanner.Attributes
nullable— forcenullable: truenonnullable/nonnull/notnull— forcenullable: falsetype=Tortype: T— verbatim TS typeMultiple comments stack on the same column. Works on SELECT target lists and DML RETURNING lists. The existing alias-suffix form (
col!/col?) still parses for back-compat; comment hints take precedence.Wired in
When any hint applies the analyzer drops the base-column
table_reffor that column, so the override surfaces verbatim in the emitted.d.tsinstead of being masked by an indexed-access (Table[\"col\"]) lookup.Test plan
comment_hints.rscovering line/block forms, thetype=andtype:separators, stacked + comma-separated attrs, attribution to the preceding column, RETURNING lists, parse-failure tolerance, and string-literal isolation.billing.mdexercising the same matrix end-to-end against live Postgres.🤖 Generated with Claude Code