From 040d4e8c6a9d4e2f74e5fe41951b58e4b535c111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Matou=C5=A1ek?= Date: Thu, 10 Feb 2022 17:30:36 -0800 Subject: [PATCH] Ide analyzer options (#58765) * IDE analyzer options * Feedback * Fix --- ...RemoveUnreachableCodeDiagnosticAnalyzer.cs | 6 +-- .../Core/Analyzers/Helpers/AnalyzerHelper.cs | 41 +++++++++++++++ ...oveUnnecessaryImportsDiagnosticAnalyzer.cs | 11 +--- ...tValidateFormatStringDiagnosticAnalyzer.cs | 5 +- .../CSharpTest/AddUsing/AddUsingNuGetTests.cs | 6 +-- .../CodeActions/CodeActionOptionsStorage.cs | 6 +-- .../SymbolSearchOptionsStorage.cs | 26 ++++++++++ .../AddImport/AddImportTests_NuGet.vb | 6 +-- .../AbstractAddImportCodeFixProvider.cs | 51 +++++++++---------- .../AddImport/IAddImportFeatureService.cs | 2 +- .../AddImport/SymbolReferenceFinder.cs | 6 --- ...olReferenceFinder_PackageAssemblySearch.cs | 2 +- .../AbstractAddPackageCodeFixProvider.cs | 8 +-- ...AbstractAddMissingImportsFeatureService.cs | 2 +- .../Portable/Diagnostics/AnalyzerHelper.cs | 1 - .../Diagnostics/WorkspaceAnalyzerOptions.cs | 22 ++++++-- .../AbstractRegexDiagnosticAnalyzer.cs | 4 +- .../Core/Portable/Fading/FadingOptions.cs | 20 ++++---- .../Options/AdvancedOptionPageControl.xaml.cs | 8 +-- .../AutomationObject.Fading.cs | 8 +-- .../AutomationObject.SymbolSearch.cs | 8 +-- .../PackageInstallerServiceFactory.cs | 12 ++--- .../AbstractDelayStartedService.cs | 32 ++++++------ .../SymbolSearch/SymbolSearchGlobalOptions.cs | 17 +------ .../VisualStudioSymbolSearchService.cs | 10 +++- .../Options/AdvancedOptionPageControl.xaml.vb | 6 +-- .../AutomationObject.Fading.vb | 8 +-- .../AutomationObject.SymbolSearch.vb | 8 +-- .../Portable/CodeActions/CodeActionOptions.cs | 20 +++++--- .../SymbolSearch/SymbolSearchOptions.cs | 30 +++-------- 30 files changed, 211 insertions(+), 181 deletions(-) create mode 100644 src/EditorFeatures/Core/SymbolSearch/SymbolSearchOptionsStorage.cs diff --git a/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs index 6cb6f0afa00eb..4efaffbe9927e 100644 --- a/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs @@ -40,11 +40,7 @@ protected override void InitializeWorker(AnalysisContext context) private void AnalyzeSemanticModel(SemanticModelAnalysisContext context) { -#if CODE_STYLE - var fadeCode = true; -#else - var fadeCode = context.GetOption(Fading.FadingOptions.FadeOutUnreachableCode, LanguageNames.CSharp); -#endif + var fadeCode = context.GetIdeOptions().FadeOutUnreachableCode; var semanticModel = context.SemanticModel; var cancellationToken = context.CancellationToken; diff --git a/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs b/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs index 9e070ce9dddfc..78fc8b8477c4a 100644 --- a/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs +++ b/src/Analyzers/Core/Analyzers/Helpers/AnalyzerHelper.cs @@ -13,8 +13,49 @@ namespace Microsoft.CodeAnalysis.Diagnostics { + internal readonly record struct IdeAnalyzerOptions( + bool FadeOutUnusedImports, + bool FadeOutUnreachableCode, + bool ReportInvalidPlaceholdersInStringDotFormatCalls, + bool ReportInvalidRegexPatterns) + { + public static readonly IdeAnalyzerOptions CodeStyleDefault = new( + FadeOutUnusedImports: false, + FadeOutUnreachableCode: false, + ReportInvalidPlaceholdersInStringDotFormatCalls: true, + ReportInvalidRegexPatterns: true); + } + internal static partial class AnalyzerHelper { + public static IdeAnalyzerOptions GetIdeOptions(this SyntaxTreeAnalysisContext context) +#if CODE_STYLE + => IdeAnalyzerOptions.CodeStyleDefault; +#else + => (context.Options is WorkspaceAnalyzerOptions workspaceOptions) ? workspaceOptions.GetIdeOptions(context.Tree.Options.Language) : IdeAnalyzerOptions.CodeStyleDefault; +#endif + + public static IdeAnalyzerOptions GetIdeOptions(this OperationAnalysisContext context) +#if CODE_STYLE + => IdeAnalyzerOptions.CodeStyleDefault; +#else + => (context.Options is WorkspaceAnalyzerOptions workspaceOptions) ? workspaceOptions.GetIdeOptions(context.Operation.Language) : IdeAnalyzerOptions.CodeStyleDefault; +#endif + + public static IdeAnalyzerOptions GetIdeOptions(this SyntaxNodeAnalysisContext context) +#if CODE_STYLE + => IdeAnalyzerOptions.CodeStyleDefault; +#else + => (context.Options is WorkspaceAnalyzerOptions workspaceOptions) ? workspaceOptions.GetIdeOptions(context.Node.Language) : IdeAnalyzerOptions.CodeStyleDefault; +#endif + + public static IdeAnalyzerOptions GetIdeOptions(this SemanticModelAnalysisContext context) +#if CODE_STYLE + => IdeAnalyzerOptions.CodeStyleDefault; +#else + => (context.Options is WorkspaceAnalyzerOptions workspaceOptions) ? workspaceOptions.GetIdeOptions(context.SemanticModel.Language) : IdeAnalyzerOptions.CodeStyleDefault; +#endif + public static T GetOption(this SemanticModelAnalysisContext context, Option2 option) { var analyzerOptions = context.Options; diff --git a/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs index a4dce10e2d908..816dcb501398a 100644 --- a/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs @@ -142,7 +142,7 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context) // for us appropriately. unnecessaryImports = MergeImports(unnecessaryImports); - var fadeOut = ShouldFade(context.Options, tree, language, cancellationToken); + var fadeOut = context.GetIdeOptions().FadeOutUnusedImports; DiagnosticDescriptor descriptor; if (GeneratedCodeUtilities.IsGeneratedCode(tree, IsRegularCommentOrDocComment, cancellationToken)) @@ -164,15 +164,6 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context) context.ReportDiagnostic(diagnostic); } } - - static bool ShouldFade(AnalyzerOptions options, SyntaxTree tree, string language, CancellationToken cancellationToken) - { -#if CODE_STYLE - return true; -#else - return options.GetOption(Fading.FadingOptions.FadeOutUnusedImports, language, tree, cancellationToken); -#endif - } } private IEnumerable GetContiguousSpans(ImmutableArray nodes) diff --git a/src/Analyzers/Core/Analyzers/ValidateFormatString/AbstractValidateFormatStringDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/ValidateFormatString/AbstractValidateFormatStringDiagnosticAnalyzer.cs index 855e4b23f8d99..8a9da43afd2dd 100644 --- a/src/Analyzers/Core/Analyzers/ValidateFormatString/AbstractValidateFormatStringDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/ValidateFormatString/AbstractValidateFormatStringDiagnosticAnalyzer.cs @@ -96,10 +96,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context, INamedTypeSymbol for return; } - var option = context.GetOption( - ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, - context.SemanticModel.Language); - if (option == false) + if (!context.GetIdeOptions().ReportInvalidPlaceholdersInStringDotFormatCalls) { return; } diff --git a/src/EditorFeatures/CSharpTest/AddUsing/AddUsingNuGetTests.cs b/src/EditorFeatures/CSharpTest/AddUsing/AddUsingNuGetTests.cs index 1a163db1b3ff6..899397848d526 100644 --- a/src/EditorFeatures/CSharpTest/AddUsing/AddUsingNuGetTests.cs +++ b/src/EditorFeatures/CSharpTest/AddUsing/AddUsingNuGetTests.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.CSharp.AddImport; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Packaging; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.SymbolSearch; @@ -35,9 +36,8 @@ public class AddUsingNuGetTests : AbstractAddUsingTests protected override void InitializeWorkspace(TestWorkspace workspace, TestParameters parameters) { - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages, LanguageNames.CSharp, true) - .WithChangedOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, LanguageNames.CSharp, true))); + workspace.GlobalOptions.SetGlobalOption(new OptionKey(SymbolSearchOptionsStorage.SearchNuGetPackages, LanguageNames.CSharp), true); + workspace.GlobalOptions.SetGlobalOption(new OptionKey(SymbolSearchOptionsStorage.SearchReferenceAssemblies, LanguageNames.CSharp), true); } internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer( diff --git a/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs b/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs index 7680a3a552668..bc5363d278095 100644 --- a/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs +++ b/src/EditorFeatures/Core/Implementation/CodeActions/CodeActionOptionsStorage.cs @@ -12,8 +12,8 @@ internal static class CodeActionOptionsStorage { internal static CodeActionOptions GetCodeActionOptions(this IGlobalOptionService globalOptions, string language, bool isBlocking) => new( - IsBlocking: isBlocking, - SearchReferenceAssemblies: globalOptions.GetOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, language), - HideAdvancedMembers: globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, language)); + SearchOptions: globalOptions.GetSymbolSearchOptions(language), + HideAdvancedMembers: globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, language), + IsBlocking: isBlocking); } } diff --git a/src/EditorFeatures/Core/SymbolSearch/SymbolSearchOptionsStorage.cs b/src/EditorFeatures/Core/SymbolSearch/SymbolSearchOptionsStorage.cs new file mode 100644 index 0000000000000..fbd8903617613 --- /dev/null +++ b/src/EditorFeatures/Core/SymbolSearch/SymbolSearchOptionsStorage.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.CodeAnalysis.Options; + +namespace Microsoft.CodeAnalysis.SymbolSearch +{ + internal static class SymbolSearchOptionsStorage + { + internal static SymbolSearchOptions GetSymbolSearchOptions(this IGlobalOptionService globalOptions, string language) + => new( + SearchReferenceAssemblies: globalOptions.GetOption(SearchReferenceAssemblies, language), + SearchNuGetPackages: globalOptions.GetOption(SearchNuGetPackages, language)); + + private const string FeatureName = "SymbolSearchOptions"; + + public static PerLanguageOption2 SearchReferenceAssemblies = + new(FeatureName, "SuggestForTypesInReferenceAssemblies", SymbolSearchOptions.Default.SearchReferenceAssemblies, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInReferenceAssemblies")); + + public static PerLanguageOption2 SearchNuGetPackages = + new(FeatureName, "SuggestForTypesInNuGetPackages", SymbolSearchOptions.Default.SearchNuGetPackages, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInNuGetPackages")); + } +} diff --git a/src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb b/src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb index f4db5fc18d4d2..5014dfda6a901 100644 --- a/src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb +++ b/src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.CodeActions Imports Microsoft.CodeAnalysis.CodeFixes Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Packaging Imports Microsoft.CodeAnalysis.Shared.Utilities Imports Microsoft.CodeAnalysis.SymbolSearch @@ -25,9 +26,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeActions.AddImp ImmutableArray.Create(New PackageSource(PackageSourceHelper.NugetOrgSourceName, "http://nuget.org")) Protected Overrides Sub InitializeWorkspace(workspace As TestWorkspace, parameters As TestParameters) - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options. - WithChangedOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages, LanguageNames.VisualBasic, True). - WithChangedOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, LanguageNames.VisualBasic, True))) + workspace.GlobalOptions.SetGlobalOption(New OptionKey(SymbolSearchOptionsStorage.SearchNuGetPackages, LanguageNames.VisualBasic), True) + workspace.GlobalOptions.SetGlobalOption(New OptionKey(SymbolSearchOptionsStorage.SearchReferenceAssemblies, LanguageNames.VisualBasic), True) End Sub Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace) As (DiagnosticAnalyzer, CodeFixProvider) diff --git a/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs b/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs index 65125d8197c34..25fcf19a4d6f3 100644 --- a/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs @@ -2,14 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Immutable; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CodeGeneration; -using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.Packaging; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.SymbolSearch; @@ -20,15 +16,15 @@ internal abstract partial class AbstractAddImportCodeFixProvider : CodeFixProvid { private const int MaxResults = 5; - private readonly IPackageInstallerService _packageInstallerService; - private readonly ISymbolSearchService _symbolSearchService; + private readonly IPackageInstallerService? _packageInstallerService; + private readonly ISymbolSearchService? _symbolSearchService; /// /// Values for these parameters can be provided (during testing) for mocking purposes. /// protected AbstractAddImportCodeFixProvider( - IPackageInstallerService packageInstallerService = null, - ISymbolSearchService symbolSearchService = null) + IPackageInstallerService? packageInstallerService = null, + ISymbolSearchService? symbolSearchService = null) { _packageInstallerService = packageInstallerService; _symbolSearchService = symbolSearchService; @@ -42,7 +38,7 @@ protected AbstractAddImportCodeFixProvider( private protected override CodeActionRequestPriority ComputeRequestPriority() => CodeActionRequestPriority.High; - public sealed override FixAllProvider GetFixAllProvider() + public sealed override FixAllProvider? GetFixAllProvider() { // Currently Fix All is not supported for this provider // https://github.com/dotnet/roslyn/issues/34457 @@ -56,30 +52,34 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var cancellationToken = context.CancellationToken; var diagnostics = context.Diagnostics; - var addImportService = document.GetLanguageService(); + var addImportService = document.GetRequiredLanguageService(); + var services = document.Project.Solution.Workspace.Services; + + var searchOptions = context.Options.SearchOptions; - var solution = document.Project.Solution; + var symbolSearchService = _symbolSearchService ?? services.GetRequiredService(); - var searchNuGetPackages = solution.Options.GetOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages, document.Project.Language); + var installerService = searchOptions.SearchNuGetPackages ? + _packageInstallerService ?? services.GetService() : null; + + var packageSources = installerService?.IsEnabled(document.Project.Id) == true + ? installerService.TryGetPackageSources() + : ImmutableArray.Empty; + + if (packageSources.IsEmpty) + { + searchOptions = searchOptions with { SearchNuGetPackages = false }; + } var placement = await AddImportPlacementOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); - var options = new AddImportOptions( - context.Options.SearchReferenceAssemblies, + var addImportOptions = new AddImportOptions( + searchOptions, context.Options.HideAdvancedMembers, placement); - var symbolSearchService = options.SearchReferenceAssemblies || searchNuGetPackages - ? _symbolSearchService ?? solution.Workspace.Services.GetService() - : null; - - var installerService = GetPackageInstallerService(document); - var packageSources = searchNuGetPackages && symbolSearchService != null && installerService?.IsEnabled(document.Project.Id) == true - ? installerService.TryGetPackageSources() - : ImmutableArray.Empty; - var fixesForDiagnostic = await addImportService.GetFixesForDiagnosticsAsync( - document, span, diagnostics, MaxResults, symbolSearchService, options, packageSources, cancellationToken).ConfigureAwait(false); + document, span, diagnostics, MaxResults, symbolSearchService, addImportOptions, packageSources, cancellationToken).ConfigureAwait(false); foreach (var (diagnostic, fixes) in fixesForDiagnostic) { @@ -88,8 +88,5 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterFixes(codeActions, diagnostic); } } - - private IPackageInstallerService GetPackageInstallerService(Document document) - => _packageInstallerService ?? document.Project.Solution.Workspace.Services.GetService(); } } diff --git a/src/Features/Core/Portable/AddImport/IAddImportFeatureService.cs b/src/Features/Core/Portable/AddImport/IAddImportFeatureService.cs index c69550cb064f9..453c8a89cd5c8 100644 --- a/src/Features/Core/Portable/AddImport/IAddImportFeatureService.cs +++ b/src/Features/Core/Portable/AddImport/IAddImportFeatureService.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.AddImport { [DataContract] internal readonly record struct AddImportOptions( - [property: DataMember(Order = 0)] bool SearchReferenceAssemblies, + [property: DataMember(Order = 0)] SymbolSearchOptions SearchOptions, [property: DataMember(Order = 1)] bool HideAdvancedMembers, [property: DataMember(Order = 2)] AddImportPlacementOptions Placement); diff --git a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs index d85f70bf82b99..6514dc0f4cb92 100644 --- a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs +++ b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder.cs @@ -62,12 +62,6 @@ public SymbolReferenceFinder( _symbolSearchService = symbolSearchService; _options = options; _packageSources = packageSources; - - if (options.SearchReferenceAssemblies || packageSources.Length > 0) - { - Contract.ThrowIfNull(symbolSearchService); - } - _syntaxFacts = document.GetLanguageService(); _namespacesInScope = GetNamespacesInScope(cancellationToken); diff --git a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder_PackageAssemblySearch.cs b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder_PackageAssemblySearch.cs index cc556990f14e1..af318c6558c01 100644 --- a/src/Features/Core/Portable/AddImport/SymbolReferenceFinder_PackageAssemblySearch.cs +++ b/src/Features/Core/Portable/AddImport/SymbolReferenceFinder_PackageAssemblySearch.cs @@ -66,7 +66,7 @@ private async Task FindNugetOrReferenceAssemblyTypeReferencesWorkerAsync( ArrayBuilder allReferences, TSimpleNameSyntax nameNode, string name, int arity, bool isAttributeSearch, CancellationToken cancellationToken) { - if (_options.SearchReferenceAssemblies) + if (_options.SearchOptions.SearchReferenceAssemblies) { cancellationToken.ThrowIfCancellationRequested(); await FindReferenceAssemblyTypeReferencesAsync( diff --git a/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs b/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs index 32a75063ea2ac..376f536c68e23 100644 --- a/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs @@ -49,16 +49,10 @@ protected async Task> GetAddPackagesCodeActionsAsync( var symbolSearchService = _symbolSearchService ?? workspaceServices.GetService(); var installerService = _packageInstallerService ?? workspaceServices.GetService(); - var language = document.Project.Language; - - var options = document.Project.Solution.Options; - var searchNugetPackages = options.GetOption( - SymbolSearchOptions.SuggestForTypesInNuGetPackages, language); - var codeActions = ArrayBuilder.GetInstance(); if (symbolSearchService != null && installerService != null && - searchNugetPackages && + context.Options.SearchOptions.SearchNuGetPackages && installerService.IsEnabled(document.Project.Id)) { var packageSources = PackageSourceHelper.GetPackageSources(installerService.TryGetPackageSources()); diff --git a/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs b/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs index e8bb5bf5b3a2f..5c6001c3ddea6 100644 --- a/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/AddMissingImports/AbstractAddMissingImportsFeatureService.cs @@ -61,7 +61,7 @@ public async Task AnalyzeAsync(Document documen var packageSources = ImmutableArray.Empty; var addImportOptions = new AddImportOptions( - SearchReferenceAssemblies: true, + SearchOptions: new(SearchReferenceAssemblies: true, SearchNuGetPackages: false), HideAdvancedMembers: options.HideAdvancedMembers, Placement: options.Placement); diff --git a/src/Features/Core/Portable/Diagnostics/AnalyzerHelper.cs b/src/Features/Core/Portable/Diagnostics/AnalyzerHelper.cs index 5dd4d72e6bd03..e404ded62f6e3 100644 --- a/src/Features/Core/Portable/Diagnostics/AnalyzerHelper.cs +++ b/src/Features/Core/Portable/Diagnostics/AnalyzerHelper.cs @@ -21,7 +21,6 @@ namespace Microsoft.CodeAnalysis.Diagnostics { internal static partial class AnalyzerHelper { - // These are the error codes of the compiler warnings. // Keep the ids the same so that de-duplication against compiler errors // works in the error list (after a build). diff --git a/src/Features/Core/Portable/Diagnostics/WorkspaceAnalyzerOptions.cs b/src/Features/Core/Portable/Diagnostics/WorkspaceAnalyzerOptions.cs index f9ae458634ce4..180f99a8a86d7 100644 --- a/src/Features/Core/Portable/Diagnostics/WorkspaceAnalyzerOptions.cs +++ b/src/Features/Core/Portable/Diagnostics/WorkspaceAnalyzerOptions.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; @@ -20,12 +21,27 @@ internal sealed class WorkspaceAnalyzerOptions : AnalyzerOptions { private readonly Solution _solution; + // IDE options for each encountered language + private ImmutableDictionary _ideOptionsCache; + public WorkspaceAnalyzerOptions(AnalyzerOptions options, Solution solution) : base(options.AdditionalFiles, options.AnalyzerConfigOptionsProvider) { _solution = solution; + _ideOptionsCache = ImmutableDictionary.Empty; } + public IdeAnalyzerOptions GetIdeOptions(string language) + => ImmutableInterlocked.GetOrAdd( + ref _ideOptionsCache, + language, + static (language, solution) => new IdeAnalyzerOptions( + FadeOutUnusedImports: solution.Options.GetOption(Fading.FadingOptions.Metadata.FadeOutUnusedImports, language), + FadeOutUnreachableCode: solution.Options.GetOption(Fading.FadingOptions.Metadata.FadeOutUnreachableCode, language), + ReportInvalidPlaceholdersInStringDotFormatCalls: solution.Options.GetOption(ValidateFormatString.ValidateFormatStringOption.ReportInvalidPlaceholdersInStringDotFormatCalls, language), + ReportInvalidRegexPatterns: solution.Options.GetOption(Features.EmbeddedLanguages.RegularExpressions.LanguageServices.RegularExpressionsOptions.ReportInvalidRegexPatterns, language)), + _solution); + public HostWorkspaceServices Services => _solution.Workspace.Services; [PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)] @@ -60,9 +76,7 @@ public override bool Equals(object obj) } public override int GetHashCode() - { - return Hash.Combine(_solution.Workspace, - Hash.Combine(_solution.WorkspaceVersion, base.GetHashCode())); - } + => Hash.Combine(_solution.Workspace, + Hash.Combine(_solution.WorkspaceVersion, base.GetHashCode())); } } diff --git a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/AbstractRegexDiagnosticAnalyzer.cs b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/AbstractRegexDiagnosticAnalyzer.cs index d7688eff7cd25..9dc30d83f5350 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/AbstractRegexDiagnosticAnalyzer.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/LanguageServices/AbstractRegexDiagnosticAnalyzer.cs @@ -24,7 +24,7 @@ internal abstract class AbstractRegexDiagnosticAnalyzer : AbstractBuiltInCodeSty protected AbstractRegexDiagnosticAnalyzer(EmbeddedLanguageInfo info) : base(DiagnosticId, EnforceOnBuildValues.Regex, - RegularExpressionsOptions.ReportInvalidRegexPatterns, + option: null, new LocalizableResourceString(nameof(FeaturesResources.Invalid_regex_pattern), FeaturesResources.ResourceManager, typeof(FeaturesResources)), new LocalizableResourceString(nameof(FeaturesResources.Regex_issue_0), FeaturesResources.ResourceManager, typeof(FeaturesResources))) { @@ -43,7 +43,7 @@ public void Analyze(SemanticModelAnalysisContext context) var syntaxTree = semanticModel.SyntaxTree; var cancellationToken = context.CancellationToken; - var option = context.GetOption(RegularExpressionsOptions.ReportInvalidRegexPatterns, syntaxTree.Options.Language); + var option = context.GetIdeOptions().ReportInvalidRegexPatterns; if (!option) return; diff --git a/src/Features/Core/Portable/Fading/FadingOptions.cs b/src/Features/Core/Portable/Fading/FadingOptions.cs index aa162469ccb70..152f0217ad468 100644 --- a/src/Features/Core/Portable/Fading/FadingOptions.cs +++ b/src/Features/Core/Portable/Fading/FadingOptions.cs @@ -14,27 +14,27 @@ namespace Microsoft.CodeAnalysis.Fading internal sealed class FadingOptions { [ExportSolutionOptionProvider, Shared] - internal sealed class Provider : IOptionProvider + internal sealed class Metadata : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Provider() + public Metadata() { } ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( FadeOutUnusedImports, FadeOutUnreachableCode); - } - private const string FeatureName = "FadingOptions"; + private const string FeatureName = "FadingOptions"; - public static readonly PerLanguageOption2 FadeOutUnusedImports = new( - FeatureName, "FadeOutUnusedImports", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnusedImports")); + public static readonly PerLanguageOption2 FadeOutUnusedImports = new( + FeatureName, "FadeOutUnusedImports", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnusedImports")); - public static readonly PerLanguageOption2 FadeOutUnreachableCode = new( - FeatureName, "FadeOutUnreachableCode", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnreachableCode")); + public static readonly PerLanguageOption2 FadeOutUnreachableCode = new( + FeatureName, "FadeOutUnreachableCode", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnreachableCode")); + } } } diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index 0c0ea7f51f845..c733aeb8a995b 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -66,8 +66,8 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(PlaceSystemNamespaceFirst, GenerationOptions.PlaceSystemNamespaceFirst, LanguageNames.CSharp); BindToOption(SeparateImportGroups, GenerationOptions.SeparateImportDirectiveGroups, LanguageNames.CSharp); - BindToOption(SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, LanguageNames.CSharp); - BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptions.SuggestForTypesInNuGetPackages, LanguageNames.CSharp); + BindToOption(SuggestForTypesInReferenceAssemblies, SymbolSearchOptionsStorage.SearchReferenceAssemblies, LanguageNames.CSharp); + BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptionsStorage.SearchNuGetPackages, LanguageNames.CSharp); BindToOption(AddUsingsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.CSharp, () => { // This option used to be backed by an experimentation flag but is no longer. @@ -84,8 +84,8 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(Show_outlining_for_comments_and_preprocessor_regions, BlockStructureOptions.Metadata.ShowOutliningForCommentsAndPreprocessorRegions, LanguageNames.CSharp); BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp); - BindToOption(Fade_out_unused_usings, FadingOptions.FadeOutUnusedImports, LanguageNames.CSharp); - BindToOption(Fade_out_unreachable_code, FadingOptions.FadeOutUnreachableCode, LanguageNames.CSharp); + BindToOption(Fade_out_unused_usings, FadingOptions.Metadata.FadeOutUnusedImports, LanguageNames.CSharp); + BindToOption(Fade_out_unreachable_code, FadingOptions.Metadata.FadeOutUnreachableCode, LanguageNames.CSharp); BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp); BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp); diff --git a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.Fading.cs b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.Fading.cs index 2f36c973be2b1..59d8f174cf6aa 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.Fading.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.Fading.cs @@ -10,14 +10,14 @@ public partial class AutomationObject { public int Fading_FadeOutUnreachableCode { - get { return GetBooleanOption(FadingOptions.FadeOutUnreachableCode); } - set { SetBooleanOption(FadingOptions.FadeOutUnreachableCode, value); } + get { return GetBooleanOption(FadingOptions.Metadata.FadeOutUnreachableCode); } + set { SetBooleanOption(FadingOptions.Metadata.FadeOutUnreachableCode, value); } } public int Fading_FadeOutUnusedImports { - get { return GetBooleanOption(FadingOptions.FadeOutUnusedImports); } - set { SetBooleanOption(FadingOptions.FadeOutUnusedImports, value); } + get { return GetBooleanOption(FadingOptions.Metadata.FadeOutUnusedImports); } + set { SetBooleanOption(FadingOptions.Metadata.FadeOutUnusedImports, value); } } } } diff --git a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.cs b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.cs index bce969be1174f..f566f959f1019 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.cs @@ -10,14 +10,14 @@ public partial class AutomationObject { public int AddImport_SuggestForTypesInReferenceAssemblies { - get { return GetBooleanOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies); } - set { SetBooleanOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, value); } + get { return GetBooleanOption(SymbolSearchOptionsStorage.SearchReferenceAssemblies); } + set { SetBooleanOption(SymbolSearchOptionsStorage.SearchReferenceAssemblies, value); } } public int AddImport_SuggestForTypesInNuGetPackages { - get { return GetBooleanOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages); } - set { SetBooleanOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages, value); } + get { return GetBooleanOption(SymbolSearchOptionsStorage.SearchNuGetPackages); } + set { SetBooleanOption(SymbolSearchOptionsStorage.SearchNuGetPackages, value); } } } } diff --git a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs index 1c9d5d6640910..9359f80eeaaee 100644 --- a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs +++ b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs @@ -105,12 +105,12 @@ public PackageInstallerService( [Import(AllowDefault = true)] Lazy? packageInstaller, [Import(AllowDefault = true)] Lazy? packageUninstaller, [Import(AllowDefault = true)] Lazy? packageSourceProvider) - : base(threadingContext, - workspace, - globalOptions, - SymbolSearchGlobalOptions.Enabled, - SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, - SymbolSearchOptions.SuggestForTypesInNuGetPackages) + : base(globalOptions, + listenerProvider, + threadingContext, + workspace, + featureEnabledOption: SymbolSearchGlobalOptions.Enabled, + perLanguageOptions: ImmutableArray.Create(SymbolSearchOptionsStorage.SearchReferenceAssemblies, SymbolSearchOptionsStorage.SearchNuGetPackages)) { _operationExecutor = operationExecutor; _workspace = workspace; diff --git a/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs b/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs index 055bad871a3d2..6c51d84bdf95c 100644 --- a/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs +++ b/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs @@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.SymbolSearch; namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch { @@ -28,11 +29,12 @@ internal abstract class AbstractDelayStartedService : ForegroundThreadAffinitize { private readonly List _registeredLanguageNames = new(); - protected readonly Workspace Workspace; + private readonly Workspace _workspace; + private readonly IAsynchronousOperationListener _asyncListener; private readonly IGlobalOptionService _globalOptions; // Option that controls if this service is enabled or not (regardless of language). - private readonly Option2 _globalSwitch; + private readonly Option2 _featureEnabledOption; // Options that control if this service is enabled or not for a particular language. private readonly ImmutableArray> _perLanguageOptions; @@ -42,17 +44,19 @@ internal abstract class AbstractDelayStartedService : ForegroundThreadAffinitize protected CancellationToken DisposalToken { get; } protected AbstractDelayStartedService( + IGlobalOptionService globalOptions, + IAsynchronousOperationListenerProvider listenerProvider, IThreadingContext threadingContext, Workspace workspace, - IGlobalOptionService globalOptions, - Option2 globalSwitch, - params PerLanguageOption2[] perLanguageOptions) + Option2 featureEnabledOption, + ImmutableArray> perLanguageOptions) : base(threadingContext) { - Workspace = workspace; + _workspace = workspace; + _asyncListener = listenerProvider.GetListener(FeatureAttribute.Workspace); _globalOptions = globalOptions; - _globalSwitch = globalSwitch; - _perLanguageOptions = perLanguageOptions.ToImmutableArray(); + _featureEnabledOption = featureEnabledOption; + _perLanguageOptions = perLanguageOptions; DisposalToken = threadingContext.DisposalToken; } @@ -64,7 +68,7 @@ internal void Connect(string languageName) { this.AssertIsForeground(); - if (!_globalOptions.GetOption(_globalSwitch)) + if (!_globalOptions.GetOption(_featureEnabledOption)) { // Feature is totally disabled. Do nothing. return; @@ -74,7 +78,7 @@ internal void Connect(string languageName) if (_registeredLanguageNames.Count == 1) { // Register to hear about option changing. - var optionsService = Workspace.Services.GetService(); + var optionsService = _workspace.Services.GetRequiredService(); optionsService.OptionChanged += OnOptionChanged; } @@ -92,8 +96,7 @@ private void OnOptionChanged(object sender, EventArgs e) return; } - var listenerProvider = Workspace.Services.GetRequiredService(); - var asyncToken = listenerProvider.GetListener().BeginAsyncOperation(nameof(AbstractDelayStartedService.EnableServiceAsync), tag: GetType()); + var asyncToken = _asyncListener.BeginAsyncOperation(nameof(AbstractDelayStartedService.EnableServiceAsync), tag: GetType()); var enableAsync = ThreadingContext.JoinableTaskFactory.RunAsync(async () => { // The first time we see that we're registered for a language, enable the @@ -112,9 +115,6 @@ private void OnOptionChanged(object sender, EventArgs e) } private bool IsRegisteredForLanguage(string language) - { - var options = Workspace.Options; - return _perLanguageOptions.Any(o => options.GetOption(o, language)); - } + => _perLanguageOptions.Any(option => _globalOptions.GetOption(option, language)); } } diff --git a/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs b/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs index 504cbc97bf450..c8fb78a4dd12c 100644 --- a/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs +++ b/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs @@ -2,27 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Immutable; -using System.Composition; -using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; namespace Microsoft.CodeAnalysis.SymbolSearch { - [ExportGlobalOptionProvider, Shared] - internal sealed class SymbolSearchGlobalOptions : IOptionProvider + internal sealed class SymbolSearchGlobalOptions { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SymbolSearchGlobalOptions() - { - } - - ImmutableArray IOptionProvider.Options => ImmutableArray.Create( - Enabled); - private const string LocalRegistryPath = @"Roslyn\Features\SymbolSearch\"; private const string FeatureName = "SymbolSearchOptions"; diff --git a/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs b/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs index d470c975da03a..1937f35cb1b9e 100644 --- a/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs +++ b/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Packaging; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.SymbolSearch; using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; using Microsoft.VisualStudio.Settings; @@ -53,11 +54,16 @@ internal partial class VisualStudioSymbolSearchService : AbstractDelayStartedSer [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public VisualStudioSymbolSearchService( IThreadingContext threadingContext, + IAsynchronousOperationListenerProvider listenerProvider, VisualStudioWorkspaceImpl workspace, IGlobalOptionService globalOptions, VSShell.SVsServiceProvider serviceProvider) - : base(threadingContext, workspace, globalOptions, SymbolSearchGlobalOptions.Enabled, - SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInNuGetPackages) + : base(globalOptions, + listenerProvider, + threadingContext, + workspace, + featureEnabledOption: SymbolSearchGlobalOptions.Enabled, + perLanguageOptions: ImmutableArray.Create(SymbolSearchOptionsStorage.SearchReferenceAssemblies, SymbolSearchOptionsStorage.SearchNuGetPackages)) { _workspace = workspace; _installerService = workspace.Services.GetService(); diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 3461b54ca5d11..db4581251e8a1 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -64,8 +64,8 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options ' Import directives BindToOption(PlaceSystemNamespaceFirst, GenerationOptions.PlaceSystemNamespaceFirst, LanguageNames.VisualBasic) BindToOption(SeparateImportGroups, GenerationOptions.SeparateImportDirectiveGroups, LanguageNames.VisualBasic) - BindToOption(SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, LanguageNames.VisualBasic) - BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptions.SuggestForTypesInNuGetPackages, LanguageNames.VisualBasic) + BindToOption(SuggestForTypesInReferenceAssemblies, SymbolSearchOptionsStorage.SearchReferenceAssemblies, LanguageNames.VisualBasic) + BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptionsStorage.SearchNuGetPackages, LanguageNames.VisualBasic) BindToOption(AddMissingImportsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.VisualBasic, Function() ' This option used to be backed by an experimentation flag but Is no longer. @@ -94,7 +94,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic) ' Fading - BindToOption(Fade_out_unused_imports, FadingOptions.FadeOutUnusedImports, LanguageNames.VisualBasic) + BindToOption(Fade_out_unused_imports, FadingOptions.Metadata.FadeOutUnusedImports, LanguageNames.VisualBasic) ' Block structure guides BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic) diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.Fading.vb b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.Fading.vb index f1666759bcb0b..b03ea8cbfce35 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.Fading.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.Fading.vb @@ -8,19 +8,19 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options Partial Public Class AutomationObject Public Property Fading_FadeOutUnreachableCode As Boolean Get - Return GetBooleanOption(FadingOptions.FadeOutUnreachableCode) + Return GetBooleanOption(FadingOptions.Metadata.FadeOutUnreachableCode) End Get Set(value As Boolean) - SetBooleanOption(FadingOptions.FadeOutUnreachableCode, value) + SetBooleanOption(FadingOptions.Metadata.FadeOutUnreachableCode, value) End Set End Property Public Property Fading_FadeOutUnusedImports As Boolean Get - Return GetBooleanOption(FadingOptions.FadeOutUnusedImports) + Return GetBooleanOption(FadingOptions.Metadata.FadeOutUnusedImports) End Get Set(value As Boolean) - SetBooleanOption(FadingOptions.FadeOutUnusedImports, value) + SetBooleanOption(FadingOptions.Metadata.FadeOutUnusedImports, value) End Set End Property End Class diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.vb b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.vb index 657487c17a899..6153d1098efb3 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.SymbolSearch.vb @@ -8,19 +8,19 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options Partial Public Class AutomationObject Public Property Option_SuggestImportsForTypesInReferenceAssemblies As Boolean Get - Return GetBooleanOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies) + Return GetBooleanOption(SymbolSearchOptionsStorage.SearchReferenceAssemblies) End Get Set(value As Boolean) - SetBooleanOption(SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, value) + SetBooleanOption(SymbolSearchOptionsStorage.SearchReferenceAssemblies, value) End Set End Property Public Property Option_SuggestImportsForTypesInNuGetPackages As Boolean Get - Return GetBooleanOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages) + Return GetBooleanOption(SymbolSearchOptionsStorage.SearchNuGetPackages) End Get Set(value As Boolean) - SetBooleanOption(SymbolSearchOptions.SuggestForTypesInNuGetPackages, value) + SetBooleanOption(SymbolSearchOptionsStorage.SearchNuGetPackages, value) End Set End Property End Class diff --git a/src/Workspaces/Core/Portable/CodeActions/CodeActionOptions.cs b/src/Workspaces/Core/Portable/CodeActions/CodeActionOptions.cs index c26901b5feda9..449e09b2c74c7 100644 --- a/src/Workspaces/Core/Portable/CodeActions/CodeActionOptions.cs +++ b/src/Workspaces/Core/Portable/CodeActions/CodeActionOptions.cs @@ -2,19 +2,25 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.Serialization; +using Microsoft.CodeAnalysis.SymbolSearch; + namespace Microsoft.CodeAnalysis.CodeActions { /// /// Options available to code fixes that are supplied by the IDE (i.e. not stored in editorconfig). /// + [DataContract] internal readonly record struct CodeActionOptions( - bool IsBlocking, - bool SearchReferenceAssemblies, - bool HideAdvancedMembers) + [property: DataMember(Order = 0)] SymbolSearchOptions SearchOptions, + [property: DataMember(Order = 1)] bool HideAdvancedMembers = false, + [property: DataMember(Order = 2)] bool IsBlocking = false) { - public static readonly CodeActionOptions Default = new( - IsBlocking: false, - SearchReferenceAssemblies: true, - HideAdvancedMembers: false); + public CodeActionOptions() + : this(SearchOptions: SymbolSearchOptions.Default) + { + } + + public static readonly CodeActionOptions Default = new(); } } diff --git a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs b/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs index 7cdecddde2a74..5ba383a870aea 100644 --- a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs +++ b/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs @@ -2,36 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Immutable; -using System.Composition; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Options.Providers; +using System.Runtime.Serialization; namespace Microsoft.CodeAnalysis.SymbolSearch { - [ExportSolutionOptionProvider, Shared] - internal sealed class SymbolSearchOptions : IOptionProvider + [DataContract] + internal readonly record struct SymbolSearchOptions( + [property: DataMember(Order = 0)] bool SearchReferenceAssemblies = true, + [property: DataMember(Order = 1)] bool SearchNuGetPackages = true) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public SymbolSearchOptions() + : this(SearchReferenceAssemblies: true) { } - public ImmutableArray Options { get; } = ImmutableArray.Create( - SuggestForTypesInReferenceAssemblies, - SuggestForTypesInNuGetPackages); - - private const string FeatureName = "SymbolSearchOptions"; - - public static PerLanguageOption2 SuggestForTypesInReferenceAssemblies = - new(FeatureName, "SuggestForTypesInReferenceAssemblies", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInReferenceAssemblies")); - - public static PerLanguageOption2 SuggestForTypesInNuGetPackages = - new(FeatureName, "SuggestForTypesInNuGetPackages", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInNuGetPackages")); + public static readonly SymbolSearchOptions Default = new(); } }