Skip to content

[APIView] Fix excess whitespace in Copilot-generated comments (#15421)#15528

Open
helen229 wants to merge 8 commits intomainfrom
fix/15421-copilot-comment-whitespace
Open

[APIView] Fix excess whitespace in Copilot-generated comments (#15421)#15528
helen229 wants to merge 8 commits intomainfrom
fix/15421-copilot-comment-whitespace

Conversation

@helen229
Copy link
Copy Markdown
Member

@helen229 helen229 commented May 6, 2026

Fixes #15421

Symptom

Copilot-generated APIView comment cards render with two blank lines between the body and the Guidelines heading and a blank line between every guideline link, making cards unnecessarily tall and sparse.

Root cause (two contributing issues)

1. Persisted markdown had extra paragraph separators

CopilotJobProcessor built the persisted CommentItemModel.CommentText markdown with three consecutive AppendLine calls between sections and an extra AppendLine() before each guideline URL:

Optional operation-specific parameters should be keyword-only.\r\n\r\n\r\n
Guidelines\r\n\r\n
https://...\r\n\r\n
https://...\r\n

2. SPA CSS was promoting inter-block newlines into visible blank lines

PR #15251 set .rendered-comment-content { white-space: pre-line; } on the whole comment body so user-typed single newlines inside a paragraph would be preserved. The unintended side effect: the markdown renderer emits literal \n between block elements (e.g. </p>\n<p>, </p>\n<ul>). Under pre-line those newlines are significant and render as visible blank lines on top of the normal <p> margin — the bulk of the gap seen in the issue screenshot.

Fix

Server-side (CopilotJobProcessor.cs)

  • Use a single blank line (one AppendLine()) as the paragraph separator before the Suggestion and **Guidelines** sections.
  • Render guideline links as a markdown bullet list (- https://…) so consecutive links are rendered compactly with no blank line between items.

Client-side (comment-thread.component.scss)

  • Reset .rendered-comment-content to white-space: normal so newlines between block elements collapse instead of rendering as blank lines.
  • Apply white-space: pre-line only to inline-content blocks (p, li, td, th, blockquote) so user-typed single newlines inside a paragraph or list item are still preserved (the original intent of [APIView] Fix comments not retaining line break formatting #15251).

After:
image

…ments

The conversion from AVC results to APIView CommentItemModel emitted three CRLFs (two blank lines) between the comment body and the Suggestion / Guidelines sections, and an extra blank line between each guideline link. In rendered markdown that produced large gaps inside the comment card.

Use a single blank line as a paragraph separator and render guideline links as a markdown bullet list so they render compactly without blank lines between items.
Copilot AI review requested due to automatic review settings May 6, 2026 19:41
Copy link
Copy Markdown
Contributor

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

This PR refines how APIView Copilot job results are converted into persisted CommentItemModel.CommentText markdown, reducing excess blank lines and rendering guideline links more compactly in the UI.

Changes:

  • Removed extra paragraph separators when composing Copilot-generated comment text.
  • Rendered guideline links as a Markdown bullet list to avoid blank lines between consecutive links.

Comment thread src/dotnet/APIView/APIViewWeb/HostedServices/CopilotJobProcessor.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

Please provide a screenshot of a new comment with multiple guidelines cited so we can see what it looks like.

helen229 added 5 commits May 7, 2026 14:50
PR #15251 set .rendered-comment-content to white-space: pre-line so user-typed single newlines inside a paragraph would be preserved. Side effect: newlines between block elements (e.g. </p>\n<p>, </p>\n<ul>) emitted by the markdown renderer are also significant under pre-line and render as visible blank lines, which is the bulk of the extra whitespace seen on Copilot-generated comments (#15421).

Reset the container to white-space: normal and scope pre-line to inline-content blocks (p, li, td, th, blockquote). This collapses inter-block whitespace while still preserving user-typed line breaks inside paragraphs and list items.
Plain markdown blank lines between blocks now collapse under the new SCSS rules. Insert a raw <br/> so a visible gap is preserved between the body/suggestion and the Guidelines list, while the rest of the card stays compact.
A single <br/> only produces one line height. Replacing it with a &nbsp; paragraph gives a real empty <p>&nbsp;</p> with its own height and margin, producing a clearly visible gap before the Guidelines section.
if (commentModel.GuidelineIds.Count > 0)
{
commentText.AppendLine();
commentText.AppendLine("&nbsp;");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do you need &nbsp; in here?? is AppendLine not enough?
I think commentText.AppendLine("<br>"); is a better alternative if AppenLind is not enough

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.

[APIView] Too much whitespace in copilot comments

4 participants