Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ZeroC.CodeBuilder/CodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public CodeBlock()

/// <summary>Adds another code block to this one, separated by newlines.</summary>
/// <param name="block">The block to add.</param>
/// <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>
Comment on lines +49 to +51
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.
public void AddBlock(CodeBlock block) => Write($"\n{block}\n");

/// <summary>Creates a new code block with the content indented by 4 spaces.</summary>
Expand Down Expand Up @@ -103,5 +106,11 @@ public void Write(string value)

/// <summary>Writes the specified value followed by a newline to the code block.</summary>
/// <param name="value">The value to write.</param>
/// <remarks><see cref="Write"/> drops empty and whitespace-only strings, so <c>WriteLine("")</c>
/// and <c>WriteLine(" ")</c> are no-ops. This is intentional: it lets callers interpolate values
/// 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.
public void WriteLine(string value) => Write($"{value}\n");
}
Loading