Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with disappearing newlines after multiline documentation comment #77521

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dgounaris
Copy link

@dgounaris dgounaris commented Mar 11, 2025

This PR fixes #76856, where multi-line doc comments ending in a newline would have the newline disappearing afterwards.

Based on my investigation, the situation can be described as follows:

  • The structured multiline comment token does not contain the newline by itself, and the normalizer's loop for RewriteTrivia skips newline tokens.
  • NeedsLineBreakAfter call can't be the target for this fix, because not every comment needs a new line after it. Wider context is needed.
  • EndsInLineBreak can be true for the doc token in cases where in reality the documentation end token is the ending token, due to the 0 width of the EndOfDocumentationCommentToken type.

The proposed fix adds a linebreak if the leading SyntaxToken is a multiline documentation ending in linebreak, and forces it to be retained during rewriting by slightly modifying EndsInLineBreak too.

As this is my first time contributing, let me know if I have not grasped the codebase correctly and there is a cleaner way to apply this.

@dgounaris dgounaris requested a review from a team as a code owner March 11, 2025 12:05
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 11, 2025
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 11, 2025
@dgounaris
Copy link
Author

@dotnet-policy-service agree

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

One small comment, otherwise LGTM.

@333fred
Copy link
Member

333fred commented Mar 11, 2025

@dgounaris can you update your comment to specifically say "fixes <issue>", so that github picks this up as actually fixing the issue? "Fixes the issue described at <issue>" doesn't do the trick.

@dgounaris
Copy link
Author

@333fred Thanks for the review, addressed the comments, feel free to have a look.

@dgounaris dgounaris requested a review from 333fred March 13, 2025 09:38
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

@dotnet/roslyn-compiler for a second review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NormalizeWhitespace breaks multi-line comments
2 participants