Skip to content

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #79584

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 25, 2025 10:52
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

c

/// or follows, then we expand to consume at least the full span of the <paramref name="firstToken"/> and
/// <paramref name="lastToken"/> so that we at least will try to format any trivia on them.
/// </summary>
internal static TextSpan GetSpanIncludingPreviousAndNextTokens(SyntaxToken firstToken, SyntaxToken lastToken)
Copy link
Member Author

Choose a reason for hiding this comment

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

the thing we're fixing is that we injected a final } into the file with an elastic-cr-lf (this is good).

However, the formatting engine wasn't ever fixing up that elastic-cr-lf because the code below effectively said "only format up to the exact end of the }, no further". This was happening because we normally try to find the 'next' token after the last touched token and format through that. But in this case, there is no next token (it's the last token in the file). So the fix is in that case to consider up through the full end of the token (which includes the trailing trivia) so we will update that properly.

@@ -2125,7 +2125,6 @@ public override void AbstractMethod()
throw new System.NotImplementedException();
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Is this because we are handling InsertFinalNewLine correctly now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

@@ -271,7 +269,7 @@ void Method()
}
}
}
</Document>
</Document>
Copy link
Member

Choose a reason for hiding this comment

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

What caused this indentation change?

Copy link
Member Author

Choose a reason for hiding this comment

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

The doc is getting formatted, and tha tcleans up the errant final whitespace we weren't touching before.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge July 25, 2025 14:21
@CyrusNajmabadi CyrusNajmabadi merged commit 7b6d22d into dotnet:main Jul 25, 2025
24 of 25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the lastTokenFormatting branch July 25, 2025 14:43
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 25, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Implement Interface" code generation does not respect editorconfig line endings in some scenarios.
4 participants