Skip to content

Commit

Permalink
Added breaking and tab logic to parameter when attribute is involved
Browse files Browse the repository at this point in the history
  • Loading branch information
bmf-bracer committed Jun 20, 2021
1 parent 38578ea commit 5583107
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
# Jetbrains doesn't say to ignore these, but it seems like they shouldn't be committed
**/.idea/**/watcherTasks.xml

.vscode

node_modules
bin
obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class ClassName

public void MethodName(
int someParameter,
[LongAttributeName(SomeFlag.SomeValue)]
AnotherObject anotherObject
[ShortAttributeName] AnotherObject anotherObject,
[VeryLongAttributeName(SomeFlag.SomeValue, SomeOtherFlag.SomeOtherLongValue)]
string tabbedBreakParameter,
bool anotherParameter
) {
return;
}
Expand Down
25 changes: 19 additions & 6 deletions Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/Parameter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using CSharpier.DocTypes;
using CSharpier.SyntaxPrinter;
using CSharpier.Utilities;
using Microsoft.CodeAnalysis.CSharp.Syntax;

Expand All @@ -10,24 +10,37 @@ public static class Parameter
{
public static Doc Print(ParameterSyntax node)
{
var hasAttribute = node.AttributeLists.Any();
var groupId = hasAttribute ? Guid.NewGuid().ToString() : string.Empty;
var docs = new List<Doc>
{
AttributeLists.Print(node, node.AttributeLists),
node.AttributeLists.Any() ? Doc.Line : Doc.Null,
hasAttribute ? Doc.IndentIfBreak(Doc.Line, groupId) : Doc.Null,
Modifiers.Print(node.Modifiers)
};

var paramDocs = new List<Doc>();
if (node.Type != null)
{
docs.Add(Node.Print(node.Type), " ");
paramDocs.Add(Node.Print(node.Type), " ");
}

docs.Add(Token.Print(node.Identifier));
paramDocs.Add(Token.Print(node.Identifier));
if (node.Default != null)
{
docs.Add(EqualsValueClause.Print(node.Default));
paramDocs.Add(EqualsValueClause.Print(node.Default));
}

return Doc.Concat(docs);
if (hasAttribute)
{
docs.Add(Doc.Concat(paramDocs));
return Doc.Concat(Doc.GroupWithId(groupId, docs.ToArray()));
}
else
{
docs.AddRange(paramDocs);
return Doc.Concat(docs);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CSharpier.DocTypes;
using CSharpier.SyntaxPrinter;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace CSharpier.SyntaxPrinter.SyntaxNodePrinters
Expand Down

0 comments on commit 5583107

Please sign in to comment.