Skip to content

Commit

Permalink
Initial quick fix for interpolated verbatim strings with comments in …
Browse files Browse the repository at this point in the history
…expression

closes #679
  • Loading branch information
belav committed Jun 6, 2022
1 parent 071dd07 commit fc6a190
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Src/CSharpier.FakeGenerators/Ignored.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public static class Ignored
{ typeof(IndexerDeclarationSyntax), new[] { "semicolon" } },
{ typeof(SyntaxTrivia), new[] { "token" } },
{ typeof(SyntaxToken), new[] { "value", "valueText" } },
{ typeof(ParameterSyntax), new[] { "exclamationExclamationToken" } }
{ typeof(ParameterSyntax), new[] { "exclamationExclamationToken" } },
{ typeof(ConversionOperatorDeclarationSyntax), new[] { "checkedKeyword" } },
{ typeof(OperatorDeclarationSyntax), new[] { "checkedKeyword" } },
{ typeof(ConversionOperatorMemberCrefSyntax), new[] { "checkedKeyword" } },
{ typeof(OperatorMemberCrefSyntax), new[] { "checkedKeyword" } }
};

public static readonly HashSet<string> UnsupportedNodes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ public static Doc Print(InterpolatedStringExpressionSyntax node, FormattingConte
docs.AddRange(node.Contents.Select(o => Node.Print(o, context)));
docs.Add(Token.Print(node.StringEndToken, context));

if (
node.StringStartToken.RawSyntaxKind() is SyntaxKind.InterpolatedVerbatimStringStartToken
)
{
return Doc.Concat(docs);
}

return Doc.Concat(
// pull out the leading trivia so it doesn't get forced flat
Token.PrintLeadingTrivia(node.StringStartToken, context),
Doc.ForceFlat(docs)
node.StringStartToken.RawSyntaxKind() is SyntaxKind.InterpolatedVerbatimStringStartToken
? Doc.Concat(docs)
: Doc.ForceFlat(docs)
);
}
}

0 comments on commit fc6a190

Please sign in to comment.