From f1b4348c6b3c9821f92389df846a11b1e60998e8 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Tue, 10 Mar 2020 14:02:44 -0700 Subject: [PATCH] Split the CodeStyle test utilities project into separate projects for legacy test framework and the new test framework. This was needed to avoid type ambiguity from same internal options types from Workspaces and CodeStyle. Also added a bunch of test helper methods for new option types and ensured that we serialize naming styles in both tests frameworks --- ...Analysis.CSharp.CodeStyle.UnitTests.csproj | 1 + ...gacyTestFramework.UnitTestUtilities.csproj | 37 +++ ...nalysis.CodeStyle.UnitTestUtilities.csproj | 10 +- ...sis.VisualBasic.CodeStyle.UnitTests.vbproj | 1 + .../AbstractCodeActionOrUserDiagnosticTest.cs | 257 ++++++++++++------ .../CSharpCodeFixVerifier`2+Test.cs | 6 +- .../CodeActions/CodeFixVerifierHelper.cs | 58 +--- .../CodeActions/OptionsCollection.cs | 58 ++-- .../VisualBasicCodeFixVerifier`2+Test.cs | 5 +- ...agnosticProviderBasedUserDiagnosticTest.cs | 17 +- ...edUserDiagnosticTest_ParenthesesOptions.cs | 50 ++-- ...DiagnosticTest.FixAllDiagnosticProvider.cs | 1 - .../Diagnostics/AbstractUserDiagnosticTest.cs | 12 +- ...Features.DiagnosticsTests.Utilities.csproj | 2 +- .../NamingStylesTestOptionSets.cs | 74 ++--- .../Extensions/WorkspaceExtensions.cs | 13 +- .../Roslyn.Services.Test.Utilities.csproj | 2 +- .../Portable/Roslyn.Test.Utilities.csproj | 1 + 18 files changed, 363 insertions(+), 242 deletions(-) create mode 100644 src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.LegacyTestFramework.UnitTestUtilities.csproj diff --git a/src/CodeStyle/CSharp/Tests/Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests.csproj b/src/CodeStyle/CSharp/Tests/Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests.csproj index 054b433663e0f..a94b577d8c9af 100644 --- a/src/CodeStyle/CSharp/Tests/Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests.csproj +++ b/src/CodeStyle/CSharp/Tests/Microsoft.CodeAnalysis.CSharp.CodeStyle.UnitTests.csproj @@ -30,6 +30,7 @@ + diff --git a/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.LegacyTestFramework.UnitTestUtilities.csproj b/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.LegacyTestFramework.UnitTestUtilities.csproj new file mode 100644 index 0000000000000..a9b8da4848ed8 --- /dev/null +++ b/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.LegacyTestFramework.UnitTestUtilities.csproj @@ -0,0 +1,37 @@ + + + + + Library + Microsoft.CodeAnalysis + net472 + $(DefineConstants),CODE_STYLE + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj b/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj index cb679dd82f41a..f7aaf0bcd9917 100644 --- a/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj +++ b/src/CodeStyle/Core/Tests/Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj @@ -15,10 +15,6 @@ - - - - @@ -36,12 +32,12 @@ - - + + - \ No newline at end of file + \ No newline at end of file diff --git a/src/CodeStyle/VisualBasic/Tests/Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests.vbproj b/src/CodeStyle/VisualBasic/Tests/Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests.vbproj index 47208c2c01ba1..5d284be6a7e2a 100644 --- a/src/CodeStyle/VisualBasic/Tests/Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests.vbproj +++ b/src/CodeStyle/VisualBasic/Tests/Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests.vbproj @@ -31,6 +31,7 @@ + diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs index 089d94a52d38f..1958ef8c9b13d 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs @@ -13,8 +13,6 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; -using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Test.Utilities; @@ -23,23 +21,25 @@ using Roslyn.Utilities; using Roslyn.Test.Utilities; using Xunit; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.CodeStyle; +namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions +{ #if CODE_STYLE -using EditorConfigFileGenerator = Microsoft.CodeAnalysis.Options.EditorConfigFileGenerator; -using Microsoft.CodeAnalysis.Internal.Options; + using TestParametersOptions = IOptionsCollection; #else -using Microsoft.CodeAnalysis.CodeStyle; -using Microsoft.CodeAnalysis.Options; + using TestParametersOptions = IDictionary; + using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions; + using System.Collections; #endif -namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions -{ [UseExportProvider] public abstract partial class AbstractCodeActionOrUserDiagnosticTest { public struct TestParameters { - internal readonly IDictionary options; + internal readonly TestParametersOptions options; internal readonly object fixProviderData; internal readonly ParseOptions parseOptions; internal readonly CompilationOptions compilationOptions; @@ -52,7 +52,7 @@ public struct TestParameters internal TestParameters( ParseOptions parseOptions = null, CompilationOptions compilationOptions = null, - IDictionary options = null, + TestParametersOptions options = null, object fixProviderData = null, int index = 0, CodeActionPriority? priority = null, @@ -74,7 +74,7 @@ internal TestParameters( public TestParameters WithParseOptions(ParseOptions parseOptions) => new TestParameters(parseOptions, compilationOptions, options, fixProviderData, index, priority, retainNonFixableDiagnostics, includeDiagnosticsOutsideSelection, title); - public TestParameters WithOptions(IDictionary options) + internal TestParameters WithOptions(TestParametersOptions options) => new TestParameters(parseOptions, compilationOptions, options, fixProviderData, index, priority, retainNonFixableDiagnostics, includeDiagnosticsOutsideSelection, title); public TestParameters WithFixProviderData(object fixProviderData) @@ -122,6 +122,7 @@ protected TestWorkspace CreateWorkspaceFromOptions( return workspace; } +#if CODE_STYLE private static void MakeProjectsAndDocumentsRooted(TestWorkspace workspace) { const string defaultRootFilePath = @"z:\"; @@ -160,7 +161,7 @@ private static void MakeProjectsAndDocumentsRooted(TestWorkspace workspace) return; } - private static void AddAnalyzerConfigDocumentWithOptions(TestWorkspace workspace, IDictionary options) + private void AddAnalyzerConfigDocumentWithOptions(TestWorkspace workspace, TestParametersOptions options) { Debug.Assert(options != null); var analyzerConfigText = GenerateAnalyzerConfigText(options); @@ -182,60 +183,18 @@ private static void AddAnalyzerConfigDocumentWithOptions(TestWorkspace workspace Assert.True(applied); return; - static string GenerateAnalyzerConfigText(IDictionary options) + string GenerateAnalyzerConfigText(TestParametersOptions options) { var textBuilder = new StringBuilder(); // Add an auto-generated header at the top so we can skip this file in expected baseline validation. textBuilder.AppendLine(AutoGeneratedAnalyzerConfigHeader); textBuilder.AppendLine(); - - foreach (var (optionKey, value) in options) - { - foreach (var location in optionKey.Option.StorageLocations) - { - if (location is IEditorConfigStorageLocation2 editorConfigStorageLocation) - { - var editorConfigString = editorConfigStorageLocation.GetEditorConfigString(value, default); - if (editorConfigString != null) - { - textBuilder.AppendLine(GetSectionHeader(optionKey)); - textBuilder.AppendLine(editorConfigString); - textBuilder.AppendLine(); - break; - } - - Assert.False(true, "Unexpected non-editorconfig option"); - } - else if (value is NamingStylePreferences namingStylePreferences) - { - textBuilder.AppendLine(GetSectionHeader(optionKey)); - EditorConfigFileGenerator.AppendNamingStylePreferencesToEditorConfig(namingStylePreferences, optionKey.Language, textBuilder); - textBuilder.AppendLine(); - break; - } - } - } - + textBuilder.AppendLine(options.GetEditorConfigText()); return textBuilder.ToString(); - - static string GetSectionHeader(OptionKey optionKey) - { - if (optionKey.Option.IsPerLanguage) - { - switch (optionKey.Language) - { - case LanguageNames.CSharp: - return "[*.cs]"; - case LanguageNames.VisualBasic: - return "[*.vb]"; - } - } - - return "[*]"; - } } } +#endif protected abstract TestWorkspace CreateWorkspaceFromFile(string initialMarkup, TestParameters parameters); @@ -345,7 +304,7 @@ internal Task TestInRegularAndScriptAsync( int index = 0, CodeActionPriority? priority = null, CompilationOptions compilationOptions = null, - IDictionary options = null, + TestParametersOptions options = null, object fixProviderData = null, ParseOptions parseOptions = null, string title = null) @@ -370,7 +329,7 @@ internal Task TestAsync( string initialMarkup, string expectedMarkup, ParseOptions parseOptions, CompilationOptions compilationOptions = null, - int index = 0, IDictionary options = null, + int index = 0, TestParametersOptions options = null, object fixProviderData = null, CodeActionPriority? priority = null) { @@ -726,56 +685,94 @@ protected static ImmutableArray FlattenActions(ImmutableArray GetNestedActions(ImmutableArray codeActions) => codeActions.SelectMany(a => a.NestedCodeActions).ToImmutableArray(); - internal (OptionKey, object) SingleOption(Option option, T enabled) - => (new OptionKey(option), enabled); + internal (OptionKey2, object) SingleOption(Option2 option, T enabled) + => (new OptionKey2(option), enabled); + + internal (OptionKey2, object) SingleOption(Option option, T enabled) + => (new OptionKey2(option), enabled); + + internal (OptionKey2, object) SingleOption(PerLanguageOption2 option, T value) + => (new OptionKey2(option, this.GetLanguage()), value); + + internal (OptionKey2, object) SingleOption(PerLanguageOption option, T value) + => (new OptionKey2(option, this.GetLanguage()), value); - protected (OptionKey, object) SingleOption(PerLanguageOption option, T value) - => (new OptionKey(option, this.GetLanguage()), value); + private protected (OptionKey2, object) SingleOption(Option2> option, T enabled, NotificationOption2 notification) + => SingleOption(option, new CodeStyleOption2(enabled, notification)); - protected (OptionKey, object) SingleOption(Option> option, T enabled, NotificationOption notification) - => SingleOption(option, new CodeStyleOption(enabled, notification)); + private protected (OptionKey2, object) SingleOption(Option> option, T enabled, NotificationOption notification) + => SingleOption(option, new CodeStyleOption2(enabled, notification)); - protected (OptionKey, object) SingleOption(Option> option, CodeStyleOption codeStyle) - => (new OptionKey(option), codeStyle); + private protected (OptionKey2, object) SingleOption(Option2> option, CodeStyleOption2 codeStyle) + => (new OptionKey2(option), codeStyle); - protected (OptionKey, object) SingleOption(PerLanguageOption> option, T enabled, NotificationOption notification) - => SingleOption(option, new CodeStyleOption(enabled, notification)); + private protected (OptionKey2, object) SingleOption(Option> option, CodeStyleOption codeStyle) + => (new OptionKey2(option), codeStyle); - protected (OptionKey, object) SingleOption(PerLanguageOption> option, CodeStyleOption codeStyle) + private protected (OptionKey2, object) SingleOption(PerLanguageOption2> option, T enabled, NotificationOption2 notification) + => SingleOption(option, new CodeStyleOption2(enabled, notification)); + + private protected (OptionKey2, object) SingleOption(PerLanguageOption> option, T enabled, NotificationOption notification) + => SingleOption(option, new CodeStyleOption2(enabled, notification)); + + private protected (OptionKey2, object) SingleOption(PerLanguageOption2> option, CodeStyleOption2 codeStyle) => SingleOption(option, codeStyle, language: GetLanguage()); - protected static (OptionKey, object) SingleOption(PerLanguageOption> option, CodeStyleOption codeStyle, string language) - => (new OptionKey(option, language), codeStyle); + private protected (OptionKey2, object) SingleOption(PerLanguageOption> option, CodeStyleOption codeStyle) + => SingleOption(option, codeStyle, language: GetLanguage()); - protected IDictionary Option(Option> option, T enabled, NotificationOption notification) + private protected static (OptionKey2, object) SingleOption(PerLanguageOption2> option, CodeStyleOption2 codeStyle, string language) + => (new OptionKey2(option, language), codeStyle); + + private protected static (OptionKey2, object) SingleOption(PerLanguageOption> option, CodeStyleOption codeStyle, string language) + => (new OptionKey2(option, language), codeStyle); + + private protected IOptionsCollection Option(Option2> option, T enabled, NotificationOption2 notification) + => OptionsSet(SingleOption(option, enabled, notification)); + + private protected IOptionsCollection Option(Option2> option, T enabled, NotificationOption notification) => OptionsSet(SingleOption(option, enabled, notification)); - protected IDictionary Option(Option> option, CodeStyleOption codeStyle) + private protected IOptionsCollection Option(Option2> option, CodeStyleOption2 codeStyle) + => OptionsSet(SingleOption(option, codeStyle)); + + private protected IOptionsCollection Option(Option> option, CodeStyleOption codeStyle) => OptionsSet(SingleOption(option, codeStyle)); - protected IDictionary Option(PerLanguageOption> option, T enabled, NotificationOption notification) + private protected IOptionsCollection Option(PerLanguageOption2> option, T enabled, NotificationOption2 notification) => OptionsSet(SingleOption(option, enabled, notification)); - protected IDictionary Option(Option option, T value) + private protected IOptionsCollection Option(PerLanguageOption> option, T enabled, NotificationOption notification) + => OptionsSet(SingleOption(option, enabled, notification)); + + private protected IOptionsCollection Option(Option2 option, T value) + => OptionsSet(SingleOption(option, value)); + + private protected IOptionsCollection Option(Option option, T value) => OptionsSet(SingleOption(option, value)); - protected IDictionary Option(PerLanguageOption option, T value) + private protected IOptionsCollection Option(PerLanguageOption2 option, T value) => OptionsSet(SingleOption(option, value)); - protected IDictionary Option(PerLanguageOption> option, CodeStyleOption codeStyle) + private protected IOptionsCollection Option(PerLanguageOption option, T value) + => OptionsSet(SingleOption(option, value)); + + private protected IOptionsCollection Option(PerLanguageOption2> option, CodeStyleOption2 codeStyle) => OptionsSet(SingleOption(option, codeStyle)); - internal static IDictionary OptionsSet( - params (OptionKey key, object value)[] options) - { - var result = new Dictionary(); - foreach (var option in options) - { - result.Add(option.key, option.value); - } + private protected IOptionsCollection Option(PerLanguageOption> option, CodeStyleOption codeStyle) + => OptionsSet(SingleOption(option, codeStyle)); - return result; - } + private protected IOptionsCollection OptionsSet(OptionKey2 option, object value) + => OptionsSet((option, value)); + +#if CODE_STYLE + internal static IOptionsCollection OptionsSet(params (OptionKey key, object value)[] options) + => throw new NotSupportedException(); +#else + internal static IOptionsCollection OptionsSet(params (OptionKey2 key, object value)[] options) + => new OptionsDictionary(options); +#endif /// /// Tests all the code actions for the given string. Each code @@ -803,5 +800,89 @@ protected async Task TestAllInRegularAndScriptAsync( await TestActionCountAsync(input, outputs.Length, parameters); } + +#if !CODE_STYLE + internal interface IOptionsCollection : IDictionary + { + } + + internal sealed class OptionsDictionary : IOptionsCollection + { + private readonly Dictionary _map; + public OptionsDictionary(params (OptionKey2 key, object value)[] options) + { + _map = new Dictionary(); + foreach (var option in options) + { + Add(option.key, option.value); + } + } + + public object this[OptionKey2 key] { get => _map[key]; set => _map[key] = value; } + + public ICollection Keys => _map.Keys; + + public ICollection Values => _map.Values; + + public int Count => _map.Count; + + public bool IsReadOnly => false; + + public void Add(OptionKey2 key, object value) + { + _map.Add(key, value); + } + + public void Add(KeyValuePair item) + { + _map.Add(item.Key, item.Value); + } + + public void Clear() + { + _map.Clear(); + } + + public bool Contains(KeyValuePair item) + { + return _map.Contains(item); + } + + public bool ContainsKey(OptionKey2 key) + { + return _map.ContainsKey(key); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + throw new NotImplementedException(); + } + + public IEnumerator> GetEnumerator() + { + return _map.GetEnumerator(); + } + + public bool Remove(OptionKey2 key) + { + return _map.Remove(key); + } + + public bool Remove(KeyValuePair item) + { + return _map.Remove(item.Key); + } + + public bool TryGetValue(OptionKey2 key, out object value) + { + return _map.TryGetValue(key, out value); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return _map.GetEnumerator(); + } + } +#endif } } diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs index c98adf1ba1a0b..034342c203e3f 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs @@ -37,10 +37,10 @@ public Test() SolutionTransforms.Add((solution, projectId) => { - var parseOptions = (CSharpParseOptions)solution.GetRequiredProject(projectId).ParseOptions!; + var parseOptions = (CSharpParseOptions)solution.GetProject(projectId)?.ParseOptions!; solution = solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion)); - var compilationOptions = solution.GetRequiredProject(projectId).CompilationOptions!; + var compilationOptions = solution.GetProject(projectId)?.CompilationOptions!; compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(compilationOptions.SpecificDiagnosticOptions.SetItems(s_nullableWarnings)); solution = solution.WithProjectCompilationOptions(projectId, compilationOptions); @@ -92,7 +92,7 @@ private static ImmutableDictionary GetNullableWarnings /// Gets a collection of options to apply to for testing. Values may be added /// using a collection initializer. /// - public OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.CSharp); + internal OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.CSharp); public string? EditorConfig { get; set; } diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CodeFixVerifierHelper.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CodeFixVerifierHelper.cs index a811ee1686ff4..20ad41ad3aaee 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CodeFixVerifierHelper.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/CodeFixVerifierHelper.cs @@ -9,17 +9,12 @@ using System.Linq; using System.Text; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; using Xunit; -#if CODE_STYLE -using OptionSet = Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions; -using Microsoft.CodeAnalysis.Internal.Options; -#else -using Microsoft.CodeAnalysis.Options; -#endif - namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions { internal static class CodeFixVerifierHelper @@ -87,7 +82,7 @@ private static void VerifyMessageHelpLinkUri(DiagnosticAnalyzer analyzer) } } - public static (SourceText? analyzerConfig, IEnumerable> options) ConvertOptionsToAnalyzerConfig(string defaultFileExtension, string? explicitEditorConfig, OptionsCollection options) + public static (SourceText? analyzerConfig, IEnumerable> options) ConvertOptionsToAnalyzerConfig(string defaultFileExtension, string? explicitEditorConfig, OptionsCollection options) { if (options.Count == 0) { @@ -95,8 +90,7 @@ public static (SourceText? analyzerConfig, IEnumerable, OptionKey, object?>(option => option.Key, option => option.Value)); - var remainingOptions = new List>(); + var remainingOptions = new List>(); var analyzerConfig = new StringBuilder(); if (explicitEditorConfig is object) @@ -112,51 +106,23 @@ public static (SourceText? analyzerConfig, IEnumerable().FirstOrDefault(); - if (editorConfigStorageLocation is null) + if (value is NamingStylePreferences namingStylePreferences) { - remainingOptions.Add(KeyValuePairUtil.Create(key, value)); + EditorConfigFileGenerator.AppendNamingStylePreferencesToEditorConfig(namingStylePreferences, key.Language!, analyzerConfig); continue; } - analyzerConfig.AppendLine(editorConfigStorageLocation.GetEditorConfigString(value, optionSet)); - } - - return (SourceText.From(analyzerConfig.ToString(), Encoding.UTF8), remainingOptions); - } - - private sealed class OptionSetWrapper : OptionSet - { - private readonly Dictionary _options; - - public OptionSetWrapper(Dictionary options) - { - _options = options; - } - -#if CODE_STYLE - public override bool TryGetValue(string key, out string value) - { - throw new NotImplementedException(); - } -#else - public override object? GetOption(OptionKey optionKey) - { - if (!_options.TryGetValue(optionKey, out var value)) + var editorConfigStorageLocation = key.Option.StorageLocations.OfType().FirstOrDefault(); + if (editorConfigStorageLocation is null) { - value = optionKey.Option.DefaultValue; + remainingOptions.Add(KeyValuePairUtil.Create(key, value)); + continue; } - return value; + analyzerConfig.AppendLine(editorConfigStorageLocation.GetEditorConfigString(value, default!)); } - public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object? value) - => throw new NotSupportedException(); - - internal override IEnumerable GetChangedOptions(OptionSet optionSet) - => SpecializedCollections.EmptyEnumerable(); - -#endif + return (SourceText.From(analyzerConfig.ToString(), Encoding.UTF8), remainingOptions); } } } diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/OptionsCollection.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/OptionsCollection.cs index 71f7e817983c8..21d1ebab6358a 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/OptionsCollection.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/OptionsCollection.cs @@ -4,47 +4,69 @@ using System.Collections; using System.Collections.Generic; - -#if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Options; -#else using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.Options; -#endif namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions { - public sealed class OptionsCollection : IReadOnlyCollection> +#if CODE_STYLE + internal interface IOptionsCollection : IReadOnlyCollection> + { + string GetEditorConfigText(); + } +#endif + + internal sealed class OptionsCollection : IReadOnlyCollection> +#if CODE_STYLE + , IOptionsCollection +#endif { - private readonly Dictionary _options = new Dictionary(); + private readonly Dictionary _options = new Dictionary(); private readonly string _languageName; + private readonly string _defaultExtension; - public OptionsCollection(string languageName) + public OptionsCollection(string languageName, params (OptionKey2 key, object value)[] options) { _languageName = languageName; + _defaultExtension = languageName == LanguageNames.CSharp ? "cs" : "vb"; + + foreach (var (key, value) in options) + { + Add(key, value); + } + } public int Count => _options.Count; - public void Add(Option option, T value) - => _options.Add(new OptionKey(option), value); + public void Add(Option2 option, T value) + => _options.Add(new OptionKey2(option), value); - public void Add(Option> option, T value, NotificationOption notification) - => _options.Add(new OptionKey(option), new CodeStyleOption(value, notification)); + public void Add(Option2> option, T value, NotificationOption2 notification) + => _options.Add(new OptionKey2(option), new CodeStyleOption2(value, notification)); - public void Add(PerLanguageOption option, T value) - => _options.Add(new OptionKey(option, _languageName), value); + public void Add(PerLanguageOption2 option, T value) + => _options.Add(new OptionKey2(option, _languageName), value); - public void Add(PerLanguageOption> option, T value) + public void Add(PerLanguageOption2> option, T value) => Add(option, value, option.DefaultValue.Notification); - public void Add(PerLanguageOption> option, T value, NotificationOption notification) - => _options.Add(new OptionKey(option, _languageName), new CodeStyleOption(value, notification)); + public void Add(PerLanguageOption2> option, T value, NotificationOption2 notification) + => _options.Add(new OptionKey2(option, _languageName), new CodeStyleOption2(value, notification)); - public IEnumerator> GetEnumerator() + public void Add(OptionKey2 optionKey, T value) + => _options.Add(optionKey, value); + + public IEnumerator> GetEnumerator() => _options.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public string GetEditorConfigText() + { + var (text, _) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(_defaultExtension, explicitEditorConfig: string.Empty, this); + return text.ToString(); + } } } diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs index 8daab14b945d1..30421d2067b20 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs @@ -8,7 +8,6 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Testing.Verifiers; using Microsoft.CodeAnalysis.VisualBasic; using Microsoft.CodeAnalysis.VisualBasic.Testing; @@ -28,7 +27,7 @@ public Test() SolutionTransforms.Add((solution, projectId) => { - var parseOptions = (VisualBasicParseOptions)solution.GetRequiredProject(projectId).ParseOptions!; + var parseOptions = (VisualBasicParseOptions)solution.GetProject(projectId)?.ParseOptions!; solution = solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion)); var (analyzerConfigSource, remainingOptions) = CodeFixVerifierHelper.ConvertOptionsToAnalyzerConfig(DefaultFileExt, EditorConfig, Options); @@ -65,7 +64,7 @@ public Test() /// Gets a collection of options to apply to for testing. Values may be added /// using a collection initializer. /// - public OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.VisualBasic); + internal OptionsCollection Options { get; } = new OptionsCollection(LanguageNames.VisualBasic); public string? EditorConfig { get; set; } diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs index 1b9c99e47a051..9eda24525ad95 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.UnitTests.Diagnostics; @@ -17,14 +18,14 @@ using Roslyn.Utilities; using Xunit; +namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics +{ #if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Options; + using TestParametersOptions = IOptionsCollection; #else -using Microsoft.CodeAnalysis.Options; + using TestParametersOptions = IDictionary; #endif -namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics -{ public abstract partial class AbstractDiagnosticProviderBasedUserDiagnosticTest : AbstractUserDiagnosticTest { private readonly ConcurrentDictionary _analyzerAndFixerMap = @@ -172,9 +173,9 @@ internal async override Task> GetDiagnosticsAsync( return (resultDiagnostics, codeActions, actionToInvoke); } - protected async Task TestDiagnosticInfoAsync( + private protected async Task TestDiagnosticInfoAsync( string initialMarkup, - IDictionary options, + TestParametersOptions options, string diagnosticId, DiagnosticSeverity diagnosticSeverity, LocalizableString diagnosticMessage = null) @@ -183,11 +184,11 @@ protected async Task TestDiagnosticInfoAsync( await TestDiagnosticInfoAsync(initialMarkup, GetScriptOptions(), null, options, diagnosticId, diagnosticSeverity, diagnosticMessage); } - protected async Task TestDiagnosticInfoAsync( + private protected async Task TestDiagnosticInfoAsync( string initialMarkup, ParseOptions parseOptions, CompilationOptions compilationOptions, - IDictionary options, + TestParametersOptions options, string diagnosticId, DiagnosticSeverity diagnosticSeverity, LocalizableString diagnosticMessage = null) diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest_ParenthesesOptions.cs b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest_ParenthesesOptions.cs index f8c83823fc3c1..430e7a04274d5 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest_ParenthesesOptions.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest_ParenthesesOptions.cs @@ -10,52 +10,56 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics { +#if !CODE_STYLE + using IOptionsCollection = IDictionary; +#endif + public abstract partial class AbstractDiagnosticProviderBasedUserDiagnosticTest : AbstractUserDiagnosticTest { #region Parentheses options - private static readonly CodeStyleOption IgnorePreference = - new CodeStyleOption(ParenthesesPreference.AlwaysForClarity, NotificationOption.None); + private static readonly CodeStyleOption2 IgnorePreference = + new CodeStyleOption2(ParenthesesPreference.AlwaysForClarity, NotificationOption2.None); - private static readonly CodeStyleOption RequireForPrecedenceClarityPreference = - new CodeStyleOption(ParenthesesPreference.AlwaysForClarity, NotificationOption.Suggestion); + private static readonly CodeStyleOption2 RequireForPrecedenceClarityPreference = + new CodeStyleOption(ParenthesesPreference.AlwaysForClarity, NotificationOption2.Suggestion); - private static readonly CodeStyleOption RemoveIfUnnecessaryPreference = - new CodeStyleOption(ParenthesesPreference.NeverIfUnnecessary, NotificationOption.Suggestion); + private static readonly CodeStyleOption2 RemoveIfUnnecessaryPreference = + new CodeStyleOption2(ParenthesesPreference.NeverIfUnnecessary, NotificationOption2.Suggestion); - private static IEnumerable>> GetAllExceptOtherParenthesesOptions() + private static IEnumerable>> GetAllExceptOtherParenthesesOptions() { - yield return CodeStyleOptions.ArithmeticBinaryParentheses; - yield return CodeStyleOptions.RelationalBinaryParentheses; - yield return CodeStyleOptions.OtherBinaryParentheses; + yield return CodeStyleOptions2.ArithmeticBinaryParentheses; + yield return CodeStyleOptions2.RelationalBinaryParentheses; + yield return CodeStyleOptions2.OtherBinaryParentheses; } - protected IDictionary RequireArithmeticBinaryParenthesesForClarity - => GetSingleRequireOption(CodeStyleOptions.ArithmeticBinaryParentheses); + private protected IOptionsCollection RequireArithmeticBinaryParenthesesForClarity + => GetSingleRequireOption(CodeStyleOptions2.ArithmeticBinaryParentheses); - protected IDictionary RequireRelationalBinaryParenthesesForClarity - => GetSingleRequireOption(CodeStyleOptions.RelationalBinaryParentheses); + private protected IOptionsCollection RequireRelationalBinaryParenthesesForClarity + => GetSingleRequireOption(CodeStyleOptions2.RelationalBinaryParentheses); - protected IDictionary RequireOtherBinaryParenthesesForClarity - => GetSingleRequireOption(CodeStyleOptions.OtherBinaryParentheses); + private protected IOptionsCollection RequireOtherBinaryParenthesesForClarity + => GetSingleRequireOption(CodeStyleOptions2.OtherBinaryParentheses); - private IEnumerable>> GetAllParenthesesOptions() - => GetAllExceptOtherParenthesesOptions().Concat(CodeStyleOptions.OtherParentheses); + private IEnumerable>> GetAllParenthesesOptions() + => GetAllExceptOtherParenthesesOptions().Concat(CodeStyleOptions2.OtherParentheses); - protected IDictionary IgnoreAllParentheses + private protected IOptionsCollection IgnoreAllParentheses => OptionsSet(GetAllParenthesesOptions().Select( o => SingleOption(o, IgnorePreference)).ToArray()); - protected IDictionary RemoveAllUnnecessaryParentheses + private protected IOptionsCollection RemoveAllUnnecessaryParentheses => OptionsSet(GetAllParenthesesOptions().Select( o => SingleOption(o, RemoveIfUnnecessaryPreference)).ToArray()); - protected IDictionary RequireAllParenthesesForClarity + private protected IOptionsCollection RequireAllParenthesesForClarity => OptionsSet(GetAllExceptOtherParenthesesOptions() .Select(o => SingleOption(o, RequireForPrecedenceClarityPreference)) - .Concat(SingleOption(CodeStyleOptions.OtherParentheses, RemoveIfUnnecessaryPreference)).ToArray()); + .Concat(SingleOption(CodeStyleOptions2.OtherParentheses, RemoveIfUnnecessaryPreference)).ToArray()); - private IDictionary GetSingleRequireOption(PerLanguageOption> option) + private IOptionsCollection GetSingleRequireOption(PerLanguageOption2> option) => OptionsSet(GetAllParenthesesOptions() .Where(o => o != option) .Select(o => SingleOption(o, RemoveIfUnnecessaryPreference)) diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.FixAllDiagnosticProvider.cs b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.FixAllDiagnosticProvider.cs index d57e439688a90..90b6c2b7629ac 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.FixAllDiagnosticProvider.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.FixAllDiagnosticProvider.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.UnitTests.Diagnostics; namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs index 95c66312507b3..ba99805c884be 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs @@ -21,12 +21,6 @@ using Roslyn.Utilities; using Xunit; -#if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Options; -#else -using Microsoft.CodeAnalysis.Options; -#endif - namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics { public abstract partial class AbstractUserDiagnosticTest : AbstractCodeActionOrUserDiagnosticTest @@ -37,7 +31,7 @@ public abstract partial class AbstractUserDiagnosticTest : AbstractCodeActionOrU internal abstract Task> GetDiagnosticsAsync( TestWorkspace workspace, TestParameters parameters); - protected async Task TestDiagnosticsAsync( + private protected async Task TestDiagnosticsAsync( string initialMarkup, TestParameters parameters = default, params DiagnosticDescription[] expected) { using var workspace = CreateWorkspaceFromOptions(initialMarkup, parameters); @@ -242,12 +236,12 @@ private static FixAllState GetFixAllState( : new FixAllState(fixAllProvider, document.Project, fixer, scope, equivalenceKey, diagnosticIds, fixAllDiagnosticProvider); } - protected Task TestActionCountInAllFixesAsync( + private protected Task TestActionCountInAllFixesAsync( string initialMarkup, int count, ParseOptions parseOptions = null, CompilationOptions compilationOptions = null, - IDictionary options = null, + IOptionsCollection options = null, object fixProviderData = null) { return TestActionCountInAllFixesAsync( diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Microsoft.CodeAnalysis.EditorFeatures.DiagnosticsTests.Utilities.csproj b/src/EditorFeatures/DiagnosticsTestUtilities/Microsoft.CodeAnalysis.EditorFeatures.DiagnosticsTests.Utilities.csproj index b1baa3c88bdd5..6e649cfd4a5f9 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Microsoft.CodeAnalysis.EditorFeatures.DiagnosticsTests.Utilities.csproj +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Microsoft.CodeAnalysis.EditorFeatures.DiagnosticsTests.Utilities.csproj @@ -52,7 +52,7 @@ - + diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs b/src/EditorFeatures/DiagnosticsTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs index 91c1c29e5fa3b..7996f500afb6e 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/NamingStyles/NamingStylesTestOptionSets.cs @@ -3,33 +3,34 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; +using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; using Microsoft.CodeAnalysis.NamingStyles; using Roslyn.Utilities; - -#if CODE_STYLE -using Microsoft.CodeAnalysis.Internal.Options; -#else using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Simplification; -#endif namespace Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles { +#if !CODE_STYLE + using IOptionsCollection = IDictionary; +#endif + public sealed class NamingStylesTestOptionSets { - private readonly OptionKey _optionKey; + private readonly string _languageName; + private readonly OptionKey2 _optionKey; public NamingStylesTestOptionSets(string languageName) { + _languageName = languageName; _optionKey = NamingStyleOptions.GetNamingPreferencesOptionKey(languageName); } - public IDictionary MergeStyles(IDictionary first, IDictionary second, string languageName) + internal IOptionsCollection MergeStyles(IOptionsCollection first, IOptionsCollection second, string languageName) { var firstPreferences = (NamingStylePreferences)first.First().Value; var secondPreferences = (NamingStylePreferences)second.First().Value; @@ -39,67 +40,67 @@ public IDictionary MergeStyles(IDictionary firstPreferences.NamingRules.AddRange(secondPreferences.NamingRules))); } - public IDictionary ClassNamesArePascalCase => + internal IOptionsCollection ClassNamesArePascalCase => Options(_optionKey, ClassNamesArePascalCaseOption()); - public IDictionary FieldNamesAreCamelCase => + internal IOptionsCollection FieldNamesAreCamelCase => Options(_optionKey, FieldNamesAreCamelCaseOption()); - public IDictionary FieldNamesAreCamelCaseWithUnderscorePrefix => + internal IOptionsCollection FieldNamesAreCamelCaseWithUnderscorePrefix => Options(_optionKey, FieldNamesAreCamelCaseWithUnderscorePrefixOption()); - public IDictionary FieldNamesAreCamelCaseWithFieldUnderscorePrefix => + internal IOptionsCollection FieldNamesAreCamelCaseWithFieldUnderscorePrefix => Options(_optionKey, FieldNamesAreCamelCaseWithFieldUnderscorePrefixOption()); - public IDictionary FieldNamesAreCamelCaseWithFieldUnderscorePrefixAndUnderscoreEndSuffix => + internal IOptionsCollection FieldNamesAreCamelCaseWithFieldUnderscorePrefixAndUnderscoreEndSuffix => Options(_optionKey, FieldNamesAreCamelCaseWithFieldUnderscorePrefixAndUnderscoreEndSuffixOption()); - public IDictionary MethodNamesArePascalCase => + internal IOptionsCollection MethodNamesArePascalCase => Options(_optionKey, MethodNamesArePascalCaseOption()); - public IDictionary ParameterNamesAreCamelCase => + internal IOptionsCollection ParameterNamesAreCamelCase => Options(_optionKey, ParameterNamesAreCamelCaseOption()); - public IDictionary ParameterNamesAreCamelCaseWithPUnderscorePrefix => + internal IOptionsCollection ParameterNamesAreCamelCaseWithPUnderscorePrefix => Options(_optionKey, ParameterNamesAreCamelCaseWithPUnderscorePrefixOption()); - public IDictionary ParameterNamesAreCamelCaseWithPUnderscorePrefixAndUnderscoreEndSuffix => + internal IOptionsCollection ParameterNamesAreCamelCaseWithPUnderscorePrefixAndUnderscoreEndSuffix => Options(_optionKey, ParameterNamesAreCamelCaseWithPUnderscorePrefixAndUnderscoreEndSuffixOption()); - public IDictionary LocalNamesAreCamelCase => + internal IOptionsCollection LocalNamesAreCamelCase => Options(_optionKey, LocalNamesAreCamelCaseOption()); - public IDictionary LocalFunctionNamesAreCamelCase => + internal IOptionsCollection LocalFunctionNamesAreCamelCase => Options(_optionKey, LocalFunctionNamesAreCamelCaseOption()); - public IDictionary PropertyNamesArePascalCase => + internal IOptionsCollection PropertyNamesArePascalCase => Options(_optionKey, PropertyNamesArePascalCaseOption()); - public IDictionary InterfaceNamesStartWithI => + internal IOptionsCollection InterfaceNamesStartWithI => Options(_optionKey, InterfaceNamesStartWithIOption()); - public IDictionary TypeParameterNamesStartWithT => + internal IOptionsCollection TypeParameterNamesStartWithT => Options(_optionKey, TypeParameterNamesStartWithTOption()); - public IDictionary ConstantsAreUpperCase => + internal IOptionsCollection ConstantsAreUpperCase => Options(_optionKey, ConstantsAreUpperCaseOption()); - public IDictionary LocalsAreCamelCaseConstantsAreUpperCase => + internal IOptionsCollection LocalsAreCamelCaseConstantsAreUpperCase => Options(_optionKey, LocalsAreCamelCaseConstantsAreUpperCaseOption()); - public IDictionary AsyncFunctionNamesEndWithAsync => + internal IOptionsCollection AsyncFunctionNamesEndWithAsync => Options(_optionKey, AsyncFunctionNamesEndWithAsyncOption()); - public IDictionary MethodNamesWithAccessibilityArePascalCase(ImmutableArray accessibilities) => + internal IOptionsCollection MethodNamesWithAccessibilityArePascalCase(ImmutableArray accessibilities) => Options(_optionKey, MethodNamesArePascalCaseOption(accessibilities)); - internal IDictionary SymbolKindsArePascalCase(ImmutableArray symbolKinds) => + internal IOptionsCollection SymbolKindsArePascalCase(ImmutableArray symbolKinds) => Options(_optionKey, SymbolKindsArePascalCaseOption(symbolKinds)); - internal IDictionary SymbolKindsArePascalCaseEmpty() => + internal IOptionsCollection SymbolKindsArePascalCaseEmpty() => Options(_optionKey, SymbolKindsArePascalCaseOption(ImmutableArray.Empty)); - internal IDictionary SymbolKindsArePascalCase(object symbolOrTypeKind) => + internal IOptionsCollection SymbolKindsArePascalCase(object symbolOrTypeKind) => SymbolKindsArePascalCase(ImmutableArray.Create(ToSymbolKindOrTypeKind(symbolOrTypeKind))); internal static SymbolSpecification.SymbolKindOrTypeKind ToSymbolKindOrTypeKind(object symbolOrTypeKind) @@ -120,16 +121,25 @@ internal static SymbolSpecification.SymbolKindOrTypeKind ToSymbolKindOrTypeKind( } } - internal IDictionary AccessibilitiesArePascalCase(ImmutableArray accessibilities) => + internal IOptionsCollection AccessibilitiesArePascalCase(ImmutableArray accessibilities) => Options(_optionKey, AccessibilitiesArePascalCaseOption(accessibilities)); - private static IDictionary Options(OptionKey option, object value) +#if CODE_STYLE + private IOptionsCollection Options(OptionKey2 option, object value) + => Options(new[] { (option, value) }); + + private IOptionsCollection Options(params (OptionKey2 key, object value)[] options) + => new OptionsCollection(_languageName, options); + +#else + private static IOptionsCollection Options(OptionKey2 option, object value) { - return new Dictionary + return new Dictionary { { option, value } }; } +#endif private static NamingStylePreferences ClassNamesArePascalCaseOption() { diff --git a/src/EditorFeatures/TestUtilities/Extensions/WorkspaceExtensions.cs b/src/EditorFeatures/TestUtilities/Extensions/WorkspaceExtensions.cs index 228ee6711e903..af78cdb4a40b8 100644 --- a/src/EditorFeatures/TestUtilities/Extensions/WorkspaceExtensions.cs +++ b/src/EditorFeatures/TestUtilities/Extensions/WorkspaceExtensions.cs @@ -2,21 +2,30 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System.Collections.Generic; +using System.Linq; using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.Editor.UnitTests.Extensions { public static class WorkspaceExtensions { - public static void ApplyOptions(this Workspace workspace, IDictionary options) + public static void ApplyOptions(this Workspace workspace, IDictionary? options) + => workspace.ApplyOptions(options.Select(kvp => (kvp.Key, kvp.Value))); + + internal static void ApplyOptions(this Workspace workspace, IDictionary? options) + => workspace.ApplyOptions(options.Select(kvp => ((OptionKey)kvp.Key, kvp.Value))); + + private static void ApplyOptions(this Workspace workspace, IEnumerable<(OptionKey key, object value)>? options) { if (options != null) { var optionSet = workspace.Options; foreach (var option in options) { - optionSet = optionSet.WithChangedOption(option.Key, option.Value); + optionSet = optionSet.WithChangedOption(option.key, option.value); } workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(optionSet)); diff --git a/src/EditorFeatures/TestUtilities/Roslyn.Services.Test.Utilities.csproj b/src/EditorFeatures/TestUtilities/Roslyn.Services.Test.Utilities.csproj index b938b5adef02e..d7d1b3032f282 100644 --- a/src/EditorFeatures/TestUtilities/Roslyn.Services.Test.Utilities.csproj +++ b/src/EditorFeatures/TestUtilities/Roslyn.Services.Test.Utilities.csproj @@ -102,7 +102,7 @@ - + diff --git a/src/Test/Utilities/Portable/Roslyn.Test.Utilities.csproj b/src/Test/Utilities/Portable/Roslyn.Test.Utilities.csproj index 336655b151e4b..a27c68f1d3f50 100644 --- a/src/Test/Utilities/Portable/Roslyn.Test.Utilities.csproj +++ b/src/Test/Utilities/Portable/Roslyn.Test.Utilities.csproj @@ -62,6 +62,7 @@ +