Skip to content

Commit

Permalink
Extract getting indentation from multiline statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm2 committed Dec 29, 2024
1 parent 619c525 commit 3bf6824
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,8 @@ private static bool IsPartOfQueryExpression(SyntaxToken token)
return queryExpression != null;
}

private static IndentationResult GetDefaultIndentationFromTokenLine(Indenter indenter, SyntaxToken token)
private static IndentationResult? TryGetIndentationFromMultilineStatement(Indenter indenter, SyntaxToken token)
{
// find containing non expression node
var nonExpressionNode = token.GetAncestors<SyntaxNode>().FirstOrDefault(n => n is StatementSyntax);
if (nonExpressionNode != null)
{
Expand All @@ -484,7 +483,16 @@ private static IndentationResult GetDefaultIndentationFromTokenLine(Indenter ind
}
}

// well, I can't find any non expression node. use default behavior
return null;
}

private static IndentationResult GetDefaultIndentationFromTokenLine(Indenter indenter, SyntaxToken token)
{
if (TryGetIndentationFromMultilineStatement(indenter, token) is { } result)
{
return result;
}

var position = indenter.GetCurrentPositionNotBelongToEndOfFileToken(indenter.LineToBeIndented.Start);

var spaceToAdd = indenter.Options.FormattingOptions.IndentationSize;
Expand Down

0 comments on commit 3bf6824

Please sign in to comment.