public override ValueTask <CleanCodeGenerationOptions> GetCleanCodeGenerationOptionsAsync(HostLanguageServices languageServices, CancellationToken cancellationToken) { var lineFormattingOptions = _lineFormattingOptionsProvider.GetLineFormattingOptions(); var codeGenerationOptions = CleanCodeGenerationOptions.GetDefault(languageServices) with { CleanupOptions = CodeCleanupOptions.GetDefault(languageServices) with { FormattingOptions = SyntaxFormattingOptions.GetDefault(languageServices).With(new LineFormattingOptions { IndentationSize = lineFormattingOptions.IndentationSize, TabSize = lineFormattingOptions.TabSize, UseTabs = lineFormattingOptions.UseTabs, NewLine = lineFormattingOptions.NewLine, }) } }; return(new ValueTask <CleanCodeGenerationOptions>(codeGenerationOptions)); }
public void OptionsAreMessagePackSerializable(string language) { var messagePackOptions = MessagePackSerializerOptions.Standard.WithResolver(MessagePackFormatters.DefaultResolver); using var workspace = new AdhocWorkspace(); var languageServices = workspace.Services.GetLanguageServices(language); var options = new object[] { SimplifierOptions.GetDefault(languageServices), SyntaxFormattingOptions.GetDefault(languageServices), CodeCleanupOptions.GetDefault(languageServices), CodeGenerationOptions.GetDefault(languageServices), IdeCodeStyleOptions.GetDefault(languageServices), CodeActionOptions.GetDefault(languageServices), IndentationOptions.GetDefault(languageServices), ExtractMethodGenerationOptions.GetDefault(languageServices), // some non-default values: new VisualBasicIdeCodeStyleOptions( new IdeCodeStyleOptions.CommonOptions() { AllowStatementImmediatelyAfterBlock = new CodeStyleOption2 <bool>(false, NotificationOption2.Error) }, PreferredModifierOrder: new CodeStyleOption2 <string>("Public Private", NotificationOption2.Error)) }; foreach (var original in options) { using var stream = new MemoryStream(); MessagePackSerializer.Serialize(stream, original, messagePackOptions); stream.Position = 0; var deserialized = MessagePackSerializer.Deserialize(original.GetType(), stream, messagePackOptions); Assert.Equal(original, deserialized); } }
ValueTask <SyntaxFormattingOptions> OptionsProvider <SyntaxFormattingOptions> .GetOptionsAsync(HostLanguageServices languageServices, CancellationToken cancellationToken) => ValueTaskFactory.FromResult(GetOptions(languageServices).CleanupOptions?.FormattingOptions ?? SyntaxFormattingOptions.GetDefault(languageServices));