提交 20f78b02 编写于 作者: M Manish Vasani

Ensure that TodoCommentOptions are serialized to OOP

Fixes #43788
TodoCommentOptions and TodoCommentOptionsProvider were defined in EditorFeatures layer and we only serialize the options defined in Workspaces and Features layer to the OOP side: https://github.com/dotnet/roslyn/blob/287a25a51324f252e61b6f2186e7df60c8a6161b/src/Workspaces/Core/Portable/Options/GlobalOptionService.cs#L79-L85

In future, we either need to add support to serialize all changed options to OOP (could be expensive) or somehow enforce that all the OOP related options are defined in Workspaces and Features layer.
上级 a9fb862d
......@@ -5,11 +5,15 @@
#nullable enable
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Editor.Implementation.TodoComments;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Options.Providers;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.WorkspaceServices
......@@ -214,6 +218,36 @@ static void TestChangedOptionsCore(PerLanguageOption2<bool> option, IOptionProvi
}
}
[Fact, WorkItem(43788, "https://github.com/dotnet/roslyn/issues/43788")]
public void TestChangedTodoCommentOptions()
{
var option = TodoCommentOptions.TokenList;
var optionService = TestOptionService.GetService(GetOptionProvider<TodoCommentOptionsProvider>());
var optionSet = optionService.GetOptions();
var optionKey = new OptionKey(option);
var currentOptionValue = optionSet.GetOption(option);
var newOptionValue = currentOptionValue + "newValue";
var newOptionSet = optionSet.WithChangedOption(optionKey, newOptionValue);
optionService.SetOptions(newOptionSet);
Assert.Equal(newOptionValue, (string?)optionService.GetOptions().GetOption(optionKey));
var languages = ImmutableHashSet.Create(LanguageNames.CSharp);
var serializableOptionSet = optionService.GetSerializableOptionsSnapshot(languages);
var changedOptions = serializableOptionSet.GetChangedOptions();
var changedOptionKey = Assert.Single(changedOptions);
Assert.Equal(optionKey, changedOptionKey);
Assert.Equal(newOptionValue, serializableOptionSet.GetOption(changedOptionKey));
}
private static TOptionProvider GetOptionProvider<TOptionProvider>()
where TOptionProvider : IOptionProvider
{
var factory = ExportProviderCache.GetOrCreateExportProviderFactory(TestHost.Catalog);
return factory.CreateExportProvider().GetExportedValues<IOptionProvider>().OfType<TOptionProvider>().FirstOrDefault();
}
[Fact]
public void TestPerLanguageCodeStyleOptions()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册