Skip to content

Commit

Permalink
fix extra space being added in invocation that is inside verbatim str…
Browse files Browse the repository at this point in the history
…ing literal that has line breaks

closes #1358
  • Loading branch information
belav committed Nov 3, 2024
1 parent 9475d2f commit 893b8aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,9 @@ SomeVerbatimString
SomeVerbatimString
".CallMethod().CallMethod().CallMethod()
);

var someStringWithLineBreakAndLongValue =
$@"
{someValue.GetValue().Name} someLongText________________________________________________________________";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@ public static Doc PrintMemberChain(ExpressionSyntax node, FormattingContext cont
var cutoff = shouldMergeFirstTwoGroups ? 3 : 2;

var forceOneLine =
groups.Count <= cutoff
&& (
groups
.Skip(shouldMergeFirstTwoGroups ? 1 : 0)
.Any(o =>
o.Last().Node
is not (
InvocationExpressionSyntax
or ElementAccessExpressionSyntax
or PostfixUnaryExpressionSyntax
{
Operand: InvocationExpressionSyntax
}
)
(
groups.Count <= cutoff
&& (
groups
.Skip(shouldMergeFirstTwoGroups ? 1 : 0)
.Any(o =>
o.Last().Node
is not (
InvocationExpressionSyntax
or ElementAccessExpressionSyntax
or PostfixUnaryExpressionSyntax
{
Operand: InvocationExpressionSyntax
}
)
)
// if the last group contains just a !, make sure it doesn't end up on a new line
|| (
groups.Last().Count == 1
&& groups.Last()[0].Node is PostfixUnaryExpressionSyntax
)
// if the last group contains just a !, make sure it doesn't end up on a new line
|| (
groups.Last().Count == 1
&& groups.Last()[0].Node is PostfixUnaryExpressionSyntax
)
);

if (
forceOneLine
)
|| node.HasParent(typeof(InterpolatedStringExpressionSyntax))
// this handles the case of a multiline string being part of an invocation chain
// conditional groups don't propagate breaks so we need to avoid the conditional group
|| groups[0]
Expand All @@ -78,8 +78,9 @@ is LiteralExpressionSyntax
Token.Text.Length: > 0
} literalExpressionSyntax
&& literalExpressionSyntax.Token.Text.Contains('\n')
)
)
);

if (forceOneLine)
{
return Doc.Group(oneLine);
}
Expand Down

0 comments on commit 893b8aa

Please sign in to comment.