in src/Bicep.Core/PrettyPrintV2/SyntaxLayouts.cs [205:349]
private IEnumerable<Document> LayoutNonNullAssertionSyntax(NonNullAssertionSyntax syntax) =>
this.Glue(syntax.BaseExpression, syntax.AssertionOperator);
private IEnumerable<Document> LayoutNullableTypeSyntax(NullableTypeSyntax syntax) =>
this.Glue(syntax.Base, syntax.NullabilityMarker);
private IEnumerable<Document> LayoutObjectPropertySyntax(ObjectPropertySyntax syntax) =>
this.Spread(
this.Glue(syntax.Key, syntax.Colon),
syntax.Value);
private IEnumerable<Document> LayoutObjectSyntax(ObjectSyntax syntax) =>
this.Bracket(
syntax.OpenBrace,
syntax.Children,
syntax.CloseBrace,
separator: LineOrCommaSpace,
padding: LineOrSpace,
forceBreak:
// Special case for objects: if the object contains a newline before
// the first property, always break the object.
StartsWithNewline(syntax.Children) &&
syntax.Properties.Any());
private IEnumerable<Document> LayoutObjectTypeAdditionalPropertiesSyntax(ObjectTypeAdditionalPropertiesSyntax syntax) =>
this.LayoutLeadingNodes(syntax.LeadingNodes)
.Concat(this.Spread(
this.Glue(syntax.Asterisk, syntax.Colon),
syntax.Value));
private IEnumerable<Document> LayoutObjectTypePropertySyntax(ObjectTypePropertySyntax syntax) =>
this.LayoutLeadingNodes(syntax.LeadingNodes)
.Concat(this.Spread(
this.Glue(syntax.Key, syntax.Colon),
syntax.Value));
private IEnumerable<Document> LayoutObjectTypeSyntax(ObjectTypeSyntax syntax) =>
this.Bracket(
syntax.OpenBrace,
syntax.Children,
syntax.CloseBrace,
separator: LineOrCommaSpace,
padding: LineOrSpace,
forceBreak:
// Special case for object types: if it contains a newline before
// the first property, always break the the object.
StartsWithNewline(syntax.Children) &&
syntax.Children.Any(x => x is ObjectTypePropertySyntax or ObjectTypeAdditionalPropertiesSyntax));
private IEnumerable<Document> LayoutOutputDeclarationSyntax(OutputDeclarationSyntax syntax) =>
this.LayoutLeadingNodes(syntax.LeadingNodes)
.Concat(this.Spread(
syntax.Keyword,
syntax.Name,
syntax.Type,
syntax.Assignment,
syntax.Value));
private IEnumerable<Document> LayoutParameterAssignmentSyntax(ParameterAssignmentSyntax syntax) =>
this.Spread(
syntax.Keyword,
syntax.Name,
syntax.Assignment,
syntax.Value);
private IEnumerable<Document> LayoutParameterDeclarationSyntax(ParameterDeclarationSyntax syntax) =>
this.LayoutLeadingNodes(syntax.LeadingNodes)
.Concat(syntax.Modifier is not null
? this.Spread(syntax.Keyword, syntax.Name, syntax.Type, syntax.Modifier)
: this.Spread(syntax.Keyword, syntax.Name, syntax.Type));
private IEnumerable<Document> LayoutParameterDefaultValueSyntax(ParameterDefaultValueSyntax syntax) =>
this.Spread(
syntax.AssignmentToken,
syntax.DefaultValue);
private IEnumerable<Document> LayoutParenthesizedExpressionSyntax(ParenthesizedExpressionSyntax syntax) =>
this.Glue(
syntax.OpenParen,
syntax.Expression,
syntax.CloseParen);
private IEnumerable<Document> LayoutProgramSyntax(ProgramSyntax syntax) =>
this.LayoutMany(syntax.Children.Append(syntax.EndOfFile))
.TrimNewlines()
.CollapseNewlines()
.SeparatedByNewline();
private IEnumerable<Document> LayoutPropertyAccessSyntax(PropertyAccessSyntax syntax) =>
syntax.SafeAccessMarker is not null
? this.Glue(
syntax.BaseExpression,
syntax.Dot,
syntax.SafeAccessMarker,
syntax.PropertyName)
: this.Glue(
syntax.BaseExpression,
syntax.Dot,
syntax.PropertyName);
private IEnumerable<Document> LayoutResourceAccessSyntax(ResourceAccessSyntax syntax) =>
this.Glue(
syntax.BaseExpression,
syntax.DoubleColon,
syntax.ResourceName);
private IEnumerable<Document> LayoutResourceDeclarationSyntax(ResourceDeclarationSyntax syntax) =>
this.LayoutResourceOrModuleDeclarationSyntax(
syntax.LeadingNodes,
syntax.Keyword,
syntax.Name,
syntax.Type,
syntax.ExistingKeyword,
syntax.Assignment,
syntax.Newlines,
syntax.Value);
private IEnumerable<Document> LayoutResourceOrModuleDeclarationSyntax(
ImmutableArray<SyntaxBase> leadingNodes,
SyntaxBase keyword,
SyntaxBase name,
SyntaxBase typeOrPath,
SyntaxBase? existingKeyword,
SyntaxBase assignment,
ImmutableArray<Token> newlines,
SyntaxBase value)
{
// The parser only allows newlines before between = and the if keyword.
// If there are dangling comments/directives attached to the newlines, we have
// to group the newlines and the IfConditionSyntx to ensure the comments
// are not dropped.
if (value is IfConditionSyntax && newlines.Any(SyntaxFacts.HasCommentOrDirective))
{
var valueGroup = this.IndentGroup(newlines.Append(value));
return this.LayoutLeadingNodes(leadingNodes).Concat(existingKeyword is not null
? this.Spread(keyword, name, typeOrPath, existingKeyword, assignment, valueGroup)
: this.Spread(keyword, name, typeOrPath, assignment, valueGroup));
}
return this.LayoutLeadingNodes(leadingNodes)
.Concat(existingKeyword is not null
? this.Spread(keyword, name, typeOrPath, existingKeyword, assignment, value)
: this.Spread(keyword, name, typeOrPath, assignment, value));
}