Skip to content

Document whitespace-suppression behavior on CodeBlock#4571

Merged
pepone merged 1 commit intoicerpc:mainfrom
pepone:docs/codeblock-whitespace-behavior
Apr 29, 2026
Merged

Document whitespace-suppression behavior on CodeBlock#4571
pepone merged 1 commit intoicerpc:mainfrom
pepone:docs/codeblock-whitespace-behavior

Conversation

@pepone
Copy link
Copy Markdown
Member

@pepone pepone commented Apr 29, 2026

Clarify WriteLine and AddBlock behavior for empty line, empty block

…ddBlock

WriteLine("") and AddBlock(emptyBlock) are intentionally no-ops: it lets
callers interpolate possibly-empty values without producing stray blank
lines (e.g. WriteLine(\$\"    {body.Indent()}\") with empty body). Vertical
whitespace in final output is managed by ToString, which collapses runs
of blank lines to at most one.

Adds <remarks> on both methods so the design intent is visible to
callers who might otherwise expect WriteLine("") to emit a blank line.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Clarifies ZeroC.CodeBuilder.CodeBlock whitespace-suppression semantics so callers understand when “empty” writes/blocks are ignored and how final vertical whitespace is normalized.

Changes:

  • Documented AddBlock behavior when adding empty blocks and how ToString normalizes vertical whitespace.
  • Documented WriteLine behavior for empty/whitespace-only input (no-op via Write) and referenced ToString blank-line collapsing.

Comment on lines +49 to +51
/// <remarks>Adding an empty <see cref="CodeBlock"/> has no effect — no phantom blank-line gap is
/// inserted. The vertical whitespace between non-empty blocks is normalized by <see cref="ToString"/>,
/// which collapses runs of blank lines to at most one.</remarks>
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The remark says adding an empty CodeBlock has no effect, but AddBlock will also effectively ignore blocks that contain only whitespace because interpolation calls CodeBlock.ToString(), which trims whitespace-only lines to empty. Consider clarifying that "empty" here includes whitespace-only content (and may differ from IsEmpty).

Suggested change
/// <remarks>Adding an empty <see cref="CodeBlock"/> has no effect — no phantom blank-line gap is
/// inserted. The vertical whitespace between non-empty blocks is normalized by <see cref="ToString"/>,
/// which collapses runs of blank lines to at most one.</remarks>
/// <remarks>Adding a <see cref="CodeBlock"/> whose rendered content is empty has no effect — no
/// phantom blank-line gap is inserted. This includes blocks that contain only whitespace, because
/// interpolation calls <see cref="ToString"/>, which normalizes such content to empty; this may
/// differ from <see cref="IsEmpty"/>. The vertical whitespace between non-empty blocks is also
/// normalized by <see cref="ToString"/>, which collapses runs of blank lines to at most one.</remarks>

Copilot uses AI. Check for mistakes.
/// that may be empty without producing stray blank lines (for example
/// <c>WriteLine($" {body.Indent()}")</c> when <c>body</c> is empty). Vertical whitespace in the
/// final output is managed by <see cref="ToString"/>, which collapses runs of blank lines to at
/// most one.</remarks>
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The remarks refer to ToString collapsing runs of blank lines, but ToString also trims leading/trailing whitespace (including newlines) from the final output. If callers might rely on leading/trailing blank lines being preserved, it may be worth calling out the Trim behavior explicitly in the docs.

Suggested change
/// most one.</remarks>
/// most one and trims leading and trailing whitespace, including leading and trailing newlines.</remarks>

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@externl externl left a comment

Choose a reason for hiding this comment

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

Looks good!

@pepone pepone merged commit 1664a66 into icerpc:main Apr 29, 2026
14 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.

3 participants