Skip to content

Use platform newline for C# elastic syntax facts#84407

Draft
mwiemer-microsoft wants to merge 1 commit into
mainfrom
copilot/csharp-syntaxfacts-platform-newline
Draft

Use platform newline for C# elastic syntax facts#84407
mwiemer-microsoft wants to merge 1 commit into
mainfrom
copilot/csharp-syntaxfacts-platform-newline

Conversation

@mwiemer-microsoft

@mwiemer-microsoft mwiemer-microsoft commented Jul 6, 2026

Copy link
Copy Markdown
Member

Extracted from #84347 as a small, reviewable slice.\n\nThis updates the C# syntax facts service so its default elastic end-of-line trivia uses the current platform newline instead of hard-coded CRLF. This is one of the lower-level pieces needed before broader code-action/refactoring line-ending preservation work.\n\nValidation:\n- dotnet test src\Workspaces\CSharpTest\Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests.csproj --filter FullyQualifiedName~CSharpSyntaxFactsServiceTests

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@JoeRobich JoeRobich left a comment

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.

Should we update VB similarly.


public SyntaxTrivia ElasticCarriageReturnLineFeed
=> SyntaxFactory.ElasticCarriageReturnLineFeed;
=> SyntaxFactory.ElasticEndOfLine(Environment.NewLine);

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.

I would prefer you rename this to ElasticNewLine or similar.

@CyrusNajmabadi

Copy link
Copy Markdown
Contributor

This change is not correct and violates the documentation of ISyntaxFacts.

Do not do this:

public SyntaxTrivia ElasticCarriageReturnLineFeed
        => SyntaxFactory.ElasticCarriageReturnLineFeed;
        => SyntaxFactory.ElasticEndOfLine(Environment.NewLine);

The point if the property is to give you the elastic CRLF for VB or C#. It is not too give you an EOL. Let alone an ENV EOL.

This also violates many Roslyn design envariants (like being isolated from the surrounding environment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants