Merge pull request #4657 from davidwengier/FormatFirstCodeBlock

This commit is contained in:
David Wengier 2021-10-07 08:10:20 +11:00 коммит произвёл GitHub
Родитель 8824cbf304 005eb138b4
Коммит 6a346687de
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 69 добавлений и 4 удалений

Просмотреть файл

@ -178,13 +178,17 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
index = (~index) - 1;
}
// This will now be set to the same value as the end of the closest source mapping.
if (index < 0)
{
csharpDesiredIndentation = 0;
// If we _still_ couldn't find the right indentation, then it probably means that the text is
// before the first source mapping location, so we can just place it in the minimum spot (realistically
// at index 0 in the razor file, but we use minCSharpIndentation because we're adjusting based on the
// generated file here)
csharpDesiredIndentation = minCSharpIndentation;
}
else
{
// index will now be set to the same value as the end of the closest source mapping.
var absoluteIndex = sourceMappingIndentationScopes[index];
csharpDesiredIndentation = sourceMappingIndentations[absoluteIndex];

Просмотреть файл

@ -731,6 +731,67 @@ expected: @"@code {
}
};
}
");
}
[Fact]
[WorkItem("https://github.com/dotnet/aspnetcore/issues/4498")]
public async Task IfBlock_TopLevel()
{
await RunFormattingTestAsync(
input: @"
@if (true)
{
}
",
expected: @"@if (true)
{
}
");
}
[Fact]
[WorkItem("https://github.com/dotnet/aspnetcore/issues/4498")]
public async Task IfBlock_TopLevel_WithOtherCode()
{
await RunFormattingTestAsync(
input: @"
@{
// foo
}
@if (true)
{
}
",
expected: @"@{
// foo
}
@if (true)
{
}
");
}
[Fact]
[WorkItem("https://github.com/dotnet/aspnetcore/issues/4498")]
public async Task IfBlock_Nested()
{
await RunFormattingTestAsync(
input: @"
<div>
@if (true)
{
}
</div>
",
expected: @"
<div>
@if (true)
{
}
</div>
");
}
}