mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-30 01:25:45 -05:00
- Avoid incrementing indents for compound binary boolean expressions. Multiple 'AND x = Y' statements were each indenting instead of having the same indent level. - Fixes https://github.com/Microsoft/vscode-mssql/issues/709
62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using System.Composition;
|
|
using Microsoft.SqlServer.Management.SqlParser.SqlCodeDom;
|
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Formatter
|
|
{
|
|
|
|
[Export(typeof(ASTNodeFormatterFactory))]
|
|
internal class SqlBinaryBooleanExpressionFormatterFactory : ASTNodeFormatterFactoryT<SqlBinaryBooleanExpression>
|
|
{
|
|
protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlBinaryBooleanExpression codeObject)
|
|
{
|
|
return new SqlBinaryBooleanExpressionFormatter(visitor, codeObject);
|
|
}
|
|
}
|
|
|
|
internal class SqlBinaryBooleanExpressionFormatter : ASTNodeFormatterT<SqlBinaryBooleanExpression>
|
|
{
|
|
SpaceSeparatedListFormatter SpaceSeparatedListFormatter { get; set; }
|
|
|
|
internal SqlBinaryBooleanExpressionFormatter(FormatterVisitor visitor, SqlBinaryBooleanExpression codeObject)
|
|
: base(visitor, codeObject)
|
|
{
|
|
SpaceSeparatedListFormatter = new SpaceSeparatedListFormatter(visitor, codeObject, true);
|
|
}
|
|
|
|
internal override void ProcessChild(SqlCodeObject child)
|
|
{
|
|
Validate.IsNotNull(nameof(child), child);
|
|
SpaceSeparatedListFormatter.ProcessChild(child);
|
|
}
|
|
|
|
internal override void ProcessPrefixRegion(int startTokenNumber, int firstChildStartTokenNumber)
|
|
{
|
|
// Binary boolean expressions
|
|
bool allowIncrement = !(CodeObject.Parent is SqlBinaryBooleanExpression);
|
|
SpaceSeparatedListFormatter.ProcessPrefixRegion(startTokenNumber, firstChildStartTokenNumber, allowIncrement);
|
|
}
|
|
|
|
internal override void ProcessSuffixRegion(int lastChildEndTokenNumber, int endTokenNumber)
|
|
{
|
|
bool allowDecrement = !(CodeObject.Parent is SqlBinaryBooleanExpression);
|
|
SpaceSeparatedListFormatter.ProcessSuffixRegion(lastChildEndTokenNumber, endTokenNumber, allowDecrement);
|
|
}
|
|
|
|
internal override void ProcessInterChildRegion(SqlCodeObject previousChild, SqlCodeObject nextChild)
|
|
{
|
|
Validate.IsNotNull(nameof(previousChild), previousChild);
|
|
Validate.IsNotNull(nameof(nextChild), nextChild);
|
|
|
|
SpaceSeparatedListFormatter.ProcessInterChildRegion(previousChild, nextChild);
|
|
}
|
|
|
|
}
|
|
}
|