Skip to content

Commit c1e0521

Browse files
committed
Make valueListBuilder easier to use and to debug
1 parent 0fa83b7 commit c1e0521

29 files changed

+220
-62
lines changed

Src/CSharpier.Core/CSharp/SyntaxPrinter/AttributeLists.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ PrintingContext context
1919
return Doc.Null;
2020
}
2121

22-
var docs = new ValueListBuilder<Doc>([null, null]);
22+
var docs = new DocListBuilder(2);
2323
Doc separator = node
2424
is TypeParameterSyntax
2525
or ParameterSyntax

Src/CSharpier.Core/CSharp/SyntaxPrinter/CSharpierIgnore.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ PrintingContext context
7373
where T : SyntaxNode
7474
{
7575
var statements = new List<Doc>();
76-
var unFormattedCode = new ValueListBuilder<char>(stackalloc char[64]);
76+
var unFormattedCode = new StringBuilder();
7777
var printUnformatted = false;
7878

7979
foreach (var node in list)
8080
{
8181
if (Token.HasLeadingCommentMatching(node, IgnoreEndRegex))
8282
{
83-
statements.Add(unFormattedCode.AsSpan().Trim().ToString());
83+
statements.Add(unFormattedCode.ToString().Trim());
8484
unFormattedCode.Clear();
8585
printUnformatted = false;
8686
}
@@ -101,11 +101,9 @@ PrintingContext context
101101

102102
if (unFormattedCode.Length > 0)
103103
{
104-
statements.Add(unFormattedCode.AsSpan().Trim().ToString());
104+
statements.Add(unFormattedCode.ToString().Trim());
105105
}
106106

107-
unFormattedCode.Dispose();
108-
109107
return statements;
110108
}
111109

Src/CSharpier.Core/CSharp/SyntaxPrinter/MembersWithForcedLines.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static List<Doc> Print<T>(
2626
result.Add(Doc.HardLine);
2727
}
2828

29-
var unFormattedCode = new ValueListBuilder<char>(stackalloc char[64]);
29+
var unFormattedCode = new StringBuilder();
3030
var printUnformatted = false;
3131
var lastMemberForcedBlankLine = false;
3232
for (var memberIndex = 0; memberIndex < members.Count; memberIndex++)
@@ -37,7 +37,7 @@ public static List<Doc> Print<T>(
3737
if (Token.HasLeadingCommentMatching(member, CSharpierIgnore.IgnoreEndRegex))
3838
{
3939
skipAddingLineBecauseIgnoreEnded = true;
40-
result.Add(unFormattedCode.AsSpan().Trim().ToString());
40+
result.Add(unFormattedCode.ToString().Trim());
4141
unFormattedCode.Clear();
4242
printUnformatted = false;
4343
}
@@ -231,11 +231,9 @@ or SyntaxKind.EndRegionDirectiveTrivia
231231

232232
if (unFormattedCode.Length > 0)
233233
{
234-
result.Add(unFormattedCode.AsSpan().ToString().Trim());
234+
result.Add(unFormattedCode.ToString().Trim());
235235
}
236236

237-
unFormattedCode.Dispose();
238-
239237
return result;
240238
}
241239
}

Src/CSharpier.Core/CSharp/SyntaxPrinter/SeparatedSyntaxList.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,16 @@ private static Doc Print<T>(
4646
)
4747
where T : SyntaxNode
4848
{
49-
var docs =
50-
list.Count <= 3
51-
? new ValueListBuilder<Doc>([null, null, null, null, null, null, null, null])
52-
: new ValueListBuilder<Doc>(list.Count * 3);
53-
var unFormattedCode = new ValueListBuilder<char>(stackalloc char[64]);
49+
var docs = list.Count <= 3 ? new DocListBuilder(8) : new DocListBuilder(list.Count * 3);
50+
var unFormattedCode = new StringBuilder();
5451
var printUnformatted = false;
5552
for (var x = startingIndex; x < list.Count; x++)
5653
{
5754
var member = list[x];
5855

5956
if (Token.HasLeadingCommentMatching(member, CSharpierIgnore.IgnoreEndRegex))
6057
{
61-
docs.Add(unFormattedCode.AsSpan().Trim().ToString());
58+
docs.Add(unFormattedCode.ToString().Trim());
6259
unFormattedCode.Clear();
6360
printUnformatted = false;
6461
}
@@ -147,11 +144,10 @@ private static Doc Print<T>(
147144

148145
if (unFormattedCode.Length > 0)
149146
{
150-
docs.Add(unFormattedCode.AsSpan().Trim().ToString());
147+
docs.Add(unFormattedCode.ToString().Trim());
151148
}
152149

153150
var output = Doc.Concat(ref docs);
154-
unFormattedCode.Dispose();
155151
docs.Dispose();
156152

157153
return output;

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/AnonymousMethodExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static class AnonymousMethodExpression
88
{
99
public static Doc Print(AnonymousMethodExpressionSyntax node, PrintingContext context)
1010
{
11-
var docs = new ValueListBuilder<Doc>([null, null, null, null]);
11+
var docs = new DocListBuilder(4);
1212
docs.Add(Modifiers.Print(node.Modifiers, context));
1313
docs.Add(Token.Print(node.DelegateKeyword, context));
1414

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/AnonymousObjectMemberDeclarator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static class AnonymousObjectMemberDeclarator
88
{
99
public static Doc Print(AnonymousObjectMemberDeclaratorSyntax node, PrintingContext context)
1010
{
11-
var docs = new ValueListBuilder<Doc>([null, null, null, null]);
11+
var docs = new DocListBuilder(4);
1212
if (
1313
node.Parent is AnonymousObjectCreationExpressionSyntax parent
1414
&& node != parent.Initializers.First()

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/Argument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static Doc Print(ArgumentSyntax node, PrintingContext context)
1414

1515
public static Doc PrintModifiers(ArgumentSyntax node, PrintingContext context)
1616
{
17-
var docs = new ValueListBuilder<Doc>([null, null]);
17+
var docs = new DocListBuilder(2);
1818
if (node.NameColon != null)
1919
{
2020
docs.Add(BaseExpressionColon.Print(node.NameColon, context));

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/AttributeList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static Doc Print(AttributeListSyntax node, PrintingContext context)
1313
return CSharpierIgnore.PrintWithoutFormatting(node, context).Trim();
1414
}
1515

16-
var docs = new ValueListBuilder<Doc>([null, null, null, null, null, null, null]);
16+
var docs = new DocListBuilder(8);
1717
if (
1818
node.Parent is CompilationUnitSyntax compilationUnitSyntax
1919
&& compilationUnitSyntax.AttributeLists.First() != node

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/BaseFieldDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static class BaseFieldDeclaration
88
{
99
public static Doc Print(BaseFieldDeclarationSyntax node, PrintingContext context)
1010
{
11-
var docs = new ValueListBuilder<Doc>([null, null, null, null, null]);
11+
var docs = new DocListBuilder(5);
1212
docs.Add(AttributeLists.Print(node, node.AttributeLists, context));
1313
docs.Add(Modifiers.PrintSorted(node.Modifiers, context));
1414
if (node is EventFieldDeclarationSyntax eventFieldDeclarationSyntax)

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/BasePropertyDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static Doc PrintAccessorDeclarationSyntax(
115115
PrintingContext context
116116
)
117117
{
118-
var docs = new ValueListBuilder<Doc>([null, null, null, null, null, null]);
118+
var docs = new DocListBuilder(6);
119119
if (
120120
node.AttributeLists.Count > 1
121121
|| node.Body != null

0 commit comments

Comments
 (0)