Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public static void GetOriginalDocumentChangesFromLineInfo(FormattingContext cont
// the formatter may have inserted a blank line after the current line too. In that case we need to make sure
// we advance the formatted line pointer past it, but also include it. This only applies if the line after the
// blank line matches the next original line and the next original line isn't blank (ie, an actual insertion)
if (iFormatted + 1 < formattedText.Lines.Count &&
while (iFormatted + 1 < formattedText.Lines.Count &&
formattedText.Lines[iFormatted + 1].Span.Length == 0 &&
iOriginal + 1 < originalText.Lines.Count &&
originalText.Lines[iOriginal + 1] is { } nextOriginalLine &&
Expand All @@ -384,6 +384,20 @@ public static void GetOriginalDocumentChangesFromLineInfo(FormattingContext cont
}
}
}
else if (originalText.Lines[iOriginal] is { } blankOriginalLine &&
blankOriginalLine.GetFirstNonWhitespaceOffset() is null)
{
// The current lines are an aligned blank pair. Consume any additional formatted blank lines
// before the next non-blank original line so the line mapping remains synchronized.
while (iFormatted + 1 < formattedText.Lines.Count &&
formattedText.Lines[iFormatted + 1].Span.Length == 0 &&
iOriginal + 1 < originalText.Lines.Count &&
originalText.Lines[iOriginal + 1].GetFirstNonWhitespaceOffset() is not null)
{
iFormatted++;
formattingChanges.Add(new TextChange(new(blankOriginalLine.EndIncludingLineBreak, 0), context.NewLineString));
}
}

if (lineInfo.SkipNextLine)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8332,6 +8332,60 @@ public interface Bar
""");
}

[Fact]
[WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/3041882")]
public async Task IncompleteObjectCreation_UseTabs()
{
TestCode input = """
@code {
private void Method()
{
value = new object()

other = true;
}
}
""";

await RunFormattingTestAsync(
input: input,
htmlFormatted: input.Text,
expected: """
@code {
private void Method()
{
value = new object()


other = true;
}
}
""",
insertSpaces: false);
}

[Fact]
[WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/3041882")]
public async Task IncompleteObjectCreation_UseSpaces()
{
TestCode input = """
@code {
private void Method()
{
value = new object()

other = true;
}
}
""";

await RunFormattingTestAsync(
input: input,
htmlFormatted: input.Text,
expected: input.Text,
insertSpaces: true);
}

[Fact]
public async Task MultipleCodeBlockDirectives()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public async Task PageForMultiGrid()
public async Task PageForGrid()
=> Assert.NotNull(await GetFormattingEditsAsync());

[Fact]
[WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/3041882")]
public async Task BoatsSectionRange092858221()
=> Assert.NotNull(await GetFormattingEditsAsync());

private async Task<TextEdit[]?> GetFormattingEditsAsync([CallerMemberName] string? testName = null)
{
var contents = GetResource(testName.AssumeNotNull(), "InitialDocument.txt").AssumeNotNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"span":{"start":683,"length":4},"newText":"\t"},{"span":{"start":732,"length":10},"newText":"\r\n\t"},{"span":{"start":827,"length":8},"newText":"\t\t"},{"span":{"start":858,"length":16},"newText":"\t\t\t\t"},{"span":{"start":899,"length":16},"newText":"\t\t\t\t"},{"span":{"start":930,"length":16},"newText":"\t\t\t\t"},{"span":{"start":974,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1013,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1051,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1091,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1137,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1183,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1220,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1267,"length":16},"newText":"\t\t\t\t"},{"span":{"start":1302,"length":12},"newText":"\t\t\t"},{"span":{"start":1341,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":1403,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":1458,"length":26},"newText":"\r\n\t\t\t"},{"span":{"start":1522,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":1573,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":1625,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":1700,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":1770,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":1827,"length":12},"newText":"\t\t\t"},{"span":{"start":1864,"length":12},"newText":"\t\t\t"},{"span":{"start":1928,"length":32},"newText":"\t\t\t\t\t\t\t\t"},{"span":{"start":1989,"length":32},"newText":"\t\t\t\t\t\t\t\t"},{"span":{"start":2050,"length":12},"newText":"\t\t\t"},{"span":{"start":2077,"length":16},"newText":"\t\t\t\t"},{"span":{"start":2131,"length":31},"newText":"\r\n\t\t\t\t\t\t\t"},{"span":{"start":2177,"length":31},"newText":"\r\n\t\t\t\t\t\t\t"},{"span":{"start":2232,"length":34},"newText":"\r\n\t\t\t\t"},{"span":{"start":2306,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2358,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2414,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2458,"length":34},"newText":"\r\n\t\t\t\t"},{"span":{"start":2532,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2579,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2637,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2676,"length":0},"newText":" "},{"span":{"start":2680,"length":34},"newText":"\r\n\t\t\t\t"},{"span":{"start":2762,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2817,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2873,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":2915,"length":20},"newText":"\t\t\t\t\t"},{"span":{"start":2951,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":3041,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3098,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3154,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3225,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3293,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3373,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3436,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3496,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3555,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3619,"length":40},"newText":"\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":3683,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":3726,"length":20},"newText":"\t\t\t\t\t"},{"span":{"start":3763,"length":16},"newText":"\t\t\t\t"},{"span":{"start":3794,"length":34},"newText":"\r\n\t\t\t\t"},{"span":{"start":3869,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":3917,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":3973,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":4012,"length":0},"newText":" "},{"span":{"start":4016,"length":68},"newText":"\r\n\r\n\t\t\t\t"},{"span":{"start":4115,"length":31},"newText":"\r\n\t\t\t\t\t\t\t"},{"span":{"start":4159,"length":28},"newText":"\t\t\t\t\t\t\t"},{"span":{"start":4218,"length":20},"newText":"\t\t\t\t\t"},{"span":{"start":4260,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":4332,"length":43},"newText":"\r\n\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":4479,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":4553,"length":43},"newText":"\r\n\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":4702,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":4774,"length":43},"newText":"\r\n\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":4923,"length":24},"newText":"\t\t\t\t\t\t"},{"span":{"start":4997,"length":43},"newText":"\r\n\t\t\t\t\t\t\t\t\t\t"},{"span":{"start":5151,"length":20},"newText":"\t\t\t\t\t"},{"span":{"start":5194,"length":16},"newText":"\t\t\t\t"},{"span":{"start":5225,"length":12},"newText":"\t\t\t"},{"span":{"start":5255,"length":8},"newText":"\t\t"},{"span":{"start":5274,"length":18},"newText":"\r\n\t\t"},{"span":{"start":5314,"length":8},"newText":"\t\t"},{"span":{"start":5325,"length":12},"newText":"\t\t"},{"span":{"start":5375,"length":16},"newText":"\t\t\t"},{"span":{"start":5423,"length":32},"newText":"\t\t\t\t\t\t"},{"span":{"start":5485,"length":32},"newText":"\t\t\t\t\t\t"},{"span":{"start":5550,"length":32},"newText":"\t\t\t\t\t\t"},{"span":{"start":5620,"length":32},"newText":"\t\t\t\t\t\t"},{"span":{"start":5685,"length":32},"newText":"\t\t\t\t\t\t"},{"span":{"start":5762,"length":13},"newText":""},{"span":{"start":5780,"length":8},"newText":"\t\t"},{"span":{"start":5793,"length":4},"newText":"\t"},{"span":{"start":5805,"length":4},"newText":"\t"},{"span":{"start":5864,"length":12},"newText":"\t\t\t"},{"span":{"start":5896,"length":12},"newText":"\t\t\t"},{"span":{"start":5949,"length":8},"newText":"\t\t"},{"span":{"start":5967,"length":4},"newText":"\t"},{"span":{"start":12596,"length":1},"newText":""},{"span":{"start":16735,"length":2},"newText":""},{"span":{"start":17271,"length":2},"newText":""},{"span":{"start":19637,"length":15},"newText":""},{"span":{"start":19702,"length":16},"newText":""},{"span":{"start":20679,"length":0},"newText":" "},{"span":{"start":20849,"length":4},"newText":"\t"},{"span":{"start":20874,"length":0},"newText":" "},{"span":{"start":20877,"length":8},"newText":"\t\t"},{"span":{"start":20905,"length":8},"newText":"\t\t"},{"span":{"start":20933,"length":4},"newText":"\t"},{"span":{"start":20940,"length":4},"newText":"\r\n\t"},{"span":{"start":20961,"length":8},"newText":"\t\t"},{"span":{"start":20989,"length":8},"newText":"\t\t"},{"span":{"start":21016,"length":8},"newText":"\t\t"},{"span":{"start":21041,"length":8},"newText":"\t\t"},{"span":{"start":21064,"length":4},"newText":"\t"},{"span":{"start":21073,"length":4},"newText":"\t"},{"span":{"start":21096,"length":0},"newText":" "},{"span":{"start":21099,"length":8},"newText":"\t\t"},{"span":{"start":21126,"length":4},"newText":"\t"}]
Loading