in src/dotnet/ReSharperPlugin.QuirkyFormatting/Psi/CodeStyle/Formatting/QuirkyCSharpFormatterInfoProvider.cs [127:158]
private void QuirkyIntAlign()
{
// This rule is to demonstrate how the IntAlignRules must be written.
// It binds an IntAlign token to the formatting context defined in the Where() clause.
// The token serves as a stretcher that pads with whitespace to the left so there would be no outdent.
// Token id equality is extremely important. The columns are defined in terms of it.
DescribeWithExternalKey<QuirkyFormattingSettingsKey, IntAlignRule>()
.Name("ALIGN_COMMAS_IN_ATTRIBUTE_INVOCATIONS")
.Where(
Parent().Satisfies((node, _) => node is IAttribute),
Right().HasType(CSharpTokenType.COMMA)
)
.SwitchOnExternalKey(
x => x.INT_ALIGN_ATTRIBUTE_COMMAS,
When(true).Calculate(
(formattingRangeContext, context) =>
{
if (formattingRangeContext == null && context == null) return null;
var attribute = (IAttribute)((FormattingRangeContext)formattingRangeContext)?.Parent;
if (attribute?.Name == null) return null;
return new IntAlignOptionValue(
$"Comma${attribute.Name.GetText()}$StartingAtOffset{attribute.GetDocumentStartOffset().Offset}",
QuirkyPriority
);
}
)
)
.Build();
}