diff --git a/src/EditorFeatures/CSharpTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.cs b/src/EditorFeatures/CSharpTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.cs index 531afa24ce496..51eaa4d96c0af 100644 --- a/src/EditorFeatures/CSharpTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.cs +++ b/src/EditorFeatures/CSharpTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.cs @@ -29,7 +29,7 @@ public class InvalidIdentifierStructureTests : AbstractSyntaxStructureProviderTe internal override async Task> GetBlockSpansWorkerAsync(Document document, int position) { var outliningService = document.GetLanguageService(); - var options = BlockStructureOptions.From(document.Project); + var options = GetOptions(); return (await outliningService.GetBlockStructureAsync(document, options, CancellationToken.None)).Spans; } diff --git a/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs index 0b0e2db7167b8..db1fad90122a2 100644 --- a/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs @@ -117,13 +117,13 @@ protected sealed override ITaggerEventSource CreateEventSource(ITextView textVie TaggerEventSources.OnTextChanged(subjectBuffer), TaggerEventSources.OnParseOptionChanged(subjectBuffer), TaggerEventSources.OnWorkspaceRegistrationChanged(subjectBuffer), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.ShowOutliningForCodeLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.ShowOutliningForDeclarationLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.ShowOutliningForCommentsAndPreprocessorRegions), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions)); + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs), + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs), + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions), + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.ShowOutliningForCodeLevelConstructs), + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.ShowOutliningForDeclarationLevelConstructs), + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.ShowOutliningForCommentsAndPreprocessorRegions), + TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions)); } protected sealed override async Task ProduceTagsAsync( @@ -143,7 +143,7 @@ protected sealed override async Task ProduceTagsAsync( if (outliningService == null) return; - var options = BlockStructureOptions.From(document.Project); + var options = GlobalOptions.GetBlockStructureOptions(document.Project); var blockStructure = await outliningService.GetBlockStructureAsync( documentSnapshotSpan.Document, options, cancellationToken).ConfigureAwait(false); diff --git a/src/EditorFeatures/Core/Options/LegacyGlobalOptionsWorkspaceService.cs b/src/EditorFeatures/Core/Options/LegacyGlobalOptionsWorkspaceService.cs new file mode 100644 index 0000000000000..c51e3a6f6fc16 --- /dev/null +++ b/src/EditorFeatures/Core/Options/LegacyGlobalOptionsWorkspaceService.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 System; +using System.Composition; +using Microsoft.CodeAnalysis.Host.Mef; + +namespace Microsoft.CodeAnalysis.Options +{ + /// + /// Enables legacy APIs to access global options from workspace. + /// + [ExportWorkspaceService(typeof(ILegacyGlobalOptionsWorkspaceService)), Shared] + internal sealed class LegacyGlobalOptionsWorkspaceService : ILegacyGlobalOptionsWorkspaceService + { + public IGlobalOptionService GlobalOptions { get; } + + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public LegacyGlobalOptionsWorkspaceService(IGlobalOptionService globalOptions) + { + GlobalOptions = globalOptions; + } + } +} diff --git a/src/EditorFeatures/Test/Structure/BlockStructureServiceTests.cs b/src/EditorFeatures/Test/Structure/BlockStructureServiceTests.cs index 99919f10f2e7b..00b8df6a0efcc 100644 --- a/src/EditorFeatures/Test/Structure/BlockStructureServiceTests.cs +++ b/src/EditorFeatures/Test/Structure/BlockStructureServiceTests.cs @@ -97,7 +97,7 @@ private static async Task> GetSpansFromWorkspaceAsync( var hostDocument = workspace.Documents.First(); var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); var outliningService = document.GetLanguageService(); - var options = BlockStructureOptions.From(document.Project); + var options = BlockStructureOptions.Default; var structure = await outliningService.GetBlockStructureAsync(document, options, CancellationToken.None); return structure.Spans; diff --git a/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs b/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs index fa71b6035e0b2..f8f24b73f8a47 100644 --- a/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs +++ b/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs @@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Structure; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.VisualStudio.Text.Adornments; @@ -52,10 +53,11 @@ static void Main(string[] args) }"; using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); + var globalOptions = workspace.GlobalOptions; + + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp), collapseRegionsWhenCollapsingToDefinitions); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForDeclarationLevelConstructs); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForCodeLevelConstructs); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -117,10 +119,11 @@ public class Bar "; using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); + var globalOptions = workspace.GlobalOptions; + + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp), collapseRegionsWhenCollapsingToDefinitions); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForDeclarationLevelConstructs); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForCodeLevelConstructs); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -161,11 +164,12 @@ public class Bar "; using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, LanguageNames.CSharp, showBlockStructureGuidesForCommentsAndPreprocessorRegions))); + var globalOptions = workspace.GlobalOptions; + + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp), collapseRegionsWhenCollapsingToDefinitions); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForDeclarationLevelConstructs); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForCodeLevelConstructs); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, LanguageNames.CSharp), showBlockStructureGuidesForCommentsAndPreprocessorRegions); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -205,10 +209,11 @@ public class Bar "; using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); + var globalOptions = workspace.GlobalOptions; + + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp), collapseRegionsWhenCollapsingToDefinitions); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForDeclarationLevelConstructs); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp), showBlockStructureGuidesForCodeLevelConstructs); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -256,10 +261,11 @@ End Module End Namespace"; using var workspace = TestWorkspace.CreateVisualBasic(code, composition: EditorTestCompositions.EditorFeaturesWpf); - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForCodeLevelConstructs))); + var globalOptions = workspace.GlobalOptions; + + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic), collapseRegionsWhenCollapsingToDefinitions); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic), showBlockStructureGuidesForDeclarationLevelConstructs); + globalOptions.SetGlobalOption(new OptionKey(BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic), showBlockStructureGuidesForCodeLevelConstructs); var tags = await GetTagsFromWorkspaceAsync(workspace); diff --git a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs index e4fff33a9b564..22ce86f000b9e 100644 --- a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs @@ -42,7 +42,7 @@ internal sealed override async Task> GetBlockSpansWork var outliner = CreateProvider(); using var actualRegions = TemporaryArray.Empty; - var options = BlockStructureOptions.From(document.Project); + var options = GetOptions(); // Calculate previousToken for tests the same way it is derived in production code var previousToken = root.DescendantNodesAndTokens(descendIntoTrivia: true).TakeWhile(nodeOrToken => nodeOrToken != node).LastOrDefault(nodeOrToken => nodeOrToken.IsToken).AsToken(); outliner.CollectBlockSpans(previousToken, node, ref actualRegions.AsRef(), options, CancellationToken.None); diff --git a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs index 46235413dbfe4..9174f91a13cb9 100644 --- a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs @@ -8,8 +8,8 @@ using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Structure; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; @@ -24,8 +24,8 @@ public abstract class AbstractSyntaxStructureProviderTests protected virtual string WorkspaceKind => CodeAnalysis.WorkspaceKind.Host; - protected virtual OptionSet UpdateOptions(OptionSet options) - => options.WithChangedOption(BlockStructureOptions.Metadata.MaximumBannerLength, LanguageName, 120); + internal virtual BlockStructureOptions GetOptions() + => new(MaximumBannerLength: 120, IsMetadataAsSource: WorkspaceKind == CodeAnalysis.WorkspaceKind.MetadataAsSource); private Task> GetBlockSpansAsync(Document document, int position) => GetBlockSpansWorkerAsync(document, position); @@ -34,43 +34,37 @@ private Task> GetBlockSpansAsync(Document document, in private protected async Task VerifyBlockSpansAsync(string markupCode, params RegionData[] expectedRegionData) { - using (var workspace = TestWorkspace.Create(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: markupCode)) - { - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(UpdateOptions(workspace.CurrentSolution.Options))); + using var workspace = TestWorkspace.Create(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: markupCode); - var hostDocument = workspace.Documents.Single(); - Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position."); - var position = hostDocument.CursorPosition.Value; + var hostDocument = workspace.Documents.Single(); + Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position."); + var position = hostDocument.CursorPosition.Value; - var expectedRegions = expectedRegionData.Select(data => CreateBlockSpan(data, hostDocument.AnnotatedSpans)).ToArray(); + var expectedRegions = expectedRegionData.Select(data => CreateBlockSpan(data, hostDocument.AnnotatedSpans)).ToArray(); - var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); - var actualRegions = await GetBlockSpansAsync(document, position); + var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); + var actualRegions = await GetBlockSpansAsync(document, position); - Assert.True(expectedRegions.Length == actualRegions.Length, $"Expected {expectedRegions.Length} regions but there were {actualRegions.Length}"); + Assert.True(expectedRegions.Length == actualRegions.Length, $"Expected {expectedRegions.Length} regions but there were {actualRegions.Length}"); - for (var i = 0; i < expectedRegions.Length; i++) - { - AssertRegion(expectedRegions[i], actualRegions[i]); - } + for (var i = 0; i < expectedRegions.Length; i++) + { + AssertRegion(expectedRegions[i], actualRegions[i]); } } protected async Task VerifyNoBlockSpansAsync(string markupCode) { - using (var workspace = TestWorkspace.Create(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: markupCode)) - { - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(UpdateOptions(workspace.Options))); + using var workspace = TestWorkspace.Create(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: markupCode); - var hostDocument = workspace.Documents.Single(); - Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position."); - var position = hostDocument.CursorPosition.Value; + var hostDocument = workspace.Documents.Single(); + Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position."); + var position = hostDocument.CursorPosition.Value; - var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); - var actualRegions = await GetBlockSpansAsync(document, position); + var document = workspace.CurrentSolution.GetDocument(hostDocument.Id); + var actualRegions = await GetBlockSpansAsync(document, position); - Assert.True(actualRegions.Length == 0, $"Expected no regions but found {actualRegions.Length}."); - } + Assert.True(actualRegions.Length == 0, $"Expected no regions but found {actualRegions.Length}."); } protected static RegionData Region(string textSpanName, string hintSpanName, string bannerText, bool autoCollapse, bool isDefaultCollapsed = false) diff --git a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs index 680daebf86cd0..1d535b787984c 100644 --- a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs @@ -23,7 +23,7 @@ internal sealed override async Task> GetBlockSpansWork var outliner = CreateProvider(); using var actualRegions = TemporaryArray.Empty; - var options = BlockStructureOptions.From(document.Project); + var options = GetOptions(); outliner.CollectBlockSpans(trivia, ref actualRegions.AsRef(), options, CancellationToken.None); // TODO: Determine why we get null outlining spans. diff --git a/src/EditorFeatures/VisualBasicTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.vb b/src/EditorFeatures/VisualBasicTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.vb index bcbeef95fe486..7d9f11a75654b 100644 --- a/src/EditorFeatures/VisualBasicTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Structure/MetadataAsSource/InvalidIdentifierStructureTests.vb @@ -30,7 +30,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining.Metadata Friend Overrides Async Function GetBlockSpansWorkerAsync(document As Document, position As Integer) As Task(Of ImmutableArray(Of BlockSpan)) Dim outliningService = document.GetLanguageService(Of BlockStructureService)() - Dim options = BlockStructureOptions.From(document.Project) + Dim options = GetOptions() Return (Await outliningService.GetBlockStructureAsync(document, options, CancellationToken.None)).Spans End Function diff --git a/src/EditorFeatures/VisualBasicTest/Structure/OverallStructureTests.vb b/src/EditorFeatures/VisualBasicTest/Structure/OverallStructureTests.vb index 28fc10b63a6fc..27165d7f36bf9 100644 --- a/src/EditorFeatures/VisualBasicTest/Structure/OverallStructureTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Structure/OverallStructureTests.vb @@ -19,7 +19,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining Friend Overrides Async Function GetBlockSpansWorkerAsync(document As Document, position As Integer) As Task(Of ImmutableArray(Of BlockSpan)) Dim outliningService = document.GetLanguageService(Of BlockStructureService)() - Dim options = BlockStructureOptions.From(document.Project) + Dim options = GetOptions() Return (Await outliningService.GetBlockStructureAsync(document, options, CancellationToken.None)).Spans End Function diff --git a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs deleted file mode 100644 index 61acfc73862de..0000000000000 --- a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs +++ /dev/null @@ -1,33 +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.GenerateOverrides -{ - internal class GenerateOverridesOptions - { - public static readonly Option2 SelectAll = new( - nameof(GenerateOverridesOptions), nameof(SelectAll), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.Specific.{nameof(GenerateOverridesOptions)}.{nameof(SelectAll)}")); - - [ExportSolutionOptionProvider, Shared] - internal class GenerateOverridesOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public GenerateOverridesOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - GenerateOverridesOptions.SelectAll); - } - } -} diff --git a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs index 101eec10fb902..69278befe05f7 100644 --- a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs +++ b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeGeneration; using Microsoft.CodeAnalysis.Editing; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PickMembers; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; @@ -18,8 +19,12 @@ namespace Microsoft.CodeAnalysis.GenerateOverrides { internal partial class GenerateOverridesCodeRefactoringProvider { - private class GenerateOverridesWithDialogCodeAction : CodeActionWithOptions + private sealed class GenerateOverridesWithDialogCodeAction : CodeActionWithOptions { + public static readonly Option2 s_globalOption = new( + "GenerateOverridesOptions", "SelectAll", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation($"TextEditor.Specific.GenerateOverridesOptions.SelectAll")); + private readonly GenerateOverridesCodeRefactoringProvider _service; private readonly Document _document; private readonly INamedTypeSymbol _containingType; @@ -44,11 +49,14 @@ public GenerateOverridesWithDialogCodeAction( public override object GetOptions(CancellationToken cancellationToken) { - var service = _service._pickMembersService_forTestingPurposes ?? _document.Project.Solution.Workspace.Services.GetRequiredService(); - return service.PickMembers( + var services = _document.Project.Solution.Workspace.Services; + var pickMembersService = _service._pickMembersService_forTestingPurposes ?? services.GetRequiredService(); + var globalOptionService = services.GetService(); + + return pickMembersService.PickMembers( FeaturesResources.Pick_members_to_override, _viableMembers, - selectAll: _document.Project.Solution.Options.GetOption(GenerateOverridesOptions.SelectAll)); + selectAll: globalOptionService?.GlobalOptions.GetOption(s_globalOption) ?? s_globalOption.DefaultValue); } protected override async Task> ComputeOperationsAsync(object options, CancellationToken cancellationToken) @@ -97,7 +105,7 @@ private Task GenerateOverrideAsync( cancellationToken: cancellationToken); } - private class ChangeOptionValueOperation : CodeActionOperation + private sealed class ChangeOptionValueOperation : CodeActionOperation { private readonly bool _selectedAll; @@ -106,12 +114,8 @@ public ChangeOptionValueOperation(bool selectedAll) public override void Apply(Workspace workspace, CancellationToken cancellationToken) { - if (workspace.Options.GetOption(GenerateOverridesOptions.SelectAll) == _selectedAll) - return; - - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions( - workspace.CurrentSolution.Options.WithChangedOption( - GenerateOverridesOptions.SelectAll, _selectedAll))); + var service = workspace.Services.GetService(); + service?.GlobalOptions.SetGlobalOption(new OptionKey(s_globalOption), _selectedAll); } } } diff --git a/src/Features/Core/Portable/Structure/BlockStructureOptions.cs b/src/Features/Core/Portable/Structure/BlockStructureOptions.cs index 7cfed666438f4..e13649d8ea6d9 100644 --- a/src/Features/Core/Portable/Structure/BlockStructureOptions.cs +++ b/src/Features/Core/Portable/Structure/BlockStructureOptions.cs @@ -2,104 +2,24 @@ // 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.Composition; -using System.Collections.Immutable; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Options.Providers; - namespace Microsoft.CodeAnalysis.Structure { - internal record struct BlockStructureOptions( - bool ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, - bool ShowBlockStructureGuidesForDeclarationLevelConstructs, - bool ShowBlockStructureGuidesForCodeLevelConstructs, - bool ShowOutliningForCommentsAndPreprocessorRegions, - bool ShowOutliningForDeclarationLevelConstructs, - bool ShowOutliningForCodeLevelConstructs, - bool CollapseRegionsWhenCollapsingToDefinitions, - int MaximumBannerLength, - bool IsMetadataAsSource) + internal readonly record struct BlockStructureOptions( + bool ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = false, + bool ShowBlockStructureGuidesForDeclarationLevelConstructs = true, + bool ShowBlockStructureGuidesForCodeLevelConstructs = true, + bool ShowOutliningForCommentsAndPreprocessorRegions = true, + bool ShowOutliningForDeclarationLevelConstructs = true, + bool ShowOutliningForCodeLevelConstructs = true, + bool CollapseRegionsWhenCollapsingToDefinitions = false, + int MaximumBannerLength = 80, + bool IsMetadataAsSource = false) { - public static readonly BlockStructureOptions Default = - new(ShowBlockStructureGuidesForCommentsAndPreprocessorRegions: Metadata.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions.DefaultValue, - ShowBlockStructureGuidesForDeclarationLevelConstructs: Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs.DefaultValue, - ShowBlockStructureGuidesForCodeLevelConstructs: Metadata.ShowBlockStructureGuidesForCodeLevelConstructs.DefaultValue, - ShowOutliningForCommentsAndPreprocessorRegions: Metadata.ShowOutliningForCommentsAndPreprocessorRegions.DefaultValue, - ShowOutliningForDeclarationLevelConstructs: Metadata.ShowOutliningForDeclarationLevelConstructs.DefaultValue, - ShowOutliningForCodeLevelConstructs: Metadata.ShowOutliningForCodeLevelConstructs.DefaultValue, - CollapseRegionsWhenCollapsingToDefinitions: Metadata.CollapseRegionsWhenCollapsingToDefinitions.DefaultValue, - MaximumBannerLength: Metadata.MaximumBannerLength.DefaultValue, - IsMetadataAsSource: false); - - public static BlockStructureOptions From(Project project) - => From(project.Solution.Options, project.Language, isMetadataAsSource: project.Solution.Workspace.Kind == WorkspaceKind.MetadataAsSource); - - public static BlockStructureOptions From(OptionSet options, string language, bool isMetadataAsSource) - => new( - ShowBlockStructureGuidesForCommentsAndPreprocessorRegions: options.GetOption(Metadata.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, language), - ShowBlockStructureGuidesForDeclarationLevelConstructs: options.GetOption(Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, language), - ShowBlockStructureGuidesForCodeLevelConstructs: options.GetOption(Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, language), - ShowOutliningForCommentsAndPreprocessorRegions: options.GetOption(Metadata.ShowOutliningForCommentsAndPreprocessorRegions, language), - ShowOutliningForDeclarationLevelConstructs: options.GetOption(Metadata.ShowOutliningForDeclarationLevelConstructs, language), - ShowOutliningForCodeLevelConstructs: options.GetOption(Metadata.ShowOutliningForCodeLevelConstructs, language), - CollapseRegionsWhenCollapsingToDefinitions: options.GetOption(Metadata.CollapseRegionsWhenCollapsingToDefinitions, language), - MaximumBannerLength: options.GetOption(Metadata.MaximumBannerLength, language), - IsMetadataAsSource: isMetadataAsSource); - - [ExportSolutionOptionProvider, Shared] - internal sealed class Metadata : IOptionProvider + public BlockStructureOptions() + : this(ShowBlockStructureGuidesForCommentsAndPreprocessorRegions: false) { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Metadata() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, - ShowBlockStructureGuidesForDeclarationLevelConstructs, - ShowBlockStructureGuidesForCodeLevelConstructs, - ShowOutliningForCommentsAndPreprocessorRegions, - ShowOutliningForDeclarationLevelConstructs, - ShowOutliningForCodeLevelConstructs, - CollapseRegionsWhenCollapsingToDefinitions, - MaximumBannerLength); - - private const string FeatureName = "BlockStructureOptions"; - - public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = new( - FeatureName, "ShowBlockStructureGuidesForCommentsAndPreprocessorRegions", defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions")); - - public static readonly PerLanguageOption2 ShowBlockStructureGuidesForDeclarationLevelConstructs = new( - FeatureName, "ShowBlockStructureGuidesForDeclarationLevelConstructs", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForDeclarationLevelConstructs")); - - public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCodeLevelConstructs = new( - FeatureName, "ShowBlockStructureGuidesForCodeLevelConstructs", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForCodeLevelConstructs")); - - public static readonly PerLanguageOption2 ShowOutliningForCommentsAndPreprocessorRegions = new( - FeatureName, "ShowOutliningForCommentsAndPreprocessorRegions", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowOutliningForCommentsAndPreprocessorRegions")); - - public static readonly PerLanguageOption2 ShowOutliningForDeclarationLevelConstructs = new( - FeatureName, "ShowOutliningForDeclarationLevelConstructs", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowOutliningForDeclarationLevelConstructs")); - - public static readonly PerLanguageOption2 ShowOutliningForCodeLevelConstructs = new( - FeatureName, "ShowOutliningForCodeLevelConstructs", defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowOutliningForCodeLevelConstructs")); - - public static readonly PerLanguageOption2 CollapseRegionsWhenCollapsingToDefinitions = new( - FeatureName, "CollapseRegionsWhenCollapsingToDefinitions", defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.CollapseRegionsWhenCollapsingToDefinitions")); - - public static readonly PerLanguageOption2 MaximumBannerLength = new( - FeatureName, "MaximumBannerLength", defaultValue: 80, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.MaximumBannerLength")); } + + public static readonly BlockStructureOptions Default = new(); } } diff --git a/src/Features/LanguageServer/Protocol/Features/Options/BlockStructureOptionsStorage.cs b/src/Features/LanguageServer/Protocol/Features/Options/BlockStructureOptionsStorage.cs new file mode 100644 index 0000000000000..ab630ee962014 --- /dev/null +++ b/src/Features/LanguageServer/Protocol/Features/Options/BlockStructureOptionsStorage.cs @@ -0,0 +1,60 @@ +// 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.Structure +{ + internal static class BlockStructureOptionsStorage + { + public static BlockStructureOptions GetBlockStructureOptions(this IGlobalOptionService globalOptions, Project project) + => GetBlockStructureOptions(globalOptions, project.Language, isMetadataAsSource: project.Solution.Workspace.Kind == WorkspaceKind.MetadataAsSource); + + public static BlockStructureOptions GetBlockStructureOptions(this IGlobalOptionService globalOptions, string language, bool isMetadataAsSource) + => new( + ShowBlockStructureGuidesForCommentsAndPreprocessorRegions: globalOptions.GetOption(ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, language), + ShowBlockStructureGuidesForDeclarationLevelConstructs: globalOptions.GetOption(ShowBlockStructureGuidesForDeclarationLevelConstructs, language), + ShowBlockStructureGuidesForCodeLevelConstructs: globalOptions.GetOption(ShowBlockStructureGuidesForCodeLevelConstructs, language), + ShowOutliningForCommentsAndPreprocessorRegions: globalOptions.GetOption(ShowOutliningForCommentsAndPreprocessorRegions, language), + ShowOutliningForDeclarationLevelConstructs: globalOptions.GetOption(ShowOutliningForDeclarationLevelConstructs, language), + ShowOutliningForCodeLevelConstructs: globalOptions.GetOption(ShowOutliningForCodeLevelConstructs, language), + CollapseRegionsWhenCollapsingToDefinitions: globalOptions.GetOption(CollapseRegionsWhenCollapsingToDefinitions, language), + MaximumBannerLength: globalOptions.GetOption(MaximumBannerLength, language), + IsMetadataAsSource: isMetadataAsSource); + + private const string FeatureName = "BlockStructureOptions"; + + public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = new( + FeatureName, "ShowBlockStructureGuidesForCommentsAndPreprocessorRegions", BlockStructureOptions.Default.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions")); + + public static readonly PerLanguageOption2 ShowBlockStructureGuidesForDeclarationLevelConstructs = new( + FeatureName, "ShowBlockStructureGuidesForDeclarationLevelConstructs", BlockStructureOptions.Default.ShowBlockStructureGuidesForDeclarationLevelConstructs, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForDeclarationLevelConstructs")); + + public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCodeLevelConstructs = new( + FeatureName, "ShowBlockStructureGuidesForCodeLevelConstructs", BlockStructureOptions.Default.ShowBlockStructureGuidesForCodeLevelConstructs, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForCodeLevelConstructs")); + + public static readonly PerLanguageOption2 ShowOutliningForCommentsAndPreprocessorRegions = new( + FeatureName, "ShowOutliningForCommentsAndPreprocessorRegions", BlockStructureOptions.Default.ShowOutliningForCommentsAndPreprocessorRegions, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowOutliningForCommentsAndPreprocessorRegions")); + + public static readonly PerLanguageOption2 ShowOutliningForDeclarationLevelConstructs = new( + FeatureName, "ShowOutliningForDeclarationLevelConstructs", BlockStructureOptions.Default.ShowOutliningForDeclarationLevelConstructs, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowOutliningForDeclarationLevelConstructs")); + + public static readonly PerLanguageOption2 ShowOutliningForCodeLevelConstructs = new( + FeatureName, "ShowOutliningForCodeLevelConstructs", BlockStructureOptions.Default.ShowOutliningForCodeLevelConstructs, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowOutliningForCodeLevelConstructs")); + + public static readonly PerLanguageOption2 CollapseRegionsWhenCollapsingToDefinitions = new( + FeatureName, "CollapseRegionsWhenCollapsingToDefinitions", BlockStructureOptions.Default.CollapseRegionsWhenCollapsingToDefinitions, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.CollapseRegionsWhenCollapsingToDefinitions")); + + public static readonly PerLanguageOption2 MaximumBannerLength = new( + FeatureName, "MaximumBannerLength", BlockStructureOptions.Default.MaximumBannerLength, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.MaximumBannerLength")); + } +} diff --git a/src/Features/LanguageServer/Protocol/Handler/FoldingRanges/FoldingRangesHandler.cs b/src/Features/LanguageServer/Protocol/Handler/FoldingRanges/FoldingRangesHandler.cs index 8a128c73832cf..60256349ba9c0 100644 --- a/src/Features/LanguageServer/Protocol/Handler/FoldingRanges/FoldingRangesHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/FoldingRanges/FoldingRangesHandler.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Structure; using Microsoft.CodeAnalysis.Text; @@ -19,13 +20,16 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Handler [Method(Methods.TextDocumentFoldingRangeName)] internal sealed class FoldingRangesHandler : AbstractStatelessRequestHandler { + private readonly IGlobalOptionService _globalOptions; + public override bool MutatesSolutionState => false; public override bool RequiresLSPSolution => true; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public FoldingRangesHandler() + public FoldingRangesHandler(IGlobalOptionService globalOptions) { + _globalOptions = globalOptions; } public override TextDocumentIdentifier? GetTextDocumentIdentifier(FoldingRangeParams request) => request.TextDocument; @@ -42,7 +46,7 @@ public FoldingRangesHandler() return Array.Empty(); } - var options = BlockStructureOptions.From(document.Project); + var options = _globalOptions.GetBlockStructureOptions(document.Project); var blockStructure = await blockStructureService.GetBlockStructureAsync(document, options, cancellationToken).ConfigureAwait(false); if (blockStructure == null) { diff --git a/src/Features/LanguageServer/Protocol/Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj b/src/Features/LanguageServer/Protocol/Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj index 82d0f6bd23084..9f91a96c8fdc0 100644 --- a/src/Features/LanguageServer/Protocol/Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj +++ b/src/Features/LanguageServer/Protocol/Microsoft.CodeAnalysis.LanguageServer.Protocol.csproj @@ -34,13 +34,15 @@ + + + - diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index a7b51832ac605..fbc2016f006c2 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -77,16 +77,16 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(Split_string_literals_on_enter, SplitStringLiteralOptions.Enabled, LanguageNames.CSharp); BindToOption(EnterOutliningMode, FeatureOnOffOptions.Outlining, LanguageNames.CSharp); - BindToOption(Show_outlining_for_declaration_level_constructs, BlockStructureOptions.Metadata.ShowOutliningForDeclarationLevelConstructs, LanguageNames.CSharp); - BindToOption(Show_outlining_for_code_level_constructs, BlockStructureOptions.Metadata.ShowOutliningForCodeLevelConstructs, LanguageNames.CSharp); - 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(Show_outlining_for_declaration_level_constructs, BlockStructureOptionsStorage.ShowOutliningForDeclarationLevelConstructs, LanguageNames.CSharp); + BindToOption(Show_outlining_for_code_level_constructs, BlockStructureOptionsStorage.ShowOutliningForCodeLevelConstructs, LanguageNames.CSharp); + BindToOption(Show_outlining_for_comments_and_preprocessor_regions, BlockStructureOptionsStorage.ShowOutliningForCommentsAndPreprocessorRegions, LanguageNames.CSharp); + BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, 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); + BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp); + BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp); BindToOption(GenerateXmlDocCommentsForTripleSlash, DocumentationCommentOptions.Metadata.AutoXmlDocCommentGeneration, LanguageNames.CSharp); BindToOption(InsertSlashSlashAtTheStartOfNewLinesWhenWritingSingleLineComments, SplitStringLiteralOptions.Enabled, LanguageNames.CSharp); diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 5c080a2bdb7cf..59c1f2df469c8 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -87,17 +87,17 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options ' Outlining BindToOption(EnableOutlining, FeatureOnOffOptions.Outlining, LanguageNames.VisualBasic) BindToOption(DisplayLineSeparators, FeatureOnOffOptions.LineSeparator, LanguageNames.VisualBasic) - BindToOption(Show_outlining_for_declaration_level_constructs, BlockStructureOptions.Metadata.ShowOutliningForDeclarationLevelConstructs, LanguageNames.VisualBasic) - BindToOption(Show_outlining_for_code_level_constructs, BlockStructureOptions.Metadata.ShowOutliningForCodeLevelConstructs, LanguageNames.VisualBasic) - BindToOption(Show_outlining_for_comments_and_preprocessor_regions, BlockStructureOptions.Metadata.ShowOutliningForCommentsAndPreprocessorRegions, LanguageNames.VisualBasic) - BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic) + BindToOption(Show_outlining_for_declaration_level_constructs, BlockStructureOptionsStorage.ShowOutliningForDeclarationLevelConstructs, LanguageNames.VisualBasic) + BindToOption(Show_outlining_for_code_level_constructs, BlockStructureOptionsStorage.ShowOutliningForCodeLevelConstructs, LanguageNames.VisualBasic) + BindToOption(Show_outlining_for_comments_and_preprocessor_regions, BlockStructureOptionsStorage.ShowOutliningForCommentsAndPreprocessorRegions, LanguageNames.VisualBasic) + BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptionsStorage.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic) ' Fading 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) - BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic) + BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptionsStorage.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic) + BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptionsStorage.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic) ' Comments BindToOption(GenerateXmlDocCommentsForTripleApostrophes, DocumentationCommentOptions.Metadata.AutoXmlDocCommentGeneration, LanguageNames.VisualBasic) diff --git a/src/Workspaces/Core/Portable/Options/ILegacyGlobalOptionsWorkspaceService.cs b/src/Workspaces/Core/Portable/Options/ILegacyGlobalOptionsWorkspaceService.cs new file mode 100644 index 0000000000000..28ef99b1777dc --- /dev/null +++ b/src/Workspaces/Core/Portable/Options/ILegacyGlobalOptionsWorkspaceService.cs @@ -0,0 +1,17 @@ +// 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.Host; + +namespace Microsoft.CodeAnalysis.Options +{ + /// + /// Enables legacy APIs to access global options from workspace. + /// Not available OOP. Only use in client code and when IGlobalOptionService can't be MEF imported. + /// + internal interface ILegacyGlobalOptionsWorkspaceService : IWorkspaceService + { + public IGlobalOptionService GlobalOptions { get; } + } +}