-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix switch indentation for list patterns #75953
base: main
Are you sure you want to change the base?
Conversation
d575e61
to
33c85a2
Compare
33c85a2
to
cd5a93b
Compare
@@ -5605,6 +5605,34 @@ public object Method(int i) | |||
await AssertFormatAsync(expectedCode, code); | |||
} | |||
|
|||
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72196")] | |||
public async Task FormatSwitchExpression_ListPatternAligned() | |||
{ |
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.
can you please use 'raw string literals' for test cases. There is a code refactoring to fix this up btw.
@@ -262,6 +262,11 @@ private static void AddBracketIndentationOperation(List<IndentBlockOperation> li | |||
// Brackets in list patterns are formatted like blocks, so align close bracket with open bracket | |||
AddIndentBlockOperation(list, bracketPair.openBracket.GetNextToken(includeZeroWidth: true), bracketPair.closeBracket.GetPreviousToken(includeZeroWidth: true)); | |||
|
|||
if (IsSwitchExpressionPattern(node)) |
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.
this needs a 'why' explanation as to why we don't want to execute teh rest of the code if we hit such a thing.
@@ -279,6 +284,11 @@ private static void AddBracketIndentationOperation(List<IndentBlockOperation> li | |||
} | |||
} | |||
|
|||
private static bool IsSwitchExpressionPattern(SyntaxNode node) |
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.
nit: i would personally inline this. It's only called in one place, and has very simple logic. If you do want to keep this as a helper method, that's ok.
--
"nits" are ideas/gentle-suggestions. But i'm deferring to your judgement here on what you prefer.
The indentation of a list pattern or collection expression is (according to pre-existing comment in the adjusted method) "relative to the start of the line the prior token is on if we're on the same line as it." However, the code was missing a check for the two tokens being on the same line.