diff --git a/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs b/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs index 13f654f90428d..32a75063ea2ac 100644 --- a/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs @@ -51,7 +51,7 @@ protected async Task> GetAddPackagesCodeActionsAsync( var language = document.Project.Language; - var options = workspaceServices.Workspace.Options; + var options = document.Project.Solution.Options; var searchNugetPackages = options.GetOption( SymbolSearchOptions.SuggestForTypesInNuGetPackages, language); diff --git a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs index 7231d9ed9e5a7..c2b3103e60a79 100644 --- a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs +++ b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Notification; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Packaging; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.TestHooks; @@ -97,6 +98,7 @@ public PackageInstallerService( VSUtilities.IUIThreadOperationExecutor operationExecutor, IAsynchronousOperationListenerProvider listenerProvider, VisualStudioWorkspaceImpl workspace, + IGlobalOptionService globalOptions, SVsServiceProvider serviceProvider, [Import("Microsoft.VisualStudio.Shell.Interop.SAsyncServiceProvider")] object asyncServiceProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, @@ -105,6 +107,7 @@ public PackageInstallerService( [Import(AllowDefault = true)] Lazy? packageSourceProvider) : base(threadingContext, workspace, + globalOptions, SymbolSearchOptions.Enabled, SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInNuGetPackages) diff --git a/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs b/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs index b51001da77763..055bad871a3d2 100644 --- a/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs +++ b/src/VisualStudio/Core/Def/SymbolSearch/AbstractDelayStartedService.cs @@ -29,9 +29,10 @@ internal abstract class AbstractDelayStartedService : ForegroundThreadAffinitize private readonly List _registeredLanguageNames = new(); protected readonly Workspace Workspace; + private readonly IGlobalOptionService _globalOptions; // Option that controls if this service is enabled or not (regardless of language). - private readonly Option2 _serviceOnOffOption; + private readonly Option2 _globalSwitch; // Options that control if this service is enabled or not for a particular language. private readonly ImmutableArray> _perLanguageOptions; @@ -43,12 +44,14 @@ internal abstract class AbstractDelayStartedService : ForegroundThreadAffinitize protected AbstractDelayStartedService( IThreadingContext threadingContext, Workspace workspace, - Option2 onOffOption, + IGlobalOptionService globalOptions, + Option2 globalSwitch, params PerLanguageOption2[] perLanguageOptions) : base(threadingContext) { Workspace = workspace; - _serviceOnOffOption = onOffOption; + _globalOptions = globalOptions; + _globalSwitch = globalSwitch; _perLanguageOptions = perLanguageOptions.ToImmutableArray(); DisposalToken = threadingContext.DisposalToken; } @@ -61,8 +64,7 @@ internal void Connect(string languageName) { this.AssertIsForeground(); - var options = Workspace.Options; - if (!options.GetOption(_serviceOnOffOption)) + if (!_globalOptions.GetOption(_globalSwitch)) { // Feature is totally disabled. Do nothing. return; diff --git a/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs b/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs new file mode 100644 index 0000000000000..504cbc97bf450 --- /dev/null +++ b/src/VisualStudio/Core/Def/SymbolSearch/SymbolSearchGlobalOptions.cs @@ -0,0 +1,33 @@ +// 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 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 + { + [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"; + + public static readonly Option2 Enabled = new( + FeatureName, "Enabled", defaultValue: true, + storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Enabled")); + } +} diff --git a/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs b/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs index bb6da5f816851..3766d742c2d38 100644 --- a/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs +++ b/src/VisualStudio/Core/Def/SymbolSearch/VisualStudioSymbolSearchService.cs @@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.AddImport; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Packaging; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.SymbolSearch; @@ -53,10 +54,10 @@ internal partial class VisualStudioSymbolSearchService : AbstractDelayStartedSer public VisualStudioSymbolSearchService( IThreadingContext threadingContext, VisualStudioWorkspaceImpl workspace, + IGlobalOptionService globalOptions, VSShell.SVsServiceProvider serviceProvider) - : base(threadingContext, workspace, SymbolSearchOptions.Enabled, - SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, - SymbolSearchOptions.SuggestForTypesInNuGetPackages) + : base(threadingContext, workspace, globalOptions, SymbolSearchOptions.Enabled, + SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInNuGetPackages) { _workspace = workspace; _installerService = workspace.Services.GetService(); diff --git a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs b/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs index 6e22bc266f22a..7cdecddde2a74 100644 --- a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs +++ b/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs @@ -2,24 +2,36 @@ // 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 { - internal static class SymbolSearchOptions + [ExportSolutionOptionProvider, Shared] + internal sealed class SymbolSearchOptions : IOptionProvider { - private const string LocalRegistryPath = @"Roslyn\Features\SymbolSearch\"; + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public SymbolSearchOptions() + { + } - public static readonly Option2 Enabled = new( - nameof(SymbolSearchOptions), nameof(Enabled), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(Enabled))); + public ImmutableArray Options { get; } = ImmutableArray.Create( + SuggestForTypesInReferenceAssemblies, + SuggestForTypesInNuGetPackages); + + private const string FeatureName = "SymbolSearchOptions"; public static PerLanguageOption2 SuggestForTypesInReferenceAssemblies = - new(nameof(SymbolSearchOptions), nameof(SuggestForTypesInReferenceAssemblies), defaultValue: true, + new(FeatureName, "SuggestForTypesInReferenceAssemblies", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInReferenceAssemblies")); public static PerLanguageOption2 SuggestForTypesInNuGetPackages = - new(nameof(SymbolSearchOptions), nameof(SuggestForTypesInNuGetPackages), defaultValue: true, + new(FeatureName, "SuggestForTypesInNuGetPackages", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInNuGetPackages")); } } diff --git a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptionsProvider.cs b/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptionsProvider.cs deleted file mode 100644 index eb3806d8f134b..0000000000000 --- a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptionsProvider.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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 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 -{ - [ExportSolutionOptionProvider, Shared] - internal class SymbolSearchOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SymbolSearchOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - SymbolSearchOptions.Enabled, - SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, - SymbolSearchOptions.SuggestForTypesInNuGetPackages); - } -}