mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-23 17:24:12 -05:00
- TSqlFormatterService with support for formatting document and text range inside document - Settings support for all formatting options. - Extensibility support so that the service can be initialized using MEF extensibility, and can find all necessary TSqlFormatters using the same process Fix Initialize request error on startup - Messages were being read from the input channel before all request handlers were registered - In particular, the Initialize request which is key for any server to talk to the client was getting lost because the message reader thread begins consuming, and we take an extra few hundred milliseconds due to MEF startup before we register the handler - The solution is to initialize the message handler so request handlers can register, but not actually start processing incoming messages until all handers are ready. This is a safer way to go and should improve reliability overall Improvements from internal prototype: - Normalizing baselines to handle the line ending differences on Mac & Linux vs. Windows - Significantly shortened most lines by implementing base class methods to wrap common objects from Visitor.Context and removing unnecessary "this." syntax - Refactored the SqlCommonTableExpressionFormatter and related classes to reduce code count significantly. This provides a pattern to follow when refactoring other classes for similar clarity. It's likely a lot of common logic could be found and reused across these. - Reduced overall code size by adding utility methods
58 lines
2.2 KiB
C#
58 lines
2.2 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.Composition;
|
|
using Microsoft.SqlServer.Management.SqlParser.SqlCodeDom;
|
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Formatter
|
|
{
|
|
|
|
[Export(typeof(ASTNodeFormatterFactory))]
|
|
internal class SqlQualifiedJoinTableExpressionFormatterFactory : ASTNodeFormatterFactoryT<SqlQualifiedJoinTableExpression>
|
|
{
|
|
protected override ASTNodeFormatter DoCreate(FormatterVisitor visitor, SqlQualifiedJoinTableExpression codeObject)
|
|
{
|
|
return new SqlQualifiedJoinTableExpressionFormatter(visitor, codeObject);
|
|
}
|
|
}
|
|
|
|
internal class SqlQualifiedJoinTableExpressionFormatter : ASTNodeFormatterT<SqlQualifiedJoinTableExpression>
|
|
{
|
|
SpaceSeparatedListFormatter SpaceSeparatedListFormatter { get; set; }
|
|
|
|
internal SqlQualifiedJoinTableExpressionFormatter(FormatterVisitor visitor, SqlQualifiedJoinTableExpression codeObject)
|
|
: base(visitor, codeObject)
|
|
{
|
|
SpaceSeparatedListFormatter = new SpaceSeparatedListFormatter(visitor, codeObject, false);
|
|
}
|
|
|
|
internal override void ProcessChild(SqlCodeObject child)
|
|
{
|
|
Validate.IsNotNull(nameof(child), child);
|
|
SpaceSeparatedListFormatter.ProcessChild(child);
|
|
}
|
|
|
|
internal override void ProcessPrefixRegion(int startTokenNumber, int firstChildStartTokenNumber)
|
|
{
|
|
SpaceSeparatedListFormatter.ProcessPrefixRegion(startTokenNumber, firstChildStartTokenNumber);
|
|
}
|
|
|
|
internal override void ProcessSuffixRegion(int lastChildEndTokenNumber, int endTokenNumber)
|
|
{
|
|
SpaceSeparatedListFormatter.ProcessSuffixRegion(lastChildEndTokenNumber, endTokenNumber);
|
|
}
|
|
|
|
internal override void ProcessInterChildRegion(SqlCodeObject previousChild, SqlCodeObject nextChild)
|
|
{
|
|
Validate.IsNotNull(nameof(previousChild), previousChild);
|
|
Validate.IsNotNull(nameof(nextChild), nextChild);
|
|
|
|
SpaceSeparatedListFormatter.ProcessInterChildRegion(previousChild, nextChild);
|
|
}
|
|
|
|
}
|
|
}
|