Skip to content

Commit

Permalink
SymbolSearchOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Oct 23, 2021
1 parent 605d3ba commit ef03058
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected async Task<ImmutableArray<CodeAction>> GetAddPackagesCodeActionsAsync(

var language = document.Project.Language;

var options = workspaceServices.Workspace.Options;
var options = document.Project.Solution.Options;
var searchNugetPackages = options.GetOption(
SymbolSearchOptions.SuggestForTypesInNuGetPackages, language);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -105,6 +107,7 @@ public PackageInstallerService(
[Import(AllowDefault = true)] Lazy<IVsPackageSourceProvider>? packageSourceProvider)
: base(threadingContext,
workspace,
globalOptions,
SymbolSearchOptions.Enabled,
SymbolSearchOptions.SuggestForTypesInReferenceAssemblies,
SymbolSearchOptions.SuggestForTypesInNuGetPackages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ internal abstract class AbstractDelayStartedService : ForegroundThreadAffinitize
private readonly List<string> _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<bool> _serviceOnOffOption;
private readonly Option2<bool> _globalSwitch;

// Options that control if this service is enabled or not for a particular language.
private readonly ImmutableArray<PerLanguageOption2<bool>> _perLanguageOptions;
Expand All @@ -43,12 +44,14 @@ internal abstract class AbstractDelayStartedService : ForegroundThreadAffinitize
protected AbstractDelayStartedService(
IThreadingContext threadingContext,
Workspace workspace,
Option2<bool> onOffOption,
IGlobalOptionService globalOptions,
Option2<bool> globalSwitch,
params PerLanguageOption2<bool>[] perLanguageOptions)
: base(threadingContext)
{
Workspace = workspace;
_serviceOnOffOption = onOffOption;
_globalOptions = globalOptions;
_globalSwitch = globalSwitch;
_perLanguageOptions = perLanguageOptions.ToImmutableArray();
DisposalToken = threadingContext.DisposalToken;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IOption> IOptionProvider.Options => ImmutableArray.Create<IOption>(
Enabled);

private const string LocalRegistryPath = @"Roslyn\Features\SymbolSearch\";
private const string FeatureName = "SymbolSearchOptions";

public static readonly Option2<bool> Enabled = new(
FeatureName, "Enabled", defaultValue: true,
storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Enabled"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IPackageInstallerService>();
Expand Down
26 changes: 19 additions & 7 deletions src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> Enabled = new(
nameof(SymbolSearchOptions), nameof(Enabled), defaultValue: true,
storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(Enabled)));
public ImmutableArray<IOption> Options { get; } = ImmutableArray.Create<IOption>(
SuggestForTypesInReferenceAssemblies,
SuggestForTypesInNuGetPackages);

private const string FeatureName = "SymbolSearchOptions";

public static PerLanguageOption2<bool> SuggestForTypesInReferenceAssemblies =
new(nameof(SymbolSearchOptions), nameof(SuggestForTypesInReferenceAssemblies), defaultValue: true,
new(FeatureName, "SuggestForTypesInReferenceAssemblies", defaultValue: true,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInReferenceAssemblies"));

public static PerLanguageOption2<bool> SuggestForTypesInNuGetPackages =
new(nameof(SymbolSearchOptions), nameof(SuggestForTypesInNuGetPackages), defaultValue: true,
new(FeatureName, "SuggestForTypesInNuGetPackages", defaultValue: true,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SuggestForTypesInNuGetPackages"));
}
}

This file was deleted.

0 comments on commit ef03058

Please sign in to comment.