Skip to content

Conversation

@pyramation
Copy link
Collaborator

fix(plpgsql-deparser): indent all lines of multi-line statements

Summary

Fixes a bug where the indent() function only indented the first line of text, causing incorrect formatting for nested PL/pgSQL blocks (IF/WHILE/LOOP/CASE).

Before (broken):

IF val > 100 THEN
    RETURN 'large';
END IF;  -- wrong: should be indented

After (fixed):

IF val > 100 THEN
    RETURN 'large';
END IF;  -- correct: properly indented

The fix changes indent + text to indent + text.replace(/\n/g, '\n' + indent) to ensure all lines receive proper indentation.

Review & Testing Checklist for Human

  • Verify the snapshot changes show correct indentation (nested blocks should have increasing indent levels)
  • Run pnpm test in packages/plpgsql-deparser to confirm all tests pass
  • If you have downstream code that parses the deparser output, verify it handles the corrected formatting

Test plan: Run the test suite and visually inspect a few of the snapshot diffs to confirm END IF, END LOOP, ELSE, ELSIF etc. are now at the correct indentation level relative to their opening statements.

Notes

This fix aligns the TypeScript implementation with the SQL implementation in constructive-db, which uses the same replace('\n', '\n' + prefix) pattern.

Link to Devin run: https://app.devin.ai/sessions/db60cce6c0f9424dbd943d47b1a7e5fa
Requested by: Dan Lynch (@pyramation)

Previously, the indent() function only indented the first line of text.
This caused incorrect formatting for nested IF/WHILE/LOOP blocks where
subsequent lines would not be properly indented.

The fix uses text.replace(/\n/g, '\n' + indent) to ensure all lines
are indented, matching the behavior of the SQL implementation in
constructive-db.
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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