This commit is contained in:
David Wengier 2024-09-05 13:15:10 +10:00
Родитель d87ad016dd
Коммит b7cd05e453
3 изменённых файлов: 7 добавлений и 20 удалений

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

@ -26,13 +26,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting;
internal class DocumentOnTypeFormattingEndpoint(
IRazorFormattingService razorFormattingService,
IHtmlFormatter htmlFormatter,
IDocumentMappingService documentMappingService,
RazorLSPOptionsMonitor optionsMonitor,
ILoggerFactory loggerFactory)
: IRazorRequestHandler<DocumentOnTypeFormattingParams, TextEdit[]?>, ICapabilitiesProvider
{
private readonly IRazorFormattingService _razorFormattingService = razorFormattingService;
private readonly IDocumentMappingService _documentMappingService = documentMappingService;
private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor;
private readonly IHtmlFormatter _htmlFormatter = htmlFormatter;
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<DocumentOnTypeFormattingEndpoint>();

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

@ -310,7 +310,7 @@ internal class RazorFormattingService : IRazorFormattingService
/// If LF line endings are more prevalent, it removes any CR characters from the text edits
/// to ensure consistency with the LF style.
/// </summary>
private TextEdit[] NormalizeLineEndings(SourceText originalText, TextEdit[] edits)
private static TextEdit[] NormalizeLineEndings(SourceText originalText, TextEdit[] edits)
{
if (originalText.HasLFLineEndings())
{

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

@ -4,12 +4,9 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Moq;
using Xunit;
using Xunit.Abstractions;
@ -23,12 +20,11 @@ public class DocumentOnTypeFormattingEndpointTest(ITestOutputHelper testOutput)
// Arrange
var uri = new Uri("file://path/test.razor");
var formattingService = new DummyRazorFormattingService();
var documentMappingService = new LspDocumentMappingService(FilePathService, new TestDocumentContextFactory(), LoggerFactory);
var optionsMonitor = GetOptionsMonitor(enableFormatting: false);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentOnTypeFormattingEndpoint(
formattingService, htmlFormatter, documentMappingService, optionsMonitor, LoggerFactory);
formattingService, htmlFormatter, optionsMonitor, LoggerFactory);
var @params = new DocumentOnTypeFormattingParams { TextDocument = new TextDocumentIdentifier { Uri = uri, } };
var requestContext = CreateRazorRequestContext(documentContext: null);
@ -52,12 +48,11 @@ public class DocumentOnTypeFormattingEndpointTest(ITestOutputHelper testOutput)
var documentContext = CreateDocumentContext(new Uri("file://path/testDifferentFile.razor"), codeDocument);
var formattingService = new DummyRazorFormattingService();
var documentMappingService = new LspDocumentMappingService(FilePathService, new TestDocumentContextFactory(), LoggerFactory);
var optionsMonitor = GetOptionsMonitor(enableFormatting: true);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentOnTypeFormattingEndpoint(
formattingService, htmlFormatter, documentMappingService, optionsMonitor, LoggerFactory);
formattingService, htmlFormatter, optionsMonitor, LoggerFactory);
var @params = new DocumentOnTypeFormattingParams()
{
TextDocument = new TextDocumentIdentifier { Uri = uri, },
@ -87,12 +82,11 @@ public class DocumentOnTypeFormattingEndpointTest(ITestOutputHelper testOutput)
var documentContext = CreateDocumentContext(uri, codeDocument);
var formattingService = new DummyRazorFormattingService();
var documentMappingService = new LspDocumentMappingService(FilePathService, new TestDocumentContextFactory(), LoggerFactory);
var optionsMonitor = GetOptionsMonitor(enableFormatting: true);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentOnTypeFormattingEndpoint(
formattingService, htmlFormatter, documentMappingService, optionsMonitor, LoggerFactory);
formattingService, htmlFormatter, optionsMonitor, LoggerFactory);
var @params = new DocumentOnTypeFormattingParams()
{
TextDocument = new TextDocumentIdentifier { Uri = uri, },
@ -123,12 +117,10 @@ public class DocumentOnTypeFormattingEndpointTest(ITestOutputHelper testOutput)
var documentContext = CreateDocumentContext(uri, codeDocument);
var formattingService = new DummyRazorFormattingService(RazorLanguageKind.Html);
var documentMappingService = new Mock<IDocumentMappingService>(MockBehavior.Strict);
documentMappingService.Setup(s => s.GetLanguageKind(codeDocument, 17, false)).Returns(RazorLanguageKind.Html);
var optionsMonitor = GetOptionsMonitor(enableFormatting: true);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentOnTypeFormattingEndpoint(
formattingService, htmlFormatter, documentMappingService.Object, optionsMonitor, LoggerFactory);
formattingService, htmlFormatter, optionsMonitor, LoggerFactory);
var @params = new DocumentOnTypeFormattingParams()
{
TextDocument = new TextDocumentIdentifier { Uri = uri, },
@ -159,12 +151,10 @@ public class DocumentOnTypeFormattingEndpointTest(ITestOutputHelper testOutput)
var documentContext = CreateDocumentContext(uri, codeDocument);
var formattingService = new DummyRazorFormattingService(RazorLanguageKind.Razor);
var documentMappingService = new Mock<IDocumentMappingService>(MockBehavior.Strict);
documentMappingService.Setup(s => s.GetLanguageKind(codeDocument, 17, false)).Returns(RazorLanguageKind.Razor);
var optionsMonitor = GetOptionsMonitor(enableFormatting: true);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentOnTypeFormattingEndpoint(
formattingService, htmlFormatter, documentMappingService.Object, optionsMonitor, LoggerFactory);
formattingService, htmlFormatter, optionsMonitor, LoggerFactory);
var @params = new DocumentOnTypeFormattingParams()
{
TextDocument = new TextDocumentIdentifier { Uri = uri, },
@ -194,12 +184,11 @@ public class DocumentOnTypeFormattingEndpointTest(ITestOutputHelper testOutput)
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);
var formattingService = new DummyRazorFormattingService();
var documentMappingService = new LspDocumentMappingService(FilePathService, documentContextFactory, LoggerFactory);
var optionsMonitor = GetOptionsMonitor(enableFormatting: true);
var htmlFormatter = new TestHtmlFormatter();
var endpoint = new DocumentOnTypeFormattingEndpoint(
formattingService, htmlFormatter, documentMappingService, optionsMonitor, LoggerFactory);
formattingService, htmlFormatter, optionsMonitor, LoggerFactory);
var @params = new DocumentOnTypeFormattingParams()
{
TextDocument = new TextDocumentIdentifier { Uri = uri, },