diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs index 430230a273caa357aff61953eaa45c78dedda766..621771f61061882b44029345ded630fabf706745 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs @@ -22,29 +22,26 @@ public abstract class AnalyzerConfigOptions /// Get an analyzer config value for the given key, using the . /// public abstract bool TryGetValue(string key, out string value); + + /// + /// Get the keys of the defined options. + /// + public abstract ImmutableArray Keys { get; } } - public abstract class DictionaryBackedAnalyzerConfigOptions : AnalyzerConfigOptions + internal sealed class CompilerAnalyzerConfigOptions : AnalyzerConfigOptions { + public static CompilerAnalyzerConfigOptions Empty { get; } = new CompilerAnalyzerConfigOptions(EmptyDictionary); + private readonly ImmutableDictionary _backing; - public DictionaryBackedAnalyzerConfigOptions(ImmutableDictionary properties) + public CompilerAnalyzerConfigOptions(ImmutableDictionary properties) { _backing = properties; } public override bool TryGetValue(string key, out string value) => _backing.TryGetValue(key, out value); - public IReadOnlyDictionary AsReadOnlyDictionary() => _backing; - } - - internal sealed class CompilerAnalyzerConfigOptions : DictionaryBackedAnalyzerConfigOptions - { - public static CompilerAnalyzerConfigOptions Empty { get; } = new CompilerAnalyzerConfigOptions(EmptyDictionary); - - public CompilerAnalyzerConfigOptions(ImmutableDictionary properties) - : base(properties) - { - } + public override ImmutableArray Keys => _backing.Keys.ToImmutableArray(); } } diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 78413f9718c17dc24f41c08f778bd0b415404da8..ca589687a62326e30693c08faf067ec18395bddd 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -1,8 +1,5 @@ Microsoft.CodeAnalysis.CommandLineArguments.ErrorLogOptions.get -> Microsoft.CodeAnalysis.ErrorLogOptions *REMOVED*Microsoft.CodeAnalysis.CommandLineArguments.ErrorLogPath.get -> string -Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions -Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions.AsReadOnlyDictionary() -> System.Collections.Generic.IReadOnlyDictionary -Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions.DictionaryBackedAnalyzerConfigOptions(System.Collections.Immutable.ImmutableDictionary properties) -> void Microsoft.CodeAnalysis.ErrorLogOptions Microsoft.CodeAnalysis.ErrorLogOptions.ErrorLogOptions(string path, Microsoft.CodeAnalysis.SarifVersion sarifVersion) -> void Microsoft.CodeAnalysis.ErrorLogOptions.Path.get -> string @@ -22,7 +19,7 @@ Microsoft.CodeAnalysis.SarifVersion.Latest = 2147483647 -> Microsoft.CodeAnalysi Microsoft.CodeAnalysis.SarifVersion.Sarif1 = 1 -> Microsoft.CodeAnalysis.SarifVersion Microsoft.CodeAnalysis.SarifVersion.Sarif2 = 2 -> Microsoft.CodeAnalysis.SarifVersion Microsoft.CodeAnalysis.SarifVersionFacts -override Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions.TryGetValue(string key, out string value) -> bool +abstract Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions.Keys.get -> System.Collections.Immutable.ImmutableArray Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier = 256 -> Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions static Microsoft.CodeAnalysis.SarifVersionFacts.TryParse(string version, out Microsoft.CodeAnalysis.SarifVersion result) -> bool Microsoft.CodeAnalysis.IMethodSymbol.IsConditional.get -> bool diff --git a/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs b/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs index 83834252482328b1187e63d1045bd18b8f13ee61..5abc812cba2cf8d6d834b9d24f707d32bf89d4ba 100644 --- a/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs +++ b/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections; -using System.Collections.Generic; +using System.Collections.Immutable; using Microsoft.CodeAnalysis.Diagnostics; +using Roslyn.Collections.Immutable; namespace Microsoft.CodeAnalysis.Options { @@ -11,63 +11,15 @@ internal static class EditorConfigStorageLocationExtensions { public static bool TryGetOption(this IEditorConfigStorageLocation editorConfigStorageLocation, AnalyzerConfigOptions analyzerConfigOptions, Type type, out object value) { - var optionDictionary = analyzerConfigOptions is DictionaryBackedAnalyzerConfigOptions dictionaryAnalyzerConfigOptions - ? dictionaryAnalyzerConfigOptions.AsReadOnlyDictionary() - : new AnalyzerConfigOptionsDictionary(analyzerConfigOptions); - - return editorConfigStorageLocation.TryGetOption(optionDictionary, type, out value); - } - - /// - /// This is a wrapper around AnalyzerConfigOptions so that it can be used as a read-only Dictionary. - /// - private class AnalyzerConfigOptionsDictionary : IReadOnlyDictionary - { - private readonly AnalyzerConfigOptions _analyzerConfigOptions; - - public AnalyzerConfigOptionsDictionary(AnalyzerConfigOptions analyzerConfigOptions) - { - _analyzerConfigOptions = analyzerConfigOptions; - } - - public string this[string key] - { - get + var optionDictionary = analyzerConfigOptions.Keys.ToImmutableDictionary( + key => key, + key => { - if (_analyzerConfigOptions.TryGetValue(key, out var value)) - { - return value; - } - - throw new KeyNotFoundException(); - } - } + analyzerConfigOptions.TryGetValue(key, out var optionValue); + return optionValue; + }); - public IEnumerable Keys => throw new NotImplementedException(); - - public IEnumerable Values => throw new NotImplementedException(); - - public int Count => throw new NotImplementedException(); - - public bool ContainsKey(string key) - { - return _analyzerConfigOptions.TryGetValue(key, out _); - } - - public IEnumerator> GetEnumerator() - { - throw new NotImplementedException(); - } - - public bool TryGetValue(string key, out string value) - { - return _analyzerConfigOptions.TryGetValue(key, out value); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } + return editorConfigStorageLocation.TryGetOption(optionDictionary, type, out value); } } } diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs index 47d6c23c06e5e0a2fb5c164c8288fe6fb99a29ef..6d4a83147170c4c67988ed35d7d3b0936226c417 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs @@ -307,12 +307,18 @@ public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) } // PROTOTYPE: why isn't this just a provided implementation? - private sealed class WorkspaceAnalyzerConfigOptions : DictionaryBackedAnalyzerConfigOptions + private sealed class WorkspaceAnalyzerConfigOptions : AnalyzerConfigOptions { + private readonly ImmutableDictionary _backing; + public WorkspaceAnalyzerConfigOptions(AnalyzerConfigOptionsResult analyzerConfigOptions) - : base(analyzerConfigOptions.AnalyzerOptions) { + _backing = analyzerConfigOptions.AnalyzerOptions; } + + public override bool TryGetValue(string key, out string value) => _backing.TryGetValue(key, out value); + + public override ImmutableArray Keys => _backing.Keys.ToImmutableArray(); } }