Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate IEditorConfigOptionMappingService from IGlobalOptionService #61899

Merged
merged 4 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.Editor.InlineRename
{
internal sealed class InlineRenameExperimentationOptions
{
public static readonly Option<bool> UseInlineAdornment = new(
public static readonly Option2<bool> UseInlineAdornment = new(
feature: "InlineRenameExperimentation",
name: "UseInlineAdornment",
defaultValue: false,
Expand Down
10 changes: 8 additions & 2 deletions src/EditorFeatures/Core/Logging/FunctionIdOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Concurrent;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;
using System.Collections.Generic;

namespace Microsoft.CodeAnalysis.Internal.Log
{
Expand All @@ -25,13 +26,18 @@ private static Option2<bool> CreateOption(FunctionId id)
storageLocation: new LocalUserProfileStorageLocation(@"Roslyn\Internal\Performance\FunctionId\" + name));
}

private static IEnumerable<FunctionId> GetFunctionIds()
=> Enum.GetValues(typeof(FunctionId)).Cast<FunctionId>();

public static IEnumerable<IOption> GetOptions()
=> GetFunctionIds().Select(GetOption);

public static Option2<bool> GetOption(FunctionId id)
=> s_options.GetOrAdd(id, s_optionCreator);

public static Func<FunctionId, bool> CreateFunctionIsEnabledPredicate(IGlobalOptionService globalOptions)
{
var functionIds = Enum.GetValues(typeof(FunctionId)).Cast<FunctionId>();
var functionIdOptions = functionIds.ToDictionary(id => id, id => globalOptions.GetOption(GetOption(id)));
var functionIdOptions = GetFunctionIds().ToDictionary(id => id, id => globalOptions.GetOption(GetOption(id)));
return functionId => functionIdOptions[functionId];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ internal sealed class NavigationBarViewOptions
{
private const string FeatureName = "NavigationBarOptions";

public static readonly PerLanguageOption<bool> ShowNavigationBar = new(FeatureName, nameof(ShowNavigationBar), defaultValue: true);
public static readonly PerLanguageOption2<bool> ShowNavigationBar = new(FeatureName, "ShowNavigationBar", defaultValue: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public override TWorkspaceService GetService<TWorkspaceService>()
private sealed class MockOptionService : ILegacyWorkspaceOptionService
{
public IGlobalOptionService GlobalOptions { get; } =
new GlobalOptionService(workspaceThreadingService: null, ImmutableArray<Lazy<IOptionProvider, LanguageMetadata>>.Empty, ImmutableArray<Lazy<IOptionPersisterProvider>>.Empty);
new GlobalOptionService(workspaceThreadingService: null, ImmutableArray<Lazy<IOptionPersisterProvider>>.Empty);

public void RegisterWorkspace(Workspace workspace)
{
Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions src/VisualStudio/Core/Impl/Options/AbstractOptionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System;
using System.Linq;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
Expand All @@ -31,7 +32,7 @@ private void EnsureOptionPageCreated()
var componentModel = (IComponentModel)this.Site.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>();
s_optionService = workspace.Services.GetService<ILegacyWorkspaceOptionService>();
s_optionStore = new OptionStore(new SolutionOptionSet(s_optionService), s_optionService.GlobalOptions.GetRegisteredOptions());
s_optionStore = new OptionStore(new SolutionOptionSet(s_optionService), Enumerable.Empty<IOption>());
}

if (pageControl == null)
Expand Down Expand Up @@ -60,7 +61,6 @@ protected override void OnActivate(System.ComponentModel.CancelEventArgs e)
{
// Reset the option store to the current state of the options.
s_optionStore.SetOptions(new SolutionOptionSet(s_optionService));
s_optionStore.SetRegisteredOptions(s_optionService.GlobalOptions.GetRegisteredOptions());

s_needsToUpdateOptionStore = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void UpdatePreview(string text)

var document = project.AddDocument("document", SourceText.From(text, Encoding.UTF8));
var fallbackFormattingOptions = _globalOptions.GetSyntaxFormattingOptions(document.Project.LanguageServices);
var optionService = workspace.Services.GetRequiredService<ILegacyWorkspaceOptionService>();
var optionService = workspace.Services.GetRequiredService<IEditorConfigOptionMappingService>();
var configOptions = OptionStore.GetOptions().AsAnalyzerConfigOptions(optionService, document.Project.Language);
var formattingService = document.GetRequiredLanguageService<ISyntaxFormattingService>();
var formattingOptions = formattingService.GetFormattingOptions(configOptions, fallbackFormattingOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,20 @@ public async Task ResetGlobalOptionsAsync(CancellationToken cancellationToken)
configurationService.Clear();

var globalOptions = await GetComponentModelServiceAsync<IGlobalOptionService>(cancellationToken);
ResetOption2(globalOptions, MetadataAsSourceOptionsStorage.NavigateToDecompiledSources);
ResetOption2(globalOptions, WorkspaceConfigurationOptionsStorage.EnableOpeningSourceGeneratedFilesInWorkspace);
ResetOption(globalOptions, MetadataAsSourceOptionsStorage.NavigateToDecompiledSources);
ResetOption(globalOptions, WorkspaceConfigurationOptionsStorage.EnableOpeningSourceGeneratedFilesInWorkspace);
ResetPerLanguageOption(globalOptions, NavigationBarViewOptions.ShowNavigationBar);
ResetPerLanguageOption2(globalOptions, VisualStudioNavigationOptions.NavigateToObjectBrowser);
ResetPerLanguageOption2(globalOptions, FeatureOnOffOptions.AddImportsOnPaste);
ResetPerLanguageOption2(globalOptions, FeatureOnOffOptions.PrettyListing);
ResetPerLanguageOption2(globalOptions, CompletionViewOptions.EnableArgumentCompletionSnippets);
ResetPerLanguageOption(globalOptions, VisualStudioNavigationOptions.NavigateToObjectBrowser);
ResetPerLanguageOption(globalOptions, FeatureOnOffOptions.AddImportsOnPaste);
ResetPerLanguageOption(globalOptions, FeatureOnOffOptions.PrettyListing);
ResetPerLanguageOption(globalOptions, CompletionViewOptions.EnableArgumentCompletionSnippets);

static void ResetOption2<T>(IGlobalOptionService globalOptions, Option2<T> option)
static void ResetOption<T>(IGlobalOptionService globalOptions, Option2<T> option)
{
globalOptions.SetGlobalOption(new OptionKey(option, language: null), option.DefaultValue);
}

static void ResetPerLanguageOption<T>(IGlobalOptionService globalOptions, PerLanguageOption<T> option)
{
globalOptions.SetGlobalOption(new OptionKey(option, LanguageNames.CSharp), option.DefaultValue);
globalOptions.SetGlobalOption(new OptionKey(option, LanguageNames.VisualBasic), option.DefaultValue);
}

static void ResetPerLanguageOption2<T>(IGlobalOptionService globalOptions, PerLanguageOption2<T> option)
static void ResetPerLanguageOption<T>(IGlobalOptionService globalOptions, PerLanguageOption2<T> option)
{
globalOptions.SetGlobalOption(new OptionKey(option, LanguageNames.CSharp), option.DefaultValue);
globalOptions.SetGlobalOption(new OptionKey(option, LanguageNames.VisualBasic), option.DefaultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.VisualStudio.LanguageServices;
Expand All @@ -18,17 +19,15 @@
namespace Roslyn.VisualStudio.DiagnosticsWindow.OptionsPages
{
[Guid(Guids.RoslynOptionPageFeatureManagerFeaturesIdString)]
internal class InternalFeaturesOnOffPage : AbstractOptionPage
internal class ForceLowMemoryModePage : AbstractOptionPage
{
protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider, OptionStore optionStore)
{
return new InternalFeaturesOptionsControl(nameof(InternalFeatureOnOffOptions), optionStore);
}
=> new Control(optionStore);

internal class InternalFeaturesOptionsControl : InternalOptionsControl
internal sealed class Control : InternalOptionsControl
{
public InternalFeaturesOptionsControl(string featureOptionName, OptionStore optionStore)
: base(featureOptionName, optionStore)
public Control(OptionStore optionStore)
: base(Array.Empty<IOption>(), optionStore)
{
}

Expand All @@ -48,14 +47,6 @@ protected override void AddOptions(Panel panel)
lowMemoryGroup.Children.Add(new TextBlock { Text = "megabytes of extra memory in devenv.exe" });

panel.Children.Add(lowMemoryGroup);

// add OOP feature options
var oopFeatureGroup = new StackPanel();

panel.Children.Add(oopFeatureGroup);

// and add the rest of the options
base.AddOptions(panel);
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -16,12 +17,12 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
{
internal partial class InternalOptionsControl : AbstractOptionPageControl
{
private readonly string _featureOptionName;
private readonly IEnumerable<IOption> _options;

public InternalOptionsControl(string featureOptionName, OptionStore optionStore)
public InternalOptionsControl(IEnumerable<IOption> options, OptionStore optionStore)
: base(optionStore)
{
_featureOptionName = featureOptionName;
_options = options;

// options
var optionsPanel = new StackPanel();
Expand Down Expand Up @@ -108,7 +109,7 @@ public InternalOptionsControl(string featureOptionName, OptionStore optionStore)

protected virtual void AddOptions(Panel panel)
{
foreach (var option in OptionStore.GetRegisteredOptions().Where(o => o.Feature == _featureOptionName).OrderBy(o => o.Name))
foreach (var option in _options)
{
if (!option.IsPerLanguage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Internal.Log;
Expand All @@ -17,7 +15,7 @@ internal class PerformanceFunctionIdPage : AbstractOptionPage
{
protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider, OptionStore optionStore)
{
return new InternalOptionsControl(nameof(FunctionIdOptions), optionStore);
return new InternalOptionsControl(FunctionIdOptions.GetOptions(), optionStore);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider s
_workspaceServices = workspace.Services;
}

return new InternalOptionsControl(nameof(LoggerOptions), optionStore);
return new InternalOptionsControl(FunctionIdOptions.GetOptions(), optionStore);
}

protected override void OnApply(PageApplyEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@
@="#0"
"Package"="{49e24138-9ee3-49e0-8ede-6b39f49303bf}"

[$RootKey$\ToolsOptionsPages\Roslyn\FeatureManager\Components]
@="#0"
"Package"="{49e24138-9ee3-49e0-8ede-6b39f49303bf}"
"Page"="{6f738951-348c-4816-9ba4-f60d92d3e98e}"

[$RootKey$\AutomationProperties\Roslyn\FeatureManager]
"Package"="{49e24138-9ee3-49e0-8ede-6b39f49303bf}"

[$RootKey$\AutomationProperties\Roslyn\FeatureManager\Components]
"Package"="{49e24138-9ee3-49e0-8ede-6b39f49303bf}"

[$RootKey$\AutomationProperties\Roslyn\FeatureManager\Components]
"Name"="Roslyn\FeatureManager.Components"

[$RootKey$\ToolsOptionsPages\Roslyn\FeatureManager]
@="#0"
"Package"="{49e24138-9ee3-49e0-8ede-6b39f49303bf}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ namespace Roslyn.VisualStudio.DiagnosticsWindow
// The option page configuration is duplicated in PackageRegistration.pkgdef.
// These attributes specify the menu structure to be used in Tools | Options. These are not
// localized because they are for internal use only.
[ProvideOptionPage(typeof(InternalFeaturesOnOffPage), @"Roslyn\FeatureManager", @"Features", categoryResourceID: 0, pageNameResourceID: 0, supportsAutomation: true, SupportsProfiles = false)]
[ProvideOptionPage(typeof(InternalComponentsOnOffPage), @"Roslyn\FeatureManager", @"Components", categoryResourceID: 0, pageNameResourceID: 0, supportsAutomation: true, SupportsProfiles = false)]
[ProvideOptionPage(typeof(ForceLowMemoryModePage), @"Roslyn\FeatureManager", @"Features", categoryResourceID: 0, pageNameResourceID: 0, supportsAutomation: true, SupportsProfiles = false)]
[ProvideOptionPage(typeof(PerformanceFunctionIdPage), @"Roslyn\Performance", @"FunctionId", categoryResourceID: 0, pageNameResourceID: 0, supportsAutomation: true, SupportsProfiles = false)]
[ProvideOptionPage(typeof(PerformanceLoggersPage), @"Roslyn\Performance", @"Loggers", categoryResourceID: 0, pageNameResourceID: 0, supportsAutomation: true, SupportsProfiles = false)]
[ProvideToolWindow(typeof(DiagnosticsWindow))]
Expand Down
Loading