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 @@ -339,7 +339,14 @@ private static void CleanupSourceMappingStart(FormattingContext context, LinePos

var text = context.SourceText;
var sourceMappingSpan = text.GetTextSpan(sourceMappingRange);
if (!ShouldFormat(context, sourceMappingSpan, allowImplicitStatements: false, out var owner))
if (!ShouldFormat(context,
sourceMappingSpan,
new ShouldFormatOptions(
AllowImplicitStatements: false,
AllowImplicitExpressions: false,
AllowSingleLineExplicitExpressions: true,
IsLineRequest: false),
out var owner))
{
// We don't want to run cleanup on this range.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private protected async Task RunOnTypeFormattingTestAsync(
filePathService, new TestDocumentContextFactory(), LoggerFactory);
var languageKind = codeDocument.GetLanguageKind(positionAfterTrigger, rightAssociative: false);

var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory, TestOutputHelper, codeDocument, razorLSPOptions, languageServerFeatureOptions);
var formattingService = await TestRazorFormattingService.CreateWithFullSupportAsync(LoggerFactory, TestOutputHelper, codeDocument, razorLSPOptions, languageServerFeatureOptions, debugAssertsEnabled: true);
var options = new FormattingOptions()
{
TabSize = tabSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,44 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting;
public class OnTypeFormattingTest(FormattingTestContext context, HtmlFormattingFixture fixture, ITestOutputHelper testOutput)
: FormattingTestBase(context, fixture.Service, testOutput), IClassFixture<FormattingTestContext>
{
[FormattingTestFact]
public async Task FormatsElseCloseBrace()
{
await RunOnTypeFormattingTestAsync(
input: """
@page "/"
@if (true)
{
<option value="@streetKind">@streetKind</option>
}
else {
<input />
}$$
@code {
private string? streetKind;
}
""",
expected: """
@page "/"
@if (true)
{
<option value="@streetKind">@streetKind</option>
}
else
{
<input />
}
@code {
private string? streetKind;
}
""",
triggerCharacter: '}');
}

[FormattingTestFact]
public async Task FormatsIfStatementInComponent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ private protected async Task RunOnTypeFormattingTestAsync(
var position = inputText.GetPosition(input.Position);

var formattingService = (RazorFormattingService)OOPExportProvider.GetExportedValue<IRazorFormattingService>();
formattingService.GetTestAccessor().SetFormattingLoggerFactory(new TestFormattingLoggerFactory(TestOutputHelper));
var accessor = formattingService.GetTestAccessor();
accessor.SetDebugAssertsEnabled(debugAssertsEnabled: true);
accessor.SetFormattingLoggerFactory(new TestFormattingLoggerFactory(TestOutputHelper));

var generatedHtml = await RemoteServiceInvoker.TryInvokeAsync<IRemoteHtmlDocumentService, string?>(document.Project.Solution,
(service, solutionInfo, ct) => service.GetHtmlDocumentTextAsync(solutionInfo, document.Id, ct),
Expand Down
Loading