Skip to content

Commit 42622cd

Browse files
authored
fix extra space being added in invocation that is inside verbatim str… (#1373)
…ing literal that has line breaks closes #1358
1 parent 9475d2f commit 42622cd

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/StringLiterals.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,9 @@ SomeVerbatimString
183183
SomeVerbatimString
184184
".CallMethod().CallMethod().CallMethod()
185185
);
186+
187+
var someStringWithLineBreakAndLongValue =
188+
$@"
189+
{someValue.GetValue().Name} someLongText________________________________________________________________";
186190
}
187191
}

Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,30 @@ public static Doc PrintMemberChain(ExpressionSyntax node, FormattingContext cont
3434
var cutoff = shouldMergeFirstTwoGroups ? 3 : 2;
3535

3636
var forceOneLine =
37-
groups.Count <= cutoff
38-
&& (
39-
groups
40-
.Skip(shouldMergeFirstTwoGroups ? 1 : 0)
41-
.Any(o =>
42-
o.Last().Node
43-
is not (
44-
InvocationExpressionSyntax
45-
or ElementAccessExpressionSyntax
46-
or PostfixUnaryExpressionSyntax
47-
{
48-
Operand: InvocationExpressionSyntax
49-
}
50-
)
37+
(
38+
groups.Count <= cutoff
39+
&& (
40+
groups
41+
.Skip(shouldMergeFirstTwoGroups ? 1 : 0)
42+
.Any(o =>
43+
o.Last().Node
44+
is not (
45+
InvocationExpressionSyntax
46+
or ElementAccessExpressionSyntax
47+
or PostfixUnaryExpressionSyntax
48+
{
49+
Operand: InvocationExpressionSyntax
50+
}
51+
)
52+
)
53+
// if the last group contains just a !, make sure it doesn't end up on a new line
54+
|| (
55+
groups.Last().Count == 1
56+
&& groups.Last()[0].Node is PostfixUnaryExpressionSyntax
5157
)
52-
// if the last group contains just a !, make sure it doesn't end up on a new line
53-
|| (
54-
groups.Last().Count == 1
55-
&& groups.Last()[0].Node is PostfixUnaryExpressionSyntax
5658
)
57-
);
58-
59-
if (
60-
forceOneLine
59+
)
60+
|| node.HasParent(typeof(InterpolatedStringExpressionSyntax))
6161
// this handles the case of a multiline string being part of an invocation chain
6262
// conditional groups don't propagate breaks so we need to avoid the conditional group
6363
|| groups[0]
@@ -78,8 +78,9 @@ is LiteralExpressionSyntax
7878
Token.Text.Length: > 0
7979
} literalExpressionSyntax
8080
&& literalExpressionSyntax.Token.Text.Contains('\n')
81-
)
82-
)
81+
);
82+
83+
if (forceOneLine)
8384
{
8485
return Doc.Group(oneLine);
8586
}

0 commit comments

Comments
 (0)