Skip to content

feat(cli): add a parse command emitting the libpg_query protobuf - #841

Merged
psteinroe merged 2 commits into
supabase-community:mainfrom
edjubert:edjubert/parse-command
Oct 8, 2026
Merged

psteinroe merged 2 commits into
supabase-community:mainfrom
edjubert:edjubert/parse-command

Conversation

@edjubert

@edjubert edjubert commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature: a new parse CLI command.

What is the current behavior?

There is no way to get the libpg_query parse tree out of the CLI. Consuming PostgreSQL parse trees from another language requires the language bindings or vendor-specific glue.

What is the new behavior?

postgres-language-server parse [FILE] reads a SQL file (or standard input) and writes the parse tree to standard output as a protobuf ParseResult message, the same contract the official language bindings expose. Any tool with a generated pg_query client can decode the output and walk the tree, using the same binary that already formats and checks SQL.

The parse mirrors how the rest of the CLI reads SQL: psql named parameters (:'name', :name) become parser-compatible placeholders of identical byte length, so every location in the tree stays aligned with the input bytes. Parser warnings go to the console; the protobuf on standard output is untouched.

Additional context

Aligns with the protobuf parse-tree direction taken in #639, from the CLI side and for non-Rust consumers: we use this command to feed a Go lineage corpus that decodes the tree with the pg_query_go dictionary, with no cgo and no duplicated parser.

Tests: assert_parse runs the command end to end and decodes its output. One test asserts a decodable ParseResult with the expected statement count; the other asserts that the statement end location falls exactly on the input's semicolon when named parameters are present, pinning the byte-length-preserving substitution.

Edouard Jubert and others added 2 commits October 8, 2026 11:17
postgres-language-server parse [FILE] reads a SQL file (or standard input) and writes the libpg_query parse tree to standard output as a protobuf ParseResult message, the same contract the official language bindings expose. Any consumer with a generated pg_query client can decode the output and walk the tree.

The parse mirrors how the rest of the CLI reads SQL: psql named parameters (:'name', :name) become parser-compatible placeholders of identical byte length, so every location in the tree stays aligned with the input bytes. Parser warnings go to the console; the protobuf on standard output is untouched.

@psteinroe psteinroe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would love to hear more about where and how you use the language server!

thanks for all the great contributions 🫶

@psteinroe
psteinroe merged commit 89bc400 into supabase-community:main Oct 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants