Skip to content

sql-pretty: add indent & config in wasm#36857

Open
justjake wants to merge 2 commits into
MaterializeInc:mainfrom
justjake:jake--sql-pretty-indent
Open

sql-pretty: add indent & config in wasm#36857
justjake wants to merge 2 commits into
MaterializeInc:mainfrom
justjake:jake--sql-pretty-indent

Conversation

@justjake
Copy link
Copy Markdown

@justjake justjake commented Jun 2, 2026

Motivation

I want to shape Materialize SQL for rendering in the terminal as part of my migration tooling.

For this use-case, 4-space indent is quite greedy for horizontal screen space, so I would prefer a 2-space indent. However everyone's opinion is different, so it should be an option.

Description

Note: I am not a Rust programmer, so this diff is mostly Codex. I reviewed the code and it looks good to me, but I am not attuned to the aesthetics of Rust. Thank you for your patience.

Add an indent field to PrettyConfig and use it when nesting pretty-printer documents. Provide Default for PrettyConfig so existing callers only specify the fields they override.

I converted several stand-alone functions into methods to make indent available to them.

Then in wasm, add prettyStrConfig and prettyStrsConfig exports that accept width,
indent, and formatMode and turns it into mz_sql_pretty::PrettyConfig.

I considered tacking the indent on as a third arg, but I think f(string, number, number) is a bad signature - too easy to confuse the number args. I considered overloading the current signature but overloads are a bit weird and I didn't want to suggest weird code. Happy to do if y'all like them (and bindgen supports...).

I added a little JavaScript test to verify the whole package works.

Verification

  • Rust unit tests.
  • New JavaScript test.

justjake added 2 commits June 1, 2026 22:37
Add an indent field to PrettyConfig and use it when nesting pretty-printer documents. Provide Default for PrettyConfig so existing callers only specify the fields they override.
Add prettyStrConfig and prettyStrsConfig exports that accept width, indent, and formatMode. Validate JS config values explicitly before constructing mz_sql_pretty::PrettyConfig.

Add a small Node test for the generated wasm package, and have bin/wasm-build run crate-local test.mjs scripts so CI exercises the generated JS wrapper.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Thank you for your submission! We really appreciate it. Like many source-available projects, we require that you sign our Contributor License Agreement (CLA) before we can accept your contribution.

You can sign the CLA by posting a comment with the message below.


I have read the Contributor License Agreement (CLA) and I hereby sign the CLA.


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Comment on lines +30 to +34
export interface PrettyConfig {
width?: number;
indent?: number;
formatMode?: PrettyFormatMode;
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is this legit? The types aren't auto-generated?

@justjake justjake marked this pull request as ready for review June 2, 2026 03:10
@justjake justjake requested review from a team as code owners June 2, 2026 03:10
@justjake
Copy link
Copy Markdown
Author

justjake commented Jun 2, 2026

I have read the Contributor License Agreement (CLA) and I hereby sign the CLA.

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.

1 participant