Skip to content

Commit

Permalink
feat: non-conditional template constraints styles
Browse files Browse the repository at this point in the history
The non-conditional styles for `dfmt_template_constraint_style` are
supported for now. The conditional ones will require line length
tracking, which is yet to be implmented.

Signed-off-by: Prajwal S N <[email protected]>
  • Loading branch information
snprajwal committed Dec 13, 2023
1 parent 0259887 commit 0897c83
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/dfmt/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -3224,12 +3224,38 @@ extern (C++) class FormatVisitor : SemanticTimeTransitiveVisitor
{
if (!constraint)
return;

final switch (config.dfmt_template_constraint_style)
{
case TemplateConstraintStyle._unspecified:
// Fallthrough to the default case
case TemplateConstraintStyle.conditional_newline_indent:
// This will be updated later on
goto case;
case TemplateConstraintStyle.always_newline_indent:
newline();
depth++;
break;
case TemplateConstraintStyle.conditional_newline:
// This will be updated later on
goto case;
case TemplateConstraintStyle.always_newline:
newline();
break;
}

write(" if");
if (config.dfmt_space_after_keywords)
write(' ');
write('(');
writeExpr(constraint);
write(')');

if (config.dfmt_template_constraint_style == TemplateConstraintStyle.always_newline_indent ||
// This condition will be updated later on
config.dfmt_template_constraint_style == TemplateConstraintStyle
.conditional_newline_indent)
depth--;
}

override void visitBaseClasses(ASTCodegen.ClassDeclaration d)
Expand Down

0 comments on commit 0897c83

Please sign in to comment.