-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Make sure Sort Usings uses the current line endings #19306
Comments
DefaultOptions.NewLineCharacterOptionId or IEditorOperations.InsertNewLine() are the only correct ways to insert a new line. Interestingly I think Roslyn already only using these, that was done as part of editorconfig support. They are exposed to users via .editorconfig. |
Cool. I think we just need to hook |
We're not likely to get to this before 15.3, but we'd welcome a PR if one appeared :-) |
@Pilchie We have other places I'm pretty sure we use either Environment.NewLine or (worse) crlf directly. Not hard bugs, but would require a test pass. |
Curious, @KirillOsenkov are you seeing this more now with VS for Mac scenarios? Wondering if we should toss it into that bucket. |
I'm seeing this during regular Roslyn dogfooding, our codebase uses \n and \r\n inserted by Roslyn are very apparent. |
OK, good to know. @jinujoseph we may need to prioritize this now that cross-plat is actually a thing we care about. |
roslyn/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs Line 58 in 50b3caa
roslyn/src/VisualStudio/Core/Def/Implementation/Options/LanguageSettingsPersister.cs Lines 84 to 95 in 50b3caa
roslyn/src/EditorFeatures/Core/Shared/Extensions/InferredIndentationExtensions.cs Lines 18 to 38 in 918f670
|
Note that Roslyn implements a formatting pass after the application of a code fix or refactoring. During this pass, elastic nodes and nodes marked with the formatter annotation will be updated to use the correct line endings. Individual code generation features should not need to worry about the line endings in the current file, as the code action infrastructure is required to account for them automatically. |
The formatting pass already handles newlines correctly for elastic trivia. The imports organizer intentionally use non-elastic trivia to retain control over the number of newline characters appearing in the result. I'm preparing a pull request to update this feature to use the correct line ending. |
* Add diags to help us diagnose lightbulb issues better * Use correct line endings when sorting imports Fixes #19306 * Binder.CreateConversion - Report use-site diagnostics for the entire conversion hierarchy. (#57175) * Merge pull request #57367 from dotnet/dev/rigibson/snap-17.1p1 * Compute val escape for extended property patterns (#57211) Co-authored-by: Cyrus Najmabadi <cyrusn@microsoft.com> Co-authored-by: Sam Harwell <Sam.Harwell@microsoft.com> Co-authored-by: AlekseyTs <AlekseyTs@users.noreply.github.com> Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com> Co-authored-by: Rikki Gibson <rigibson@microsoft.com> Co-authored-by: Alireza Habibi <habibi.alireza@outlook.com>
I've noticed that IDE features such as Sort Usings will use a fixed line ending (Environment.NewLine?) when they need to generate a line break. This creates a problem in a file that uses LF for line endings.
The Editor has options for this:
DefaultOptions.NewLineCharacterOptionId
andDefaultOptions.ReplicateNewLineCharacterOptionId
. Not sure whether the editor exposes these to the user in some way (and if not, we should work with the editor to expose them).But in any case respecting these options would be nice. Ideally inferring the line endings setting from the file and using that.
The text was updated successfully, but these errors were encountered: