-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix #endregion indentation when followed by labels #81200
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
Conversation
Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
| } | ||
| """); | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76168")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a48ed5b
...aredUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/CSharpTriviaFormatter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
|
|
||
| // Use the maximum to handle cases where #endregion is in a deeper scope than #region | ||
| var indentation = Math.Max(regionIndentation, defaultIndentation); | ||
| return LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines, indentation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot i don't understand why we need to use this 'maximum' concept? i think it would suffice to always align the #endregion with the #region.
if there is a case that makes you think your logic is correct, then please add a test demonstrating why that's teh desirable behavior. Otherwise, simplify this.
Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
Fix #endregion indentation when followed by labels
Plan
#endregiondirective improperly indented when followed by a label #75919)Issue
When a
#endregiondirective is followed by a label, the formatter incorrectly indents the#endregionto the same level as the label, instead of matching the indentation of the corresponding#regiondirective.Root Cause
The formatter was using "default indentation" for
#regionand#endregiondirectives. This default indentation is calculated based on the position where the directive appears, which can be influenced by the following token. When a label follows#endregion, the formatter's indentation calculation is affected by the label's reduced indentation, causing#endregionto be incorrectly indented.Solution
Modified
CSharpTriviaFormatter.GetLineColumnRuleBetween()to:#endregiondirectives, find the matching#regionusingGetMatchingDirective()#endregionwith its matching#regionindentationThis ensures
#endregionalways aligns with its matching#region, preventing labels or other following constructs from incorrectly influencing the indentation. This provides consistent and predictable behavior.Testing
EndRegionFollowedByLabeldemonstrating the fix ✅Fixes #75919
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.