Skip to content

Commit

Permalink
Fix issue with eating comments on raw literals with c# that has new l…
Browse files Browse the repository at this point in the history
…ines

closes #937
  • Loading branch information
belav committed Aug 23, 2023
1 parent 81b6789 commit f74c01c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,18 @@ four
} ";

ReadOnlySpan<byte> utf8StringLiteral = "hello"u8;

var rawLiteralWithExpressionThatWeDontFormat = new StringContent(
// this comment shouldn't go away
$$"""
{
"params": "{{searchFilter switch
{
SearchFilter.Video => "EgIQAQ%3D%3D",
_ => null
}}}"
}
"""
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public static Doc Print(InterpolatedStringExpressionSyntax node, FormattingConte
// and new lines in expressions in them are rare.
if (node.Contents.Any(o => o is InterpolationSyntax && o.ToString().Contains('\n')))
{
return node.ToString();
return Doc.Concat(
Token.PrintLeadingTrivia(node.GetLeadingTrivia(), context),
node.ToString()
);
}

var docs = new List<Doc>
Expand Down

0 comments on commit f74c01c

Please sign in to comment.