Skip to content

Commit

Permalink
Revert "Separate IEditorConfigOptionMappingService from IGlobalOption…
Browse files Browse the repository at this point in the history
…Service (dotnet#61899)"

This reverts commit 29a29d5.
  • Loading branch information
chsienki committed Jun 23, 2022
1 parent deda2b2 commit 92e42f3
Show file tree
Hide file tree
Showing 29 changed files with 410 additions and 250 deletions.
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 Option2<bool> UseInlineAdornment = new(
public static readonly Option<bool> UseInlineAdornment = new(
feature: "InlineRenameExperimentation",
name: "UseInlineAdornment",
defaultValue: false,
Expand Down
10 changes: 2 additions & 8 deletions src/EditorFeatures/Core/Logging/FunctionIdOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Concurrent;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;
using System.Collections.Generic;

namespace Microsoft.CodeAnalysis.Internal.Log
{
Expand All @@ -26,18 +25,13 @@ 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 functionIdOptions = GetFunctionIds().ToDictionary(id => id, id => globalOptions.GetOption(GetOption(id)));
var functionIds = Enum.GetValues(typeof(FunctionId)).Cast<FunctionId>();
var functionIdOptions = functionIds.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 PerLanguageOption2<bool> ShowNavigationBar = new(FeatureName, "ShowNavigationBar", defaultValue: true);
public static readonly PerLanguageOption<bool> ShowNavigationBar = new(FeatureName, nameof(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<IOptionPersisterProvider>>.Empty);
new GlobalOptionService(workspaceThreadingService: null, ImmutableArray<Lazy<IOptionProvider, LanguageMetadata>>.Empty, ImmutableArray<Lazy<IOptionPersisterProvider>>.Empty);

public void RegisterWorkspace(Workspace workspace)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.Diagnostics
{
internal sealed partial class AnalyzerConfigOptionSet
{
private sealed class AnalyzerConfigOptionsImpl : AnalyzerConfigOptions
{
private readonly AnalyzerConfigOptions _options;
private readonly AnalyzerConfigOptions _fallbackOptions;

public AnalyzerConfigOptionsImpl(AnalyzerConfigOptions options, AnalyzerConfigOptions fallbackOptions)
{
_options = options;
_fallbackOptions = fallbackOptions;
}

public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value)
{
if (_options.TryGetValue(key, out value))
{
return true;
}

return _fallbackOptions.TryGetValue(key, out value);
}

public override IEnumerable<string> Keys
=> _options.Keys.Concat(_fallbackOptions.Keys.Where(key => !_options.TryGetValue(key, out _)));
}
}
}
53 changes: 53 additions & 0 deletions src/Features/Core/Portable/Diagnostics/AnalyzerConfigOptionSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.Generic;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
/// This class proxies requests for option values first to the <see cref="AnalyzerConfigOptions" /> then to a backup <see cref="OptionSet" /> if provided.
/// </summary>
internal sealed partial class AnalyzerConfigOptionSet : OptionSet
{
private readonly AnalyzerConfigOptions _analyzerConfigOptions;
private readonly OptionSet? _optionSet;

public AnalyzerConfigOptionSet(AnalyzerConfigOptions analyzerConfigOptions, OptionSet? optionSet)
{
_analyzerConfigOptions = analyzerConfigOptions;
_optionSet = optionSet;
}

private protected override object GetOptionCore(OptionKey optionKey)
{
// First try to find the option from the .editorconfig options parsed by the compiler.
if (_analyzerConfigOptions.TryGetEditorConfigOption<object>(optionKey.Option, out var value))
{
return value;
}

// Fallback to looking for option from the document's optionset if unsuccessful.
return _optionSet?.GetOption(optionKey) ?? optionKey.Option.DefaultValue!;
}

public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object? value)
=> throw new NotImplementedException();

private protected override AnalyzerConfigOptions CreateAnalyzerConfigOptions(ILegacyWorkspaceOptionService optionService, string? language)
{
if (_optionSet is null)
{
return _analyzerConfigOptions;
}

return new AnalyzerConfigOptionsImpl(_analyzerConfigOptions, _optionSet.AsAnalyzerConfigOptions(optionService, language));
}

internal override IEnumerable<OptionKey> GetChangedOptions(OptionSet optionSet)
=> throw new NotImplementedException();
}
}
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,7 +5,6 @@
#nullable disable

using System;
using System.Linq;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
Expand All @@ -32,7 +31,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), Enumerable.Empty<IOption>());
s_optionStore = new OptionStore(new SolutionOptionSet(s_optionService), s_optionService.GlobalOptions.GetRegisteredOptions());
}

if (pageControl == null)
Expand Down Expand Up @@ -61,6 +60,7 @@ 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<IEditorConfigOptionMappingService>();
var optionService = workspace.Services.GetRequiredService<ILegacyWorkspaceOptionService>();
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,20 +44,26 @@ public async Task ResetGlobalOptionsAsync(CancellationToken cancellationToken)
configurationService.Clear();

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

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

static void ResetPerLanguageOption<T>(IGlobalOptionService globalOptions, PerLanguageOption2<T> option)
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)
{
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
@@ -0,0 +1,21 @@
// 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.

#nullable disable

using System;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Editor.Shared.Options;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
{
[Guid(Guids.RoslynOptionPageFeatureManagerComponentsIdString)]
internal class InternalComponentsOnOffPage : AbstractOptionPage
{
protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider, OptionStore optionStore)
{
return new InternalOptionsControl(nameof(EditorComponentOnOffOptions), optionStore);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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 @@ -19,15 +18,17 @@
namespace Roslyn.VisualStudio.DiagnosticsWindow.OptionsPages
{
[Guid(Guids.RoslynOptionPageFeatureManagerFeaturesIdString)]
internal class ForceLowMemoryModePage : AbstractOptionPage
internal class InternalFeaturesOnOffPage : AbstractOptionPage
{
protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider, OptionStore optionStore)
=> new Control(optionStore);
{
return new InternalFeaturesOptionsControl(nameof(InternalFeatureOnOffOptions), optionStore);
}

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

Expand All @@ -47,6 +48,14 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#nullable disable

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

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

// options
var optionsPanel = new StackPanel();
Expand Down Expand Up @@ -109,7 +108,7 @@ public InternalOptionsControl(IEnumerable<IOption> options, OptionStore optionSt

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

protected override void OnApply(PageApplyEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@
@="#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,7 +28,8 @@ 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(ForceLowMemoryModePage), @"Roslyn\FeatureManager", @"Features", categoryResourceID: 0, pageNameResourceID: 0, supportsAutomation: true, SupportsProfiles = false)]
[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(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

0 comments on commit 92e42f3

Please sign in to comment.