Repository navigation
feat(cli): add a parse command emitting the libpg_query protobuf - #841
Merged
psteinroe merged 2 commits intoOct 8, 2026
Merged
Conversation
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
approved these changes
Oct 8, 2026
psteinroe
left a comment
Collaborator
There was a problem hiding this comment.
would love to hear more about where and how you use the language server!
thanks for all the great contributions 🫶
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.
What kind of change does this PR introduce?
Feature: a new
parseCLI 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 protobufParseResultmessage, the same contract the official language bindings expose. Any tool with a generatedpg_queryclient 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_godictionary, with no cgo and no duplicated parser.Tests:
assert_parseruns the command end to end and decodes its output. One test asserts a decodableParseResultwith 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.