mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 01:25:41 -05:00
TSQL Formatter Service (#229)
- 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
This commit is contained in:
@@ -119,7 +119,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplySingleLineInsert()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"This is a test.",
|
||||
"This is a working test.",
|
||||
new FileChange
|
||||
@@ -135,7 +135,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplySingleLineReplace()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"This is a potentially broken test.",
|
||||
"This is a working test.",
|
||||
new FileChange
|
||||
@@ -151,7 +151,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplySingleLineDelete()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"This is a test of the emergency broadcasting system.",
|
||||
"This is a test.",
|
||||
new FileChange
|
||||
@@ -167,7 +167,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplyMultiLineInsert()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"first\r\nsecond\r\nfifth",
|
||||
"first\r\nsecond\r\nthird\r\nfourth\r\nfifth",
|
||||
new FileChange
|
||||
@@ -183,7 +183,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplyMultiLineReplace()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"first\r\nsecoXX\r\nXXfth",
|
||||
"first\r\nsecond\r\nthird\r\nfourth\r\nfifth",
|
||||
new FileChange
|
||||
@@ -199,7 +199,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplyMultiLineReplaceWithRemovedLines()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"first\r\nsecoXX\r\nREMOVE\r\nTHESE\r\nLINES\r\nXXfth",
|
||||
"first\r\nsecond\r\nthird\r\nfourth\r\nfifth",
|
||||
new FileChange
|
||||
@@ -215,7 +215,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
[Fact]
|
||||
public void CanApplyMultiLineDelete()
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"first\r\nsecond\r\nREMOVE\r\nTHESE\r\nLINES\r\nthird",
|
||||
"first\r\nsecond\r\nthird",
|
||||
new FileChange
|
||||
@@ -235,7 +235,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
typeof(ArgumentOutOfRangeException),
|
||||
() =>
|
||||
{
|
||||
this.AssertFileChange(
|
||||
AssertFileChange(
|
||||
"first\r\nsecond\r\nREMOVE\r\nTHESE\r\nLINES\r\nthird",
|
||||
"first\r\nsecond\r\nthird",
|
||||
new FileChange
|
||||
@@ -275,7 +275,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
|
||||
public ScriptFileGetLinesTests()
|
||||
{
|
||||
this.scriptFile =
|
||||
scriptFile =
|
||||
ScriptFileTests.GetTestScriptFile(
|
||||
"Line One\r\nLine Two\r\nLine Three\r\nLine Four\r\nLine Five\r\n");
|
||||
}
|
||||
@@ -284,7 +284,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
public void CanGetWholeLine()
|
||||
{
|
||||
string[] lines =
|
||||
this.scriptFile.GetLinesInRange(
|
||||
scriptFile.GetLinesInRange(
|
||||
new BufferRange(5, 1, 5, 10));
|
||||
|
||||
Assert.Equal(1, lines.Length);
|
||||
@@ -295,7 +295,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
public void CanGetMultipleWholeLines()
|
||||
{
|
||||
string[] lines =
|
||||
this.scriptFile.GetLinesInRange(
|
||||
scriptFile.GetLinesInRange(
|
||||
new BufferRange(2, 1, 4, 10));
|
||||
|
||||
Assert.Equal(TestStringLines.Skip(1).Take(3), lines);
|
||||
@@ -305,7 +305,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
public void CanGetSubstringInSingleLine()
|
||||
{
|
||||
string[] lines =
|
||||
this.scriptFile.GetLinesInRange(
|
||||
scriptFile.GetLinesInRange(
|
||||
new BufferRange(4, 3, 4, 8));
|
||||
|
||||
Assert.Equal(1, lines.Length);
|
||||
@@ -316,7 +316,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
public void CanGetEmptySubstringRange()
|
||||
{
|
||||
string[] lines =
|
||||
this.scriptFile.GetLinesInRange(
|
||||
scriptFile.GetLinesInRange(
|
||||
new BufferRange(4, 3, 4, 3));
|
||||
|
||||
Assert.Equal(1, lines.Length);
|
||||
@@ -334,7 +334,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
};
|
||||
|
||||
string[] lines =
|
||||
this.scriptFile.GetLinesInRange(
|
||||
scriptFile.GetLinesInRange(
|
||||
new BufferRange(2, 6, 4, 9));
|
||||
|
||||
Assert.Equal(expectedLines, lines);
|
||||
@@ -351,7 +351,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
};
|
||||
|
||||
string[] lines =
|
||||
this.scriptFile.GetLinesInRange(
|
||||
scriptFile.GetLinesInRange(
|
||||
new BufferRange(2, 9, 4, 1));
|
||||
|
||||
Assert.Equal(expectedLines, lines);
|
||||
@@ -364,7 +364,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
|
||||
public ScriptFilePositionTests()
|
||||
{
|
||||
this.scriptFile =
|
||||
scriptFile =
|
||||
ScriptFileTests.GetTestScriptFile(@"
|
||||
First line
|
||||
Second line is longer
|
||||
@@ -375,12 +375,12 @@ First line
|
||||
[Fact]
|
||||
public void CanOffsetByLine()
|
||||
{
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
1, 1,
|
||||
2, 0,
|
||||
3, 1);
|
||||
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
3, 1,
|
||||
-2, 0,
|
||||
1, 1);
|
||||
@@ -389,12 +389,12 @@ First line
|
||||
[Fact]
|
||||
public void CanOffsetByColumn()
|
||||
{
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
2, 1,
|
||||
0, 2,
|
||||
2, 3);
|
||||
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
2, 5,
|
||||
0, -3,
|
||||
2, 2);
|
||||
@@ -447,7 +447,7 @@ First line
|
||||
[Fact]
|
||||
public void CanFindBeginningOfLine()
|
||||
{
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
4, 12,
|
||||
pos => pos.GetLineStart(),
|
||||
4, 5);
|
||||
@@ -456,7 +456,7 @@ First line
|
||||
[Fact]
|
||||
public void CanFindEndOfLine()
|
||||
{
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
4, 12,
|
||||
pos => pos.GetLineEnd(),
|
||||
4, 15);
|
||||
@@ -465,7 +465,7 @@ First line
|
||||
[Fact]
|
||||
public void CanComposePositionOperations()
|
||||
{
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
4, 12,
|
||||
pos => pos.AddOffset(-1, 1).GetLineStart(),
|
||||
3, 3);
|
||||
@@ -476,7 +476,7 @@ First line
|
||||
int lineOffset, int columnOffset,
|
||||
int expectedLine, int expectedColumn)
|
||||
{
|
||||
this.AssertNewPosition(
|
||||
AssertNewPosition(
|
||||
originalLine, originalColumn,
|
||||
pos => pos.AddOffset(lineOffset, columnOffset),
|
||||
expectedLine, expectedColumn);
|
||||
@@ -490,7 +490,7 @@ First line
|
||||
var newPosition =
|
||||
positionOperation(
|
||||
new FilePosition(
|
||||
this.scriptFile,
|
||||
scriptFile,
|
||||
originalLine,
|
||||
originalColumn));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user