Cleanup default RemoteAutoInsertOptions (#10852)

* Using default constructor per David's suggestion to avoid having two copies of default values

* More PR feedback

* PR feedback - formatting
This commit is contained in:
Alex Gavrilov 2024-09-10 19:23:08 -04:00 коммит произвёл GitHub
Родитель 2511efed42
Коммит d8b0c49923
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 6 добавлений и 9 удалений

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

@ -1,7 +1,6 @@
using System.Runtime.Serialization;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.Settings;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.CodeAnalysis.Razor.Remote;
@ -15,21 +14,17 @@ internal readonly record struct RemoteAutoInsertOptions
public bool FormatOnType { get; init; } = true;
[DataMember(Order = 2)]
public RazorFormattingOptions FormattingOptions { get; init; } = new RazorFormattingOptions()
{
InsertSpaces = true,
TabSize = 4
};
public RazorFormattingOptions FormattingOptions { get; init; } = new();
public RemoteAutoInsertOptions()
{
}
public static RemoteAutoInsertOptions From(ClientSettings clientSettings, FormattingOptions formattingOptions)
public static RemoteAutoInsertOptions From(ClientSettings clientSettings, RazorFormattingOptions formattingOptions)
=> new()
{
EnableAutoClosingTags = clientSettings.AdvancedSettings.AutoClosingTags,
FormatOnType = clientSettings.AdvancedSettings.FormatOnType,
FormattingOptions = RazorFormattingOptions.From(formattingOptions, codeBlockBraceOnNextLine: false)
FormattingOptions = formattingOptions
};
}

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

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
using Microsoft.CodeAnalysis.Razor.AutoInsert;
using Microsoft.CodeAnalysis.Razor.Formatting;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.Protocol.AutoInsert;
using Microsoft.CodeAnalysis.Razor.Remote;
@ -92,7 +93,8 @@ internal class CohostOnAutoInsertEndpoint(
_logger.LogDebug($"Resolving auto-insertion for {razorDocument.FilePath}");
var clientSettings = _clientSettingsManager.GetClientSettings();
var autoInsertOptions = RemoteAutoInsertOptions.From(clientSettings, request.Options);
var razorFormattingOptions = RazorFormattingOptions.From(request.Options, codeBlockBraceOnNextLine: false);
var autoInsertOptions = RemoteAutoInsertOptions.From(clientSettings, razorFormattingOptions);
_logger.LogDebug($"Calling OOP to resolve insertion at {request.Position} invoked by typing '{request.Character}'");
var data = await _remoteServiceInvoker.TryInvokeAsync<IRemoteAutoInsertService, Response>(