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.1k stars 4.04k forks source link

C# Extract Method refactoring does not adhere to editorconfig settings for line endings #67711

Open vsfeedback opened 1 year ago

vsfeedback commented 1 year ago

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] If you select some code (in C#, Javascript or Typescript) and use one of the refactoring helper functions which would extract the code and add any new lines would not adhere to the editorconfig settings which may be set to LF, instead the new lines are added as CRLF which causes mixed line ending issues.


Original Comments

Feedback Bot on 8/22/2022, 09:51 PM:

(private comment, text removed)

Feedback Bot on 12/1/2022, 00:55 AM:

(private comment, text removed)

Sam Harwell on 4/10/2023, 09:31 AM:

Hi Dan Petitt,

Note that every refactoring is responsible for its own behavior. Based on the recording provided, I’ve narrowed this issue to specifically refer to the behavior of the C# Extract Method refactoring and assigned it to that team.

Thank you,
Sam Harwell


Original Solutions

(no solutions)

sharwell commented 1 year ago

📝 note that the code refactoring infrastructure automatically adjusts line endings by default. If the refactoring is producing mixed line endings, it means the refactorings has produced code changes that explicitly removed the elastic and formatting annotations to instruct the infrastructure to not alter the specific contents of the change, even if those changes fail to adhere to the style. When fixing this issue, the best place to start is a new parameterized unit test that runs the same refactoring on a source file, once with the file set to LF line endings and a second time with the file set to CRLF line endings. When fixing this issue, note the following: