зеркало из https://github.com/dotnet/razor.git
Merge pull request #4657 from davidwengier/FormatFirstCodeBlock
This commit is contained in:
Коммит
6a346687de
|
@ -178,13 +178,17 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
|
||||||
index = (~index) - 1;
|
index = (~index) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will now be set to the same value as the end of the closest source mapping.
|
|
||||||
if (index < 0)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
// index will now be set to the same value as the end of the closest source mapping.
|
||||||
var absoluteIndex = sourceMappingIndentationScopes[index];
|
var absoluteIndex = sourceMappingIndentationScopes[index];
|
||||||
csharpDesiredIndentation = sourceMappingIndentations[absoluteIndex];
|
csharpDesiredIndentation = sourceMappingIndentations[absoluteIndex];
|
||||||
|
|
||||||
|
|
|
@ -419,7 +419,7 @@ Hello World
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
expected: @"Hello World
|
expected: @"Hello World
|
||||||
@functions {
|
@functions {
|
||||||
public class Foo { }
|
public class Foo { }
|
||||||
}
|
}
|
||||||
");
|
");
|
||||||
|
@ -434,7 +434,7 @@ input: @"
|
||||||
public class Foo{}
|
public class Foo{}
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
expected: @" @functions {
|
expected: @"@functions {
|
||||||
public class Foo { }
|
public class Foo { }
|
||||||
}
|
}
|
||||||
");
|
");
|
||||||
|
@ -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>
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче