dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.05k stars 4.03k forks source link

Make SyntaxNodeExtensions.RemoveNode end of line configurable #22924

Closed maca88 closed 5 years ago

maca88 commented 7 years ago

Version Used: 2.4.0

Currently, the EOL that may be added by RemoveNode or RemoveNodes is CRLF and cannot be changed. By making the EOL configurable, we would be able to preserve the EOL of the original document, as we could do it with NormalizeWhitespace.

jcouv commented 7 years ago

Tagging @gafter @DustinCampbell for thoughts on this request.

CyrusNajmabadi commented 7 years ago

When does RemoveNode add an EOF? Why is RemoveNode ever adding anything?

maca88 commented 7 years ago

When does RemoveNode add an EOF?

One example that occurred to me is when KeepUnbalancedDirectives option is used. In this unit test an EOL is added before #region Fred.

By changing the NormalizeLineEndings method to replace all CRLF EOL with LF then the cu variable prior the RemoveNode call is:

\nclass C\n{\n// before\n#region Fred\n// more before\nvoid M()\n{\n} // after\n#endregion\n}

and after RemoveNode call cu2 is:

\nclass C\n{\n\r\n#region Fred\n#endregion\n}
CyrusNajmabadi commented 7 years ago

Oh. I misread. I thought it was EOF, not EOL. Yes. EOL should be configurable. SyntaxRemoveOptions would be a good place to put this info.

gafter commented 5 years ago

Fixed in https://github.com/dotnet/roslyn/pull/23165