diff --git a/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs b/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs index 80e640532ff1b..6cb6f0afa00eb 100644 --- a/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs +++ b/src/Analyzers/CSharp/Analyzers/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs @@ -7,7 +7,6 @@ using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Fading; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Utilities; using Roslyn.Utilities; @@ -41,8 +40,11 @@ protected override void InitializeWorker(AnalysisContext context) private void AnalyzeSemanticModel(SemanticModelAnalysisContext context) { - var fadeCode = context.GetOption(FadingOptions.FadeOutUnreachableCode, LanguageNames.CSharp); - +#if CODE_STYLE + var fadeCode = true; +#else + var fadeCode = context.GetOption(Fading.FadingOptions.FadeOutUnreachableCode, LanguageNames.CSharp); +#endif var semanticModel = context.SemanticModel; var cancellationToken = context.CancellationToken; diff --git a/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs index a20583d5b79a1..78821f3195619 100644 --- a/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/RemoveUnnecessaryImports/AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs @@ -9,7 +9,6 @@ using System.Threading; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Fading; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -165,7 +164,11 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context) static bool ShouldFade(AnalyzerOptions options, SyntaxTree tree, string language, CancellationToken cancellationToken) { - return options.GetOption(FadingOptions.FadeOutUnusedImports, language, tree, cancellationToken); +#if CODE_STYLE + return true; +#else + return options.GetOption(Fading.FadingOptions.FadeOutUnusedImports, language, tree, cancellationToken); +#endif } } diff --git a/src/EditorFeatures/CSharp/AddImports/CSharpAddImportsPasteCommandHandler.cs b/src/EditorFeatures/CSharp/AddImports/CSharpAddImportsPasteCommandHandler.cs index ede93d30ce629..9ba110442a275 100644 --- a/src/EditorFeatures/CSharp/AddImports/CSharpAddImportsPasteCommandHandler.cs +++ b/src/EditorFeatures/CSharp/AddImports/CSharpAddImportsPasteCommandHandler.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.Editor.Implementation.AddImports; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Utilities; @@ -28,7 +29,8 @@ internal class CSharpAddImportsPasteCommandHandler : AbstractAddImportsPasteComm { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpAddImportsPasteCommandHandler(IThreadingContext threadingContext) : base(threadingContext) + public CSharpAddImportsPasteCommandHandler(IThreadingContext threadingContext, IGlobalOptionService globalOptions) + : base(threadingContext, globalOptions) { } diff --git a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs index 819ce884a7abd..067eedae2946a 100644 --- a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs +++ b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs @@ -16,6 +16,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Commanding; @@ -55,8 +56,9 @@ internal partial class AutomaticLineEnderCommandHandler : AbstractAutomaticLineE [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public AutomaticLineEnderCommandHandler( ITextUndoHistoryRegistry undoRegistry, - IEditorOperationsFactoryService editorOperations) - : base(undoRegistry, editorOperations) + IEditorOperationsFactoryService editorOperations, + IGlobalOptionService globalOptions) + : base(undoRegistry, editorOperations, globalOptions) { } diff --git a/src/EditorFeatures/CSharp/BlockCommentEditing/BlockCommentEditingCommandHandler.cs b/src/EditorFeatures/CSharp/BlockCommentEditing/BlockCommentEditingCommandHandler.cs index 1dd004be805a0..15bf787879fa2 100644 --- a/src/EditorFeatures/CSharp/BlockCommentEditing/BlockCommentEditingCommandHandler.cs +++ b/src/EditorFeatures/CSharp/BlockCommentEditing/BlockCommentEditingCommandHandler.cs @@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text.Shared.Extensions; @@ -33,18 +34,21 @@ internal sealed class BlockCommentEditingCommandHandler : ICommandHandler EditorFeaturesResources.Block_Comment_Editing; @@ -57,7 +61,7 @@ public bool ExecuteCommand(ReturnKeyCommandArgs args, CommandExecutionContext co private bool TryHandleReturnKey(ITextBuffer subjectBuffer, ITextView textView) { - if (!subjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutoInsertBlockCommentStartString)) + if (!_globalOptions.GetOption(FeatureOnOffOptions.AutoInsertBlockCommentStartString, LanguageNames.CSharp)) return false; var caretPosition = textView.GetCaretPoint(subjectBuffer); diff --git a/src/EditorFeatures/CSharp/BlockCommentEditing/CloseBlockCommentCommandHandler.cs b/src/EditorFeatures/CSharp/BlockCommentEditing/CloseBlockCommentCommandHandler.cs index b0958f0125a83..1ba9332213877 100644 --- a/src/EditorFeatures/CSharp/BlockCommentEditing/CloseBlockCommentCommandHandler.cs +++ b/src/EditorFeatures/CSharp/BlockCommentEditing/CloseBlockCommentCommandHandler.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text.Shared.Extensions; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; @@ -22,10 +23,13 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.BlockCommentEditing [Order(After = nameof(BlockCommentEditingCommandHandler))] internal sealed class CloseBlockCommentCommandHandler : ICommandHandler { + private readonly IGlobalOptionService _globalOptions; + [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CloseBlockCommentCommandHandler() + public CloseBlockCommentCommandHandler(IGlobalOptionService globalOptions) { + _globalOptions = globalOptions; } public string DisplayName => EditorFeaturesResources.Block_Comment_Editing; @@ -49,7 +53,7 @@ public bool ExecuteCommand(TypeCharCommandArgs args, CommandExecutionContext exe if (line.End == position && line.IsEmptyOrWhitespace(0, line.Length - 2)) { - if (args.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutoInsertBlockCommentStartString) && + if (_globalOptions.GetOption(FeatureOnOffOptions.AutoInsertBlockCommentStartString, LanguageNames.CSharp) && BlockCommentEditingCommandHandler.IsCaretInsideBlockCommentSyntax(caret.Value, out _, out _)) { args.SubjectBuffer.Replace(new VisualStudio.Text.Span(position - 1, 1), "/"); diff --git a/src/EditorFeatures/CSharp/BraceMatching/StringLiteralBraceMatcher.cs b/src/EditorFeatures/CSharp/BraceMatching/StringLiteralBraceMatcher.cs index fd894088276e7..aadd11b6a2b89 100644 --- a/src/EditorFeatures/CSharp/BraceMatching/StringLiteralBraceMatcher.cs +++ b/src/EditorFeatures/CSharp/BraceMatching/StringLiteralBraceMatcher.cs @@ -25,7 +25,7 @@ public StringLiteralBraceMatcher() { } - public async Task FindBracesAsync(Document document, int position, CancellationToken cancellationToken) + public async Task FindBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var token = root.FindToken(position); diff --git a/src/EditorFeatures/CSharp/CompleteStatement/CompleteStatementCommandHandler.cs b/src/EditorFeatures/CSharp/CompleteStatement/CompleteStatementCommandHandler.cs index 7cd49b0f0a6a5..7408575ea9ca3 100644 --- a/src/EditorFeatures/CSharp/CompleteStatement/CompleteStatementCommandHandler.cs +++ b/src/EditorFeatures/CSharp/CompleteStatement/CompleteStatementCommandHandler.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text.Shared.Extensions; @@ -42,15 +43,20 @@ internal sealed class CompleteStatementCommandHandler : IChainedCommandHandler nextCommandHandler) => nextCommandHandler(); [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CompleteStatementCommandHandler(ITextUndoHistoryRegistry textUndoHistoryRegistry, IEditorOperationsFactoryService editorOperationsFactoryService) + public CompleteStatementCommandHandler( + ITextUndoHistoryRegistry textUndoHistoryRegistry, + IEditorOperationsFactoryService editorOperationsFactoryService, + IGlobalOptionService globalOptions) { _textUndoHistoryRegistry = textUndoHistoryRegistry; _editorOperationsFactoryService = editorOperationsFactoryService; + _globalOptions = globalOptions; } public string DisplayName => CSharpEditorResources.Complete_statement_on_semicolon; @@ -76,7 +82,7 @@ public void ExecuteCommand(TypeCharCommandArgs args, Action nextCommandHandler, transaction.Complete(); } - private static bool BeforeExecuteCommand(bool speculative, TypeCharCommandArgs args, CommandExecutionContext executionContext) + private bool BeforeExecuteCommand(bool speculative, TypeCharCommandArgs args, CommandExecutionContext executionContext) { if (args.TypedChar != ';' || !args.TextView.Selection.IsEmpty) { @@ -89,7 +95,7 @@ private static bool BeforeExecuteCommand(bool speculative, TypeCharCommandArgs a return false; } - if (!args.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutomaticallyCompleteStatementOnSemicolon)) + if (!_globalOptions.GetOption(FeatureOnOffOptions.AutomaticallyCompleteStatementOnSemicolon)) { return false; } diff --git a/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler.cs b/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler.cs index 3940ec75a7ffa..f892125681301 100644 --- a/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler.cs +++ b/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler.cs @@ -8,6 +8,7 @@ using System.Diagnostics.CodeAnalysis; using System.Threading; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Utilities; @@ -41,6 +42,7 @@ internal partial class EventHookupCommandHandler : ForegroundThreadAffinitizedOb { private readonly IInlineRenameService _inlineRenameService; private readonly IAsynchronousOperationListener _asyncListener; + private readonly IGlobalOptionService _globalOptions; internal readonly EventHookupSessionManager EventHookupSessionManager; @@ -52,12 +54,14 @@ internal partial class EventHookupCommandHandler : ForegroundThreadAffinitizedOb public EventHookupCommandHandler( IThreadingContext threadingContext, IInlineRenameService inlineRenameService, - IAsynchronousOperationListenerProvider listenerProvider, - EventHookupSessionManager eventHookupSessionManager) + EventHookupSessionManager eventHookupSessionManager, + IGlobalOptionService globalOptions, + IAsynchronousOperationListenerProvider listenerProvider) : base(threadingContext) { _inlineRenameService = inlineRenameService; _asyncListener = listenerProvider.GetListener(FeatureAttribute.EventHookup); + _globalOptions = globalOptions; this.EventHookupSessionManager = eventHookupSessionManager; } diff --git a/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs b/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs index 0146657d01fff..76dc07e72e453 100644 --- a/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs +++ b/src/EditorFeatures/CSharp/EventHookup/EventHookupCommandHandler_TabKeyCommand.cs @@ -35,7 +35,7 @@ internal partial class EventHookupCommandHandler : IChainedCommandHandler Enabled = - new(nameof(SplitStringLiteralOptions), nameof(Enabled), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SplitStringLiterals")); - } - - [ExportOptionProvider(LanguageNames.CSharp), Shared] - internal class SplitStringLiteralOptionsProvider : IOptionProvider + [ExportGlobalOptionProvider(LanguageNames.CSharp), Shared] + internal sealed class SplitStringLiteralOptions : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SplitStringLiteralOptionsProvider() + public SplitStringLiteralOptions() { } - public ImmutableArray Options { get; } = ImmutableArray.Create( - SplitStringLiteralOptions.Enabled); + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + Enabled); + + public static PerLanguageOption2 Enabled = + new(nameof(SplitStringLiteralOptions), nameof(Enabled), defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SplitStringLiterals")); } } diff --git a/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs b/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs index c8a226d23dc9d..f7a5dd890fd90 100644 --- a/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs +++ b/src/EditorFeatures/CSharpTest/BlockCommentEditing/CloseBlockCommentTests.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.UnitTests; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Text; @@ -282,8 +283,8 @@ public void NotClosedAfterAsteriskSpaceWithOptionOff() "; Verify(code, expected, workspace => { - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions( - workspace.CurrentSolution.Options.WithChangedOption(FeatureOnOffOptions.AutoInsertBlockCommentStartString, LanguageNames.CSharp, false))); + var globalOptions = workspace.GetService(); + globalOptions.SetGlobalOption(new OptionKey(FeatureOnOffOptions.AutoInsertBlockCommentStartString, LanguageNames.CSharp), false); }); } diff --git a/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs b/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs index 4933a359b5bf0..d68fd335c8968 100644 --- a/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/SemanticClassifierTests.cs @@ -2608,13 +2608,13 @@ public async Task TestCreateWithBufferNotInWorkspace() WpfTestRunner.RequireWpfFact($"Creates an {nameof(IWpfTextView)} explicitly with an unrelated buffer"); using var disposableView = workspace.ExportProvider.GetExportedValue().CreateDisposableTextView(extraBuffer); var listenerProvider = workspace.ExportProvider.GetExportedValue(); - var globalOptionsService = workspace.ExportProvider.GetExportedValue(); + var globalOptions = workspace.ExportProvider.GetExportedValue(); var provider = new SemanticClassificationViewTaggerProvider( - workspace.ExportProvider.GetExportedValue(), - workspace.ExportProvider.GetExportedValue(), - listenerProvider, - globalOptionsService); + workspace.GetService(), + workspace.GetService(), + globalOptions, + listenerProvider); using var tagger = (IDisposable)provider.CreateTagger(disposableView.TextView, extraBuffer); using (var edit = extraBuffer.CreateEdit()) diff --git a/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs b/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs index 355d9c91818a8..b96ffd5624886 100644 --- a/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs +++ b/src/EditorFeatures/CSharpTest/Classification/SyntacticTaggerTests.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Microsoft.CodeAnalysis.Shared.TestHooks; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text.Shared.Extensions; using Microsoft.VisualStudio.Text; @@ -42,8 +43,9 @@ public async Task TestTagsChangedForPortionThatChanged() var tagComputer = new SyntacticClassificationTaggerProvider.TagComputer( new SyntacticClassificationTaggerProvider( - workspace.ExportProvider.GetExportedValue(), + workspace.GetService(), typeMap: null, + workspace.GetService(), AsynchronousOperationListenerProvider.NullProvider), subjectBuffer, AsynchronousOperationListenerProvider.NullListener, @@ -99,8 +101,9 @@ public async Task TestTagsChangedAfterDelete() var tagComputer = new SyntacticClassificationTaggerProvider.TagComputer( new SyntacticClassificationTaggerProvider( - workspace.ExportProvider.GetExportedValue(), + workspace.GetService(), typeMap, + workspace.GetService(), AsynchronousOperationListenerProvider.NullProvider), subjectBuffer, AsynchronousOperationListenerProvider.NullListener, diff --git a/src/EditorFeatures/CSharpTest/CompleteStatement/CSharpCompleteStatementCommandHandlerTests.cs b/src/EditorFeatures/CSharpTest/CompleteStatement/CSharpCompleteStatementCommandHandlerTests.cs index fca445bce63c1..2cbd4e5a2ac15 100644 --- a/src/EditorFeatures/CSharpTest/CompleteStatement/CSharpCompleteStatementCommandHandlerTests.cs +++ b/src/EditorFeatures/CSharpTest/CompleteStatement/CSharpCompleteStatementCommandHandlerTests.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.UnitTests.CompleteStatement; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.VisualStudio.Commanding; using Roslyn.Test.Utilities; @@ -4180,7 +4181,8 @@ public int XValue Verify(code, expected, ExecuteTest, setOptionsOpt: workspace => { - workspace.SetOptions(workspace.Options.WithChangedOption(FeatureOnOffOptions.AutomaticallyCompleteStatementOnSemicolon, false)); + var globalOptions = workspace.GetService(); + globalOptions.SetGlobalOption(new OptionKey(FeatureOnOffOptions.AutomaticallyCompleteStatementOnSemicolon), false); }); } protected override TestWorkspace CreateTestWorkspace(string code) diff --git a/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs b/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs index 777d4295d248c..6f15921ec319f 100644 --- a/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs +++ b/src/EditorFeatures/CSharpTest/EventHookup/EventHookupTestState.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.Editor.UnitTests; using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; using Microsoft.CodeAnalysis.Editor.UnitTests.Extensions; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Utilities; @@ -32,10 +33,11 @@ public EventHookupTestState(XElement workspaceElement, OptionsCollection options : base(workspaceElement, s_composition) { _commandHandler = new EventHookupCommandHandler( - Workspace.ExportProvider.GetExportedValue(), + Workspace.GetService(), Workspace.GetService(), - Workspace.ExportProvider.GetExportedValue(), - Workspace.ExportProvider.GetExportedValue()); + Workspace.GetService(), + Workspace.GetService(), + Workspace.GetService()); _testSessionHookupMutex = new Mutex(false); _commandHandler.TESTSessionHookupMutex = _testSessionHookupMutex; diff --git a/src/EditorFeatures/CSharpTest/Interactive/BraceMatching/InteractiveBraceHighlightingTests.cs b/src/EditorFeatures/CSharpTest/Interactive/BraceMatching/InteractiveBraceHighlightingTests.cs index 9a62468cb5b7f..8a8b2be06ad0a 100644 --- a/src/EditorFeatures/CSharpTest/Interactive/BraceMatching/InteractiveBraceHighlightingTests.cs +++ b/src/EditorFeatures/CSharpTest/Interactive/BraceMatching/InteractiveBraceHighlightingTests.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.Shared.TestHooks; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; @@ -38,6 +39,7 @@ private static async Task>> ProduceTagsA var producer = new BraceHighlightingViewTaggerProvider( workspace.ExportProvider.GetExportedValue(), workspace.GetService(), + workspace.GetService(), AsynchronousOperationListenerProvider.NullProvider); var context = new TaggerContext( diff --git a/src/EditorFeatures/Core.Cocoa/CommandHandlers/GoToMatchingBraceCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/CommandHandlers/GoToMatchingBraceCommandHandler.cs index 99d397155f437..3c333a5a2422b 100644 --- a/src/EditorFeatures/Core.Cocoa/CommandHandlers/GoToMatchingBraceCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/CommandHandlers/GoToMatchingBraceCommandHandler.cs @@ -38,10 +38,10 @@ public bool ExecuteCommand(GotoBraceCommandArgs args, VSCommanding.CommandExecut { var snapshot = args.SubjectBuffer.CurrentSnapshot; var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); + var options = BraceMatchingOptions.From(document.Project); var caretPosition = args.TextView.Caret.Position.BufferPosition.Position; - - var task = _braceMatchingService.FindMatchingSpanAsync(document, caretPosition, executionContext.OperationContext.UserCancellationToken); + var task = _braceMatchingService.FindMatchingSpanAsync(document, caretPosition, options, executionContext.OperationContext.UserCancellationToken); var span = task.WaitAndGetResult(executionContext.OperationContext.UserCancellationToken); if (!span.HasValue) diff --git a/src/EditorFeatures/Core.Cocoa/Snippets/AbstractSnippetCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/Snippets/AbstractSnippetCommandHandler.cs index 3faf051b03365..a1132db92c8a7 100644 --- a/src/EditorFeatures/Core.Cocoa/Snippets/AbstractSnippetCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/Snippets/AbstractSnippetCommandHandler.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Commanding; @@ -31,14 +32,20 @@ internal abstract class AbstractSnippetCommandHandler : { protected readonly IExpansionServiceProvider ExpansionServiceProvider; protected readonly IExpansionManager ExpansionManager; + protected readonly IGlobalOptionService GlobalOptions; public string DisplayName => FeaturesResources.Snippets; - public AbstractSnippetCommandHandler(IThreadingContext threadingContext, IExpansionServiceProvider expansionServiceProvider, IExpansionManager expansionManager) + public AbstractSnippetCommandHandler( + IThreadingContext threadingContext, + IExpansionServiceProvider expansionServiceProvider, + IExpansionManager expansionManager, + IGlobalOptionService globalOptions) : base(threadingContext) { - this.ExpansionServiceProvider = expansionServiceProvider; - this.ExpansionManager = expansionManager; + ExpansionServiceProvider = expansionServiceProvider; + ExpansionManager = expansionManager; + GlobalOptions = globalOptions; } protected abstract AbstractSnippetExpansionClient GetSnippetExpansionClient(ITextView textView, ITextBuffer subjectBuffer); @@ -281,9 +288,9 @@ protected bool TryHandleTypedSnippet(ITextView textView, ITextBuffer subjectBuff return GetSnippetExpansionClient(textView, subjectBuffer).TryInsertExpansion(startPosition, endPosition); } - protected static bool AreSnippetsEnabled(EditorCommandArgs args) + protected bool AreSnippetsEnabled(EditorCommandArgs args) { - return args.SubjectBuffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.Snippets) && + return GlobalOptions.GetOption(InternalFeatureOnOffOptions.Snippets) && // TODO (https://github.com/dotnet/roslyn/issues/5107): enable in interactive !(Workspace.TryGetWorkspace(args.SubjectBuffer.AsTextContainer(), out var workspace) && workspace.Kind == WorkspaceKind.Interactive); } diff --git a/src/EditorFeatures/Core.Cocoa/Snippets/CSharpSnippets/SnippetCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/Snippets/CSharpSnippets/SnippetCommandHandler.cs index a90a7e4056f5f..44e71467aa243 100644 --- a/src/EditorFeatures/Core.Cocoa/Snippets/CSharpSnippets/SnippetCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/Snippets/CSharpSnippets/SnippetCommandHandler.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Commanding; @@ -35,8 +36,12 @@ internal sealed class SnippetCommandHandler : { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SnippetCommandHandler(IThreadingContext threadingContext, IExpansionServiceProvider expansionServiceProvider, IExpansionManager expansionManager) - : base(threadingContext, expansionServiceProvider, expansionManager) + public SnippetCommandHandler( + IThreadingContext threadingContext, + IExpansionServiceProvider expansionServiceProvider, + IExpansionManager expansionManager, + IGlobalOptionService globalOptions) + : base(threadingContext, expansionServiceProvider, expansionManager, globalOptions) { } diff --git a/src/EditorFeatures/Core.Cocoa/Structure/StructureTaggerProvider.cs b/src/EditorFeatures/Core.Cocoa/Structure/StructureTaggerProvider.cs index fabe6cecf8b1a..bb1f14418d076 100644 --- a/src/EditorFeatures/Core.Cocoa/Structure/StructureTaggerProvider.cs +++ b/src/EditorFeatures/Core.Cocoa/Structure/StructureTaggerProvider.cs @@ -6,6 +6,7 @@ using System.ComponentModel.Composition; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Projection; @@ -26,8 +27,9 @@ public StructureTaggerProvider( IThreadingContext threadingContext, IEditorOptionsFactoryService editorOptionsFactoryService, IProjectionBufferFactoryService projectionBufferFactoryService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, editorOptionsFactoryService, projectionBufferFactoryService, listenerProvider) + : base(threadingContext, editorOptionsFactoryService, projectionBufferFactoryService, globalOptions, listenerProvider) { } diff --git a/src/EditorFeatures/Core.Wpf/Adornments/AbstractAdornmentManagerProvider.cs b/src/EditorFeatures/Core.Wpf/Adornments/AbstractAdornmentManagerProvider.cs index c6265c6c55bc8..84d9057cf591d 100644 --- a/src/EditorFeatures/Core.Wpf/Adornments/AbstractAdornmentManagerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/Adornments/AbstractAdornmentManagerProvider.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Tagging; @@ -21,14 +22,17 @@ internal abstract class AbstractAdornmentManagerProvider : protected readonly IThreadingContext ThreadingContext; protected readonly IViewTagAggregatorFactoryService TagAggregatorFactoryService; protected readonly IAsynchronousOperationListener AsyncListener; + protected readonly IGlobalOptionService GlobalOptions; protected AbstractAdornmentManagerProvider( IThreadingContext threadingContext, IViewTagAggregatorFactoryService tagAggregatorFactoryService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) { ThreadingContext = threadingContext; TagAggregatorFactoryService = tagAggregatorFactoryService; + GlobalOptions = globalOptions; AsyncListener = listenerProvider.GetListener(this.FeatureAttributeName); } @@ -44,7 +48,7 @@ public void TextViewCreated(IWpfTextView textView) throw new ArgumentNullException(nameof(textView)); } - if (!textView.TextBuffer.GetFeatureOnOffOption(EditorComponentOnOffOptions.Adornment)) + if (!GlobalOptions.GetOption(EditorComponentOnOffOptions.Adornment)) { return; } diff --git a/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManager.cs b/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManager.cs index efa63f14972cf..97ce478c2c1e3 100644 --- a/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManager.cs +++ b/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManager.cs @@ -9,6 +9,7 @@ using System.Windows.Controls; using Microsoft.CodeAnalysis.Editor.Implementation.Adornments; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; @@ -27,17 +28,23 @@ internal class InlineDiagnosticsAdornmentManager : AbstractAdornmentManager _endLineTagAggregator; + private readonly IGlobalOptionService _globalOptions; public InlineDiagnosticsAdornmentManager( - IThreadingContext threadingContext, IWpfTextView textView, IViewTagAggregatorFactoryService tagAggregatorFactoryService, - IAsynchronousOperationListener asyncListener, string adornmentLayerName, + IThreadingContext threadingContext, + IWpfTextView textView, + IViewTagAggregatorFactoryService tagAggregatorFactoryService, + IAsynchronousOperationListener asyncListener, + string adornmentLayerName, IClassificationFormatMapService classificationFormatMapService, - IClassificationTypeRegistryService classificationTypeRegistryService) + IClassificationTypeRegistryService classificationTypeRegistryService, + IGlobalOptionService globalOptions) : base(threadingContext, textView, tagAggregatorFactoryService, asyncListener, adornmentLayerName) { _classificationRegistryService = classificationTypeRegistryService; _formatMap = classificationFormatMapService.GetClassificationFormatMap(textView); _formatMap.ClassificationFormatMappingChanged += OnClassificationFormatMappingChanged; + _globalOptions = globalOptions; TextView.ViewportWidthChanged += TextView_ViewportWidthChanged; _endLineTagAggregator = tagAggregatorFactoryService.CreateTagAggregator(textView); @@ -72,13 +79,14 @@ private void TextView_ViewportWidthChanged(object sender, EventArgs e) return; } - if (!TryTextView_ViewportWidthChanged(out var workspace, out var document)) + var document = TextView.TextBuffer.AsTextContainer()?.GetOpenDocumentInCurrentContext(); + if (document is null) { AdornmentLayer.RemoveAllAdornments(); return; } - var option = workspace.Options.GetOption(InlineDiagnosticsOptions.Location, document.Project.Language); + var option = _globalOptions.GetOption(InlineDiagnosticsOptions.Location, document.Project.Language); if (option == InlineDiagnosticsLocations.PlacedAtEndOfEditor) { var normalizedCollectionSpan = new NormalizedSnapshotSpanCollection(TextView.TextViewLines.FormattedSpan); @@ -86,27 +94,6 @@ private void TextView_ViewportWidthChanged(object sender, EventArgs e) } } - private bool TryTextView_ViewportWidthChanged( - [NotNullWhen(true)] out Workspace? workspace, - [NotNullWhen(true)] out Document? document) - { - var sourceContainer = TextView.TextBuffer.AsTextContainer(); - workspace = null; - document = null; - if (sourceContainer is null) - { - return false; - } - - if (!Workspace.TryGetWorkspace(sourceContainer, out workspace)) - { - return false; - } - - document = sourceContainer.GetOpenDocumentInCurrentContext(); - return document != null; - } - private void OnClassificationFormatMappingChanged(object sender, EventArgs e) { // this method should only run on UI thread as we do WPF here. diff --git a/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManagerProvider.cs b/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManagerProvider.cs index d5aab3bbd7288..14c05cc22f1bf 100644 --- a/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManagerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsAdornmentManagerProvider.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.Editor.Implementation.Adornments; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; @@ -37,10 +38,11 @@ public InlineDiagnosticsAdornmentManagerProvider( #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. IThreadingContext threadingContext, IViewTagAggregatorFactoryService tagAggregatorFactoryService, - IAsynchronousOperationListenerProvider listenerProvider, IClassificationFormatMapService classificationFormatMapService, - IClassificationTypeRegistryService classificationTypeRegistryService) - : base(threadingContext, tagAggregatorFactoryService, listenerProvider) + IClassificationTypeRegistryService classificationTypeRegistryService, + IGlobalOptionService globalOptions, + IAsynchronousOperationListenerProvider listenerProvider) + : base(threadingContext, tagAggregatorFactoryService, globalOptions, listenerProvider) { _classificationFormatMapService = classificationFormatMapService; _classificationTypeRegistryService = classificationTypeRegistryService; @@ -55,7 +57,7 @@ protected override void CreateAdornmentManager(IWpfTextView textView) // the manager keeps itself alive by listening to text view events. _ = new InlineDiagnosticsAdornmentManager( ThreadingContext, textView, TagAggregatorFactoryService, AsyncListener, - AdornmentLayerName, _classificationFormatMapService, _classificationTypeRegistryService); + AdornmentLayerName, _classificationFormatMapService, _classificationTypeRegistryService, GlobalOptions); } } } diff --git a/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsTaggerProvider.cs b/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsTaggerProvider.cs index cd31f98ec2861..8f71dc18992b8 100644 --- a/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsTaggerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/InlineDiagnostics/InlineDiagnosticsTaggerProvider.cs @@ -41,11 +41,12 @@ internal class InlineDiagnosticsTaggerProvider : AbstractDiagnosticsAdornmentTag public InlineDiagnosticsTaggerProvider( IThreadingContext threadingContext, IDiagnosticService diagnosticService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider, IEditorFormatMapService editorFormatMapService, IClassificationFormatMapService classificationFormatMapService, IClassificationTypeRegistryService classificationTypeRegistryService) - : base(threadingContext, diagnosticService, listenerProvider) + : base(threadingContext, diagnosticService, globalOptions, listenerProvider) { _editorFormatMap = editorFormatMapService.GetEditorFormatMap("text"); _classificationFormatMapService = classificationFormatMapService; @@ -89,7 +90,7 @@ diagnostic.Severity is DiagnosticSeverity.Warning or DiagnosticSeverity.Error && return null; } - var locationOption = workspace.Options.GetOption(InlineDiagnosticsOptions.Location, document.Project.Language); + var locationOption = GlobalOptions.GetOption(InlineDiagnosticsOptions.Location, document.Project.Language); var navigateService = workspace.Services.GetRequiredService(); return new InlineDiagnosticsTag(errorType, diagnostic, _editorFormatMap, _classificationFormatMapService, _classificationTypeRegistryService, locationOption, navigateService); diff --git a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsKeyProcessorProvider.cs b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsKeyProcessorProvider.cs index 7ea4847b68ce8..6829d8a1c7a21 100644 --- a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsKeyProcessorProvider.cs +++ b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsKeyProcessorProvider.cs @@ -4,6 +4,7 @@ using System; using System.ComponentModel.Composition; +using System.Runtime.CompilerServices; using System.Windows.Input; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.InlineHints; @@ -20,28 +21,28 @@ namespace Microsoft.CodeAnalysis.Editor.InlineHints [TextViewRole(PredefinedTextViewRoles.Interactive)] [ContentType(ContentTypeNames.RoslynContentType)] [Name(nameof(InlineHintsKeyProcessorProvider))] - internal class InlineHintsKeyProcessorProvider : IKeyProcessorProvider + internal sealed class InlineHintsKeyProcessorProvider : IKeyProcessorProvider { - private readonly IGlobalOptionService _globalOptionService; + private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public InlineHintsKeyProcessorProvider(IGlobalOptionService globalOptionService) + public InlineHintsKeyProcessorProvider(IGlobalOptionService globalOptions) { - _globalOptionService = globalOptionService; + _globalOptions = globalOptions; } public KeyProcessor GetAssociatedProcessor(IWpfTextView wpfTextView) - => new InlineHintsKeyProcessor(_globalOptionService, wpfTextView); + => new InlineHintsKeyProcessor(_globalOptions, wpfTextView); - private class InlineHintsKeyProcessor : KeyProcessor + private sealed class InlineHintsKeyProcessor : KeyProcessor { - private readonly IGlobalOptionService _globalOptionService; + private readonly IGlobalOptionService _globalOptions; private readonly IWpfTextView _view; - public InlineHintsKeyProcessor(IGlobalOptionService globalOptionService, IWpfTextView view) + public InlineHintsKeyProcessor(IGlobalOptionService globalOptions, IWpfTextView view) { - _globalOptionService = globalOptionService; + _globalOptions = globalOptions; _view = view; _view.Closed += OnViewClosed; _view.LostAggregateFocus += OnLostFocus; @@ -108,14 +109,14 @@ private void ToggleOff() private void Toggle(bool on) { // No need to do anything if we're already in the requested state - var state = _globalOptionService.GetOption(InlineHintsOptions.DisplayAllOverride); + var state = _globalOptions.GetOption(InlineHintsGlobalStateOption.DisplayAllOverride); if (state == on) return; // We can only enter the on-state if the user has the chord feature enabled. We can always enter the // off state though. - on = on && _globalOptionService.GetOption(InlineHintsOptions.DisplayAllHintsWhilePressingAltF1); - _globalOptionService.RefreshOption(new OptionKey(InlineHintsOptions.DisplayAllOverride), on); + on = on && _globalOptions.GetOption(InlineHintsViewOptions.DisplayAllHintsWhilePressingAltF1); + _globalOptions.RefreshOption(new OptionKey(InlineHintsGlobalStateOption.DisplayAllOverride), on); } } } diff --git a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs index 572183444d060..11caa28addd81 100644 --- a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs +++ b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.InlineHints; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Classification; @@ -145,7 +146,7 @@ public IEnumerable> GetTags(NormalizedSnapshotSp } var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); - var classify = document?.Project.Solution.Options.GetOption(InlineHintsOptions.ColorHints, document?.Project.Language) ?? false; + var classify = document != null && _taggerProvider.GlobalOptions.GetOption(InlineHintsViewOptions.ColorHints, document.Project.Language); var selectedSpans = new List>(); for (var i = 0; i < _cache.Count; i++) diff --git a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTaggerProvider.cs b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTaggerProvider.cs index 38386268787be..cadb2605fd2e3 100644 --- a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTaggerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTaggerProvider.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Adornments; @@ -37,6 +38,7 @@ internal class InlineHintsTaggerProvider : IViewTaggerProvider public readonly IToolTipService ToolTipService; public readonly ClassificationTypeMap TypeMap; public readonly Lazy StreamingFindUsagesPresenter; + public readonly IGlobalOptionService GlobalOptions; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] @@ -49,18 +51,20 @@ public InlineHintsTaggerProvider( IAsynchronousOperationListenerProvider listenerProvider, IToolTipService toolTipService, ClassificationTypeMap typeMap, - Lazy streamingFindUsagesPresenter) + Lazy streamingFindUsagesPresenter, + IGlobalOptionService globalOptions) { _viewTagAggregatorFactoryService = viewTagAggregatorFactoryService; - this.ClassificationFormatMapService = classificationFormatMapService; - this.ClassificationTypeRegistryService = classificationTypeRegistryService; - this.ThreadingContext = threadingContext; - this.OperationExecutor = operationExecutor; - this.ToolTipService = toolTipService; - this.StreamingFindUsagesPresenter = streamingFindUsagesPresenter; - this.TypeMap = typeMap; + ClassificationFormatMapService = classificationFormatMapService; + ClassificationTypeRegistryService = classificationTypeRegistryService; + ThreadingContext = threadingContext; + OperationExecutor = operationExecutor; + ToolTipService = toolTipService; + StreamingFindUsagesPresenter = streamingFindUsagesPresenter; + TypeMap = typeMap; + GlobalOptions = globalOptions; - this.AsynchronousOperationListener = listenerProvider.GetListener(FeatureAttribute.InlineHints); + AsynchronousOperationListener = listenerProvider.GetListener(FeatureAttribute.InlineHints); } public ITagger? CreateTagger(ITextView textView, ITextBuffer buffer) where T : ITag diff --git a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsViewOptions.cs b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsViewOptions.cs new file mode 100644 index 0000000000000..5b5bc6ae4b7f6 --- /dev/null +++ b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsViewOptions.cs @@ -0,0 +1,37 @@ +// 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.Editor.InlineHints +{ + [ExportGlobalOptionProvider, Shared] + internal sealed class InlineHintsViewOptions : IOptionProvider + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public InlineHintsViewOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + DisplayAllHintsWhilePressingAltF1, + ColorHints); + + private const string FeatureName = "InlineHintsOptions"; + + public static readonly Option2 DisplayAllHintsWhilePressingAltF1 = new( + FeatureName, "DisplayAllHintsWhilePressingAltF1", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.Specific.DisplayAllHintsWhilePressingAltF1")); + + public static readonly PerLanguageOption2 ColorHints = new( + FeatureName, "ColorHints", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorHints")); + } +} diff --git a/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorAdornmentManagerProvider.cs b/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorAdornmentManagerProvider.cs index 8c07406d74aab..c089982b37298 100644 --- a/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorAdornmentManagerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorAdornmentManagerProvider.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Editor.LineSeparators; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Tagging; @@ -43,8 +44,9 @@ internal class LineSeparatorAdornmentManagerProvider : public LineSeparatorAdornmentManagerProvider( IThreadingContext threadingContext, IViewTagAggregatorFactoryService tagAggregatorFactoryService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, tagAggregatorFactoryService, listenerProvider) + : base(threadingContext, tagAggregatorFactoryService, globalOptions, listenerProvider) { } diff --git a/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorTaggerProvider.cs b/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorTaggerProvider.cs index 585f686c9f2b3..17fbcbe0b569c 100644 --- a/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorTaggerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/LineSeparators/LineSeparatorTaggerProvider.cs @@ -51,8 +51,9 @@ internal partial class LineSeparatorTaggerProvider : AsynchronousTaggerProvider< public LineSeparatorTaggerProvider( IThreadingContext threadingContext, IEditorFormatMapService editorFormatMapService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.LineSeparators)) + : base(threadingContext, globalOptions, listenerProvider.GetListener(FeatureAttribute.LineSeparators)) { _editorFormatMap = editorFormatMapService.GetEditorFormatMap("text"); _editorFormatMap.FormatMappingChanged += OnFormatMappingChanged; @@ -86,9 +87,7 @@ protected override async Task ProduceTagsAsync( return; } - var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); - - if (!documentOptions.GetOption(FeatureOnOffOptions.LineSeparator)) + if (!GlobalOptions.GetOption(FeatureOnOffOptions.LineSeparator, document.Project.Language)) { return; } diff --git a/src/EditorFeatures/Core.Wpf/Structure/StructureTaggerProvider.cs b/src/EditorFeatures/Core.Wpf/Structure/StructureTaggerProvider.cs index 7d8c163b424b1..a453c6dcf7649 100644 --- a/src/EditorFeatures/Core.Wpf/Structure/StructureTaggerProvider.cs +++ b/src/EditorFeatures/Core.Wpf/Structure/StructureTaggerProvider.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; @@ -35,8 +36,9 @@ public StructureTaggerProvider( IEditorOptionsFactoryService editorOptionsFactoryService, IProjectionBufferFactoryService projectionBufferFactoryService, ITextEditorFactoryService textEditorFactoryService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, editorOptionsFactoryService, projectionBufferFactoryService, listenerProvider) + : base(threadingContext, editorOptionsFactoryService, projectionBufferFactoryService, globalOptions, listenerProvider) { _textEditorFactoryService = textEditorFactoryService; } diff --git a/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs b/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs index 6e0b3f91b00d6..feb6c93be0401 100644 --- a/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs +++ b/src/EditorFeatures/Core.Wpf/Suggestions/SuggestedActionsSource.cs @@ -446,7 +446,7 @@ await InvokeBelowInputPriorityAsync(() => return null; } - if (document.Project.Solution.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && + if (GlobalOptions.GetOption(EditorComponentOnOffOptions.CodeRefactorings) && state.Target.Owner._codeRefactoringService != null && state.Target.SubjectBuffer.SupportsRefactorings()) { diff --git a/src/EditorFeatures/Core/EmbeddedLanguages/RegularExpressions/RegexBraceMatcher.cs b/src/EditorFeatures/Core/EmbeddedLanguages/RegularExpressions/RegexBraceMatcher.cs index c0a80047240b8..3f562e8beec83 100644 --- a/src/EditorFeatures/Core/EmbeddedLanguages/RegularExpressions/RegexBraceMatcher.cs +++ b/src/EditorFeatures/Core/EmbeddedLanguages/RegularExpressions/RegexBraceMatcher.cs @@ -11,9 +11,7 @@ using Microsoft.CodeAnalysis.Editor; using Microsoft.CodeAnalysis.EmbeddedLanguages.Common; using Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions; -using Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions.LanguageServices; using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions { @@ -31,11 +29,9 @@ public RegexBraceMatcher(RegexEmbeddedLanguage language) => _language = language; public async Task FindBracesAsync( - Document document, int position, CancellationToken cancellationToken) + Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { - var option = document.Project.Solution.Workspace.Options.GetOption( - RegularExpressionsOptions.HighlightRelatedRegexComponentsUnderCursor, document.Project.Language); - if (!option) + if (!options.HighlightRelatedRegexComponentsUnderCursor) { return null; } diff --git a/src/EditorFeatures/Core/Extensibility/BraceMatching/AbstractDirectiveTriviaBraceMatcher.cs b/src/EditorFeatures/Core/Extensibility/BraceMatching/AbstractDirectiveTriviaBraceMatcher.cs index d407350895a7f..3cbbc7115f29c 100644 --- a/src/EditorFeatures/Core/Extensibility/BraceMatching/AbstractDirectiveTriviaBraceMatcher.cs +++ b/src/EditorFeatures/Core/Extensibility/BraceMatching/AbstractDirectiveTriviaBraceMatcher.cs @@ -27,7 +27,7 @@ internal abstract class AbstractDirectiveTriviaBraceMatcher FindBracesAsync(Document document, int position, CancellationToken cancellationToken) + public async Task FindBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var token = root.FindToken(position, findInsideTrivia: true); @@ -60,8 +60,8 @@ internal abstract class AbstractDirectiveTriviaBraceMatcher From(project.Solution.Options, project.Language); + + public static BraceMatchingOptions From(OptionSet options, string language) + => new( + HighlightRelatedRegexComponentsUnderCursor: options.GetOption(RegularExpressionsOptions.HighlightRelatedRegexComponentsUnderCursor, language)); + } +} diff --git a/src/EditorFeatures/Core/Extensibility/BraceMatching/IBraceMatcher.cs b/src/EditorFeatures/Core/Extensibility/BraceMatching/IBraceMatcher.cs index 30f000c2577e9..854d754348611 100644 --- a/src/EditorFeatures/Core/Extensibility/BraceMatching/IBraceMatcher.cs +++ b/src/EditorFeatures/Core/Extensibility/BraceMatching/IBraceMatcher.cs @@ -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.Threading; using System.Threading.Tasks; @@ -11,6 +9,6 @@ namespace Microsoft.CodeAnalysis.Editor { internal interface IBraceMatcher { - Task FindBracesAsync(Document document, int position, CancellationToken cancellationToken = default); + Task FindBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken); } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptAsynchronousTaggerProvider.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptAsynchronousTaggerProvider.cs index fcf723050fe2c..7f279ad88fbe5 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptAsynchronousTaggerProvider.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptAsynchronousTaggerProvider.cs @@ -15,10 +15,8 @@ internal abstract class VSTypeScriptAsynchronousTaggerProvider : Asynchron protected VSTypeScriptAsynchronousTaggerProvider( IThreadingContext threadingContext, IAsynchronousOperationListenerProvider asyncListenerProvider, -#pragma warning disable IDE0060 // TODO: use global options VSTypeScriptGlobalOptions globalOptions) -#pragma warning restore IDE0060 - : base(threadingContext, asyncListenerProvider.GetListener(FeatureAttribute.Classification)) + : base(threadingContext, globalOptions.Service, asyncListenerProvider.GetListener(FeatureAttribute.Classification)) { } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptBraceMatcher.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptBraceMatcher.cs index 0dcae7d611478..f42a5fbf4ee4a 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptBraceMatcher.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptBraceMatcher.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { internal abstract class VSTypeScriptBraceMatcher : IBraceMatcher { - Task IBraceMatcher.FindBracesAsync(Document document, int position, CancellationToken cancellationToken) + Task IBraceMatcher.FindBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) => FindBracesAsync(document, position, cancellationToken); protected abstract Task FindBracesAsync(Document document, int position, CancellationToken cancellationToken); diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGlobalOptions.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGlobalOptions.cs index 9aff74d0b2173..1311cc193745e 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGlobalOptions.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/VSTypeScriptGlobalOptions.cs @@ -27,5 +27,7 @@ public bool BlockForCompletionItems get => _globalOptions.GetOption(CompletionViewOptions.BlockForCompletionItems, InternalLanguageNames.TypeScript); set => _globalOptions.SetGlobalOption(new OptionKey(CompletionViewOptions.BlockForCompletionItems, InternalLanguageNames.TypeScript), value); } + + internal IGlobalOptionService Service => _globalOptions; } } diff --git a/src/EditorFeatures/Core/IBraceMatchingService.cs b/src/EditorFeatures/Core/IBraceMatchingService.cs index 0211579f18f3f..e2a520c284dee 100644 --- a/src/EditorFeatures/Core/IBraceMatchingService.cs +++ b/src/EditorFeatures/Core/IBraceMatchingService.cs @@ -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.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Text; @@ -12,19 +10,8 @@ namespace Microsoft.CodeAnalysis.Editor { internal interface IBraceMatchingService { - Task GetMatchingBracesAsync(Document document, int position, CancellationToken cancellationToken = default); + Task GetMatchingBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken); } - internal struct BraceMatchingResult - { - public TextSpan LeftSpan { get; } - public TextSpan RightSpan { get; } - - public BraceMatchingResult(TextSpan leftSpan, TextSpan rightSpan) - : this() - { - this.LeftSpan = leftSpan; - this.RightSpan = rightSpan; - } - } + internal readonly record struct BraceMatchingResult(TextSpan LeftSpan, TextSpan RightSpan); } diff --git a/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs b/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs index 8407408ce36d5..d49e1eb3154d2 100644 --- a/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs +++ b/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Commanding; @@ -30,20 +31,21 @@ internal abstract class AbstractAddImportsPasteCommandHandler : IChainedCommandH protected abstract string DialogText { get; } private readonly IThreadingContext _threadingContext; + private readonly IGlobalOptionService _globalOptions; - public AbstractAddImportsPasteCommandHandler(IThreadingContext threadingContext) - => _threadingContext = threadingContext; + public AbstractAddImportsPasteCommandHandler(IThreadingContext threadingContext, IGlobalOptionService globalOptions) + { + _threadingContext = threadingContext; + _globalOptions = globalOptions; + } public CommandState GetCommandState(PasteCommandArgs args, Func nextCommandHandler) => nextCommandHandler(); public void ExecuteCommand(PasteCommandArgs args, Action nextCommandHandler, CommandExecutionContext executionContext) { - // Check that the feature is enabled before doing any work - var optionValue = args.SubjectBuffer.GetOptionalFeatureOnOffOption(FeatureOnOffOptions.AddImportsOnPaste); - // If the feature is not explicitly enabled we can exit early - if (optionValue != true) + if (_globalOptions.GetOption(FeatureOnOffOptions.AddImportsOnPaste, args.SubjectBuffer.GetLanguageName()) != true) { nextCommandHandler(); return; diff --git a/src/EditorFeatures/Core/Implementation/AutomaticCompletion/AbstractAutomaticLineEnderCommandHandler.cs b/src/EditorFeatures/Core/Implementation/AutomaticCompletion/AbstractAutomaticLineEnderCommandHandler.cs index 631f6cf926c9e..bc05d24f30234 100644 --- a/src/EditorFeatures/Core/Implementation/AutomaticCompletion/AbstractAutomaticLineEnderCommandHandler.cs +++ b/src/EditorFeatures/Core/Implementation/AutomaticCompletion/AbstractAutomaticLineEnderCommandHandler.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Commanding; @@ -22,15 +23,18 @@ internal abstract class AbstractAutomaticLineEnderCommandHandler : { private readonly ITextUndoHistoryRegistry _undoRegistry; private readonly IEditorOperationsFactoryService _editorOperationsFactoryService; + private readonly IGlobalOptionService _globalOptions; public string DisplayName => EditorFeaturesResources.Automatic_Line_Ender; protected AbstractAutomaticLineEnderCommandHandler( ITextUndoHistoryRegistry undoRegistry, - IEditorOperationsFactoryService editorOperationsFactoryService) + IEditorOperationsFactoryService editorOperationsFactoryService, + IGlobalOptionService globalOptions) { _undoRegistry = undoRegistry; _editorOperationsFactoryService = editorOperationsFactoryService; + _globalOptions = globalOptions; } /// @@ -84,7 +88,7 @@ public void ExecuteCommand(AutomaticLineEnderCommandArgs args, Action nextHandle } // feature off - if (!document.Project.Solution.Workspace.Options.GetOption(InternalFeatureOnOffOptions.AutomaticLineEnder)) + if (!_globalOptions.GetOption(InternalFeatureOnOffOptions.AutomaticLineEnder)) { NextAction(operations, nextHandler); return; diff --git a/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractBraceMatcher.cs b/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractBraceMatcher.cs index 62d1b2dd17765..14d17b7a5379b 100644 --- a/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractBraceMatcher.cs +++ b/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractBraceMatcher.cs @@ -57,6 +57,7 @@ where tok.Span.Length > 0 public async Task FindBracesAsync( Document document, int position, + BraceMatchingOptions options, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractEmbeddedLanguageBraceMatcher.cs b/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractEmbeddedLanguageBraceMatcher.cs index a0dd558a4db1e..ed2974b5972ca 100644 --- a/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractEmbeddedLanguageBraceMatcher.cs +++ b/src/EditorFeatures/Core/Implementation/BraceMatching/AbstractEmbeddedLanguageBraceMatcher.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.BraceMatching internal abstract class AbstractEmbeddedLanguageBraceMatcher : IBraceMatcher { public async Task FindBracesAsync( - Document document, int position, CancellationToken cancellationToken) + Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { var languagesProvider = document.GetLanguageService(); if (languagesProvider != null) @@ -29,7 +29,7 @@ internal abstract class AbstractEmbeddedLanguageBraceMatcher : IBraceMatcher if (braceMatcher != null) { var result = await braceMatcher.FindBracesAsync( - document, position, cancellationToken).ConfigureAwait(false); + document, position, options, cancellationToken).ConfigureAwait(false); if (result != null) { return result; diff --git a/src/EditorFeatures/Core/Implementation/BraceMatching/BraceHighlightingViewTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/BraceMatching/BraceHighlightingViewTaggerProvider.cs index 8ef99a4a5b9b3..7e21e6aef9fe1 100644 --- a/src/EditorFeatures/Core/Implementation/BraceMatching/BraceHighlightingViewTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/BraceMatching/BraceHighlightingViewTaggerProvider.cs @@ -39,8 +39,9 @@ internal class BraceHighlightingViewTaggerProvider : AsynchronousViewTaggerProvi public BraceHighlightingViewTaggerProvider( IThreadingContext threadingContext, IBraceMatchingService braceMatcherService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.BraceHighlighting)) + : base(threadingContext, globalOptions, listenerProvider.GetListener(FeatureAttribute.BraceHighlighting)) { _braceMatcherService = braceMatcherService; } @@ -64,19 +65,21 @@ protected override Task ProduceTagsAsync( return Task.CompletedTask; } + var options = BraceMatchingOptions.From(document.Project); + return ProduceTagsAsync( - context, document, documentSnapshotSpan.SnapshotSpan.Snapshot, caretPosition.Value, cancellationToken); + context, document, documentSnapshotSpan.SnapshotSpan.Snapshot, caretPosition.Value, options, cancellationToken); } internal async Task ProduceTagsAsync( - TaggerContext context, Document document, ITextSnapshot snapshot, int position, CancellationToken cancellationToken) + TaggerContext context, Document document, ITextSnapshot snapshot, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.Tagger_BraceHighlighting_TagProducer_ProduceTags, cancellationToken)) { if (position >= 0 && position <= snapshot.Length) { var (bracesLeftOfPosition, bracesRightOfPosition) = await GetAllMatchingBracesAsync( - _braceMatcherService, document, position, cancellationToken).ConfigureAwait(false); + _braceMatcherService, document, position, options, cancellationToken).ConfigureAwait(false); AddBraces(context, snapshot, bracesLeftOfPosition); AddBraces(context, snapshot, bracesRightOfPosition); @@ -103,10 +106,11 @@ internal async Task ProduceTagsAsync( IBraceMatchingService service, Document document, int position, + BraceMatchingOptions options, CancellationToken cancellationToken) { // These are the matching spans when checking the token to the right of the position. - var rightOfPosition = await service.GetMatchingBracesAsync(document, position, cancellationToken).ConfigureAwait(false); + var rightOfPosition = await service.GetMatchingBracesAsync(document, position, options, cancellationToken).ConfigureAwait(false); // The braces to the right of the position should only be added if the position is // actually within the span of the start brace. Note that this is what we want for @@ -142,7 +146,7 @@ internal async Task ProduceTagsAsync( // { ^} // <@ ^@> - var leftOfPosition = await service.GetMatchingBracesAsync(document, position - 1, cancellationToken).ConfigureAwait(false); + var leftOfPosition = await service.GetMatchingBracesAsync(document, position - 1, options, cancellationToken).ConfigureAwait(false); if (leftOfPosition.HasValue && position <= leftOfPosition.Value.RightSpan.End && diff --git a/src/EditorFeatures/Core/Implementation/BraceMatching/BraceMatchingService.cs b/src/EditorFeatures/Core/Implementation/BraceMatching/BraceMatchingService.cs index 27bc7dd72cedd..9ec0c50b28102 100644 --- a/src/EditorFeatures/Core/Implementation/BraceMatching/BraceMatchingService.cs +++ b/src/EditorFeatures/Core/Implementation/BraceMatching/BraceMatchingService.cs @@ -28,7 +28,7 @@ public BraceMatchingService( _braceMatchers = braceMatchers.ToImmutableArray(); } - public async Task GetMatchingBracesAsync(Document document, int position, CancellationToken cancellationToken) + public async Task GetMatchingBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); if (position < 0 || position > text.Length) @@ -40,7 +40,7 @@ public BraceMatchingService( foreach (var matcher in matchers) { cancellationToken.ThrowIfCancellationRequested(); - var braces = await matcher.Value.FindBracesAsync(document, position, cancellationToken).ConfigureAwait(false); + var braces = await matcher.Value.FindBracesAsync(document, position, options, cancellationToken).ConfigureAwait(false); if (braces.HasValue) { return braces; diff --git a/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs index 03d3090841d54..85b5fb1f4e261 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs @@ -38,7 +38,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Classification internal partial class SemanticClassificationViewTaggerProvider : AsynchronousViewTaggerProvider { private readonly ClassificationTypeMap _typeMap; - private readonly IGlobalOptionService _globalOptionsService; + private readonly IGlobalOptionService _globalOptions; // We want to track text changes so that we can try to only reclassify a method body if // all edits were contained within one. @@ -50,12 +50,12 @@ internal partial class SemanticClassificationViewTaggerProvider : AsynchronousVi public SemanticClassificationViewTaggerProvider( IThreadingContext threadingContext, ClassificationTypeMap typeMap, - IAsynchronousOperationListenerProvider listenerProvider, - IGlobalOptionService globalOptionsService) - : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.Classification)) + IGlobalOptionService globalOptions, + IAsynchronousOperationListenerProvider listenerProvider) + : base(threadingContext, globalOptions, listenerProvider.GetListener(FeatureAttribute.Classification)) { _typeMap = typeMap; - _globalOptionsService = globalOptionsService; + _globalOptions = globalOptions; } protected override TaggerDelay EventChangeDelay => TaggerDelay.Short; @@ -120,7 +120,7 @@ protected override Task ProduceTagsAsync( return Task.CompletedTask; // If the LSP semantic tokens feature flag is enabled, return nothing to prevent conflicts. - var isLspSemanticTokensEnabled = _globalOptionsService.GetOption(LspOptions.LspSemanticTokensFeatureFlag); + var isLspSemanticTokensEnabled = _globalOptions.GetOption(LspOptions.LspSemanticTokensFeatureFlag); if (isLspSemanticTokensEnabled) { return Task.CompletedTask; diff --git a/src/EditorFeatures/Core/Implementation/Classification/SyntacticClassificationTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Classification/SyntacticClassificationTaggerProvider.cs index 091218daf17dc..4dc841b722fea 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/SyntacticClassificationTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/SyntacticClassificationTaggerProvider.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Tagging; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; @@ -26,6 +27,7 @@ internal partial class SyntacticClassificationTaggerProvider : ForegroundThreadA { private readonly IAsynchronousOperationListener _listener; private readonly SyntacticClassificationTypeMap _typeMap; + private readonly IGlobalOptionService _globalOptions; private readonly ConditionalWeakTable _tagComputers = new(); @@ -34,17 +36,19 @@ internal partial class SyntacticClassificationTaggerProvider : ForegroundThreadA public SyntacticClassificationTaggerProvider( IThreadingContext threadingContext, SyntacticClassificationTypeMap typeMap, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) : base(threadingContext, assertIsForeground: false) { _typeMap = typeMap; + _globalOptions = globalOptions; _listener = listenerProvider.GetListener(FeatureAttribute.Classification); } public ITagger? CreateTagger(ITextBuffer buffer) where T : ITag { this.AssertIsForeground(); - if (!buffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.SyntacticColorizer)) + if (!_globalOptions.GetOption(InternalFeatureOnOffOptions.SyntacticColorizer)) return null; if (!_tagComputers.TryGetValue(buffer, out var tagComputer)) diff --git a/src/EditorFeatures/Core/Implementation/CodeDefinitionWindow/DefinitionContextTracker.cs b/src/EditorFeatures/Core/Implementation/CodeDefinitionWindow/DefinitionContextTracker.cs index 45ed6a47bd7e7..44a4f4fa7c36e 100644 --- a/src/EditorFeatures/Core/Implementation/CodeDefinitionWindow/DefinitionContextTracker.cs +++ b/src/EditorFeatures/Core/Implementation/CodeDefinitionWindow/DefinitionContextTracker.cs @@ -19,6 +19,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.MetadataAsSource; using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; @@ -44,6 +45,7 @@ internal class DefinitionContextTracker : ITextViewConnectionListener private readonly ICodeDefinitionWindowService _codeDefinitionWindowService; private readonly IThreadingContext _threadingContext; private readonly IAsynchronousOperationListener _asyncListener; + private readonly IGlobalOptionService _globalOptions; private CancellationTokenSource? _currentUpdateCancellationToken; @@ -53,11 +55,13 @@ public DefinitionContextTracker( IMetadataAsSourceFileService metadataAsSourceFileService, ICodeDefinitionWindowService codeDefinitionWindowService, IThreadingContext threadingContext, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) { _metadataAsSourceFileService = metadataAsSourceFileService; _codeDefinitionWindowService = codeDefinitionWindowService; _threadingContext = threadingContext; + _globalOptions = globalOptions; _asyncListener = listenerProvider.GetListener(FeatureAttribute.CodeDefinitionWindow); } @@ -205,7 +209,7 @@ internal async Task> GetContextFrom } else if (_metadataAsSourceFileService.IsNavigableMetadataSymbol(symbol)) { - var allowDecompilation = document.Project.Solution.Workspace.Options.GetOption(FeatureOnOffOptions.NavigateToDecompiledSources); + var allowDecompilation = _globalOptions.GetOption(FeatureOnOffOptions.NavigateToDecompiledSources); var declarationFile = await _metadataAsSourceFileService.GetGeneratedFileAsync(document.Project, symbol, signaturesOnly: false, allowDecompilation, cancellationToken).ConfigureAwait(false); var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span; return ImmutableArray.Create(new CodeDefinitionWindowLocation(symbol.ToDisplayString(), declarationFile.FilePath, identifierSpan.Start)); diff --git a/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsAdornmentTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsAdornmentTaggerProvider.cs index 5900df1884756..44f15bd41d844 100644 --- a/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsAdornmentTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsAdornmentTaggerProvider.cs @@ -7,6 +7,7 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.QuickInfo; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Adornments; @@ -21,8 +22,9 @@ internal abstract class AbstractDiagnosticsAdornmentTaggerProvider : public AbstractDiagnosticsAdornmentTaggerProvider( IThreadingContext threadingContext, IDiagnosticService diagnosticService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, diagnosticService, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles)) + : base(threadingContext, diagnosticService, globalOptions, listenerProvider.GetListener(FeatureAttribute.ErrorSquiggles)) { } diff --git a/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs index 829619b272c62..337881d45f6f1 100644 --- a/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Diagnostics/AbstractDiagnosticsTaggerProvider.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.ErrorReporting; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; @@ -54,8 +55,9 @@ internal abstract partial class AbstractDiagnosticsTaggerProvider : Asynch protected AbstractDiagnosticsTaggerProvider( IThreadingContext threadingContext, IDiagnosticService diagnosticService, + IGlobalOptionService globalOptions, IAsynchronousOperationListener listener) - : base(threadingContext, listener) + : base(threadingContext, globalOptions, listener) { _diagnosticService = diagnosticService; _diagnosticService.DiagnosticsUpdated += OnDiagnosticsUpdated; diff --git a/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsClassificationTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsClassificationTaggerProvider.cs index 019c02abee611..78624c22629ed 100644 --- a/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsClassificationTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsClassificationTaggerProvider.cs @@ -47,8 +47,9 @@ public DiagnosticsClassificationTaggerProvider( IDiagnosticService diagnosticService, ClassificationTypeMap typeMap, IEditorOptionsFactoryService editorOptionsFactoryService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, diagnosticService, listenerProvider.GetListener(FeatureAttribute.Classification)) + : base(threadingContext, diagnosticService, globalOptions, listenerProvider.GetListener(FeatureAttribute.Classification)) { _typeMap = typeMap; _classificationTag = new ClassificationTag(_typeMap.GetClassificationType(ClassificationTypeDefinitions.UnnecessaryCode)); diff --git a/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSquiggleTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSquiggleTaggerProvider.cs index 17a62b90d5e54..4052177329404 100644 --- a/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSquiggleTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSquiggleTaggerProvider.cs @@ -37,8 +37,9 @@ internal partial class DiagnosticsSquiggleTaggerProvider : AbstractDiagnosticsAd public DiagnosticsSquiggleTaggerProvider( IThreadingContext threadingContext, IDiagnosticService diagnosticService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, diagnosticService, listenerProvider) + : base(threadingContext, diagnosticService, globalOptions, listenerProvider) { } diff --git a/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSuggestionTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSuggestionTaggerProvider.cs index 550b4330b4f06..f0e4ab402b94c 100644 --- a/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSuggestionTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Diagnostics/DiagnosticsSuggestionTaggerProvider.cs @@ -37,8 +37,9 @@ internal partial class DiagnosticsSuggestionTaggerProvider : public DiagnosticsSuggestionTaggerProvider( IThreadingContext threadingContext, IDiagnosticService diagnosticService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, diagnosticService, listenerProvider) + : base(threadingContext, diagnosticService, globalOptions, listenerProvider) { } diff --git a/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTaggerProvider.cs index 2a5b9f311bce2..1d80ad78dfe39 100644 --- a/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTaggerProvider.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; @@ -39,8 +40,9 @@ internal partial class ActiveStatementTaggerProvider : AsynchronousTaggerProvide [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public ActiveStatementTaggerProvider( IThreadingContext threadingContext, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.Classification)) + : base(threadingContext, globalOptions, listenerProvider.GetListener(FeatureAttribute.Classification)) { } diff --git a/src/EditorFeatures/Core/Implementation/EditorLayerExtensionManager.cs b/src/EditorFeatures/Core/Implementation/EditorLayerExtensionManager.cs index e3e30a7f9e5cc..0551a3b8bcc82 100644 --- a/src/EditorFeatures/Core/Implementation/EditorLayerExtensionManager.cs +++ b/src/EditorFeatures/Core/Implementation/EditorLayerExtensionManager.cs @@ -49,17 +49,17 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) internal class ExtensionManager : AbstractExtensionManager { private readonly List _errorHandlers; - private readonly IGlobalOptionService _optionsService; + private readonly IGlobalOptionService _globalOptions; private readonly IErrorReportingService _errorReportingService; private readonly IErrorLoggerService _errorLoggerService; public ExtensionManager( - IGlobalOptionService optionsService, + IGlobalOptionService globalOptions, IErrorReportingService errorReportingService, IErrorLoggerService errorLoggerService, List errorHandlers) { - _optionsService = optionsService; + _globalOptions = globalOptions; _errorHandlers = errorHandlers; _errorReportingService = errorReportingService; _errorLoggerService = errorLoggerService; @@ -70,7 +70,7 @@ public override void HandleException(object provider, Exception exception) if (provider is CodeFixProvider or FixAllProvider or CodeRefactoringProvider) { if (!IsIgnored(provider) && - _optionsService.GetOption(ExtensionManagerOptions.DisableCrashingExtensions)) + _globalOptions.GetOption(ExtensionManagerOptions.DisableCrashingExtensions)) { base.HandleException(provider, exception); @@ -97,7 +97,7 @@ public override void HandleException(object provider, Exception exception) } else { - if (_optionsService.GetOption(ExtensionManagerOptions.DisableCrashingExtensions)) + if (_globalOptions.GetOption(ExtensionManagerOptions.DisableCrashingExtensions)) { base.HandleException(provider, exception); } diff --git a/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.Paste.cs b/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.Paste.cs index c379482adf461..8eacc8339465f 100644 --- a/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.Paste.cs +++ b/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.Paste.cs @@ -49,26 +49,29 @@ public void ExecuteCommand(PasteCommandArgs args, Action nextHandler, CommandExe private static void ExecuteCommandWorker(PasteCommandArgs args, SnapshotPoint? caretPosition, CancellationToken cancellationToken) { - if (!args.SubjectBuffer.CanApplyChangeDocumentToWorkspace()) + if (!caretPosition.HasValue) { return; } - if (!args.SubjectBuffer.GetFeatureOnOffOption(FormattingBehaviorOptions.FormatOnPaste) || - !caretPosition.HasValue) + var document = args.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); + if (document == null) { return; } - var trackingSpan = caretPosition.Value.Snapshot.CreateTrackingSpan(caretPosition.Value.Position, 0, SpanTrackingMode.EdgeInclusive); + var solution = document.Project.Solution; + if (!solution.Options.GetOption(FormattingBehaviorOptions.FormatOnPaste, document.Project.Language)) + { + return; + } - var document = args.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - if (document == null) + if (!solution.Workspace.CanApplyChange(ApplyChangesKind.ChangeDocument)) { return; } - var formattingRuleService = document.Project.Solution.Workspace.Services.GetService(); + var formattingRuleService = solution.Workspace.Services.GetService(); if (formattingRuleService != null && formattingRuleService.ShouldNotFormatOrCommitOnPaste(document)) { return; @@ -80,6 +83,7 @@ private static void ExecuteCommandWorker(PasteCommandArgs args, SnapshotPoint? c return; } + var trackingSpan = caretPosition.Value.Snapshot.CreateTrackingSpan(caretPosition.Value.Position, 0, SpanTrackingMode.EdgeInclusive); var span = trackingSpan.GetSpan(args.SubjectBuffer.CurrentSnapshot).Span.ToTextSpan(); var changes = formattingService.GetFormattingChangesOnPasteAsync( document, span, documentOptions: null, cancellationToken).WaitAndGetResult(cancellationToken); @@ -88,7 +92,7 @@ private static void ExecuteCommandWorker(PasteCommandArgs args, SnapshotPoint? c return; } - document.Project.Solution.Workspace.ApplyTextChanges(document.Id, changes, cancellationToken); + solution.Workspace.ApplyTextChanges(document.Id, changes, cancellationToken); } } } diff --git a/src/EditorFeatures/Core/Implementation/KeywordHighlighting/HighlighterViewTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/KeywordHighlighting/HighlighterViewTaggerProvider.cs index aeef3cb7e90e0..2401f0b76d42d 100644 --- a/src/EditorFeatures/Core/Implementation/KeywordHighlighting/HighlighterViewTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/KeywordHighlighting/HighlighterViewTaggerProvider.cs @@ -47,8 +47,9 @@ internal class HighlighterViewTaggerProvider : AsynchronousViewTaggerProvider _refactorNotifyServices; private readonly ITextUndoHistoryRegistry _undoHistoryRegistry; + private readonly IGlobalOptionService _globalOptions; private RenameTrackingCommitter _renameTrackingCommitter; - public RenameTrackingCodeAction(Document document, string title, IEnumerable refactorNotifyServices, ITextUndoHistoryRegistry undoHistoryRegistry) + public RenameTrackingCodeAction( + Document document, + string title, + IEnumerable refactorNotifyServices, + ITextUndoHistoryRegistry undoHistoryRegistry, + IGlobalOptionService globalOptions) { _document = document; _title = title; _refactorNotifyServices = refactorNotifyServices; _undoHistoryRegistry = undoHistoryRegistry; + _globalOptions = globalOptions; } public override string Title => _title; @@ -54,8 +62,7 @@ protected override Task> ComputeOperationsAsync protected override async Task> ComputePreviewOperationsAsync(CancellationToken cancellationToken) { - var documentOptions = await _document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); - if (!documentOptions.GetOption(FeatureOnOffOptions.RenameTrackingPreview) || + if (!_globalOptions.GetOption(FeatureOnOffOptions.RenameTrackingPreview, _document.Project.Language) || !TryInitializeRenameTrackingCommitter(cancellationToken)) { return await SpecializedTasks.EmptyEnumerable().ConfigureAwait(false); diff --git a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.StateMachine.cs b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.StateMachine.cs index 38303ffe9bd5d..74a5de8b254c3 100644 --- a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.StateMachine.cs +++ b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.StateMachine.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; @@ -33,7 +34,7 @@ internal sealed partial class RenameTrackingTaggerProvider /// Keeps track of the rename tracking state for a given text buffer by tracking its /// changes over time. /// - private class StateMachine : ForegroundThreadAffinitizedObject + private sealed class StateMachine : ForegroundThreadAffinitizedObject { private readonly IInlineRenameService _inlineRenameService; private readonly IAsynchronousOperationListener _asyncListener; @@ -47,6 +48,7 @@ private class StateMachine : ForegroundThreadAffinitizedObject private int _refCount; + public readonly IGlobalOptionService GlobalOptions; public TrackingSession TrackingSession { get; private set; } public ITextBuffer Buffer => _buffer; @@ -57,8 +59,9 @@ public StateMachine( IThreadingContext threadingContext, ITextBuffer buffer, IInlineRenameService inlineRenameService, - IAsynchronousOperationListener asyncListener, - IDiagnosticAnalyzerService diagnosticAnalyzerService) + IDiagnosticAnalyzerService diagnosticAnalyzerService, + IGlobalOptionService globalOptions, + IAsynchronousOperationListener asyncListener) : base(threadingContext) { _buffer = buffer; @@ -66,13 +69,14 @@ public StateMachine( _inlineRenameService = inlineRenameService; _asyncListener = asyncListener; _diagnosticAnalyzerService = diagnosticAnalyzerService; + GlobalOptions = globalOptions; } private void Buffer_Changed(object sender, TextContentChangedEventArgs e) { AssertIsForeground(); - if (!_buffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.RenameTracking)) + if (!GlobalOptions.GetOption(InternalFeatureOnOffOptions.RenameTracking)) { // When disabled, ignore all text buffer changes and do not trigger retagging return; @@ -310,8 +314,7 @@ public bool CanInvokeRename( trackingSession.OriginalName, snapshotSpan.GetText()); - return (new RenameTrackingCodeAction( - document, title, refactorNotifyServices, undoHistoryRegistry), + return (new RenameTrackingCodeAction(document, title, refactorNotifyServices, undoHistoryRegistry, GlobalOptions), snapshotSpan.Span.ToTextSpan()); } } diff --git a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.Tagger.cs b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.Tagger.cs index 8697d91275b01..cd84927ced6ec 100644 --- a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.Tagger.cs +++ b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.Tagger.cs @@ -51,7 +51,7 @@ IEnumerable> ITagger.GetTags(NormalizedSnapshotSp private IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans, T tag) where T : ITag { - if (!_stateMachine.Buffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.RenameTracking)) + if (!_stateMachine.GlobalOptions.GetOption(InternalFeatureOnOffOptions.RenameTracking)) { // Changes aren't being triggered by the buffer, but there may still be taggers // out there which we should prevent from doing work. diff --git a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.cs index bedb12af88e09..eb25f64846d20 100644 --- a/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/RenameTracking/RenameTrackingTaggerProvider.cs @@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; @@ -43,6 +44,7 @@ internal sealed partial class RenameTrackingTaggerProvider : ITaggerProvider private readonly IAsynchronousOperationListener _asyncListener; private readonly IInlineRenameService _inlineRenameService; private readonly IDiagnosticAnalyzerService _diagnosticAnalyzerService; + private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] @@ -50,17 +52,19 @@ public RenameTrackingTaggerProvider( IThreadingContext threadingContext, IInlineRenameService inlineRenameService, IDiagnosticAnalyzerService diagnosticAnalyzerService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) { _threadingContext = threadingContext; _inlineRenameService = inlineRenameService; _diagnosticAnalyzerService = diagnosticAnalyzerService; + _globalOptions = globalOptions; _asyncListener = listenerProvider.GetListener(FeatureAttribute.RenameTracking); } public ITagger CreateTagger(ITextBuffer buffer) where T : ITag { - var stateMachine = buffer.Properties.GetOrCreateSingletonProperty(() => new StateMachine(_threadingContext, buffer, _inlineRenameService, _asyncListener, _diagnosticAnalyzerService)); + var stateMachine = buffer.Properties.GetOrCreateSingletonProperty(() => new StateMachine(_threadingContext, buffer, _inlineRenameService, _diagnosticAnalyzerService, _globalOptions, _asyncListener)); return new Tagger(stateMachine) as ITagger; } diff --git a/src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndentProvider.cs b/src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndentProvider.cs index 0111f7db77370..91fa421930441 100644 --- a/src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndentProvider.cs +++ b/src/EditorFeatures/Core/Implementation/SmartIndent/SmartIndentProvider.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Utilities; @@ -18,10 +19,13 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent [ContentType(ContentTypeNames.RoslynContentType)] internal class SmartIndentProvider : ISmartIndentProvider { + private readonly IGlobalOptionService _globalOptions; + [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SmartIndentProvider() + public SmartIndentProvider(IGlobalOptionService globalOptions) { + _globalOptions = globalOptions; } public ISmartIndent CreateSmartIndent(ITextView textView) @@ -31,7 +35,7 @@ public ISmartIndent CreateSmartIndent(ITextView textView) throw new ArgumentNullException(nameof(textView)); } - if (!textView.TextBuffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.SmartIndenter)) + if (!_globalOptions.GetOption(InternalFeatureOnOffOptions.SmartIndenter)) { return null; } diff --git a/src/EditorFeatures/Core/Implementation/SplitComment/SplitCommentOptions.cs b/src/EditorFeatures/Core/Implementation/SplitComment/SplitCommentOptions.cs index cb77f0eb07a6f..e00bdc8b827f2 100644 --- a/src/EditorFeatures/Core/Implementation/SplitComment/SplitCommentOptions.cs +++ b/src/EditorFeatures/Core/Implementation/SplitComment/SplitCommentOptions.cs @@ -11,23 +11,20 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.SplitComment { - internal class SplitCommentOptions - { - public static PerLanguageOption2 Enabled = - new PerLanguageOption2(nameof(SplitCommentOptions), nameof(Enabled), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SplitComments")); - } - - [ExportOptionProvider, Shared] - internal class SplitCommentOptionsProvider : IOptionProvider + [ExportGlobalOptionProvider, Shared] + internal sealed class SplitCommentOptions : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SplitCommentOptionsProvider() + public SplitCommentOptions() { } - public ImmutableArray Options { get; } = ImmutableArray.Create( - SplitCommentOptions.Enabled); + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + Enabled); + + public static PerLanguageOption2 Enabled = + new PerLanguageOption2(nameof(SplitCommentOptions), nameof(Enabled), defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.SplitComments")); } } diff --git a/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs b/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs index 439ce2722c06d..d08e0b5fe7d33 100644 --- a/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Structure/AbstractStructureTaggerProvider.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.ErrorReporting; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Structure; @@ -46,8 +47,9 @@ protected AbstractStructureTaggerProvider( IThreadingContext threadingContext, IEditorOptionsFactoryService editorOptionsFactoryService, IProjectionBufferFactoryService projectionBufferFactoryService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) - : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.Outlining)) + : base(threadingContext, globalOptions, listenerProvider.GetListener(FeatureAttribute.Outlining)) { EditorOptionsFactoryService = editorOptionsFactoryService; ProjectionBufferFactoryService = projectionBufferFactoryService; @@ -63,13 +65,12 @@ protected override bool ComputeInitialTagsSynchronously(ITextBuffer subjectBuffe if (openDocument == null) return false; - var workspace = openDocument.Project.Solution.Workspace; - if (!workspace.Options.GetOption(FeatureOnOffOptions.Outlining, openDocument.Project.Language)) + if (!GlobalOptions.GetOption(FeatureOnOffOptions.Outlining, openDocument.Project.Language)) return false; // If we're a metadata-as-source doc, we need to compute the initial set of tags synchronously // so that we can collapse all the .IsImplementation tags to keep the UI clean and condensed. - var isMetadataAsSource = workspace.Kind == WorkspaceKind.MetadataAsSource; + var isMetadataAsSource = openDocument.Project.Solution.Workspace.Kind == WorkspaceKind.MetadataAsSource; if (isMetadataAsSource) return true; @@ -116,13 +117,13 @@ protected sealed override ITaggerEventSource CreateEventSource(ITextView textVie TaggerEventSources.OnTextChanged(subjectBuffer), TaggerEventSources.OnParseOptionChanged(subjectBuffer), TaggerEventSources.OnWorkspaceRegistrationChanged(subjectBuffer), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.ShowOutliningForCodeLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.ShowOutliningForDeclarationLevelConstructs), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.ShowOutliningForCommentsAndPreprocessorRegions), - TaggerEventSources.OnOptionChanged(subjectBuffer, BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions)); + 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)); } protected sealed override async Task ProduceTagsAsync( diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptions.cs b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptions.cs index e3cfd77d0edd6..edd9baadfe565 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptions.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptions.cs @@ -2,12 +2,27 @@ // 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.Editor.Implementation.Suggestions { - internal static class SuggestionsOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class SuggestionsOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public SuggestionsOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + AsynchronousQuickActionsDisableFeatureFlag); + private const string FeatureName = "SuggestionsOptions"; public static readonly Option2 AsynchronousQuickActionsDisableFeatureFlag = new(FeatureName, nameof(AsynchronousQuickActionsDisableFeatureFlag), defaultValue: false, diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptionsProvider.cs b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptionsProvider.cs deleted file mode 100644 index 268b00dd38064..0000000000000 --- a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestionsOptionsProvider.cs +++ /dev/null @@ -1,26 +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.Editor.Implementation.Suggestions -{ - [ExportOptionProvider, Shared] - internal sealed class SuggestionsOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SuggestionsOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - SuggestionsOptions.AsynchronousQuickActionsDisableFeatureFlag); - } -} diff --git a/src/EditorFeatures/Core/InlineDiagnostics/InlineDiagnosticsOptions.cs b/src/EditorFeatures/Core/InlineDiagnostics/InlineDiagnosticsOptions.cs index 54096d6880787..7fdd27c56f116 100644 --- a/src/EditorFeatures/Core/InlineDiagnostics/InlineDiagnosticsOptions.cs +++ b/src/EditorFeatures/Core/InlineDiagnostics/InlineDiagnosticsOptions.cs @@ -11,32 +11,29 @@ namespace Microsoft.CodeAnalysis.Editor.InlineDiagnostics { - internal static class InlineDiagnosticsOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class InlineDiagnosticsOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public InlineDiagnosticsOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + EnableInlineDiagnostics, + Location); + public static readonly PerLanguageOption2 EnableInlineDiagnostics = - new(nameof(InlineDiagnosticsOptions), - nameof(EnableInlineDiagnostics), + new("InlineDiagnosticsOptions", + "EnableInlineDiagnostics", defaultValue: false, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineDiagnostics")); public static readonly PerLanguageOption2 Location = - new(nameof(InlineDiagnosticsOptions), - nameof(Location), + new("InlineDiagnosticsOptions", + "Location", defaultValue: InlineDiagnosticsLocations.PlacedAtEndOfCode, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineDiagnostics.LocationOption")); } - - [ExportOptionProvider, Shared] - internal sealed class InlineDiagnosticsOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public InlineDiagnosticsOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - InlineDiagnosticsOptions.EnableInlineDiagnostics, - InlineDiagnosticsOptions.Location); - } } diff --git a/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs b/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs index 5ba487c5deba2..88fde964d8ac5 100644 --- a/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs +++ b/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.InlineHints; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text.Shared.Extensions; @@ -50,8 +51,9 @@ internal class InlineHintsDataTaggerProvider : AsynchronousViewTaggerProvider GetSpansToTag(ITextView textView, ITextBuffer subjectBuffer) diff --git a/src/EditorFeatures/Core/Options/ColorSchemeOptions.cs b/src/EditorFeatures/Core/Options/ColorSchemeOptions.cs index 93089680b4b98..2f5f4b329fda2 100644 --- a/src/EditorFeatures/Core/Options/ColorSchemeOptions.cs +++ b/src/EditorFeatures/Core/Options/ColorSchemeOptions.cs @@ -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.Collections.Immutable; using System.Composition; @@ -14,8 +12,19 @@ namespace Microsoft.CodeAnalysis.Editor.Options { - internal static class ColorSchemeOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class ColorSchemeOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public ColorSchemeOptions() + { + } + + ImmutableArray IOptionProvider.Options => ImmutableArray.Create( + ColorScheme, + LegacyUseEnhancedColors); + internal const string ColorSchemeSettingKey = "TextEditor.Roslyn.ColorScheme"; public static readonly Option2 ColorScheme = new(nameof(ColorSchemeOptions), @@ -36,18 +45,4 @@ public enum UseEnhancedColors Use = 1 } } - - [ExportOptionProvider, Shared] - internal class ColorSchemeOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ColorSchemeOptionsProvider() - { - } - - public ImmutableArray Options => ImmutableArray.Create( - ColorSchemeOptions.ColorScheme, - ColorSchemeOptions.LegacyUseEnhancedColors); - } } diff --git a/src/EditorFeatures/Core/Options/CompletionViewOptions.cs b/src/EditorFeatures/Core/Options/CompletionViewOptions.cs index 83b863e9162ea..71bd290d76c9b 100644 --- a/src/EditorFeatures/Core/Options/CompletionViewOptions.cs +++ b/src/EditorFeatures/Core/Options/CompletionViewOptions.cs @@ -11,24 +11,21 @@ namespace Microsoft.CodeAnalysis.Completion { - internal static class CompletionViewOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class CompletionViewOptions : IOptionProvider { - [ExportOptionProvider, Shared] - internal sealed class Provider : IOptionProvider + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public CompletionViewOptions() { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Provider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - ShowCompletionItemFilters, - HighlightMatchingPortionsOfCompletionListItems, - EnableArgumentCompletionSnippets, - BlockForCompletionItems); } + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + ShowCompletionItemFilters, + HighlightMatchingPortionsOfCompletionListItems, + EnableArgumentCompletionSnippets, + BlockForCompletionItems); + private const string FeatureName = "CompletionOptions"; public static readonly PerLanguageOption2 HighlightMatchingPortionsOfCompletionListItems = diff --git a/src/EditorFeatures/Core/Options/ExtensionManagerOptions.cs b/src/EditorFeatures/Core/Options/ExtensionManagerOptions.cs index 6a3cc9e2b2afe..5aa30ccad5b63 100644 --- a/src/EditorFeatures/Core/Options/ExtensionManagerOptions.cs +++ b/src/EditorFeatures/Core/Options/ExtensionManagerOptions.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,21 +11,19 @@ namespace Microsoft.CodeAnalysis.Editor.Options { - internal partial class ExtensionManagerOptions - { - public static readonly Option DisableCrashingExtensions = new(nameof(ExtensionManagerOptions), nameof(DisableCrashingExtensions), defaultValue: true); - } - - [ExportOptionProvider, Shared] - internal class ExtensionManagerOptionsProvider : IOptionProvider + [ExportGlobalOptionProvider, Shared] + internal sealed class ExtensionManagerOptions : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public ExtensionManagerOptionsProvider() + public ExtensionManagerOptions() { } public ImmutableArray Options { get; } = ImmutableArray.Create( - ExtensionManagerOptions.DisableCrashingExtensions); + DisableCrashingExtensions); + + public static readonly Option DisableCrashingExtensions = new( + nameof(ExtensionManagerOptions), nameof(DisableCrashingExtensions), defaultValue: true); } } diff --git a/src/EditorFeatures/Core/Options/NavigationBarViewOptions.cs b/src/EditorFeatures/Core/Options/NavigationBarViewOptions.cs index 384df00b51dea..3334ded376ec7 100644 --- a/src/EditorFeatures/Core/Options/NavigationBarViewOptions.cs +++ b/src/EditorFeatures/Core/Options/NavigationBarViewOptions.cs @@ -11,21 +11,18 @@ namespace Microsoft.CodeAnalysis.Editor.Options { - internal static class NavigationBarViewOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class NavigationBarViewOptions : IOptionProvider { - [ExportOptionProvider, Shared] - internal sealed class Provider : IOptionProvider + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public NavigationBarViewOptions() { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Provider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - ShowNavigationBar); } + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + ShowNavigationBar); + private const string FeatureName = "NavigationBarOptions"; public static readonly PerLanguageOption ShowNavigationBar = new(FeatureName, nameof(ShowNavigationBar), defaultValue: true); diff --git a/src/EditorFeatures/Core/Options/SignatureHelpViewOptions.cs b/src/EditorFeatures/Core/Options/SignatureHelpViewOptions.cs index bb98bb7707722..027bc6995ca6f 100644 --- a/src/EditorFeatures/Core/Options/SignatureHelpViewOptions.cs +++ b/src/EditorFeatures/Core/Options/SignatureHelpViewOptions.cs @@ -11,21 +11,18 @@ namespace Microsoft.CodeAnalysis.Editor.Options { - internal static class SignatureHelpViewOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class SignatureHelpViewOptions : IOptionProvider { - [ExportOptionProvider, Shared] - internal sealed class Provider : IOptionProvider + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public SignatureHelpViewOptions() { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public Provider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - ShowSignatureHelp); } + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + ShowSignatureHelp); + private const string FeatureName = "SignatureHelpOptions"; public static readonly PerLanguageOption2 ShowSignatureHelp = new(FeatureName, nameof(ShowSignatureHelp), defaultValue: true); diff --git a/src/EditorFeatures/Core/ReferenceHighlighting/ReferenceHighlightingViewTaggerProvider.cs b/src/EditorFeatures/Core/ReferenceHighlighting/ReferenceHighlightingViewTaggerProvider.cs index 4e1ed3d5f4b58..9efa11206ebfa 100644 --- a/src/EditorFeatures/Core/ReferenceHighlighting/ReferenceHighlightingViewTaggerProvider.cs +++ b/src/EditorFeatures/Core/ReferenceHighlighting/ReferenceHighlightingViewTaggerProvider.cs @@ -51,9 +51,9 @@ internal partial class ReferenceHighlightingViewTaggerProvider : AsynchronousVie [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] public ReferenceHighlightingViewTaggerProvider( IThreadingContext threadingContext, - IAsynchronousOperationListenerProvider listenerProvider, - IGlobalOptionService globalOptions) - : base(threadingContext, listenerProvider.GetListener(FeatureAttribute.ReferenceHighlighting)) + IGlobalOptionService globalOptions, + IAsynchronousOperationListenerProvider listenerProvider) + : base(threadingContext, globalOptions, listenerProvider.GetListener(FeatureAttribute.ReferenceHighlighting)) { _globalOptions = globalOptions; } diff --git a/src/EditorFeatures/Core/Shared/Extensions/IBraceMatchingServiceExtensions.cs b/src/EditorFeatures/Core/Shared/Extensions/IBraceMatchingServiceExtensions.cs index c1fb0a4133575..752216cd48f85 100644 --- a/src/EditorFeatures/Core/Shared/Extensions/IBraceMatchingServiceExtensions.cs +++ b/src/EditorFeatures/Core/Shared/Extensions/IBraceMatchingServiceExtensions.cs @@ -14,10 +14,11 @@ internal static class IBraceMatchingServiceExtensions this IBraceMatchingService service, Document document, int position, + BraceMatchingOptions options, CancellationToken cancellationToken) { // These are the matching spans when checking the token to the right of the position. - var braces1 = await service.GetMatchingBracesAsync(document, position, cancellationToken).ConfigureAwait(false); + var braces1 = await service.GetMatchingBracesAsync(document, position, options, cancellationToken).ConfigureAwait(false); // These are the matching spans when checking the token to the left of the position. BraceMatchingResult? braces2 = null; @@ -25,7 +26,7 @@ internal static class IBraceMatchingServiceExtensions // Ensure caret is valid at left of position. if (position > 0) { - braces2 = await service.GetMatchingBracesAsync(document, position - 1, cancellationToken).ConfigureAwait(false); + braces2 = await service.GetMatchingBracesAsync(document, position - 1, options, cancellationToken).ConfigureAwait(false); } // Favor matches where the position is on the outside boundary of the braces. i.e. if we diff --git a/src/EditorFeatures/Core/Shared/Extensions/ITextBufferExtensions.cs b/src/EditorFeatures/Core/Shared/Extensions/ITextBufferExtensions.cs index 18145d4a67c02..f450c5f63ccce 100644 --- a/src/EditorFeatures/Core/Shared/Extensions/ITextBufferExtensions.cs +++ b/src/EditorFeatures/Core/Shared/Extensions/ITextBufferExtensions.cs @@ -2,72 +2,15 @@ // 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 System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; -using Microsoft.CodeAnalysis.ErrorReporting; -using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Editor.Shared.Extensions { internal static partial class ITextBufferExtensions { - internal static bool GetFeatureOnOffOption(this ITextBuffer buffer, Option2 option) - { - var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - - if (document != null) - { - return document.Project.Solution.Options.GetOption(option); - } - - return option.DefaultValue; - } - - internal static T GetFeatureOnOffOption(this ITextBuffer buffer, PerLanguageOption2 option) - { - // Add a FailFast to help diagnose 984249. Hopefully this will let us know what the issue is. - try - { - var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - - if (document != null) - { - return document.Project.Solution.Options.GetOption(option, document.Project.Language); - } - - return option.DefaultValue; - } - catch (Exception e) when (FatalError.ReportAndPropagate(e)) - { - throw ExceptionUtilities.Unreachable; - } - } - - internal static bool? GetOptionalFeatureOnOffOption(this ITextBuffer buffer, PerLanguageOption2 option) - { - // Add a FailFast to help diagnose 984249. Hopefully this will let us know what the issue is. - try - { - var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - - if (document != null) - { - return document.Project.Solution.Options.GetOption(option, document.Project.Language); - } - - return option.DefaultValue; - } - catch (Exception e) when (FatalError.ReportAndPropagate(e)) - { - throw ExceptionUtilities.Unreachable; - } - } - internal static bool IsInLspEditorContext(this ITextBuffer buffer) { if (buffer.TryGetWorkspace(out var workspace)) diff --git a/src/EditorFeatures/Core/Shared/Options/ComponentOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/ComponentOnOffOptions.cs index 276f0a19632c0..2f0fc7ff4f41c 100644 --- a/src/EditorFeatures/Core/Shared/Options/ComponentOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/ComponentOnOffOptions.cs @@ -14,37 +14,30 @@ namespace Microsoft.CodeAnalysis.Editor.Shared.Options /// /// options to indicate whether a certain component in Roslyn is enabled or not /// - internal static class EditorComponentOnOffOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class EditorComponentOnOffOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public EditorComponentOnOffOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + Adornment, + Tagger, + CodeRefactorings); + private const string LocalRegistryPath = @"Roslyn\Internal\OnOff\Components\"; + private const string FeatureName = "EditorComponentOnOffOptions"; - public static readonly Option2 Adornment = new(nameof(EditorComponentOnOffOptions), nameof(Adornment), defaultValue: true, + public static readonly Option2 Adornment = new(FeatureName, "Adornment", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Adornment")); - public static readonly Option2 Tagger = new(nameof(EditorComponentOnOffOptions), nameof(Tagger), defaultValue: true, + public static readonly Option2 Tagger = new(FeatureName, "Tagger", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Tagger")); - public static readonly Option2 CodeRefactorings = new(nameof(EditorComponentOnOffOptions), nameof(CodeRefactorings), defaultValue: true, + public static readonly Option2 CodeRefactorings = new(FeatureName, "CodeRefactorings", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Code Refactorings")); - - public static readonly Option2 ShowCodeRefactoringsWhenQueriedForCodeFixes = new( - nameof(EditorComponentOnOffOptions), nameof(ShowCodeRefactoringsWhenQueriedForCodeFixes), defaultValue: false, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(ShowCodeRefactoringsWhenQueriedForCodeFixes))); - } - - [ExportOptionProvider, Shared] - internal class EditorComponentOnOffOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public EditorComponentOnOffOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - EditorComponentOnOffOptions.Adornment, - EditorComponentOnOffOptions.Tagger, - EditorComponentOnOffOptions.CodeRefactorings, - EditorComponentOnOffOptions.ShowCodeRefactoringsWhenQueriedForCodeFixes); } } diff --git a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs index 999828212742a..1b83726ad86fc 100644 --- a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs @@ -6,133 +6,122 @@ using System.Collections.Immutable; using System.Composition; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.InheritanceMargin; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Options.Providers; namespace Microsoft.CodeAnalysis.Editor.Shared.Options { - internal static class FeatureOnOffOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class FeatureOnOffOptions : IOptionProvider { - public static readonly PerLanguageOption2 EndConstruct = new(nameof(FeatureOnOffOptions), nameof(EndConstruct), defaultValue: true, + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public FeatureOnOffOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + EndConstruct, + AutomaticInsertionOfAbstractOrInterfaceMembers, + LineSeparator, + Outlining, + KeywordHighlighting, + ReferenceHighlighting, + AutoInsertBlockCommentStartString, + PrettyListing, + RenameTrackingPreview, + RenameTracking, + RefactoringVerification, + NavigateToDecompiledSources, + AddImportsOnPaste, + OfferRemoveUnusedReferences, + OfferRemoveUnusedReferencesFeatureFlag, + ShowInheritanceMargin, + InheritanceMarginCombinedWithIndicatorMargin, + AutomaticallyCompleteStatementOnSemicolon, + SkipAnalyzersForImplicitlyTriggeredBuilds); + + private const string FeatureName = "FeatureOnOffOptions"; + + public static readonly PerLanguageOption2 EndConstruct = new(FeatureName, "EndConstruct", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AutoEndInsert")); // This value is only used by Visual Basic, and so is using the old serialization name that was used by VB. - public static readonly PerLanguageOption2 AutomaticInsertionOfAbstractOrInterfaceMembers = new(nameof(FeatureOnOffOptions), nameof(AutomaticInsertionOfAbstractOrInterfaceMembers), defaultValue: true, + public static readonly PerLanguageOption2 AutomaticInsertionOfAbstractOrInterfaceMembers = new(FeatureName, "AutomaticInsertionOfAbstractOrInterfaceMembers", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AutoRequiredMemberInsert")); - public static readonly PerLanguageOption2 LineSeparator = new(nameof(FeatureOnOffOptions), nameof(LineSeparator), defaultValue: false, + public static readonly PerLanguageOption2 LineSeparator = new(FeatureName, "LineSeparator", defaultValue: false, storageLocation: new RoamingProfileStorageLocation(language => language == LanguageNames.VisualBasic ? "TextEditor.%LANGUAGE%.Specific.DisplayLineSeparators" : "TextEditor.%LANGUAGE%.Specific.Line Separator")); - public static readonly PerLanguageOption2 Outlining = new(nameof(FeatureOnOffOptions), nameof(Outlining), defaultValue: true, + public static readonly PerLanguageOption2 Outlining = new(FeatureName, "Outlining", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Outlining")); - public static readonly PerLanguageOption2 KeywordHighlighting = new(nameof(FeatureOnOffOptions), nameof(KeywordHighlighting), defaultValue: true, + public static readonly PerLanguageOption2 KeywordHighlighting = new(FeatureName, "KeywordHighlighting", defaultValue: true, storageLocation: new RoamingProfileStorageLocation(language => language == LanguageNames.VisualBasic ? "TextEditor.%LANGUAGE%.Specific.EnableHighlightRelatedKeywords" : "TextEditor.%LANGUAGE%.Specific.Keyword Highlighting")); - public static readonly PerLanguageOption2 ReferenceHighlighting = new(nameof(FeatureOnOffOptions), nameof(ReferenceHighlighting), defaultValue: true, + public static readonly PerLanguageOption2 ReferenceHighlighting = new(FeatureName, "ReferenceHighlighting", defaultValue: true, storageLocation: new RoamingProfileStorageLocation(language => language == LanguageNames.VisualBasic ? "TextEditor.%LANGUAGE%.Specific.EnableHighlightReferences" : "TextEditor.%LANGUAGE%.Specific.Reference Highlighting")); - public static readonly PerLanguageOption2 AutoInsertBlockCommentStartString = new(nameof(FeatureOnOffOptions), nameof(AutoInsertBlockCommentStartString), defaultValue: true, + public static readonly PerLanguageOption2 AutoInsertBlockCommentStartString = new(FeatureName, "AutoInsertBlockCommentStartString", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Insert Block Comment Start String")); - public static readonly PerLanguageOption2 PrettyListing = new(nameof(FeatureOnOffOptions), nameof(PrettyListing), defaultValue: true, + public static readonly PerLanguageOption2 PrettyListing = new(FeatureName, "PrettyListing", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PrettyListing")); - public static readonly PerLanguageOption2 RenameTrackingPreview = new(nameof(FeatureOnOffOptions), nameof(RenameTrackingPreview), defaultValue: true, + public static readonly PerLanguageOption2 RenameTrackingPreview = new(FeatureName, "RenameTrackingPreview", defaultValue: true, storageLocation: new RoamingProfileStorageLocation(language => language == LanguageNames.VisualBasic ? "TextEditor.%LANGUAGE%.Specific.RenameTrackingPreview" : "TextEditor.%LANGUAGE%.Specific.Rename Tracking Preview")); /// - /// This option is currently used by Roslyn, but we might want to implement it in the + /// This option is not currently used by Roslyn, but we might want to implement it in the /// future. Keeping the option while it's unimplemented allows all upgrade paths to /// maintain any customized value for this setting, even through versions that have not /// implemented this feature yet. /// - public static readonly PerLanguageOption2 RenameTracking = new(nameof(FeatureOnOffOptions), nameof(RenameTracking), defaultValue: true); + public static readonly PerLanguageOption2 RenameTracking = new(FeatureName, "RenameTracking", defaultValue: true); /// - /// This option is currently used by Roslyn, but we might want to implement it in the + /// This option is not currently used by Roslyn, but we might want to implement it in the /// future. Keeping the option while it's unimplemented allows all upgrade paths to /// maintain any customized value for this setting, even through versions that have not /// implemented this feature yet. /// public static readonly PerLanguageOption2 RefactoringVerification = new( - nameof(FeatureOnOffOptions), nameof(RefactoringVerification), defaultValue: false); - - public static readonly PerLanguageOption2 StreamingGoToImplementation = new( - nameof(FeatureOnOffOptions), nameof(StreamingGoToImplementation), defaultValue: true); + FeatureName, "RefactoringVerification", defaultValue: false); public static readonly Option2 NavigateToDecompiledSources = new( - nameof(FeatureOnOffOptions), nameof(NavigateToDecompiledSources), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.{nameof(NavigateToDecompiledSources)}")); - - public static readonly Option2 UseEnhancedColors = new( - nameof(FeatureOnOffOptions), nameof(UseEnhancedColors), defaultValue: 1, - storageLocation: new RoamingProfileStorageLocation("WindowManagement.Options.UseEnhancedColorsForManagedLanguages")); + FeatureName, "NavigateToDecompiledSources", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.NavigateToDecompiledSources")); public static readonly PerLanguageOption2 AddImportsOnPaste = new( - nameof(FeatureOnOffOptions), nameof(AddImportsOnPaste), defaultValue: null, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(AddImportsOnPaste)}")); + FeatureName, "AddImportsOnPaste", defaultValue: null, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste")); public static readonly Option2 OfferRemoveUnusedReferences = new( - nameof(FeatureOnOffOptions), nameof(OfferRemoveUnusedReferences), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.{nameof(OfferRemoveUnusedReferences)}")); + FeatureName, "OfferRemoveUnusedReferences", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.OfferRemoveUnusedReferences")); public static readonly Option OfferRemoveUnusedReferencesFeatureFlag = new( - nameof(FeatureOnOffOptions), nameof(OfferRemoveUnusedReferencesFeatureFlag), defaultValue: false, + FeatureName, "OfferRemoveUnusedReferencesFeatureFlag", defaultValue: false, new FeatureFlagStorageLocation("Roslyn.RemoveUnusedReferences")); - public static readonly PerLanguageOption2 ShowInheritanceMargin = - new(nameof(FeatureOnOffOptions), - nameof(ShowInheritanceMargin), - defaultValue: true, - new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowInheritanceMargin")); + public static readonly PerLanguageOption2 ShowInheritanceMargin = new( + FeatureName, "ShowInheritanceMargin", defaultValue: true, + new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowInheritanceMargin")); - public static readonly Option2 InheritanceMarginCombinedWithIndicatorMargin = - new(nameof(FeatureOnOffOptions), - nameof(InheritanceMarginCombinedWithIndicatorMargin), - defaultValue: true, - new RoamingProfileStorageLocation($"TextEditor.{nameof(InheritanceMarginCombinedWithIndicatorMargin)}")); + public static readonly Option2 InheritanceMarginCombinedWithIndicatorMargin = new( + FeatureName, "InheritanceMarginCombinedWithIndicatorMargin", defaultValue: true, + new RoamingProfileStorageLocation("TextEditor.InheritanceMarginCombinedWithIndicatorMargin")); public static readonly Option2 AutomaticallyCompleteStatementOnSemicolon = new( - nameof(FeatureOnOffOptions), nameof(AutomaticallyCompleteStatementOnSemicolon), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.{nameof(AutomaticallyCompleteStatementOnSemicolon)}")); + FeatureName, "AutomaticallyCompleteStatementOnSemicolon", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.AutomaticallyCompleteStatementOnSemicolon")); + /// + /// Not used by Roslyn but exposed in C# and VB option UI. Used by TestWindow and Project System. + /// TODO: remove https://github.com/dotnet/roslyn/issues/57253 + /// public static readonly Option2 SkipAnalyzersForImplicitlyTriggeredBuilds = new( - nameof(FeatureOnOffOptions), nameof(SkipAnalyzersForImplicitlyTriggeredBuilds), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.{nameof(SkipAnalyzersForImplicitlyTriggeredBuilds)}")); - } - - [ExportOptionProvider, Shared] - internal class FeatureOnOffOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public FeatureOnOffOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - FeatureOnOffOptions.EndConstruct, - FeatureOnOffOptions.AutomaticInsertionOfAbstractOrInterfaceMembers, - FeatureOnOffOptions.LineSeparator, - FeatureOnOffOptions.Outlining, - FeatureOnOffOptions.KeywordHighlighting, - FeatureOnOffOptions.ReferenceHighlighting, - FeatureOnOffOptions.AutoInsertBlockCommentStartString, - FeatureOnOffOptions.PrettyListing, - FeatureOnOffOptions.RenameTrackingPreview, - FeatureOnOffOptions.RenameTracking, - FeatureOnOffOptions.RefactoringVerification, - FeatureOnOffOptions.StreamingGoToImplementation, - FeatureOnOffOptions.NavigateToDecompiledSources, - FeatureOnOffOptions.UseEnhancedColors, - FeatureOnOffOptions.AddImportsOnPaste, - FeatureOnOffOptions.OfferRemoveUnusedReferences, - FeatureOnOffOptions.OfferRemoveUnusedReferencesFeatureFlag, - FeatureOnOffOptions.ShowInheritanceMargin, - FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin, - FeatureOnOffOptions.AutomaticallyCompleteStatementOnSemicolon, - FeatureOnOffOptions.SkipAnalyzersForImplicitlyTriggeredBuilds); + FeatureName, "SkipAnalyzersForImplicitlyTriggeredBuilds", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.SkipAnalyzersForImplicitlyTriggeredBuilds")); } } diff --git a/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs index 8e829dc297b7f..471ef185655b0 100644 --- a/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/InternalFeatureOnOffOptions.cs @@ -12,98 +12,66 @@ namespace Microsoft.CodeAnalysis.Editor.Shared.Options { - internal static class InternalFeatureOnOffOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class InternalFeatureOnOffOptions : IOptionProvider { - internal const string LocalRegistryPath = StorageOptions.LocalRegistryPath; + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public InternalFeatureOnOffOptions() + { + } - public static readonly Option2 BraceMatching = new(nameof(InternalFeatureOnOffOptions), nameof(BraceMatching), defaultValue: true, + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + BraceMatching, + Classification, + SemanticColorizer, + SyntacticColorizer, + AutomaticLineEnder, + SmartIndenter, + Squiggles, + FormatOnSave, + RenameTracking, + EventHookup, + Snippets, + BackgroundAnalysisMemoryMonitor); + + private const string LocalRegistryPath = StorageOptions.LocalRegistryPath; + private const string FeatureName = "InternalFeatureOnOffOptions"; + + public static readonly Option2 BraceMatching = new(FeatureName, "BraceMatching", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Brace Matching")); - public static readonly Option2 Classification = new(nameof(InternalFeatureOnOffOptions), nameof(Classification), defaultValue: true, + public static readonly Option2 Classification = new(FeatureName, "Classification", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Classification")); - public static readonly Option2 SemanticColorizer = new(nameof(InternalFeatureOnOffOptions), nameof(SemanticColorizer), defaultValue: true, + public static readonly Option2 SemanticColorizer = new(FeatureName, "SemanticColorizer", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Semantic Colorizer")); - public static readonly Option2 SyntacticColorizer = new(nameof(InternalFeatureOnOffOptions), nameof(SyntacticColorizer), defaultValue: true, + public static readonly Option2 SyntacticColorizer = new(FeatureName, "SyntacticColorizer", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Syntactic Colorizer")); - public static readonly Option2 AutomaticPairCompletion = new(nameof(InternalFeatureOnOffOptions), nameof(AutomaticPairCompletion), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Automatic Pair Completion")); - - public static readonly Option2 AutomaticLineEnder = new(nameof(InternalFeatureOnOffOptions), nameof(AutomaticLineEnder), defaultValue: true, + public static readonly Option2 AutomaticLineEnder = new(FeatureName, "AutomaticLineEnder", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Automatic Line Ender")); - public static readonly Option2 SmartIndenter = new(nameof(InternalFeatureOnOffOptions), nameof(SmartIndenter), defaultValue: true, + public static readonly Option2 SmartIndenter = new(FeatureName, "SmartIndenter", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Smart Indenter")); - public static readonly Option2 CompletionSet = new(nameof(InternalFeatureOnOffOptions), nameof(CompletionSet), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Completion Set")); - - public static readonly Option2 KeywordHighlight = new(nameof(InternalFeatureOnOffOptions), nameof(KeywordHighlight), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Keyword Highlight")); - - public static readonly Option2 QuickInfo = new(nameof(InternalFeatureOnOffOptions), nameof(QuickInfo), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Quick Info")); - - public static readonly Option2 Squiggles = new(nameof(InternalFeatureOnOffOptions), nameof(Squiggles), defaultValue: true, + public static readonly Option2 Squiggles = new(FeatureName, "Squiggles", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Squiggles")); - public static readonly Option2 FormatOnSave = new(nameof(InternalFeatureOnOffOptions), nameof(FormatOnSave), defaultValue: true, + public static readonly Option2 FormatOnSave = new(FeatureName, "FormatOnSave", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "FormatOnSave")); - public static readonly Option2 RenameTracking = new(nameof(InternalFeatureOnOffOptions), nameof(RenameTracking), defaultValue: true, + public static readonly Option2 RenameTracking = new(FeatureName, "RenameTracking", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Rename Tracking")); - public static readonly Option2 EventHookup = new(nameof(InternalFeatureOnOffOptions), nameof(EventHookup), defaultValue: true, + public static readonly Option2 EventHookup = new(FeatureName, "EventHookup", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Event Hookup")); - /// Due to https://github.com/dotnet/roslyn/issues/5393, the name "Snippets" is unusable for serialization. - /// (Summary: Some builds incorrectly set it without providing a way to clear it so it exists in many registries.) - public static readonly Option2 Snippets = new(nameof(InternalFeatureOnOffOptions), nameof(Snippets), defaultValue: true, + public static readonly Option2 Snippets = new(FeatureName, "Snippets", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Snippets2")); - public static readonly Option2 TodoComments = new(nameof(InternalFeatureOnOffOptions), nameof(TodoComments), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Todo Comments")); - - public static readonly Option2 DesignerAttributes = new(nameof(InternalFeatureOnOffOptions), nameof(DesignerAttributes), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Designer Attribute")); - - public static readonly Option2 BackgroundAnalysisMemoryMonitor = new(nameof(InternalFeatureOnOffOptions), "FullSolutionAnalysisMemoryMonitor", defaultValue: true, + public static readonly Option2 BackgroundAnalysisMemoryMonitor = new(FeatureName, "FullSolutionAnalysisMemoryMonitor", defaultValue: true, storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Full Solution Analysis Memory Monitor")); - - public static readonly Option2 ProjectReferenceConversion = new(nameof(InternalFeatureOnOffOptions), nameof(ProjectReferenceConversion), defaultValue: true, - storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + "Project Reference Conversion")); - } - - [ExportOptionProvider, Shared] - internal class InternalFeatureOnOffOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public InternalFeatureOnOffOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - InternalFeatureOnOffOptions.BraceMatching, - InternalFeatureOnOffOptions.Classification, - InternalFeatureOnOffOptions.SemanticColorizer, - InternalFeatureOnOffOptions.SyntacticColorizer, - InternalFeatureOnOffOptions.AutomaticPairCompletion, - InternalFeatureOnOffOptions.AutomaticLineEnder, - InternalFeatureOnOffOptions.SmartIndenter, - InternalFeatureOnOffOptions.CompletionSet, - InternalFeatureOnOffOptions.KeywordHighlight, - InternalFeatureOnOffOptions.QuickInfo, - InternalFeatureOnOffOptions.Squiggles, - InternalFeatureOnOffOptions.FormatOnSave, - InternalFeatureOnOffOptions.RenameTracking, - InternalFeatureOnOffOptions.EventHookup, - InternalFeatureOnOffOptions.Snippets, - InternalFeatureOnOffOptions.TodoComments, - InternalFeatureOnOffOptions.DesignerAttributes, - InternalFeatureOnOffOptions.BackgroundAnalysisMemoryMonitor, - InternalFeatureOnOffOptions.ProjectReferenceConversion); } } diff --git a/src/EditorFeatures/Core/Shared/Options/PerformanceFunctionIdOptionsProvider.cs b/src/EditorFeatures/Core/Shared/Options/PerformanceFunctionIdOptionsProvider.cs index a94e78639bd3c..488a1aafdf106 100644 --- a/src/EditorFeatures/Core/Shared/Options/PerformanceFunctionIdOptionsProvider.cs +++ b/src/EditorFeatures/Core/Shared/Options/PerformanceFunctionIdOptionsProvider.cs @@ -13,8 +13,8 @@ namespace Microsoft.CodeAnalysis.Editor.Shared.Options { - [ExportOptionProvider, Shared] - internal class PerformanceFunctionIdOptionsProvider : IOptionProvider + [ExportGlobalOptionProvider, Shared] + internal sealed class PerformanceFunctionIdOptionsProvider : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] diff --git a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs index 9723c85c686bb..876d3a3b4ccfe 100644 --- a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs +++ b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs @@ -370,13 +370,8 @@ private IEnumerable> GetNonIntersectingTagSpans(IEnumerable>(); - var perLanguageOptions = _dataSource.PerLanguageOptions ?? SpecializedCollections.EmptyEnumerable>(); - - return options.Any(option => !_subjectBuffer.GetFeatureOnOffOption(option)) || - perLanguageOptions.Any(option => !_subjectBuffer.GetFeatureOnOffOption(option)); - } + => _dataSource.Options.Any(option => !_dataSource.GlobalOptions.GetOption(option)) || + _dataSource.PerLanguageOptions.Any(option => !_dataSource.GlobalOptions.GetOption(option, _subjectBuffer.GetLanguageName())); private Task ProduceTagsAsync(TaggerContext context, CancellationToken cancellationToken) { diff --git a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs index 1f323a6edf105..5e4d03efeba5a 100644 --- a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs +++ b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs @@ -31,6 +31,7 @@ internal abstract partial class AbstractAsynchronousTaggerProvider : Foreg private readonly object _uniqueKey = new(); protected readonly IAsynchronousOperationListener AsyncListener; + protected readonly IGlobalOptionService GlobalOptions; /// /// The behavior the tagger engine will have when text changes happen to the subject buffer @@ -57,8 +58,7 @@ internal abstract partial class AbstractAsynchronousTaggerProvider : Foreg protected virtual SpanTrackingMode SpanTrackingMode => SpanTrackingMode.EdgeExclusive; /// - /// Options controlling this tagger. The tagger infrastructure will check this option - /// against the buffer it is associated with to see if it should tag or not. + /// Global options controlling if the tagger should tag or not. /// /// An empty enumerable can be returned to indicate that this tagger should /// run unconditionally. @@ -84,9 +84,11 @@ internal abstract partial class AbstractAsynchronousTaggerProvider : Foreg protected AbstractAsynchronousTaggerProvider( IThreadingContext threadingContext, + IGlobalOptionService globalOptions, IAsynchronousOperationListener asyncListener) : base(threadingContext) { + GlobalOptions = globalOptions; AsyncListener = asyncListener; #if DEBUG @@ -96,7 +98,7 @@ protected AbstractAsynchronousTaggerProvider( protected ITagger? CreateTaggerWorker(ITextView textViewOpt, ITextBuffer subjectBuffer) where T : ITag { - if (!subjectBuffer.GetFeatureOnOffOption(EditorComponentOnOffOptions.Tagger)) + if (!GlobalOptions.GetOption(EditorComponentOnOffOptions.Tagger)) return null; var tagSource = GetOrCreateTagSource(textViewOpt, subjectBuffer); diff --git a/src/EditorFeatures/Core/Tagging/AsynchronousTaggerProvider.cs b/src/EditorFeatures/Core/Tagging/AsynchronousTaggerProvider.cs index 89463df9b1def..047b233bdba2d 100644 --- a/src/EditorFeatures/Core/Tagging/AsynchronousTaggerProvider.cs +++ b/src/EditorFeatures/Core/Tagging/AsynchronousTaggerProvider.cs @@ -6,6 +6,7 @@ using System; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Tagging; @@ -17,8 +18,9 @@ internal abstract class AsynchronousTaggerProvider : AbstractAsynchronousT { protected AsynchronousTaggerProvider( IThreadingContext threadingContext, + IGlobalOptionService globalOptions, IAsynchronousOperationListener asyncListener) - : base(threadingContext, asyncListener) + : base(threadingContext, globalOptions, asyncListener) { } diff --git a/src/EditorFeatures/Core/Tagging/AsynchronousViewTaggerProvider.cs b/src/EditorFeatures/Core/Tagging/AsynchronousViewTaggerProvider.cs index 6c5af89d184fa..9331e87c69ac7 100644 --- a/src/EditorFeatures/Core/Tagging/AsynchronousViewTaggerProvider.cs +++ b/src/EditorFeatures/Core/Tagging/AsynchronousViewTaggerProvider.cs @@ -4,6 +4,7 @@ using System; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; @@ -14,8 +15,11 @@ namespace Microsoft.CodeAnalysis.Editor.Tagging internal abstract class AsynchronousViewTaggerProvider : AbstractAsynchronousTaggerProvider, IViewTaggerProvider where TTag : ITag { - protected AsynchronousViewTaggerProvider(IThreadingContext threadingContext, IAsynchronousOperationListener asyncListener) - : base(threadingContext, asyncListener) + protected AsynchronousViewTaggerProvider( + IThreadingContext threadingContext, + IGlobalOptionService globalOptions, + IAsynchronousOperationListener asyncListener) + : base(threadingContext, globalOptions, asyncListener) { } diff --git a/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs b/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs index 9155db2204a64..85b953bc897c5 100644 --- a/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs +++ b/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs @@ -19,11 +19,11 @@ using Microsoft.CodeAnalysis.Editor.UnitTests.Utilities; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Microsoft.CodeAnalysis.Notification; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text.Shared.Extensions; -using Microsoft.VisualStudio.Composition; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; @@ -100,10 +100,11 @@ public RenameTrackingTestState( notificationService.NotificationCallback = callback; var tracker = new RenameTrackingTaggerProvider( - Workspace.ExportProvider.GetExportedValue(), - Workspace.ExportProvider.GetExport().Value, - Workspace.ExportProvider.GetExport().Value, - Workspace.ExportProvider.GetExportedValue()); + Workspace.GetService(), + Workspace.GetService(), + Workspace.GetService(), + Workspace.GetService(), + Workspace.GetService()); _tagger = tracker.CreateTagger(_hostDocument.GetTextBuffer()); diff --git a/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs b/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs index 8a083c788f04b..fa71b6035e0b2 100644 --- a/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs +++ b/src/EditorFeatures/Test/Structure/StructureTaggerTests.cs @@ -53,9 +53,9 @@ static void Main(string[] args) using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); + .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -118,9 +118,9 @@ public class Bar using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); + .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -162,10 +162,10 @@ public class Bar using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, LanguageNames.CSharp, showBlockStructureGuidesForCommentsAndPreprocessorRegions))); + .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 tags = await GetTagsFromWorkspaceAsync(workspace); @@ -206,9 +206,9 @@ public class Bar using var workspace = TestWorkspace.CreateCSharp(code, composition: EditorTestCompositions.EditorFeaturesWpf); workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); + .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp, collapseRegionsWhenCollapsingToDefinitions) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForDeclarationLevelConstructs) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.CSharp, showBlockStructureGuidesForCodeLevelConstructs))); var tags = await GetTagsFromWorkspaceAsync(workspace); @@ -257,9 +257,9 @@ End Module using var workspace = TestWorkspace.CreateVisualBasic(code, composition: EditorTestCompositions.EditorFeaturesWpf); workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options - .WithChangedOption(BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic, collapseRegionsWhenCollapsingToDefinitions) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForDeclarationLevelConstructs) - .WithChangedOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForCodeLevelConstructs))); + .WithChangedOption(BlockStructureOptions.Metadata.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic, collapseRegionsWhenCollapsingToDefinitions) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForDeclarationLevelConstructs) + .WithChangedOption(BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic, showBlockStructureGuidesForCodeLevelConstructs))); var tags = await GetTagsFromWorkspaceAsync(workspace); diff --git a/src/EditorFeatures/Test/Tagging/AsynchronousTaggerTests.cs b/src/EditorFeatures/Test/Tagging/AsynchronousTaggerTests.cs index a692484381b96..b6637a4f7599d 100644 --- a/src/EditorFeatures/Test/Tagging/AsynchronousTaggerTests.cs +++ b/src/EditorFeatures/Test/Tagging/AsynchronousTaggerTests.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Editor.Tagging; using Microsoft.CodeAnalysis.Editor.UnitTests; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text.Shared.Extensions; @@ -64,9 +65,10 @@ static List> tagProducer(SnapshotSpan span, CancellationToken var eventSource = CreateEventSource(); var taggerProvider = new TestTaggerProvider( - workspace.ExportProvider.GetExportedValue(), + workspace.GetService(), tagProducer, eventSource, + workspace.GetService(), asyncListener); var document = workspace.Documents.First(); @@ -152,8 +154,9 @@ public TestTaggerProvider( IThreadingContext threadingContext, Callback callback, ITaggerEventSource eventSource, + IGlobalOptionService globalOptions, IAsynchronousOperationListener asyncListener) - : base(threadingContext, asyncListener) + : base(threadingContext, globalOptions, asyncListener) { _callback = callback; _eventSource = eventSource; diff --git a/src/EditorFeatures/Test2/Classification/ClassificationTests.vb b/src/EditorFeatures/Test2/Classification/ClassificationTests.vb index 444b68677732f..08f0721532827 100644 --- a/src/EditorFeatures/Test2/Classification/ClassificationTests.vb +++ b/src/EditorFeatures/Test2/Classification/ClassificationTests.vb @@ -43,10 +43,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Classification Dim listenerProvider = workspace.ExportProvider.GetExportedValue(Of IAsynchronousOperationListenerProvider) Dim provider = New SemanticClassificationViewTaggerProvider( - workspace.ExportProvider.GetExportedValue(Of IThreadingContext), + workspace.GetService(Of IThreadingContext), workspace.GetService(Of ClassificationTypeMap), - listenerProvider, - workspace.ExportProvider.GetExportedValue(Of IGlobalOptionService)) + workspace.GetService(Of IGlobalOptionService), + listenerProvider) Dim buffer = workspace.Documents.First().GetTextBuffer() Dim tagger = provider.CreateTagger(Of IClassificationTag)( diff --git a/src/EditorFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb b/src/EditorFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb index 7ff6ad62d5b99..c1765e4e792c7 100644 --- a/src/EditorFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb +++ b/src/EditorFeatures/Test2/InlineHints/AbstractInlineHintsTests.vb @@ -3,8 +3,10 @@ ' See the LICENSE file in the project root for more information. Imports System.Threading +Imports Microsoft.CodeAnalysis.Editor.InlineHints Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.InlineHints +Imports Microsoft.CodeAnalysis.Options Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints <[UseExportProvider]> @@ -14,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints WpfTestRunner.RequireWpfFact($"{NameOf(AbstractInlineHintsTests)}.{NameOf(Me.VerifyParamHints)} creates asynchronous taggers") workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options.WithChangedOption( - InlineHintsOptions.EnabledForParameters, + InlineParameterHintsOptions.Metadata.EnabledForParameters, workspace.CurrentSolution.Projects().First().Language, optionIsEnabled))) @@ -48,11 +50,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints Protected Async Function VerifyTypeHints(test As XElement, Optional optionIsEnabled As Boolean = True, Optional ephemeral As Boolean = False) As Task Using workspace = TestWorkspace.Create(test) WpfTestRunner.RequireWpfFact($"{NameOf(AbstractInlineHintsTests)}.{NameOf(Me.VerifyTypeHints)} creates asynchronous taggers") + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) Dim language = workspace.CurrentSolution.Projects().First().Language + workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions( - workspace.Options.WithChangedOption(InlineHintsOptions.EnabledForTypes, language, optionIsEnabled AndAlso Not ephemeral). - WithChangedOption(InlineHintsOptions.DisplayAllOverride, ephemeral))) + workspace.CurrentSolution.Options.WithChangedOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, language, optionIsEnabled AndAlso Not ephemeral))) + + globalOptions.SetGlobalOption(New OptionKey(InlineHintsGlobalStateOption.DisplayAllOverride), ephemeral) Dim hostDocument = workspace.Documents.Single() Dim snapshot = hostDocument.GetTextBuffer().CurrentSnapshot diff --git a/src/EditorFeatures/Test2/KeywordHighlighting/AbstractKeywordHighlightingTests.vb b/src/EditorFeatures/Test2/KeywordHighlighting/AbstractKeywordHighlightingTests.vb index fc4536d45f85a..a66c75b5854e4 100644 --- a/src/EditorFeatures/Test2/KeywordHighlighting/AbstractKeywordHighlightingTests.vb +++ b/src/EditorFeatures/Test2/KeywordHighlighting/AbstractKeywordHighlightingTests.vb @@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Editor.Shared.Options Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Editor.Tagging Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Shared.TestHooks Imports Microsoft.VisualStudio.Text Imports Roslyn.Utilities @@ -24,16 +25,16 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.KeywordHighlighting Dim snapshot = testDocument.GetTextBuffer().CurrentSnapshot Dim caretPosition = testDocument.CursorPosition.Value Dim document As Document = workspace.CurrentSolution.Projects.First.Documents.First + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) - Dim options = workspace.Options.WithChangedOption(FeatureOnOffOptions.KeywordHighlighting, document.Project.Language, optionIsEnabled) - document = document.WithSolutionOptions(options) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.KeywordHighlighting, document.Project.Language), optionIsEnabled) WpfTestRunner.RequireWpfFact($"{NameOf(AbstractKeywordHighlightingTests)}.{NameOf(Me.VerifyHighlightsAsync)} creates asynchronous taggers") - Dim highlightingService = workspace.GetService(Of IHighlightingService)() Dim tagProducer = New HighlighterViewTaggerProvider( - workspace.ExportProvider.GetExportedValue(Of IThreadingContext), - highlightingService, + workspace.GetService(Of IThreadingContext), + workspace.GetService(Of IHighlightingService)(), + globalOptions, AsynchronousOperationListenerProvider.NullProvider) Dim context = New TaggerContext(Of KeywordHighlightTag)(document, snapshot, New SnapshotPoint(snapshot, caretPosition)) diff --git a/src/EditorFeatures/Test2/ReferenceHighlighting/AbstractReferenceHighlightingTests.vb b/src/EditorFeatures/Test2/ReferenceHighlighting/AbstractReferenceHighlightingTests.vb index 853f82c3a8e91..1c2c8c701ad2d 100644 --- a/src/EditorFeatures/Test2/ReferenceHighlighting/AbstractReferenceHighlightingTests.vb +++ b/src/EditorFeatures/Test2/ReferenceHighlighting/AbstractReferenceHighlightingTests.vb @@ -29,8 +29,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.ReferenceHighlighting Dim globalOptions = workspace.GetService(Of IGlobalOptionService) Dim tagProducer = New ReferenceHighlightingViewTaggerProvider( workspace.GetService(Of IThreadingContext), - AsynchronousOperationListenerProvider.NullProvider, - globalOptions) + globalOptions, + AsynchronousOperationListenerProvider.NullProvider) Dim hostDocument = workspace.Documents.Single(Function(d) d.CursorPosition.HasValue) Dim caretPosition = hostDocument.CursorPosition.Value diff --git a/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb b/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb index 0eba7cbd0b4e2..0e116da62d27f 100644 --- a/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb +++ b/src/EditorFeatures/Test2/Rename/RenameTestHelpers.vb @@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Editor.UnitTests.RenameTracking Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Shared.TestHooks Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text.Shared.Extensions @@ -114,10 +115,11 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename Public Function CreateRenameTrackingTagger(workspace As TestWorkspace, document As TestHostDocument) As ITagger(Of RenameTrackingTag) Dim tracker = New RenameTrackingTaggerProvider( - workspace.ExportProvider.GetExportedValue(Of IThreadingContext), - workspace.ExportProvider.GetExport(Of IInlineRenameService)().Value, - workspace.ExportProvider.GetExport(Of IDiagnosticAnalyzerService)().Value, - workspace.ExportProvider.GetExportedValue(Of IAsynchronousOperationListenerProvider)) + workspace.GetService(Of IThreadingContext), + workspace.GetService(Of IInlineRenameService)(), + workspace.GetService(Of IDiagnosticAnalyzerService)(), + workspace.GetService(Of IGlobalOptionService)(), + workspace.GetService(Of IAsynchronousOperationListenerProvider)) Return tracker.CreateTagger(Of RenameTrackingTag)(document.GetTextBuffer()) End Function diff --git a/src/EditorFeatures/TestUtilities/BraceHighlighting/AbstractBraceHighlightingTests.cs b/src/EditorFeatures/TestUtilities/BraceHighlighting/AbstractBraceHighlightingTests.cs index 72fec43873ec8..e181761bb4bcd 100644 --- a/src/EditorFeatures/TestUtilities/BraceHighlighting/AbstractBraceHighlightingTests.cs +++ b/src/EditorFeatures/TestUtilities/BraceHighlighting/AbstractBraceHighlightingTests.cs @@ -10,6 +10,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.Shared.TestHooks; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; @@ -43,6 +44,7 @@ protected async Task TestBraceHighlightingAsync( var provider = new BraceHighlightingViewTaggerProvider( workspace.GetService(), GetBraceMatchingService(workspace), + workspace.GetService(), AsynchronousOperationListenerProvider.NullProvider); var testDocument = workspace.Documents.First(); diff --git a/src/EditorFeatures/TestUtilities/BraceHighlighting/MultiCharacterBraceHighlightingTests.cs b/src/EditorFeatures/TestUtilities/BraceHighlighting/MultiCharacterBraceHighlightingTests.cs index 2e422348e53fb..9b8848a4bc59f 100644 --- a/src/EditorFeatures/TestUtilities/BraceHighlighting/MultiCharacterBraceHighlightingTests.cs +++ b/src/EditorFeatures/TestUtilities/BraceHighlighting/MultiCharacterBraceHighlightingTests.cs @@ -28,7 +28,7 @@ internal override IBraceMatchingService GetBraceMatchingService(TestWorkspace wo private class TestBraceMatchingService : IBraceMatchingService { public async Task GetMatchingBracesAsync( - Document document, int position, CancellationToken cancellationToken = default) + Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { var text = (await document.GetTextAsync(cancellationToken)).ToString(); var braces = GetMatchingBraces(text, position); diff --git a/src/EditorFeatures/TestUtilities/BraceMatching/AbstractBraceMatcherTests.cs b/src/EditorFeatures/TestUtilities/BraceMatching/AbstractBraceMatcherTests.cs index aab46139734fa..702b2e31319e2 100644 --- a/src/EditorFeatures/TestUtilities/BraceMatching/AbstractBraceMatcherTests.cs +++ b/src/EditorFeatures/TestUtilities/BraceMatching/AbstractBraceMatcherTests.cs @@ -30,8 +30,9 @@ protected async Task TestAsync(string markup, string expectedCode, ParseOptions var position = workspace.Documents.Single().CursorPosition.Value; var document = workspace.CurrentSolution.GetDocument(workspace.Documents.First().Id); var braceMatcher = workspace.GetService(); + var braceMatchingOptions = BraceMatchingOptions.From(document.Project); - var foundSpan = await braceMatcher.FindMatchingSpanAsync(document, position, CancellationToken.None); + var foundSpan = await braceMatcher.FindMatchingSpanAsync(document, position, braceMatchingOptions, CancellationToken.None); MarkupTestFile.GetSpans(expectedCode, out var parsedExpectedCode, out ImmutableArray expectedSpans); if (expectedSpans.Any()) diff --git a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs index 7ebc2c79f6919..e4fff33a9b564 100644 --- a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxNodeStructureProviderTests.cs @@ -42,12 +42,10 @@ internal sealed override async Task> GetBlockSpansWork var outliner = CreateProvider(); using var actualRegions = TemporaryArray.Empty; - var optionProvider = new BlockStructureOptionProvider( - document.Project.Solution.Options, - isMetadataAsSource: document.Project.Solution.Workspace.Kind == CodeAnalysis.WorkspaceKind.MetadataAsSource); + var options = BlockStructureOptions.From(document.Project); // 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(), optionProvider, CancellationToken.None); + outliner.CollectBlockSpans(previousToken, node, ref actualRegions.AsRef(), options, CancellationToken.None); // TODO: Determine why we get null outlining spans. return actualRegions.ToImmutableAndClear(); diff --git a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs index bb63f70446788..46235413dbfe4 100644 --- a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxStructureProviderTests.cs @@ -25,7 +25,7 @@ public abstract class AbstractSyntaxStructureProviderTests protected virtual string WorkspaceKind => CodeAnalysis.WorkspaceKind.Host; protected virtual OptionSet UpdateOptions(OptionSet options) - => options.WithChangedOption(BlockStructureOptions.MaximumBannerLength, LanguageName, 120); + => options.WithChangedOption(BlockStructureOptions.Metadata.MaximumBannerLength, LanguageName, 120); private Task> GetBlockSpansAsync(Document document, int position) => GetBlockSpansWorkerAsync(document, position); @@ -36,7 +36,7 @@ private protected async Task VerifyBlockSpansAsync(string markupCode, params Reg { using (var workspace = TestWorkspace.Create(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: markupCode)) { - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(UpdateOptions(workspace.Options))); + workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(UpdateOptions(workspace.CurrentSolution.Options))); var hostDocument = workspace.Documents.Single(); Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position."); diff --git a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs index abf7853f64696..680daebf86cd0 100644 --- a/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Structure/AbstractSyntaxTriviaStructureProviderTests.cs @@ -23,10 +23,8 @@ internal sealed override async Task> GetBlockSpansWork var outliner = CreateProvider(); using var actualRegions = TemporaryArray.Empty; - var optionProvider = new BlockStructureOptionProvider( - document.Project.Solution.Options, - isMetadataAsSource: document.Project.Solution.Workspace.Kind == CodeAnalysis.WorkspaceKind.MetadataAsSource); - outliner.CollectBlockSpans(trivia, ref actualRegions.AsRef(), optionProvider, CancellationToken.None); + var options = BlockStructureOptions.From(document.Project); + outliner.CollectBlockSpans(trivia, ref actualRegions.AsRef(), options, CancellationToken.None); // TODO: Determine why we get null outlining spans. return actualRegions.ToImmutableAndClear(); diff --git a/src/EditorFeatures/VisualBasic/AddImports/VisualBasicAddImportsOnPasteCommandHandler.vb b/src/EditorFeatures/VisualBasic/AddImports/VisualBasicAddImportsOnPasteCommandHandler.vb index f91ff03e5ac2e..eaf6b5eb55c46 100644 --- a/src/EditorFeatures/VisualBasic/AddImports/VisualBasicAddImportsOnPasteCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/AddImports/VisualBasicAddImportsOnPasteCommandHandler.vb @@ -5,6 +5,7 @@ Imports System.ComponentModel.Composition Imports Microsoft.CodeAnalysis.Editor.Implementation.AddImports Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Utilities @@ -20,8 +21,9 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.AddImports - Public Sub New(threadingContext As [Shared].Utilities.IThreadingContext) - MyBase.New(threadingContext) + Public Sub New(threadingContext As [Shared].Utilities.IThreadingContext, + globalOptions As IGlobalOptionService) + MyBase.New(threadingContext, globalOptions) End Sub Public Overrides ReadOnly Property DisplayName As String = VBEditorResources.Add_Missing_Imports_on_Paste diff --git a/src/EditorFeatures/VisualBasic/AutomaticCompletion/AutomaticLineEnderCommandHandler.vb b/src/EditorFeatures/VisualBasic/AutomaticCompletion/AutomaticLineEnderCommandHandler.vb index 51d9b6d91ad81..561c150b4911e 100644 --- a/src/EditorFeatures/VisualBasic/AutomaticCompletion/AutomaticLineEnderCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/AutomaticCompletion/AutomaticLineEnderCommandHandler.vb @@ -6,6 +6,7 @@ Imports System.ComponentModel.Composition Imports System.Threading Imports Microsoft.CodeAnalysis.Editor.Implementation.AutomaticCompletion Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion @@ -27,9 +28,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.AutomaticCompletion Public Sub New(undoRegistry As ITextUndoHistoryRegistry, - editorOperations As IEditorOperationsFactoryService) + editorOperations As IEditorOperationsFactoryService, + globalOptions As IGlobalOptionService) - MyBase.New(undoRegistry, editorOperations) + MyBase.New(undoRegistry, editorOperations, globalOptions) End Sub Protected Overrides Sub NextAction(editorOperation As IEditorOperations, nextAction As Action) @@ -42,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.AutomaticCompletion Return False End Function - Protected Overrides Sub ModifySelectedNode(args as AutomaticLineEnderCommandArgs, document As Document, selectedNode As SyntaxNode, addBrace As Boolean, caretPosition As Integer, cancellationToken As CancellationToken) + Protected Overrides Sub ModifySelectedNode(args As AutomaticLineEnderCommandArgs, document As Document, selectedNode As SyntaxNode, addBrace As Boolean, caretPosition As Integer, cancellationToken As CancellationToken) End Sub Protected Overrides Function GetValidNodeToModifyBraces(document As Document, caretPosition As Integer, cancellationToken As CancellationToken) As (SyntaxNode, Boolean)? diff --git a/src/EditorFeatures/VisualBasic/AutomaticEndConstructCorrection/ViewCreationListener.vb b/src/EditorFeatures/VisualBasic/AutomaticEndConstructCorrection/ViewCreationListener.vb index da9b1c4403168..c38fbac2d60d7 100644 --- a/src/EditorFeatures/VisualBasic/AutomaticEndConstructCorrection/ViewCreationListener.vb +++ b/src/EditorFeatures/VisualBasic/AutomaticEndConstructCorrection/ViewCreationListener.vb @@ -6,6 +6,7 @@ Imports System.Collections.ObjectModel Imports System.ComponentModel.Composition Imports Microsoft.CodeAnalysis.Editor.Host Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.VisualStudio.Text Imports Microsoft.VisualStudio.Text.Editor Imports Microsoft.VisualStudio.Utilities @@ -21,11 +22,14 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.AutomaticEndConstructCorrect Implements ITextViewConnectionListener Private ReadOnly _uiThreadOperationExecutor As IUIThreadOperationExecutor + Private ReadOnly _globalOptions As IGlobalOptionService - Public Sub New(uiThreadOperationExecutor As IUIThreadOperationExecutor) + Public Sub New(uiThreadOperationExecutor As IUIThreadOperationExecutor, + globalOptions As IGlobalOptionService) _uiThreadOperationExecutor = uiThreadOperationExecutor + _globalOptions = globalOptions End Sub Public Sub SubjectBuffersConnected( @@ -33,7 +37,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.AutomaticEndConstructCorrect reason As ConnectionReason, subjectBuffers As IReadOnlyCollection(Of ITextBuffer)) Implements ITextViewConnectionListener.SubjectBuffersConnected - If Not subjectBuffers(0).GetFeatureOnOffOption(FeatureOnOffOptions.EndConstruct) Then + If Not _globalOptions.GetOption(FeatureOnOffOptions.EndConstruct, LanguageNames.VisualBasic) Then Return End If diff --git a/src/EditorFeatures/VisualBasic/BraceMatching/InterpolatedStringBraceMatcher.vb b/src/EditorFeatures/VisualBasic/BraceMatching/InterpolatedStringBraceMatcher.vb index 8dee901b2d40b..647e6d44a6c9a 100644 --- a/src/EditorFeatures/VisualBasic/BraceMatching/InterpolatedStringBraceMatcher.vb +++ b/src/EditorFeatures/VisualBasic/BraceMatching/InterpolatedStringBraceMatcher.vb @@ -23,7 +23,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.BraceMatching Public Async Function FindBraces( document As Document, position As Integer, - Optional cancellationToken As CancellationToken = Nothing + options As BraceMatchingOptions, + cancellationToken As CancellationToken ) As Task(Of BraceMatchingResult?) Implements IBraceMatcher.FindBracesAsync Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) diff --git a/src/EditorFeatures/VisualBasic/BraceMatching/StringLiteralBraceMatcher.vb b/src/EditorFeatures/VisualBasic/BraceMatching/StringLiteralBraceMatcher.vb index 8003b4b36b916..2a974bfc107f9 100644 --- a/src/EditorFeatures/VisualBasic/BraceMatching/StringLiteralBraceMatcher.vb +++ b/src/EditorFeatures/VisualBasic/BraceMatching/StringLiteralBraceMatcher.vb @@ -19,8 +19,9 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.BraceMatching End Sub Public Async Function FindBraces(document As Document, - position As Integer, - Optional cancellationToken As CancellationToken = Nothing) As Task(Of BraceMatchingResult?) Implements IBraceMatcher.FindBracesAsync + position As Integer, + options As BraceMatchingOptions, + cancellationToken As CancellationToken) As Task(Of BraceMatchingResult?) Implements IBraceMatcher.FindBracesAsync Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) Dim token = root.FindToken(position) diff --git a/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb b/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb index d6e945f79e9e4..fca0dc6fa43f6 100644 --- a/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/EndConstructGeneration/EndConstructCommandHandler.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.CodeCleanup Imports Microsoft.CodeAnalysis.CodeCleanup.Providers Imports Microsoft.CodeAnalysis.Editor.Implementation.EndConstructGeneration Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.VisualStudio.Commanding @@ -32,22 +33,25 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.EndConstructGeneration Private ReadOnly _editorOperationsFactoryService As IEditorOperationsFactoryService Private ReadOnly _undoHistoryRegistry As ITextUndoHistoryRegistry - - Public ReadOnly Property DisplayName As String Implements INamed.DisplayName - Get - Return VBEditorResources.End_Construct - End Get - End Property + Private ReadOnly _globalOptions As IGlobalOptionService Public Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService, - undoHistoryRegistry As ITextUndoHistoryRegistry) + undoHistoryRegistry As ITextUndoHistoryRegistry, + globalOptions As IGlobalOptionService) - Me._editorOperationsFactoryService = editorOperationsFactoryService - Me._undoHistoryRegistry = undoHistoryRegistry + _editorOperationsFactoryService = editorOperationsFactoryService + _undoHistoryRegistry = undoHistoryRegistry + _globalOptions = globalOptions End Sub + Public ReadOnly Property DisplayName As String Implements INamed.DisplayName + Get + Return VBEditorResources.End_Construct + End Get + End Property + Public Function GetCommandState_ReturnKeyCommandHandler(args As ReturnKeyCommandArgs, nextHandler As Func(Of CommandState)) As CommandState Implements IChainedCommandHandler(Of ReturnKeyCommandArgs).GetCommandState Return nextHandler() End Function @@ -63,7 +67,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.EndConstructGeneration Public Sub ExecuteCommand_TypeCharCommandHandler(args As TypeCharCommandArgs, nextHandler As Action, context As CommandExecutionContext) Implements IChainedCommandHandler(Of TypeCharCommandArgs).ExecuteCommand nextHandler() - If Not args.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.EndConstruct) Then + If Not _globalOptions.GetOption(FeatureOnOffOptions.EndConstruct, LanguageNames.VisualBasic) Then Return End If @@ -94,7 +98,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.EndConstructGeneration End Sub Private Sub ExecuteEndConstructOnReturn(textView As ITextView, subjectBuffer As ITextBuffer, nextHandler As Action) - If Not subjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.EndConstruct) OrElse + If Not _globalOptions.GetOption(FeatureOnOffOptions.EndConstruct, LanguageNames.VisualBasic) OrElse Not subjectBuffer.CanApplyChangeDocumentToWorkspace() Then nextHandler() Return diff --git a/src/EditorFeatures/VisualBasic/ImplementAbstractClass/ImplementAbstractClassCommandHandler.vb b/src/EditorFeatures/VisualBasic/ImplementAbstractClass/ImplementAbstractClassCommandHandler.vb index f73473eaeb6bb..4796e2a8ed7f6 100644 --- a/src/EditorFeatures/VisualBasic/ImplementAbstractClass/ImplementAbstractClassCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/ImplementAbstractClass/ImplementAbstractClassCommandHandler.vb @@ -7,6 +7,7 @@ Imports System.Diagnostics.CodeAnalysis Imports System.Threading Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers Imports Microsoft.CodeAnalysis.ImplementAbstractClass +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion @@ -24,8 +25,9 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.ImplementAbstractClass - Public Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService) - MyBase.New(editorOperationsFactoryService) + Public Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService, + globalOptions As IGlobalOptionService) + MyBase.New(editorOperationsFactoryService, globalOptions) End Sub Protected Overrides Function TryGetNewDocument( diff --git a/src/EditorFeatures/VisualBasic/ImplementInterface/ImplementInterfaceCommandHandler.vb b/src/EditorFeatures/VisualBasic/ImplementInterface/ImplementInterfaceCommandHandler.vb index df4d73bb522df..d89a89fdf71e9 100644 --- a/src/EditorFeatures/VisualBasic/ImplementInterface/ImplementInterfaceCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/ImplementInterface/ImplementInterfaceCommandHandler.vb @@ -7,6 +7,7 @@ Imports System.Diagnostics.CodeAnalysis Imports System.Threading Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers Imports Microsoft.CodeAnalysis.ImplementInterface +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion @@ -24,8 +25,9 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.ImplementInterface - Public Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService) - MyBase.New(editorOperationsFactoryService) + Public Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService, + globalOptions As IGlobalOptionService) + MyBase.New(editorOperationsFactoryService, globalOptions) End Sub Protected Overrides Function TryGetNewDocument( diff --git a/src/EditorFeatures/VisualBasic/LineCommit/CommitCommandHandler.vb b/src/EditorFeatures/VisualBasic/LineCommit/CommitCommandHandler.vb index 89d399eb02a4e..fbb111d29a3ff 100644 --- a/src/EditorFeatures/VisualBasic/LineCommit/CommitCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/LineCommit/CommitCommandHandler.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Formatting Imports Microsoft.CodeAnalysis.Formatting.Rules +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text.Shared.Extensions Imports Microsoft.VisualStudio.Commanding @@ -42,6 +43,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit Private ReadOnly _editorOperationsFactoryService As IEditorOperationsFactoryService Private ReadOnly _smartIndentationService As ISmartIndentationService Private ReadOnly _textUndoHistoryRegistry As ITextUndoHistoryRegistry + Private ReadOnly _globalOptions As IGlobalOptionService Public ReadOnly Property DisplayName As String Implements INamed.DisplayName Get @@ -55,12 +57,14 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit bufferManagerFactory As CommitBufferManagerFactory, editorOperationsFactoryService As IEditorOperationsFactoryService, smartIndentationService As ISmartIndentationService, - textUndoHistoryRegistry As ITextUndoHistoryRegistry) + textUndoHistoryRegistry As ITextUndoHistoryRegistry, + globalOptions As IGlobalOptionService) _bufferManagerFactory = bufferManagerFactory _editorOperationsFactoryService = editorOperationsFactoryService _smartIndentationService = smartIndentationService _textUndoHistoryRegistry = textUndoHistoryRegistry + _globalOptions = globalOptions End Sub Public Sub ExecuteCommand(args As FormatDocumentCommandArgs, nextHandler As Action, context As CommandExecutionContext) Implements IChainedCommandHandler(Of FormatDocumentCommandArgs).ExecuteCommand @@ -117,7 +121,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit End Function Public Sub ExecuteCommand(args As ReturnKeyCommandArgs, nextHandler As Action, context As CommandExecutionContext) Implements IChainedCommandHandler(Of ReturnKeyCommandArgs).ExecuteCommand - If Not args.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.PrettyListing) Then + If Not _globalOptions.GetOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic) Then nextHandler() Return End If @@ -229,7 +233,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit ' Do the paste in the same transaction as the commit/format nextHandler() - If Not args.SubjectBuffer.GetFeatureOnOffOption(FormattingBehaviorOptions.FormatOnPaste) Then + If Not _globalOptions.GetOption(FormattingBehaviorOptions.FormatOnPaste, LanguageNames.VisualBasic) Then transaction.Complete() Return End If @@ -261,7 +265,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit End Function Public Sub ExecuteCommand(args As SaveCommandArgs, nextHandler As Action, context As CommandExecutionContext) Implements IChainedCommandHandler(Of SaveCommandArgs).ExecuteCommand - If args.SubjectBuffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.FormatOnSave) Then + If _globalOptions.GetOption(InternalFeatureOnOffOptions.FormatOnSave) Then Using context.OperationContext.AddScope(allowCancellation:=True, VBEditorResources.Formatting_Document) Using transaction = _textUndoHistoryRegistry.GetHistory(args.TextView.TextBuffer).CreateTransaction(VBEditorResources.Format_on_Save) _bufferManagerFactory.CreateForBuffer(args.SubjectBuffer).CommitDirty(isExplicitFormat:=False, cancellationToken:=context.OperationContext.UserCancellationToken) diff --git a/src/EditorFeatures/VisualBasic/LineCommit/CommitFormatter.vb b/src/EditorFeatures/VisualBasic/LineCommit/CommitFormatter.vb index ed7467677a2af..8edbfac6ee5b1 100644 --- a/src/EditorFeatures/VisualBasic/LineCommit/CommitFormatter.vb +++ b/src/EditorFeatures/VisualBasic/LineCommit/CommitFormatter.vb @@ -27,9 +27,12 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit p.Name <> PredefinedCodeCleanupProviderNames.Format End Function + Private ReadOnly _globalOptions As IGlobalOptionService + - Public Sub New() + Public Sub New(globalOptions As IGlobalOptionService) + _globalOptions = globalOptions End Sub Public Sub CommitRegion(spanToFormat As SnapshotSpan, @@ -56,9 +59,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit Return End If - Dim inferredIndentationService = document.Project.Solution.Workspace.Services.GetRequiredService(Of IInferredIndentationService)() - Dim documentOptions = inferredIndentationService.GetDocumentOptionsWithInferredIndentationAsync(document, isExplicitFormat, cancellationToken).WaitAndGetResult(cancellationToken) - If Not (isExplicitFormat OrElse documentOptions.GetOption(FeatureOnOffOptions.PrettyListing)) Then + If Not (isExplicitFormat OrElse _globalOptions.GetOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic)) Then Return End If @@ -68,12 +69,15 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit End If ' create commit formatting cleanup provider that has line commit specific behavior + Dim inferredIndentationService = document.Project.Solution.Workspace.Services.GetRequiredService(Of IInferredIndentationService)() + Dim documentOptions = inferredIndentationService.GetDocumentOptionsWithInferredIndentationAsync(document, isExplicitFormat, cancellationToken).WaitAndGetResult(cancellationToken) Dim commitFormattingCleanup = GetCommitFormattingCleanupProvider( document, documentOptions, spanToFormat, baseSnapshot, baseTree, - dirtyRegion, document.GetSyntaxTreeSynchronously(cancellationToken), + dirtyRegion, + document.GetSyntaxTreeSynchronously(cancellationToken), cancellationToken) Dim codeCleanups = CodeCleaner.GetDefaultProviders(document). diff --git a/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb b/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb index 71e34b2250c22..275b1febc61c0 100644 --- a/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb +++ b/src/EditorFeatures/VisualBasic/Utilities/CommandHandlers/AbstractImplementAbstractClassOrInterfaceCommandHandler.vb @@ -6,6 +6,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Editor.Implementation.EndConstructGeneration Imports Microsoft.CodeAnalysis.Formatting +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Simplification Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text.Shared.Extensions @@ -21,6 +22,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers Implements ICommandHandler(Of ReturnKeyCommandArgs) Private ReadOnly _editorOperationsFactoryService As IEditorOperationsFactoryService + Private ReadOnly _globalOptions As IGlobalOptionService Public ReadOnly Property DisplayName As String Implements INamed.DisplayName Get @@ -28,8 +30,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers End Get End Property - Protected Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService) + Protected Sub New(editorOperationsFactoryService As IEditorOperationsFactoryService, + globalOptions As IGlobalOptionService) _editorOperationsFactoryService = editorOperationsFactoryService + _globalOptions = globalOptions End Sub Protected MustOverride Overloads Function TryGetNewDocument( @@ -108,7 +112,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities.CommandHandlers Return False End If - If Not args.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutomaticInsertionOfAbstractOrInterfaceMembers) Then + If Not _globalOptions.GetOption(FeatureOnOffOptions.AutomaticInsertionOfAbstractOrInterfaceMembers, LanguageNames.VisualBasic) Then Return False End If diff --git a/src/EditorFeatures/VisualBasicTest/AutomaticCompletion/AutomaticLineEnderTests.vb b/src/EditorFeatures/VisualBasicTest/AutomaticCompletion/AutomaticLineEnderTests.vb index 18cfd23fb71d6..e329368be9d33 100644 --- a/src/EditorFeatures/VisualBasicTest/AutomaticCompletion/AutomaticLineEnderTests.vb +++ b/src/EditorFeatures/VisualBasicTest/AutomaticCompletion/AutomaticLineEnderTests.vb @@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Editor.VisualBasic.AutomaticCompletion Imports Microsoft.CodeAnalysis.Editor.VisualBasic.EndConstructGeneration +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Text.Editor.Commanding.Commands Imports Microsoft.VisualStudio.Text.Operations @@ -275,8 +276,9 @@ End Module Protected Overrides Function CreateNextHandler(workspace As TestWorkspace) As Action Dim endConstructor = New EndConstructCommandHandler( - GetExportedValue(Of IEditorOperationsFactoryService)(workspace), - GetExportedValue(Of ITextUndoHistoryRegistry)(workspace)) + workspace.GetService(Of IEditorOperationsFactoryService), + workspace.GetService(Of ITextUndoHistoryRegistry), + workspace.GetService(Of IGlobalOptionService)) Dim view = workspace.Documents.Single().GetTextView() Dim buffer = workspace.Documents.Single().GetTextBuffer() diff --git a/src/EditorFeatures/VisualBasicTest/BraceMatching/BraceHighlightingTests.vb b/src/EditorFeatures/VisualBasicTest/BraceMatching/BraceHighlightingTests.vb index c7fa03533f9ea..6ace85d59cb76 100644 --- a/src/EditorFeatures/VisualBasicTest/BraceMatching/BraceHighlightingTests.vb +++ b/src/EditorFeatures/VisualBasicTest/BraceMatching/BraceHighlightingTests.vb @@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.Editor.Implementation.BraceMatching Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Editor.Tagging Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Shared.TestHooks Imports Microsoft.CodeAnalysis.Text Imports Microsoft.VisualStudio.Text @@ -28,6 +29,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.BraceMatching Dim producer = New BraceHighlightingViewTaggerProvider( workspace.ExportProvider.GetExportedValue(Of IThreadingContext), workspace.GetService(Of IBraceMatchingService), + workspace.GetService(Of IGlobalOptionService), AsynchronousOperationListenerProvider.NullProvider) Dim doc = buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault() diff --git a/src/EditorFeatures/VisualBasicTest/EndConstructGeneration/EndConstructTestingHelpers.vb b/src/EditorFeatures/VisualBasicTest/EndConstructGeneration/EndConstructTestingHelpers.vb index 21a377466428c..0f144ae5cd0e8 100644 --- a/src/EditorFeatures/VisualBasicTest/EndConstructGeneration/EndConstructTestingHelpers.vb +++ b/src/EditorFeatures/VisualBasicTest/EndConstructGeneration/EndConstructTestingHelpers.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Editor.VisualBasic.EndConstructGeneration +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.VisualStudio.Composition Imports Microsoft.VisualStudio.Text Imports Microsoft.VisualStudio.Text.Editor @@ -26,11 +27,6 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.EndConstructGenera Return mock.Object End Function - Private Sub DisableLineCommit(workspace As Workspace) - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options _ - .WithChangedOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic, False))) - End Sub - Private Sub VerifyTypedCharApplied(doFunc As Func(Of VisualBasicEndConstructService, ITextView, ITextBuffer, Boolean), before As String, after As String, @@ -39,7 +35,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.EndConstructGenera Dim caretPos = before.IndexOf("$$", StringComparison.Ordinal) Dim beforeText = before.Replace("$$", "") Using workspace = TestWorkspace.CreateVisualBasic(beforeText, composition:=EditorTestCompositions.EditorFeatures) - DisableLineCommit(workspace) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic), False) Dim view = workspace.Documents.First().GetTextView() view.Caret.MoveTo(New SnapshotPoint(view.TextSnapshot, caretPos)) @@ -68,7 +65,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.EndConstructGenera after As String, afterCaret As Integer()) Using workspace = TestWorkspace.CreateVisualBasic(before, composition:=EditorTestCompositions.EditorFeatures) - DisableLineCommit(workspace) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic), False) Dim textView = workspace.Documents.First().GetTextView() Dim subjectBuffer = workspace.Documents.First().GetTextBuffer() @@ -211,7 +209,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.EndConstructGenera ' create separate composition Using workspace = TestWorkspace.CreateVisualBasic(before, composition:=EditorTestCompositions.EditorFeatures) - DisableLineCommit(workspace) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic), False) Dim view = workspace.Documents.First().GetTextView() Dim line = view.TextSnapshot.GetLineFromLineNumber(beforeCaret(0)) @@ -221,10 +220,11 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.EndConstructGenera view.Caret.MoveTo(New SnapshotPoint(view.TextSnapshot, line.Start + beforeCaret(1))) End If - Dim factory = workspace.ExportProvider.GetExportedValue(Of IEditorOperationsFactoryService)() + Dim factory = workspace.GetService(Of IEditorOperationsFactoryService)() Dim endConstructor = New EndConstructCommandHandler( - factory, - workspace.ExportProvider.GetExportedValue(Of ITextUndoHistoryRegistry)()) + factory, + workspace.GetService(Of ITextUndoHistoryRegistry), + globalOptions) Dim operations = factory.GetEditorOperations(view) endConstructor.ExecuteCommand_ReturnKeyCommandHandler(New ReturnKeyCommandArgs(view, view.TextBuffer), Sub() operations.InsertNewLine(), TestCommandExecutionContext.Create()) diff --git a/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartIndentProviderTests.vb b/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartIndentProviderTests.vb index 5c0fc063f468d..69f6c4f127afb 100644 --- a/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartIndentProviderTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Formatting/Indentation/SmartIndentProviderTests.vb @@ -2,6 +2,7 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent Imports Microsoft.CodeAnalysis.Editor.Shared.Options Imports Microsoft.CodeAnalysis.Editor.UnitTests @@ -25,7 +26,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Formatting.Indenta Public Sub GetSmartIndent2() Using workspace = TestWorkspace.CreateCSharp("") - Assert.Equal(True, workspace.Options.GetOption(InternalFeatureOnOffOptions.SmartIndenter)) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + Assert.Equal(True, globalOptions.GetOption(InternalFeatureOnOffOptions.SmartIndenter)) Dim document = workspace.Projects.Single().Documents.Single() Dim provider = workspace.ExportProvider.GetExportedValues(Of ISmartIndentProvider)().OfType(Of SmartIndentProvider)().Single() @@ -39,8 +41,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Formatting.Indenta Public Sub GetSmartIndent3() Using workspace = TestWorkspace.CreateCSharp("") - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options _ - .WithChangedOption(InternalFeatureOnOffOptions.SmartIndenter, False))) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(InternalFeatureOnOffOptions.SmartIndenter), False) Dim document = workspace.Projects.Single().Documents.Single() Dim provider = workspace.ExportProvider.GetExportedValues(Of ISmartIndentProvider)().OfType(Of SmartIndentProvider)().Single() diff --git a/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassCommandHandlerTests.vb b/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassCommandHandlerTests.vb index 77305751e789a..e4ef207b0c98b 100644 --- a/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassCommandHandlerTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassCommandHandlerTests.vb @@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Editor.VisualBasic.ImplementAbstractClass Imports Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text Imports Microsoft.VisualStudio.Commanding Imports Microsoft.VisualStudio.Text @@ -207,7 +208,7 @@ End Class view.Caret.MoveTo(New SnapshotPoint(snapshot, cursorPosition)) Dim commandHandler As ICommandHandler(Of ReturnKeyCommandArgs) = - New ImplementAbstractClassCommandHandler(workspace.GetService(Of IEditorOperationsFactoryService)) + New ImplementAbstractClassCommandHandler(workspace.GetService(Of IEditorOperationsFactoryService), workspace.GetService(Of IGlobalOptionService)) commandHandler.ExecuteCommand(New ReturnKeyCommandArgs(view, view.TextBuffer), nextHandler, TestCommandExecutionContext.Create()) Dim text = view.TextBuffer.CurrentSnapshot.AsText().ToString() diff --git a/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceCommandHandlerTests.vb b/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceCommandHandlerTests.vb index 317550f93db7c..2db099b7fa555 100644 --- a/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceCommandHandlerTests.vb +++ b/src/EditorFeatures/VisualBasicTest/ImplementInterface/ImplementInterfaceCommandHandlerTests.vb @@ -38,7 +38,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ImplementInterface Dim cursorPosition = document.CursorPosition.Value view.Caret.MoveTo(New SnapshotPoint(view.TextBuffer.CurrentSnapshot, cursorPosition)) - Return New ImplementInterfaceCommandHandler(workspace.GetService(Of IEditorOperationsFactoryService)) + Return New ImplementInterfaceCommandHandler(workspace.GetService(Of IEditorOperationsFactoryService), workspace.GetService(Of IGlobalOptionService)) End Function Private Shared Function GetWorkspace(code As String) As TestWorkspace diff --git a/src/EditorFeatures/VisualBasicTest/LineCommit/CommitOnMiscellaneousCommandsTests.vb b/src/EditorFeatures/VisualBasicTest/LineCommit/CommitOnMiscellaneousCommandsTests.vb index 07794c36904bd..8f3b41f60bcc2 100644 --- a/src/EditorFeatures/VisualBasicTest/LineCommit/CommitOnMiscellaneousCommandsTests.vb +++ b/src/EditorFeatures/VisualBasicTest/LineCommit/CommitOnMiscellaneousCommandsTests.vb @@ -5,6 +5,7 @@ Imports Microsoft.CodeAnalysis.Editor.Shared.Options Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.VisualStudio.Text.Editor.Commanding.Commands Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.LineCommit @@ -71,8 +72,8 @@ End Class ) Dim workspace = testData.Workspace - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options _ - .WithChangedOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic, False))) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic), False) testData.CommandHandler.ExecuteCommand(New PasteCommandArgs(testData.View, testData.Buffer), Sub() testData.EditorOperations.InsertText("Class Program" & vbCrLf & " Sub M(abc As Integer)" & vbCrLf & " Dim a = 7" & vbCrLf & " End Sub" & vbCrLf & "End Class"), @@ -130,8 +131,8 @@ End Class ) Dim workspace = testData.Workspace - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options _ - .WithChangedOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic, False))) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic), False) testData.Buffer.Insert(57, " ") testData.CommandHandler.ExecuteCommand(New SaveCommandArgs(testData.View, testData.Buffer), Sub() Exit Sub, TestCommandExecutionContext.Create()) @@ -179,8 +180,9 @@ End Module ' Turn off pretty listing Dim workspace = testData.Workspace - workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options _ - .WithChangedOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic, False))) + Dim globalOptions = workspace.GetService(Of IGlobalOptionService) + globalOptions.SetGlobalOption(New OptionKey(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic), False) + testData.CommandHandler.ExecuteCommand(New FormatDocumentCommandArgs(testData.View, testData.Buffer), Sub() Exit Sub, TestCommandExecutionContext.Create()) Assert.Equal(" Sub Main()", testData.Buffer.CurrentSnapshot.GetLineFromLineNumber(1).GetText()) End Using diff --git a/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb b/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb index 5ee239b0bcd43..d731c2adaca28 100644 --- a/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb +++ b/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb @@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Imports Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit Imports Microsoft.CodeAnalysis.Indentation +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text.Shared.Extensions Imports Microsoft.VisualStudio.Text @@ -66,7 +67,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.LineCommit commitManagerFactory, workspace.GetService(Of IEditorOperationsFactoryService), workspace.GetService(Of ISmartIndentationService), - textUndoHistoryRegistry) + textUndoHistoryRegistry, + workspace.GetService(Of IGlobalOptionService)) End Sub Friend Sub AssertHadCommit(expectCommit As Boolean) diff --git a/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs b/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs index 8df9289bc2dcd..1339652374230 100644 --- a/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs +++ b/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs @@ -11,6 +11,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.InlineHints; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.CSharp.InlineHints @@ -25,7 +26,8 @@ internal class CSharpInlineParameterNameHintsService : AbstractInlineParameterNa { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpInlineParameterNameHintsService() + public CSharpInlineParameterNameHintsService(IGlobalOptionService globalOptions) + : base(globalOptions) { } diff --git a/src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs b/src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs index cc423d436e8a3..7094a527a8e28 100644 --- a/src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs +++ b/src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs @@ -9,17 +9,19 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.InlineHints; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.InlineHints { [ExportLanguageService(typeof(IInlineTypeHintsService), LanguageNames.CSharp), Shared] - internal class CSharpInlineTypeHintsService : AbstractInlineTypeHintsService + internal sealed class CSharpInlineTypeHintsService : AbstractInlineTypeHintsService { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public CSharpInlineTypeHintsService() + public CSharpInlineTypeHintsService(IGlobalOptionService globalOptions) + : base(globalOptions) { } diff --git a/src/Features/CSharp/Portable/Structure/CSharpStructureHelpers.cs b/src/Features/CSharp/Portable/Structure/CSharpStructureHelpers.cs index 47001eb397b70..bc564aac5873b 100644 --- a/src/Features/CSharp/Portable/Structure/CSharpStructureHelpers.cs +++ b/src/Features/CSharp/Portable/Structure/CSharpStructureHelpers.cs @@ -244,14 +244,14 @@ void completeSingleLineCommentGroup(ref TemporaryArray spans) public static void CollectCommentBlockSpans( SyntaxNode node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider) + in BlockStructureOptions options) { if (node == null) { throw new ArgumentNullException(nameof(node)); } - if (optionProvider.IsMetadataAsSource && TryGetLeadingCollapsibleSpan(node, out var span)) + if (options.IsMetadataAsSource && TryGetLeadingCollapsibleSpan(node, out var span)) { spans.Add(span); } diff --git a/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs index 14638d16f3fce..acec24d90d3ea 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/AccessorDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, AccessorDeclarationSyntax accessorDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(accessorDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(accessorDeclaration, ref spans, options); // fault tolerance if (accessorDeclaration.Body == null || @@ -34,7 +34,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // All accessor kinds are grouped together in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.AsNode() is AccessorDeclarationSyntax); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/AnonymousMethodExpressionStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/AnonymousMethodExpressionStructureProvider.cs index a53b6b1e73be2..5541026c4c452 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/AnonymousMethodExpressionStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/AnonymousMethodExpressionStructureProvider.cs @@ -15,7 +15,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, AnonymousMethodExpressionSyntax anonymousMethod, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { // fault tolerance diff --git a/src/Features/CSharp/Portable/Structure/Providers/ArrowExpressionClauseStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/ArrowExpressionClauseStructureProvider.cs index 21301d972cf5f..a0a45b8d14eb0 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/ArrowExpressionClauseStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/ArrowExpressionClauseStructureProvider.cs @@ -19,7 +19,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, ArrowExpressionClauseSyntax node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { spans.Add(new BlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs index b59accf107b35..3fd19d90d02b7 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/BlockSyntaxStructureProvider.cs @@ -20,7 +20,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, BlockSyntax node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { var parentKind = node.Parent.Kind(); diff --git a/src/Features/CSharp/Portable/Structure/Providers/CompilationUnitStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/CompilationUnitStructureProvider.cs index 1b528a7b557db..c0c012b04da11 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/CompilationUnitStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/CompilationUnitStructureProvider.cs @@ -18,10 +18,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, CompilationUnitSyntax compilationUnit, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(compilationUnit, ref spans, options); // extern aliases and usings are outlined in a single region var externsAndUsings = new List(); diff --git a/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs index af5309dfb3217..51a8e689a7133 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, ConstructorDeclarationSyntax constructorDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(constructorDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(constructorDeclaration, ref spans, options); // fault tolerance if (constructorDeclaration.Body == null || @@ -34,7 +34,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Whitespace between constructors is collapsed in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConstructorDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs index 404baf5b15a2a..1fca42d7847c6 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/ConversionOperatorDeclarationStructureProvider.cs @@ -17,10 +17,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, ConversionOperatorDeclarationSyntax operatorDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, ref spans, options); // fault tolerance if (operatorDeclaration.Body == null || @@ -36,7 +36,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Whitespace between conversion operators is collapsed in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.ConversionOperatorDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/DelegateDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/DelegateDeclarationStructureProvider.cs index 839fea7a838ef..3f963743b6bcb 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/DelegateDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/DelegateDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, DelegateDeclarationSyntax delegateDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(delegateDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(delegateDeclaration, ref spans, options); } } } diff --git a/src/Features/CSharp/Portable/Structure/Providers/DestructorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/DestructorDeclarationStructureProvider.cs index 60855c52d25dc..7e8269264cdb2 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/DestructorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/DestructorDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, DestructorDeclarationSyntax destructorDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(destructorDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(destructorDeclaration, ref spans, options); // fault tolerance if (destructorDeclaration.Body == null || diff --git a/src/Features/CSharp/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.cs index 7a35a141329c3..cc87122c54323 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.cs @@ -16,7 +16,7 @@ internal class DisabledTextTriviaStructureProvider : AbstractSyntaxTriviaStructu public override void CollectBlockSpans( SyntaxTrivia trivia, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { CollectBlockSpans(trivia.SyntaxTree, trivia, ref spans, cancellationToken); diff --git a/src/Features/CSharp/Portable/Structure/Providers/DocumentationCommentStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/DocumentationCommentStructureProvider.cs index d2d6dfe0a9606..2d80e3076c5c9 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/DocumentationCommentStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/DocumentationCommentStructureProvider.cs @@ -17,7 +17,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, DocumentationCommentTriviaSyntax documentationComment, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { var startPos = documentationComment.FullSpan.Start; @@ -27,7 +27,7 @@ protected override void CollectBlockSpans( var span = TextSpan.FromBounds(startPos, endPos); - var bannerLength = optionProvider.GetOption(BlockStructureOptions.MaximumBannerLength, LanguageNames.CSharp); + var bannerLength = options.MaximumBannerLength; var bannerText = CSharpFileBannerFacts.Instance.GetBannerText( documentationComment, bannerLength, cancellationToken); diff --git a/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs index fbe7f5633b270..9461b52e7f90d 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/EnumDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, EnumDeclarationSyntax enumDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(enumDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(enumDeclaration, ref spans, options); if (!enumDeclaration.OpenBraceToken.IsMissing && !enumDeclaration.CloseBraceToken.IsMissing) @@ -29,7 +29,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Whitespace between type declarations is collapsed in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.cs index 81f7c5380a25e..91ec40a9dfc5a 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, EnumMemberDeclarationSyntax enumMemberDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(enumMemberDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(enumMemberDeclaration, ref spans, options); } } } diff --git a/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs index a0b7717372e47..49cc0abd0fd94 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/EventDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, EventDeclarationSyntax eventDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(eventDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(eventDeclaration, ref spans, options); // fault tolerance if (eventDeclaration.AccessorList == null || @@ -35,7 +35,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Full events are grouped together with event field definitions in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.EventDeclaration) || nextSibling.IsKind(SyntaxKind.EventFieldDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/EventFieldDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/EventFieldDeclarationStructureProvider.cs index 11f41d2a56a01..59dc197288819 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/EventFieldDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/EventFieldDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, EventFieldDeclarationSyntax eventFieldDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(eventFieldDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(eventFieldDeclaration, ref spans, options); } } } diff --git a/src/Features/CSharp/Portable/Structure/Providers/FieldDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/FieldDeclarationStructureProvider.cs index 76a1d0e22d056..9fc8d9f74baff 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/FieldDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/FieldDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, FieldDeclarationSyntax fieldDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(fieldDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(fieldDeclaration, ref spans, options); } } } diff --git a/src/Features/CSharp/Portable/Structure/Providers/FileScopedNamespaceDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/FileScopedNamespaceDeclarationStructureProvider.cs index a665e3984a2dc..9a16c31d0a9be 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/FileScopedNamespaceDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/FileScopedNamespaceDeclarationStructureProvider.cs @@ -17,11 +17,11 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, FileScopedNamespaceDeclarationSyntax fileScopedNamespaceDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { // add leading comments - CSharpStructureHelpers.CollectCommentBlockSpans(fileScopedNamespaceDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(fileScopedNamespaceDeclaration, ref spans, options); // extern aliases and usings are outlined in a single region var externsAndUsings = Enumerable.Union(fileScopedNamespaceDeclaration.Externs, fileScopedNamespaceDeclaration.Usings).ToImmutableArray(); @@ -29,7 +29,7 @@ protected override void CollectBlockSpans( // add any leading comments before the extern aliases and usings if (externsAndUsings.Any()) { - CSharpStructureHelpers.CollectCommentBlockSpans(externsAndUsings.First(), ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(externsAndUsings.First(), ref spans, options); } spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs index 5c1e5ae372c8c..29499939004d0 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/IndexerDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, IndexerDeclarationSyntax indexerDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(indexerDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(indexerDeclaration, ref spans, options); // fault tolerance if (indexerDeclaration.AccessorList == null || @@ -35,7 +35,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Indexers are grouped together with properties in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.IndexerDeclaration) || nextSibling.IsKind(SyntaxKind.PropertyDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/InitializerExpressionStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/InitializerExpressionStructureProvider.cs index 814a7681523e4..6c82d8582e48f 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/InitializerExpressionStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/InitializerExpressionStructureProvider.cs @@ -18,7 +18,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, InitializerExpressionSyntax node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { if (node.Parent is InitializerExpressionSyntax) diff --git a/src/Features/CSharp/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.cs index 1ec4e31d4d250..76d98bf372055 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.cs @@ -15,7 +15,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, InterpolatedStringExpressionSyntax node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { if (node.StringStartToken.IsMissing || diff --git a/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs index 3e31683fe6c71..8973cde510b84 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/MethodDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, MethodDeclarationSyntax methodDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(methodDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(methodDeclaration, ref spans, options); // fault tolerance if (methodDeclaration.Body == null || @@ -34,7 +34,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Whitespace between methods is collapsed in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.MethodDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.cs index d607e76e564e0..26e2bb297313b 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.cs @@ -16,11 +16,11 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, NamespaceDeclarationSyntax namespaceDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { // add leading comments - CSharpStructureHelpers.CollectCommentBlockSpans(namespaceDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(namespaceDeclaration, ref spans, options); if (!namespaceDeclaration.OpenBraceToken.IsMissing && !namespaceDeclaration.CloseBraceToken.IsMissing) @@ -42,7 +42,7 @@ protected override void CollectBlockSpans( // add any leading comments before the extern aliases and usings if (externsAndUsings.Count > 0) { - CSharpStructureHelpers.CollectCommentBlockSpans(externsAndUsings.First(), ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(externsAndUsings.First(), ref spans, options); } spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs index 6b7f1e3f84510..28b11f3cc3b67 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/OperatorDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, OperatorDeclarationSyntax operatorDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(operatorDeclaration, ref spans, options); // fault tolerance if (operatorDeclaration.Body == null || @@ -34,7 +34,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Whitespace between operators is collapsed in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.OperatorDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/ParenthesizedLambdaExpressionStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/ParenthesizedLambdaExpressionStructureProvider.cs index 3f9d56ae968b1..1b73b2afea3de 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/ParenthesizedLambdaExpressionStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/ParenthesizedLambdaExpressionStructureProvider.cs @@ -15,7 +15,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, ParenthesizedLambdaExpressionSyntax lambdaExpression, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { // fault tolerance diff --git a/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs index 8439ea2f9b894..4dcbf978181bd 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/PropertyDeclarationStructureProvider.cs @@ -15,10 +15,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, PropertyDeclarationSyntax propertyDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(propertyDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(propertyDeclaration, ref spans, options); // fault tolerance if (propertyDeclaration.AccessorList == null || @@ -34,7 +34,7 @@ protected override void CollectBlockSpans( // Check IsNode to compress blank lines after this node if it is the last child of the parent. // // Properties are grouped together with indexers in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.IsKind(SyntaxKind.PropertyDeclaration) || nextSibling.IsKind(SyntaxKind.IndexerDeclaration)); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/RegionDirectiveStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/RegionDirectiveStructureProvider.cs index 6e90e945ec694..e2d67b9339a0f 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/RegionDirectiveStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/RegionDirectiveStructureProvider.cs @@ -33,7 +33,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, RegionDirectiveTriviaSyntax regionDirective, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { var match = regionDirective.GetMatchingDirective(cancellationToken); @@ -47,8 +47,7 @@ protected override void CollectBlockSpans( // #endregion // // For other files, auto-collapse regions based on the user option. - var autoCollapse = optionProvider.IsMetadataAsSource || optionProvider.GetOption( - BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.CSharp); + var autoCollapse = options.IsMetadataAsSource || options.CollapseRegionsWhenCollapsingToDefinitions; spans.Add(new BlockSpan( isCollapsible: true, @@ -56,7 +55,7 @@ protected override void CollectBlockSpans( type: BlockTypes.PreprocessorRegion, bannerText: GetBannerText(regionDirective), autoCollapse: autoCollapse, - isDefaultCollapsed: !optionProvider.IsMetadataAsSource)); + isDefaultCollapsed: !options.IsMetadataAsSource)); } } } diff --git a/src/Features/CSharp/Portable/Structure/Providers/SimpleLambdaExpressionStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/SimpleLambdaExpressionStructureProvider.cs index c2bb460cbdd0e..191184c361181 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/SimpleLambdaExpressionStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/SimpleLambdaExpressionStructureProvider.cs @@ -15,7 +15,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, SimpleLambdaExpressionSyntax lambdaExpression, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { // fault tolerance diff --git a/src/Features/CSharp/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.cs index 50a7e17a21dfe..b7c8cafa4d5d3 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.cs @@ -15,7 +15,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, LiteralExpressionSyntax node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { if (node.IsKind(SyntaxKind.StringLiteralExpression) && diff --git a/src/Features/CSharp/Portable/Structure/Providers/SwitchStatementStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/SwitchStatementStructureProvider.cs index e37485cbd82a3..a946d401055ff 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/SwitchStatementStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/SwitchStatementStructureProvider.cs @@ -18,7 +18,7 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, SwitchStatementSyntax node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { spans.Add(new BlockSpan( diff --git a/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs b/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs index 53410026e500a..b07bdd503d6a7 100644 --- a/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs +++ b/src/Features/CSharp/Portable/Structure/Providers/TypeDeclarationStructureProvider.cs @@ -18,10 +18,10 @@ protected override void CollectBlockSpans( SyntaxToken previousToken, TypeDeclarationSyntax typeDeclaration, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { - CSharpStructureHelpers.CollectCommentBlockSpans(typeDeclaration, ref spans, optionProvider); + CSharpStructureHelpers.CollectCommentBlockSpans(typeDeclaration, ref spans, options); if (!typeDeclaration.OpenBraceToken.IsMissing && !typeDeclaration.CloseBraceToken.IsMissing) @@ -38,7 +38,7 @@ protected override void CollectBlockSpans( // Collapse to Definitions doesn't collapse type nodes, but a Toggle All Outlining would collapse groups // of types to the compressed form of not showing blank lines. All kinds of types are grouped together // in Metadata as Source. - var compressEmptyLines = optionProvider.IsMetadataAsSource + var compressEmptyLines = options.IsMetadataAsSource && (!nextSibling.IsNode || nextSibling.AsNode() is BaseTypeDeclarationSyntax); spans.AddIfNotNull(CSharpStructureHelpers.CreateBlockSpan( 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/Features/Core/Portable/BraceCompletion/BraceCompletionOptions.cs b/src/Features/Core/Portable/BraceCompletion/BraceCompletionOptions.cs index 8ac4e7768e097..15801380d8d2b 100644 --- a/src/Features/Core/Portable/BraceCompletion/BraceCompletionOptions.cs +++ b/src/Features/Core/Portable/BraceCompletion/BraceCompletionOptions.cs @@ -17,7 +17,7 @@ internal class BraceCompletionOptions nameof(BraceCompletionOptions), nameof(AutoFormattingOnCloseBrace), defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.Auto Formatting On Close Brace")); - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class BraceCompletionOptionsProvider : IOptionProvider { [ImportingConstructor] @@ -27,7 +27,7 @@ public BraceCompletionOptionsProvider() } public ImmutableArray Options { get; } = ImmutableArray.Create( - BraceCompletionOptions.AutoFormattingOnCloseBrace); + AutoFormattingOnCloseBrace); } } } diff --git a/src/Features/Core/Portable/Completion/CompletionOptions.cs b/src/Features/Core/Portable/Completion/CompletionOptions.cs index 8bc054c9ecc6b..314b7f592dd79 100644 --- a/src/Features/Core/Portable/Completion/CompletionOptions.cs +++ b/src/Features/Core/Portable/Completion/CompletionOptions.cs @@ -100,7 +100,7 @@ public RecommendationServiceOptions ToRecommendationServiceOptions() public OptionSet ToSet(string language) => WithChangedOptions(OptionValueSet.Empty, language); - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class Metadata : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/Diagnostics/DiagnosticOptions.cs b/src/Features/Core/Portable/Diagnostics/DiagnosticOptions.cs index 5dcb198922995..cca8fb8c55d9d 100644 --- a/src/Features/Core/Portable/Diagnostics/DiagnosticOptions.cs +++ b/src/Features/Core/Portable/Diagnostics/DiagnosticOptions.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class DiagnosticOptions : IOptionProvider { private const string FeatureName = "DiagnosticOptions"; diff --git a/src/Features/Core/Portable/Diagnostics/InternalDiagnosticsOptionsProvider.cs b/src/Features/Core/Portable/Diagnostics/InternalDiagnosticsOptionsProvider.cs index 6482a505c4339..aee8374fae8f4 100644 --- a/src/Features/Core/Portable/Diagnostics/InternalDiagnosticsOptionsProvider.cs +++ b/src/Features/Core/Portable/Diagnostics/InternalDiagnosticsOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,8 +11,8 @@ namespace Microsoft.CodeAnalysis.Diagnostics { - [ExportOptionProvider, Shared] - internal class InternalDiagnosticsOptionsProvider : IOptionProvider + [ExportSolutionOptionProvider, Shared] + internal sealed class InternalDiagnosticsOptionsProvider : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] diff --git a/src/Features/Core/Portable/DocumentationComments/DocumentationCommentOptions.cs b/src/Features/Core/Portable/DocumentationComments/DocumentationCommentOptions.cs index 2df993fbd329e..3612d368496da 100644 --- a/src/Features/Core/Portable/DocumentationComments/DocumentationCommentOptions.cs +++ b/src/Features/Core/Portable/DocumentationComments/DocumentationCommentOptions.cs @@ -18,7 +18,7 @@ internal readonly record struct DocumentationCommentOptions( bool UseTabs, string NewLine) { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class Metadata : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegularExpressionsOptions.cs b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegularExpressionsOptions.cs index c22370e924143..bf1af476a145c 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegularExpressionsOptions.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/RegularExpressions/RegularExpressionsOptions.cs @@ -28,7 +28,7 @@ internal class RegularExpressionsOptions storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.HighlightRelatedRegexComponentsUnderCursor")); } - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class RegularExpressionsOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/ExtractMethod/ExtractMethodOptionsProvider.cs b/src/Features/Core/Portable/ExtractMethod/ExtractMethodOptionsProvider.cs index af8105713d4bb..ab5682fb2fb56 100644 --- a/src/Features/Core/Portable/ExtractMethod/ExtractMethodOptionsProvider.cs +++ b/src/Features/Core/Portable/ExtractMethod/ExtractMethodOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.ExtractMethod { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class ExtractMethodOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/Fading/FadingOptions.cs b/src/Features/Core/Portable/Fading/FadingOptions.cs new file mode 100644 index 0000000000000..aa162469ccb70 --- /dev/null +++ b/src/Features/Core/Portable/Fading/FadingOptions.cs @@ -0,0 +1,40 @@ +// 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.Fading +{ + internal sealed class FadingOptions + { + [ExportSolutionOptionProvider, Shared] + internal sealed class Provider : IOptionProvider + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public Provider() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + FadeOutUnusedImports, + FadeOutUnreachableCode); + } + + private const string FeatureName = "FadingOptions"; + + public static readonly PerLanguageOption2 FadeOutUnusedImports = new( + FeatureName, "FadeOutUnusedImports", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnusedImports")); + + public static readonly PerLanguageOption2 FadeOutUnreachableCode = new( + FeatureName, "FadeOutUnreachableCode", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.FadeOutUnreachableCode")); + } +} diff --git a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs index 82b2abed04297..61acfc73862de 100644 --- a/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs +++ b/src/Features/Core/Portable/GenerateOverrides/GenerateOverridesOptions.cs @@ -17,7 +17,7 @@ internal class GenerateOverridesOptions nameof(GenerateOverridesOptions), nameof(SelectAll), defaultValue: true, storageLocation: new RoamingProfileStorageLocation($"TextEditor.Specific.{nameof(GenerateOverridesOptions)}.{nameof(SelectAll)}")); - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class GenerateOverridesOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypeOptionsProvider.cs b/src/Features/Core/Portable/ImplementType/ImplementTypeOptionsProvider.cs index 2d20f7f22096e..937942765e476 100644 --- a/src/Features/Core/Portable/ImplementType/ImplementTypeOptionsProvider.cs +++ b/src/Features/Core/Portable/ImplementType/ImplementTypeOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.ImplementType { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class ImplementTypeOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs b/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs index c50f4a93c2fa3..521ed98ac7763 100644 --- a/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs +++ b/src/Features/Core/Portable/InlineHints/AbstractInlineParameterNameHintsService.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; @@ -17,6 +18,8 @@ namespace Microsoft.CodeAnalysis.InlineHints { internal abstract class AbstractInlineParameterNameHintsService : IInlineParameterNameHintsService { + private readonly IGlobalOptionService _globalOptions; + protected enum HintKind { Literal, @@ -24,6 +27,11 @@ protected enum HintKind Other } + public AbstractInlineParameterNameHintsService(IGlobalOptionService globalOptions) + { + _globalOptions = globalOptions; + } + protected abstract void AddAllParameterNameHintLocations( SemanticModel semanticModel, ISyntaxFactsService syntaxFacts, @@ -35,25 +43,24 @@ protected abstract void AddAllParameterNameHintLocations( public async Task> GetInlineHintsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) { - var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); + var options = InlineParameterHintsOptions.From(document.Project); var displayOptions = SymbolDescriptionOptions.From(document.Project); + var displayAllOverride = _globalOptions.GetOption(InlineHintsGlobalStateOption.DisplayAllOverride); - var displayAllOverride = options.GetOption(InlineHintsOptions.DisplayAllOverride); - - var enabledForParameters = displayAllOverride || options.GetOption(InlineHintsOptions.EnabledForParameters); + var enabledForParameters = displayAllOverride || options.EnabledForParameters; if (!enabledForParameters) return ImmutableArray.Empty; - var literalParameters = displayAllOverride || options.GetOption(InlineHintsOptions.ForLiteralParameters); - var objectCreationParameters = displayAllOverride || options.GetOption(InlineHintsOptions.ForObjectCreationParameters); - var otherParameters = displayAllOverride || options.GetOption(InlineHintsOptions.ForOtherParameters); + var literalParameters = displayAllOverride || options.ForLiteralParameters; + var objectCreationParameters = displayAllOverride || options.ForObjectCreationParameters; + var otherParameters = displayAllOverride || options.ForOtherParameters; if (!literalParameters && !objectCreationParameters && !otherParameters) return ImmutableArray.Empty; - var indexerParameters = displayAllOverride || options.GetOption(InlineHintsOptions.ForIndexerParameters); - var suppressForParametersThatDifferOnlyBySuffix = !displayAllOverride && options.GetOption(InlineHintsOptions.SuppressForParametersThatDifferOnlyBySuffix); - var suppressForParametersThatMatchMethodIntent = !displayAllOverride && options.GetOption(InlineHintsOptions.SuppressForParametersThatMatchMethodIntent); - var suppressForParametersThatMatchArgumentName = !displayAllOverride && options.GetOption(InlineHintsOptions.SuppressForParametersThatMatchArgumentName); + var indexerParameters = displayAllOverride || options.ForIndexerParameters; + var suppressForParametersThatDifferOnlyBySuffix = !displayAllOverride && options.SuppressForParametersThatDifferOnlyBySuffix; + var suppressForParametersThatMatchMethodIntent = !displayAllOverride && options.SuppressForParametersThatMatchMethodIntent; + var suppressForParametersThatMatchArgumentName = !displayAllOverride && options.SuppressForParametersThatMatchArgumentName; var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs b/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs index 03823f01184eb..ca8e1b990878d 100644 --- a/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs +++ b/src/Features/Core/Portable/InlineHints/AbstractInlineTypeHintsService.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; @@ -21,6 +22,13 @@ internal abstract class AbstractInlineTypeHintsService : IInlineTypeHintsService genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.AllowDefaultLiteral | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier | SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + private readonly IGlobalOptionService _globalOptions; + + public AbstractInlineTypeHintsService(IGlobalOptionService globalOptions) + { + _globalOptions = globalOptions; + } + protected abstract TypeHint? TryGetTypeHint( SemanticModel semanticModel, SyntaxNode node, bool displayAllOverride, @@ -32,17 +40,17 @@ internal abstract class AbstractInlineTypeHintsService : IInlineTypeHintsService public async Task> GetInlineHintsAsync( Document document, TextSpan textSpan, CancellationToken cancellationToken) { - var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); + var options = InlineTypeHintsOptions.From(document.Project); var displayOptions = SymbolDescriptionOptions.From(document.Project); + var displayAllOverride = _globalOptions.GetOption(InlineHintsGlobalStateOption.DisplayAllOverride); - var displayAllOverride = options.GetOption(InlineHintsOptions.DisplayAllOverride); - var enabledForTypes = options.GetOption(InlineHintsOptions.EnabledForTypes); + var enabledForTypes = options.EnabledForTypes; if (!enabledForTypes && !displayAllOverride) return ImmutableArray.Empty; - var forImplicitVariableTypes = enabledForTypes && options.GetOption(InlineHintsOptions.ForImplicitVariableTypes); - var forLambdaParameterTypes = enabledForTypes && options.GetOption(InlineHintsOptions.ForLambdaParameterTypes); - var forImplicitObjectCreation = enabledForTypes && options.GetOption(InlineHintsOptions.ForImplicitObjectCreation); + var forImplicitVariableTypes = enabledForTypes && options.ForImplicitVariableTypes; + var forLambdaParameterTypes = enabledForTypes && options.ForLambdaParameterTypes; + var forImplicitObjectCreation = enabledForTypes && options.ForImplicitObjectCreation; if (!forImplicitVariableTypes && !forLambdaParameterTypes && !forImplicitObjectCreation && !displayAllOverride) return ImmutableArray.Empty; diff --git a/src/Features/Core/Portable/InlineHints/InlineHintsGlobalStateOption.cs b/src/Features/Core/Portable/InlineHints/InlineHintsGlobalStateOption.cs new file mode 100644 index 0000000000000..20f67b7fbf050 --- /dev/null +++ b/src/Features/Core/Portable/InlineHints/InlineHintsGlobalStateOption.cs @@ -0,0 +1,20 @@ +// 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.InlineHints +{ + /// + /// TODO: remove. https://github.com/dotnet/roslyn/issues/57283 + /// + internal sealed class InlineHintsGlobalStateOption + { + /// + /// Non-persisted option used to switch to displaying everything while the user is holding ctrl-alt. + /// + public static readonly Option2 DisplayAllOverride = + new("InlineHintsOptions", "DisplayAllOverride", defaultValue: false); + } +} diff --git a/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs b/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs deleted file mode 100644 index a2ed6c959aff0..0000000000000 --- a/src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs +++ /dev/null @@ -1,131 +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.InlineHints -{ - internal static class InlineHintsOptions - { - public static readonly Option2 DisplayAllHintsWhilePressingAltF1 = - new(nameof(InlineHintsOptions), - nameof(DisplayAllHintsWhilePressingAltF1), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.Specific.DisplayAllHintsWhilePressingAltF1")); - - public static readonly PerLanguageOption2 ColorHints = - new(nameof(InlineHintsOptions), - nameof(ColorHints), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorHints")); - - /// - /// Non-persisted option used to switch to displaying everything while the user is holding ctrl-alt. - /// - public static readonly Option2 DisplayAllOverride = - new(nameof(DisplayAllOverride), - nameof(EnabledForParameters), - defaultValue: false); - - public static readonly PerLanguageOption2 EnabledForParameters = - new(nameof(InlineHintsOptions), - nameof(EnabledForParameters), - defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints")); - - public static readonly PerLanguageOption2 ForLiteralParameters = - new(nameof(InlineHintsOptions), - nameof(ForLiteralParameters), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForLiteralParameters")); - - public static readonly PerLanguageOption2 ForObjectCreationParameters = - new(nameof(InlineHintsOptions), - nameof(ForObjectCreationParameters), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForObjectCreationParameters")); - - public static readonly PerLanguageOption2 ForOtherParameters = - new(nameof(InlineHintsOptions), - nameof(ForOtherParameters), - defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForOtherParameters")); - - public static readonly PerLanguageOption2 ForIndexerParameters = - new(nameof(InlineHintsOptions), - nameof(ForIndexerParameters), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForArrayIndexers")); - - public static readonly PerLanguageOption2 SuppressForParametersThatDifferOnlyBySuffix = - new(nameof(InlineHintsOptions), - nameof(SuppressForParametersThatDifferOnlyBySuffix), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatDifferOnlyBySuffix")); - - public static readonly PerLanguageOption2 SuppressForParametersThatMatchMethodIntent = - new(nameof(InlineHintsOptions), - nameof(SuppressForParametersThatMatchMethodIntent), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchMethodIntent")); - - public static readonly PerLanguageOption2 SuppressForParametersThatMatchArgumentName = - new(nameof(InlineHintsOptions), - nameof(SuppressForParametersThatMatchArgumentName), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchArgumentName")); - - public static readonly PerLanguageOption2 EnabledForTypes = - new(nameof(InlineHintsOptions), - nameof(EnabledForTypes), - defaultValue: false, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints")); - - public static readonly PerLanguageOption2 ForImplicitVariableTypes = - new(nameof(InlineHintsOptions), - nameof(ForImplicitVariableTypes), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitVariableTypes")); - - public static readonly PerLanguageOption2 ForLambdaParameterTypes = - new(nameof(InlineHintsOptions), - nameof(ForLambdaParameterTypes), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForLambdaParameterTypes")); - - public static readonly PerLanguageOption2 ForImplicitObjectCreation = - new(nameof(InlineHintsOptions), - nameof(ForImplicitObjectCreation), - defaultValue: true, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitObjectCreation")); - } - - [ExportOptionProvider, Shared] - internal sealed class InlineHintsOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public InlineHintsOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - InlineHintsOptions.DisplayAllHintsWhilePressingAltF1, - InlineHintsOptions.ColorHints, - InlineHintsOptions.EnabledForParameters, - InlineHintsOptions.ForLiteralParameters, - InlineHintsOptions.ForIndexerParameters, - InlineHintsOptions.ForObjectCreationParameters, - InlineHintsOptions.ForOtherParameters, - InlineHintsOptions.EnabledForTypes, - InlineHintsOptions.ForImplicitVariableTypes, - InlineHintsOptions.ForLambdaParameterTypes, - InlineHintsOptions.ForImplicitObjectCreation); - } -} diff --git a/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs b/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs new file mode 100644 index 0000000000000..5d3730ff573a7 --- /dev/null +++ b/src/Features/Core/Portable/InlineHints/InlineParameterHintsOptions.cs @@ -0,0 +1,167 @@ +// 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.InlineHints +{ + internal record struct InlineParameterHintsOptions( + bool EnabledForParameters, + bool ForLiteralParameters, + bool ForIndexerParameters, + bool ForObjectCreationParameters, + bool ForOtherParameters, + bool SuppressForParametersThatDifferOnlyBySuffix, + bool SuppressForParametersThatMatchMethodIntent, + bool SuppressForParametersThatMatchArgumentName) + { + public static InlineParameterHintsOptions From(Project project) + => From(project.Solution.Options, project.Language); + + public static InlineParameterHintsOptions From(OptionSet options, string language) + => new( + EnabledForParameters: options.GetOption(Metadata.EnabledForParameters, language), + ForLiteralParameters: options.GetOption(Metadata.ForLiteralParameters, language), + ForIndexerParameters: options.GetOption(Metadata.ForIndexerParameters, language), + ForObjectCreationParameters: options.GetOption(Metadata.ForObjectCreationParameters, language), + ForOtherParameters: options.GetOption(Metadata.ForOtherParameters, language), + SuppressForParametersThatDifferOnlyBySuffix: options.GetOption(Metadata.SuppressForParametersThatDifferOnlyBySuffix, language), + SuppressForParametersThatMatchMethodIntent: options.GetOption(Metadata.SuppressForParametersThatMatchMethodIntent, language), + SuppressForParametersThatMatchArgumentName: options.GetOption(Metadata.SuppressForParametersThatMatchArgumentName, language)); + + [ExportSolutionOptionProvider, Shared] + internal sealed class Metadata : IOptionProvider + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public Metadata() + { + } + + public ImmutableArray Options { get; } = ImmutableArray.Create( + EnabledForParameters, + ForLiteralParameters, + ForIndexerParameters, + ForObjectCreationParameters, + ForOtherParameters, + SuppressForParametersThatDifferOnlyBySuffix, + SuppressForParametersThatMatchMethodIntent, + SuppressForParametersThatMatchArgumentName); + + private const string FeatureName = "InlineHintsOptions"; + + public static readonly PerLanguageOption2 EnabledForParameters = + new(FeatureName, + nameof(EnabledForParameters), + defaultValue: false, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints")); + + public static readonly PerLanguageOption2 ForLiteralParameters = + new(FeatureName, + nameof(ForLiteralParameters), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForLiteralParameters")); + + public static readonly PerLanguageOption2 ForObjectCreationParameters = + new(FeatureName, + nameof(ForObjectCreationParameters), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForObjectCreationParameters")); + + public static readonly PerLanguageOption2 ForOtherParameters = + new(FeatureName, + nameof(ForOtherParameters), + defaultValue: false, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForOtherParameters")); + + public static readonly PerLanguageOption2 ForIndexerParameters = + new(FeatureName, + nameof(ForIndexerParameters), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForArrayIndexers")); + + public static readonly PerLanguageOption2 SuppressForParametersThatDifferOnlyBySuffix = + new(FeatureName, + nameof(SuppressForParametersThatDifferOnlyBySuffix), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatDifferOnlyBySuffix")); + + public static readonly PerLanguageOption2 SuppressForParametersThatMatchMethodIntent = + new(FeatureName, + nameof(SuppressForParametersThatMatchMethodIntent), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchMethodIntent")); + + public static readonly PerLanguageOption2 SuppressForParametersThatMatchArgumentName = + new(FeatureName, + nameof(SuppressForParametersThatMatchArgumentName), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchArgumentName")); + } + } + + internal record struct InlineTypeHintsOptions( + bool EnabledForTypes, + bool ForImplicitVariableTypes, + bool ForLambdaParameterTypes, + bool ForImplicitObjectCreation) + { + public static InlineTypeHintsOptions From(Project project) + => From(project.Solution.Options, project.Language); + + public static InlineTypeHintsOptions From(OptionSet options, string language) + => new( + EnabledForTypes: options.GetOption(Metadata.EnabledForTypes, language), + ForImplicitVariableTypes: options.GetOption(Metadata.ForImplicitVariableTypes, language), + ForLambdaParameterTypes: options.GetOption(Metadata.ForLambdaParameterTypes, language), + ForImplicitObjectCreation: options.GetOption(Metadata.ForImplicitObjectCreation, language)); + + [ExportSolutionOptionProvider, Shared] + internal sealed class Metadata : IOptionProvider + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public Metadata() + { + } + + public ImmutableArray Options { get; } = ImmutableArray.Create( + EnabledForTypes, + ForImplicitVariableTypes, + ForLambdaParameterTypes, + ForImplicitObjectCreation); + + private const string FeatureName = "InlineHintsOptions"; + + public static readonly PerLanguageOption2 EnabledForTypes = + new(FeatureName, + nameof(EnabledForTypes), + defaultValue: false, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints")); + + public static readonly PerLanguageOption2 ForImplicitVariableTypes = + new(FeatureName, + nameof(ForImplicitVariableTypes), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitVariableTypes")); + + public static readonly PerLanguageOption2 ForLambdaParameterTypes = + new(FeatureName, + nameof(ForLambdaParameterTypes), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForLambdaParameterTypes")); + + public static readonly PerLanguageOption2 ForImplicitObjectCreation = + new(FeatureName, + nameof(ForImplicitObjectCreation), + defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitObjectCreation")); + } + } +} diff --git a/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs b/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs index efdc81382159e..6b3ed191919cb 100644 --- a/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs +++ b/src/Features/Core/Portable/Navigation/NavigationOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Navigation { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class NavigationOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs b/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs index c3a5fd190fccf..96bf53f33c547 100644 --- a/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs +++ b/src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs @@ -15,7 +15,7 @@ internal readonly record struct QuickInfoOptions( bool ShowRemarksInQuickInfo, bool IncludeNavigationHintsInQuickInfo) { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class Metadata : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/SolutionCrawler/InternalSolutionCrawlerOptionsProvider.cs b/src/Features/Core/Portable/SolutionCrawler/InternalSolutionCrawlerOptionsProvider.cs index 2a5e8c14adad1..c97f10c44d793 100644 --- a/src/Features/Core/Portable/SolutionCrawler/InternalSolutionCrawlerOptionsProvider.cs +++ b/src/Features/Core/Portable/SolutionCrawler/InternalSolutionCrawlerOptionsProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.SolutionCrawler { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class InternalSolutionCrawlerOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Features/Core/Portable/Structure/BlockStructureContext.cs b/src/Features/Core/Portable/Structure/BlockStructureContext.cs index 0039d87e3c1bf..1a7315d8ef50f 100644 --- a/src/Features/Core/Portable/Structure/BlockStructureContext.cs +++ b/src/Features/Core/Portable/Structure/BlockStructureContext.cs @@ -2,27 +2,25 @@ // 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.Collections.Immutable; using System.Threading; namespace Microsoft.CodeAnalysis.Structure { - internal class BlockStructureContext + internal sealed class BlockStructureContext { private readonly ImmutableArray.Builder _spans = ImmutableArray.CreateBuilder(); public SyntaxTree SyntaxTree { get; } - public BlockStructureOptionProvider OptionProvider { get; } + public BlockStructureOptions Options { get; } public CancellationToken CancellationToken { get; } internal ImmutableArray Spans => _spans.ToImmutable(); - public BlockStructureContext(SyntaxTree syntaxTree, BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken) + public BlockStructureContext(SyntaxTree syntaxTree, BlockStructureOptions options, CancellationToken cancellationToken) { SyntaxTree = syntaxTree; - OptionProvider = optionProvider; + Options = options; CancellationToken = cancellationToken; } diff --git a/src/Features/Core/Portable/Structure/BlockStructureOptionProvider.cs b/src/Features/Core/Portable/Structure/BlockStructureOptionProvider.cs deleted file mode 100644 index b593d68af9794..0000000000000 --- a/src/Features/Core/Portable/Structure/BlockStructureOptionProvider.cs +++ /dev/null @@ -1,24 +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 Microsoft.CodeAnalysis.Options; - -namespace Microsoft.CodeAnalysis.Structure -{ - internal sealed class BlockStructureOptionProvider - { - private readonly OptionSet _options; - - public BlockStructureOptionProvider(OptionSet options, bool isMetadataAsSource) - { - _options = options; - IsMetadataAsSource = isMetadataAsSource; - } - - public bool IsMetadataAsSource { get; } - - public T GetOption(PerLanguageOption2 option, string language) - => _options.GetOption(option, language); - } -} diff --git a/src/Features/Core/Portable/Structure/BlockStructureOptions.cs b/src/Features/Core/Portable/Structure/BlockStructureOptions.cs index 1b0e7c1123d19..a952ea35c3539 100644 --- a/src/Features/Core/Portable/Structure/BlockStructureOptions.cs +++ b/src/Features/Core/Portable/Structure/BlockStructureOptions.cs @@ -2,44 +2,93 @@ // 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 static class BlockStructureOptions + internal record struct BlockStructureOptions( + bool ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, + bool ShowBlockStructureGuidesForDeclarationLevelConstructs, + bool ShowBlockStructureGuidesForCodeLevelConstructs, + bool ShowOutliningForCommentsAndPreprocessorRegions, + bool ShowOutliningForDeclarationLevelConstructs, + bool ShowOutliningForCodeLevelConstructs, + bool CollapseRegionsWhenCollapsingToDefinitions, + int MaximumBannerLength, + bool IsMetadataAsSource) { - public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = new( - nameof(BlockStructureOptions), nameof(ShowBlockStructureGuidesForCommentsAndPreprocessorRegions), defaultValue: false, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(ShowBlockStructureGuidesForCommentsAndPreprocessorRegions)}")); + public static BlockStructureOptions From(Project project) + => From(project.Solution.Options, project.Language, isMetadataAsSource: project.Solution.Workspace.Kind == WorkspaceKind.MetadataAsSource); - public static readonly PerLanguageOption2 ShowBlockStructureGuidesForDeclarationLevelConstructs = new( - nameof(BlockStructureOptions), nameof(ShowBlockStructureGuidesForDeclarationLevelConstructs), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(ShowBlockStructureGuidesForDeclarationLevelConstructs)}")); + 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); - public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCodeLevelConstructs = new( - nameof(BlockStructureOptions), nameof(ShowBlockStructureGuidesForCodeLevelConstructs), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(ShowBlockStructureGuidesForCodeLevelConstructs)}")); + [ExportSolutionOptionProvider, Shared] + internal sealed class Metadata : IOptionProvider + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public Metadata() + { + } - public static readonly PerLanguageOption2 ShowOutliningForCommentsAndPreprocessorRegions = new( - nameof(BlockStructureOptions), nameof(ShowOutliningForCommentsAndPreprocessorRegions), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(ShowOutliningForCommentsAndPreprocessorRegions)}")); + public ImmutableArray Options { get; } = ImmutableArray.Create( + ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, + ShowBlockStructureGuidesForDeclarationLevelConstructs, + ShowBlockStructureGuidesForCodeLevelConstructs, + ShowOutliningForCommentsAndPreprocessorRegions, + ShowOutliningForDeclarationLevelConstructs, + ShowOutliningForCodeLevelConstructs, + CollapseRegionsWhenCollapsingToDefinitions, + MaximumBannerLength); - public static readonly PerLanguageOption2 ShowOutliningForDeclarationLevelConstructs = new( - nameof(BlockStructureOptions), nameof(ShowOutliningForDeclarationLevelConstructs), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(ShowOutliningForDeclarationLevelConstructs)}")); + private const string FeatureName = "BlockStructureOptions"; - public static readonly PerLanguageOption2 ShowOutliningForCodeLevelConstructs = new( - nameof(BlockStructureOptions), nameof(ShowOutliningForCodeLevelConstructs), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(ShowOutliningForCodeLevelConstructs)}")); + public static readonly PerLanguageOption2 ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = new( + FeatureName, "ShowBlockStructureGuidesForCommentsAndPreprocessorRegions", defaultValue: false, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions")); - public static readonly PerLanguageOption2 CollapseRegionsWhenCollapsingToDefinitions = new( - nameof(BlockStructureOptions), nameof(CollapseRegionsWhenCollapsingToDefinitions), defaultValue: false, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(CollapseRegionsWhenCollapsingToDefinitions)}")); + public static readonly PerLanguageOption2 ShowBlockStructureGuidesForDeclarationLevelConstructs = new( + FeatureName, "ShowBlockStructureGuidesForDeclarationLevelConstructs", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowBlockStructureGuidesForDeclarationLevelConstructs")); - public static readonly PerLanguageOption2 MaximumBannerLength = new( - nameof(BlockStructureOptions), - nameof(MaximumBannerLength), defaultValue: 80, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(MaximumBannerLength)}")); + 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")); + } } } diff --git a/src/Features/Core/Portable/Structure/BlockStructureServiceWithProviders.cs b/src/Features/Core/Portable/Structure/BlockStructureServiceWithProviders.cs index 0b35ad0fe701c..7543d0317b84b 100644 --- a/src/Features/Core/Portable/Structure/BlockStructureServiceWithProviders.cs +++ b/src/Features/Core/Portable/Structure/BlockStructureServiceWithProviders.cs @@ -55,30 +55,26 @@ public override async Task GetBlockStructureAsync( public BlockStructure GetBlockStructure( SyntaxTree syntaxTree, - OptionSet options, - bool isMetadataAsSource, + in BlockStructureOptions options, CancellationToken cancellationToken) { - var context = CreateContext(syntaxTree, options, isMetadataAsSource, cancellationToken); + var context = CreateContext(syntaxTree, options, cancellationToken); return GetBlockStructure(context, _providers); } private static async Task CreateContextAsync(Document document, CancellationToken cancellationToken) { var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); - var options = document.Project.Solution.Options; - var isMetadataAsSource = document.Project.Solution.Workspace.Kind == WorkspaceKind.MetadataAsSource; - return CreateContext(syntaxTree, options, isMetadataAsSource, cancellationToken); + var options = BlockStructureOptions.From(document.Project); + return CreateContext(syntaxTree, options, cancellationToken); } private static BlockStructureContext CreateContext( SyntaxTree syntaxTree, - OptionSet options, - bool isMetadataAsSource, + in BlockStructureOptions options, CancellationToken cancellationToken) { - var optionProvider = new BlockStructureOptionProvider(options, isMetadataAsSource); - return new BlockStructureContext(syntaxTree, optionProvider, cancellationToken); + return new BlockStructureContext(syntaxTree, options, cancellationToken); } private static BlockStructure GetBlockStructure( @@ -93,38 +89,17 @@ private static BlockStructure GetBlockStructure( private static BlockStructure CreateBlockStructure(BlockStructureContext context) { - var language = context.SyntaxTree.Options.Language; - - var showIndentGuidesForCodeLevelConstructs = context.OptionProvider.GetOption(BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, language); - var showIndentGuidesForDeclarationLevelConstructs = context.OptionProvider.GetOption(BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, language); - var showIndentGuidesForCommentsAndPreprocessorRegions = context.OptionProvider.GetOption(BlockStructureOptions.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions, language); - var showOutliningForCodeLevelConstructs = context.OptionProvider.GetOption(BlockStructureOptions.ShowOutliningForCodeLevelConstructs, language); - var showOutliningForDeclarationLevelConstructs = context.OptionProvider.GetOption(BlockStructureOptions.ShowOutliningForDeclarationLevelConstructs, language); - var showOutliningForCommentsAndPreprocessorRegions = context.OptionProvider.GetOption(BlockStructureOptions.ShowOutliningForCommentsAndPreprocessorRegions, language); - using var _ = ArrayBuilder.GetInstance(out var updatedSpans); foreach (var span in context.Spans) { - var updatedSpan = UpdateBlockSpan(span, - showIndentGuidesForCodeLevelConstructs, - showIndentGuidesForDeclarationLevelConstructs, - showIndentGuidesForCommentsAndPreprocessorRegions, - showOutliningForCodeLevelConstructs, - showOutliningForDeclarationLevelConstructs, - showOutliningForCommentsAndPreprocessorRegions); + var updatedSpan = UpdateBlockSpan(span, context.Options); updatedSpans.Add(updatedSpan); } return new BlockStructure(updatedSpans.ToImmutable()); } - private static BlockSpan UpdateBlockSpan(BlockSpan blockSpan, - bool showIndentGuidesForCodeLevelConstructs, - bool showIndentGuidesForDeclarationLevelConstructs, - bool showIndentGuidesForCommentsAndPreprocessorRegions, - bool showOutliningForCodeLevelConstructs, - bool showOutliningForDeclarationLevelConstructs, - bool showOutliningForCommentsAndPreprocessorRegions) + private static BlockSpan UpdateBlockSpan(BlockSpan blockSpan, in BlockStructureOptions options) { var type = blockSpan.Type; @@ -132,9 +107,9 @@ private static BlockSpan UpdateBlockSpan(BlockSpan blockSpan, var isMemberLevel = BlockTypes.IsCodeLevelConstruct(type); var isComment = BlockTypes.IsCommentOrPreprocessorRegion(type); - if ((!showIndentGuidesForDeclarationLevelConstructs && isTopLevel) || - (!showIndentGuidesForCodeLevelConstructs && isMemberLevel) || - (!showIndentGuidesForCommentsAndPreprocessorRegions && isComment)) + if ((!options.ShowBlockStructureGuidesForDeclarationLevelConstructs && isTopLevel) || + (!options.ShowBlockStructureGuidesForCodeLevelConstructs && isMemberLevel) || + (!options.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions && isComment)) { type = BlockTypes.Nonstructural; } @@ -142,9 +117,9 @@ private static BlockSpan UpdateBlockSpan(BlockSpan blockSpan, var isCollapsible = blockSpan.IsCollapsible; if (isCollapsible) { - if ((!showOutliningForDeclarationLevelConstructs && isTopLevel) || - (!showOutliningForCodeLevelConstructs && isMemberLevel) || - (!showOutliningForCommentsAndPreprocessorRegions && isComment)) + if ((!options.ShowOutliningForDeclarationLevelConstructs && isTopLevel) || + (!options.ShowOutliningForCodeLevelConstructs && isMemberLevel) || + (!options.ShowOutliningForCommentsAndPreprocessorRegions && isComment)) { isCollapsible = false; } diff --git a/src/Features/Core/Portable/Structure/Syntax/AbstractBlockStructureProvider.cs b/src/Features/Core/Portable/Structure/Syntax/AbstractBlockStructureProvider.cs index 025bff73be755..9dcab85ab51ce 100644 --- a/src/Features/Core/Portable/Structure/Syntax/AbstractBlockStructureProvider.cs +++ b/src/Features/Core/Portable/Structure/Syntax/AbstractBlockStructureProvider.cs @@ -37,7 +37,7 @@ public override void ProvideBlockStructure(BlockStructureContext context) var syntaxRoot = context.SyntaxTree.GetRoot(context.CancellationToken); using var spans = TemporaryArray.Empty; BlockSpanCollector.CollectBlockSpans( - syntaxRoot, context.OptionProvider, _nodeProviderMap, _triviaProviderMap, ref spans.AsRef(), context.CancellationToken); + syntaxRoot, context.Options, _nodeProviderMap, _triviaProviderMap, ref spans.AsRef(), context.CancellationToken); foreach (var span in spans) context.AddBlockSpan(span); diff --git a/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxNodeStructureProvider.cs b/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxNodeStructureProvider.cs index 565a0a936f3ee..6beaa906d84f0 100644 --- a/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxNodeStructureProvider.cs +++ b/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxNodeStructureProvider.cs @@ -14,7 +14,7 @@ internal abstract class AbstractSyntaxNodeStructureProvider : Abstr public sealed override void CollectBlockSpans( SyntaxTrivia trivia, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { throw new NotSupportedException(); @@ -24,18 +24,20 @@ public sealed override void CollectBlockSpans( SyntaxToken previousToken, SyntaxNode node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { if (node is TSyntaxNode tSyntax) { - CollectBlockSpans(previousToken, tSyntax, ref spans, optionProvider, cancellationToken); + CollectBlockSpans(previousToken, tSyntax, ref spans, options, cancellationToken); } } protected abstract void CollectBlockSpans( SyntaxToken previousToken, - TSyntaxNode node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, CancellationToken cancellationToken); + TSyntaxNode node, + ref TemporaryArray spans, + BlockStructureOptions options, + CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxStructureProvider.cs b/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxStructureProvider.cs index d828bbf910e6e..f29dee02fe424 100644 --- a/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxStructureProvider.cs +++ b/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxStructureProvider.cs @@ -13,13 +13,13 @@ public abstract void CollectBlockSpans( SyntaxToken previousToken, SyntaxNode node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken); public abstract void CollectBlockSpans( SyntaxTrivia trivia, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxTriviaStructureProvider.cs b/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxTriviaStructureProvider.cs index 46c870df5bbf6..b8a3a5c66bd32 100644 --- a/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxTriviaStructureProvider.cs +++ b/src/Features/Core/Portable/Structure/Syntax/AbstractSyntaxTriviaStructureProvider.cs @@ -14,7 +14,7 @@ public sealed override void CollectBlockSpans( SyntaxToken previousToken, SyntaxNode node, ref TemporaryArray spans, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, CancellationToken cancellationToken) { throw new NotSupportedException(); diff --git a/src/Features/Core/Portable/Structure/Syntax/BlockSpanCollector.cs b/src/Features/Core/Portable/Structure/Syntax/BlockSpanCollector.cs index a11cbd9bf8dcf..2493ec8572345 100644 --- a/src/Features/Core/Portable/Structure/Syntax/BlockSpanCollector.cs +++ b/src/Features/Core/Portable/Structure/Syntax/BlockSpanCollector.cs @@ -9,20 +9,20 @@ namespace Microsoft.CodeAnalysis.Structure { - internal class BlockSpanCollector + internal sealed class BlockSpanCollector { - private readonly BlockStructureOptionProvider _optionProvider; + private readonly BlockStructureOptions _options; private readonly ImmutableDictionary> _nodeProviderMap; private readonly ImmutableDictionary> _triviaProviderMap; private readonly CancellationToken _cancellationToken; private BlockSpanCollector( - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, ImmutableDictionary> nodeOutlinerMap, ImmutableDictionary> triviaOutlinerMap, CancellationToken cancellationToken) { - _optionProvider = optionProvider; + _options = options; _nodeProviderMap = nodeOutlinerMap; _triviaProviderMap = triviaOutlinerMap; _cancellationToken = cancellationToken; @@ -30,13 +30,13 @@ private BlockSpanCollector( public static void CollectBlockSpans( SyntaxNode syntaxRoot, - BlockStructureOptionProvider optionProvider, + BlockStructureOptions options, ImmutableDictionary> nodeOutlinerMap, ImmutableDictionary> triviaOutlinerMap, ref TemporaryArray spans, CancellationToken cancellationToken) { - var collector = new BlockSpanCollector(optionProvider, nodeOutlinerMap, triviaOutlinerMap, cancellationToken); + var collector = new BlockSpanCollector(options, nodeOutlinerMap, triviaOutlinerMap, cancellationToken); collector.Collect(syntaxRoot, ref spans); } @@ -67,7 +67,7 @@ private void GetBlockSpans(SyntaxToken previousToken, SyntaxNode node, ref Tempo { _cancellationToken.ThrowIfCancellationRequested(); - provider.CollectBlockSpans(previousToken, node, ref spans, _optionProvider, _cancellationToken); + provider.CollectBlockSpans(previousToken, node, ref spans, _options, _cancellationToken); } } } @@ -89,7 +89,7 @@ private void GetOutliningSpans(SyntaxTriviaList triviaList, ref TemporaryArray(); - var blockStructure = blockStructureService.GetBlockStructure(syntaxTree, options, isMetadataAsSource, cancellationToken); + var blockStructure = blockStructureService.GetBlockStructure(syntaxTree, options, cancellationToken); if (blockStructure == null) { return Array.Empty(); diff --git a/src/Features/LanguageServer/Protocol/LspOptions.cs b/src/Features/LanguageServer/Protocol/LspOptions.cs index 906289a453d7a..427a909d4b0e2 100644 --- a/src/Features/LanguageServer/Protocol/LspOptions.cs +++ b/src/Features/LanguageServer/Protocol/LspOptions.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer { - [ExportOptionProvider, Shared] + [ExportGlobalOptionProvider, Shared] internal sealed class LspOptions : IOptionProvider { private const string LocalRegistryPath = @"Roslyn\Internal\Lsp\"; diff --git a/src/Features/Lsif/Generator/Generator.cs b/src/Features/Lsif/Generator/Generator.cs index 3785c40127635..7a7274f736a6f 100644 --- a/src/Features/Lsif/Generator/Generator.cs +++ b/src/Features/Lsif/Generator/Generator.cs @@ -16,6 +16,7 @@ using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.QuickInfo; +using Microsoft.CodeAnalysis.Structure; using Roslyn.Utilities; using Methods = Microsoft.VisualStudio.LanguageServer.Protocol.Methods; @@ -249,7 +250,8 @@ SymbolKind.RangeVariable or lsifJsonWriter.Write(Edge.Create("contains", documentVertex.GetId(), rangeVertices, idFactory)); // Write the folding ranges for the document. - var foldingRanges = FoldingRangesHandler.GetFoldingRanges(syntaxTree, languageServices, options, isMetadataAsSource: false, CancellationToken.None); + var blockStructureOptions = BlockStructureOptions.From(options, languageServices.Language, isMetadataAsSource: false); + var foldingRanges = FoldingRangesHandler.GetFoldingRanges(syntaxTree, languageServices, blockStructureOptions, CancellationToken.None); var foldingRangeResult = new FoldingRangeResult(foldingRanges, idFactory); lsifJsonWriter.Write(foldingRangeResult); lsifJsonWriter.Write(Edge.Create(Methods.TextDocumentFoldingRangeName, documentVertex.GetId(), foldingRangeResult.GetId(), idFactory)); diff --git a/src/Features/VisualBasic/Portable/InlineHints/VisualBasicInlineParameterNameHintsService.vb b/src/Features/VisualBasic/Portable/InlineHints/VisualBasicInlineParameterNameHintsService.vb index 838b8737998a0..1e17e2066398c 100644 --- a/src/Features/VisualBasic/Portable/InlineHints/VisualBasicInlineParameterNameHintsService.vb +++ b/src/Features/VisualBasic/Portable/InlineHints/VisualBasicInlineParameterNameHintsService.vb @@ -7,6 +7,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.InlineHints Imports Microsoft.CodeAnalysis.LanguageServices +Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -17,7 +18,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.InlineHints - Public Sub New() + Public Sub New(globalOptions As IGlobalOptionService) + MyBase.New(globalOptions) End Sub Protected Overrides Sub AddAllParameterNameHintLocations( diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/AccessorDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/AccessorDeclarationStructureProvider.vb index 56e445fd1f9ea..e5c0ad0f10bbf 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/AccessorDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/AccessorDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, accessorDeclaration As AccessorStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(accessorDeclaration, spans, optionProvider) + CollectCommentsRegions(accessorDeclaration, spans, options) Dim block = TryCast(accessorDeclaration.Parent, AccessorBlockSyntax) If Not block?.EndBlockStatement.IsMissing Then diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/CollectionInitializerStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/CollectionInitializerStructureProvider.vb index 76bf0a27446f1..5fdc2a85b6887 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/CollectionInitializerStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/CollectionInitializerStructureProvider.vb @@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As CollectionInitializerSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) ' We don't want to make a span for the "{ ... }" in "From { ... }". The latter diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/CompilationUnitStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/CompilationUnitStructureProvider.vb index 50523aeffbbf7..a7c159c0a37ba 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/CompilationUnitStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/CompilationUnitStructureProvider.vb @@ -15,9 +15,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, compilationUnit As CompilationUnitSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(compilationUnit, spans, optionProvider) + CollectCommentsRegions(compilationUnit, spans, options) If Not compilationUnit.Imports.IsEmpty Then Dim startPos = compilationUnit.Imports.First().SpanStart diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.vb index ff861ec423769..8a34075867c20 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/ConstructorDeclarationStructureProvider.vb @@ -14,10 +14,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, constructorDeclaration As SubNewStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(constructorDeclaration, spans, optionProvider) + CollectCommentsRegions(constructorDeclaration, spans, options) Dim block = TryCast(constructorDeclaration.Parent, ConstructorBlockSyntax) If Not block?.EndBlockStatement.IsMissing Then diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/DelegateDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/DelegateDeclarationStructureProvider.vb index 83a0aafcd10e8..3c6309b2177c3 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/DelegateDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/DelegateDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, delegateDeclaration As DelegateStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(delegateDeclaration, spans, optionProvider) + CollectCommentsRegions(delegateDeclaration, spans, options) End Sub End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.vb index 3b2fe689ce6bf..ffc46e6c907e9 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/DisabledTextTriviaStructureProvider.vb @@ -13,7 +13,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Public Overrides Sub CollectBlockSpans(trivia As SyntaxTrivia, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) If trivia.Kind = SyntaxKind.DisabledTextTrivia Then ' Don't include trailing line breaks in spanToCollapse diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/DoLoopBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/DoLoopBlockStructureProvider.vb index 897c409618476..15f50596fcfee 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/DoLoopBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/DoLoopBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As DoLoopBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.DoStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/DocumentationCommentStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/DocumentationCommentStructureProvider.vb index 73ee233ffbcd8..a820ea14bbdef 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/DocumentationCommentStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/DocumentationCommentStructureProvider.vb @@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, documentationComment As DocumentationCommentTriviaSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) Dim firstCommentToken = documentationComment.ChildNodesAndTokens().FirstOrNull() Dim lastCommentToken = documentationComment.ChildNodesAndTokens().LastOrNull() @@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Dim fullSpan = TextSpan.FromBounds(startPos, endPos) - Dim maxBannerLength = optionProvider.GetOption(BlockStructureOptions.MaximumBannerLength, LanguageNames.VisualBasic) + Dim maxBannerLength = options.MaximumBannerLength Dim bannerText = VisualBasicFileBannerFacts.Instance.GetBannerText( documentationComment, maxBannerLength, cancellationToken) diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/EnumDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/EnumDeclarationStructureProvider.vb index 652b59cf48022..d80a4c8a8a9c1 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/EnumDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/EnumDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, enumDeclaration As EnumStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(enumDeclaration, spans, optionProvider) + CollectCommentsRegions(enumDeclaration, spans, options) Dim block = TryCast(enumDeclaration.Parent, EnumBlockSyntax) If Not block?.EndEnumStatement.IsMissing Then @@ -24,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure block, bannerNode:=enumDeclaration, autoCollapse:=True, type:=BlockTypes.Type, isCollapsible:=True)) - CollectCommentsRegions(block.EndEnumStatement, spans, optionProvider) + CollectCommentsRegions(block.EndEnumStatement, spans, options) End If End Sub End Class diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.vb index 0c38fa7f9412f..6f69be4eeaaec 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/EnumMemberDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, enumMemberDeclaration As EnumMemberDeclarationSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(enumMemberDeclaration, spans, optionProvider) + CollectCommentsRegions(enumMemberDeclaration, spans, options) End Sub End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/EventDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/EventDeclarationStructureProvider.vb index 73c0cfc507838..63c589135d134 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/EventDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/EventDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, eventDeclaration As EventStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(eventDeclaration, spans, optionProvider) + CollectCommentsRegions(eventDeclaration, spans, options) Dim block = TryCast(eventDeclaration.Parent, EventBlockSyntax) If Not block?.EndEventStatement.IsMissing Then @@ -24,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure block, bannerNode:=eventDeclaration, autoCollapse:=True, type:=BlockTypes.Member, isCollapsible:=True)) - CollectCommentsRegions(block.EndEventStatement, spans, optionProvider) + CollectCommentsRegions(block.EndEventStatement, spans, options) End If End Sub End Class diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/ExternalMethodDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/ExternalMethodDeclarationStructureProvider.vb index f78e050adc983..d6ece26c30a5f 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/ExternalMethodDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/ExternalMethodDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, externalMethodDeclaration As DeclareStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(externalMethodDeclaration, spans, optionProvider) + CollectCommentsRegions(externalMethodDeclaration, spans, options) End Sub End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/FieldDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/FieldDeclarationStructureProvider.vb index fb1b2454c9659..169e8a679159f 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/FieldDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/FieldDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, fieldDeclaration As FieldDeclarationSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(fieldDeclaration, spans, optionProvider) + CollectCommentsRegions(fieldDeclaration, spans, options) End Sub End Class End Namespace diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/ForBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/ForBlockStructureProvider.vb index a4be19330abbd..fd91efe945f8d 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/ForBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/ForBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As ForBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.ForOrForEachStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/ForEachBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/ForEachBlockStructureProvider.vb index f11b219d5a93a..8d52dad6ad464 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/ForEachBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/ForEachBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As ForEachBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.ForOrForEachStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.vb index ddd3f506d7ad7..7ea0896215908 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/InterpolatedStringExpressionStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As InterpolatedStringExpressionSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) If node.DollarSignDoubleQuoteToken.IsMissing OrElse node.DoubleQuoteToken.IsMissing Then diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/MethodDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/MethodDeclarationStructureProvider.vb index a5bfd82ac5fa4..749e31acb30eb 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/MethodDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/MethodDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, methodDeclaration As MethodStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(methodDeclaration, spans, optionProvider) + CollectCommentsRegions(methodDeclaration, spans, options) Dim block = TryCast(methodDeclaration.Parent, MethodBlockSyntax) If Not block?.EndBlockStatement.IsMissing Then diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/MultiLineIfBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/MultiLineIfBlockStructureProvider.vb index d049e1731d390..2063bab8cb731 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/MultiLineIfBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/MultiLineIfBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As MultiLineIfBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.IfStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/MultilineLambdaStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/MultilineLambdaStructureProvider.vb index 16a8d12928362..be48cb907c22b 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/MultilineLambdaStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/MultilineLambdaStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, lambdaExpression As MultiLineLambdaExpressionSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) If Not lambdaExpression.EndSubOrFunctionStatement.IsMissing Then spans.AddIfNotNull(CreateBlockSpanFromBlock( diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.vb index 80c8338da31da..6beafc9da0139 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/NamespaceDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, namespaceDeclaration As NamespaceStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(namespaceDeclaration, spans, optionProvider) + CollectCommentsRegions(namespaceDeclaration, spans, options) Dim block = TryCast(namespaceDeclaration.Parent, NamespaceBlockSyntax) If Not block?.EndNamespaceStatement.IsMissing Then @@ -24,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure block, bannerNode:=namespaceDeclaration, autoCollapse:=False, type:=BlockTypes.Namespace, isCollapsible:=True)) - CollectCommentsRegions(block.EndNamespaceStatement, spans, optionProvider) + CollectCommentsRegions(block.EndNamespaceStatement, spans, options) End If End Sub End Class diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/ObjectCreationInitializerStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/ObjectCreationInitializerStructureProvider.vb index 3119bfb8703ff..b46b720965b1b 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/ObjectCreationInitializerStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/ObjectCreationInitializerStructureProvider.vb @@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As ObjectCreationInitializerSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) ' ObjectCreationInitializerSyntax is either "With { ... }" or "From { ... }" diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/OperatorDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/OperatorDeclarationStructureProvider.vb index 31211b98ffe1e..8d93bf24cb82b 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/OperatorDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/OperatorDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, operatorDeclaration As OperatorStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(operatorDeclaration, spans, optionProvider) + CollectCommentsRegions(operatorDeclaration, spans, options) Dim block = TryCast(operatorDeclaration.Parent, OperatorBlockSyntax) If Not block?.EndBlockStatement.IsMissing Then diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/PropertyDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/PropertyDeclarationStructureProvider.vb index 4050ac7c6c2c4..a17901d314ea3 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/PropertyDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/PropertyDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, propertyDeclaration As PropertyStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(propertyDeclaration, spans, optionProvider) + CollectCommentsRegions(propertyDeclaration, spans, options) Dim block = TryCast(propertyDeclaration.Parent, PropertyBlockSyntax) If Not block?.EndPropertyStatement.IsMissing Then @@ -24,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure block, bannerNode:=propertyDeclaration, autoCollapse:=True, type:=BlockTypes.Member, isCollapsible:=True)) - CollectCommentsRegions(block.EndPropertyStatement, spans, optionProvider) + CollectCommentsRegions(block.EndPropertyStatement, spans, options) End If End Sub End Class diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/RegionDirectiveStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/RegionDirectiveStructureProvider.vb index d02a35f257e7e..295d00778fa5b 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/RegionDirectiveStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/RegionDirectiveStructureProvider.vb @@ -25,7 +25,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, regionDirective As RegionDirectiveTriviaSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, CancellationToken As CancellationToken) Dim matchingDirective = regionDirective.GetMatchingStartOrEndDirective(CancellationToken) If matchingDirective IsNot Nothing Then @@ -37,15 +37,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure ' #End Region ' ' For other files, auto-collapse regions based on the user option. - Dim autoCollapse = optionProvider.IsMetadataAsSource OrElse optionProvider.GetOption( - BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, LanguageNames.VisualBasic) + Dim autoCollapse = options.IsMetadataAsSource OrElse options.CollapseRegionsWhenCollapsingToDefinitions Dim span = TextSpan.FromBounds(regionDirective.SpanStart, matchingDirective.Span.End) spans.AddIfNotNull(CreateBlockSpan( span, span, GetBannerText(regionDirective), autoCollapse:=autoCollapse, - isDefaultCollapsed:=Not optionProvider.IsMetadataAsSource, + isDefaultCollapsed:=Not options.IsMetadataAsSource, type:=BlockTypes.PreprocessorRegion, isCollapsible:=True)) End If diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/SelectBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/SelectBlockStructureProvider.vb index 04008510d733b..54d37a5db2190 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/SelectBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/SelectBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As SelectBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.SelectStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.vb index bcd8b8337849c..edbc57ab0b12b 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/StringLiteralExpressionStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As LiteralExpressionSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) If node.IsKind(SyntaxKind.StringLiteralExpression) AndAlso Not node.ContainsDiagnostics Then diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/SyncLockBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/SyncLockBlockStructureProvider.vb index 4d0cc0cd4ff4c..f80788c969027 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/SyncLockBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/SyncLockBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As SyncLockBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.SyncLockStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/TryBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/TryBlockStructureProvider.vb index 07845b925d632..5521c8c9410fd 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/TryBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/TryBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As TryBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.TryStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/TypeDeclarationStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/TypeDeclarationStructureProvider.vb index 52a88248f4b41..8b867f778f10f 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/TypeDeclarationStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/TypeDeclarationStructureProvider.vb @@ -14,9 +14,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, typeDeclaration As TypeStatementSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) - CollectCommentsRegions(typeDeclaration, spans, optionProvider) + CollectCommentsRegions(typeDeclaration, spans, options) Dim block = TryCast(typeDeclaration.Parent, TypeBlockSyntax) If Not block?.EndBlockStatement.IsMissing Then @@ -24,7 +24,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure block, bannerNode:=typeDeclaration, autoCollapse:=False, type:=BlockTypes.Type, isCollapsible:=True)) - CollectCommentsRegions(block.EndBlockStatement, spans, optionProvider) + CollectCommentsRegions(block.EndBlockStatement, spans, options) End If End Sub End Class diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/UsingBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/UsingBlockStructureProvider.vb index 32a8ed65c3f14..6014ae7aff7c3 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/UsingBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/UsingBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As UsingBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.UsingStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/WhileBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/WhileBlockStructureProvider.vb index 4af6c9414a63d..44f15e4d5cb5c 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/WhileBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/WhileBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As WhileBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.WhileStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/WithBlockStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/WithBlockStructureProvider.vb index 1e0835d4a1834..b698ddbf2fd72 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/WithBlockStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/WithBlockStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, node As WithBlockSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) spans.AddIfNotNull(CreateBlockSpanFromBlock( node, node.WithStatement, autoCollapse:=False, diff --git a/src/Features/VisualBasic/Portable/Structure/Providers/XmlExpressionStructureProvider.vb b/src/Features/VisualBasic/Portable/Structure/Providers/XmlExpressionStructureProvider.vb index 1ec2df746cf1a..c9869c64055d1 100644 --- a/src/Features/VisualBasic/Portable/Structure/Providers/XmlExpressionStructureProvider.vb +++ b/src/Features/VisualBasic/Portable/Structure/Providers/XmlExpressionStructureProvider.vb @@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Protected Overrides Sub CollectBlockSpans(previousToken As SyntaxToken, xmlExpression As XmlNodeSyntax, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider, + options As BlockStructureOptions, cancellationToken As CancellationToken) ' If this XML expression is inside structured trivia (i.e. an XML doc comment), don't outline. If xmlExpression.HasAncestor(Of DocumentationCommentTriviaSyntax)() Then diff --git a/src/Features/VisualBasic/Portable/Structure/VisualBasicStructureHelpers.vb b/src/Features/VisualBasic/Portable/Structure/VisualBasicStructureHelpers.vb index 2a7d3d8331201..fcc30690997c3 100644 --- a/src/Features/VisualBasic/Portable/Structure/VisualBasicStructureHelpers.vb +++ b/src/Features/VisualBasic/Portable/Structure/VisualBasicStructureHelpers.vb @@ -78,13 +78,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure Friend Sub CollectCommentsRegions(node As SyntaxNode, ByRef spans As TemporaryArray(Of BlockSpan), - optionProvider As BlockStructureOptionProvider) + options As BlockStructureOptions) If node Is Nothing Then Throw New ArgumentNullException(NameOf(node)) End If Dim span As BlockSpan = Nothing - If optionProvider.IsMetadataAsSource AndAlso TryGetLeadingCollapsibleSpan(node, span) Then + If options.IsMetadataAsSource AndAlso TryGetLeadingCollapsibleSpan(node, span) Then spans.Add(span) Else Dim triviaList = node.GetLeadingTrivia() diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FSharpBraceMatcher.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FSharpBraceMatcher.cs index 52a4367a7fbc0..59badf84a22b4 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FSharpBraceMatcher.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FSharpBraceMatcher.cs @@ -26,17 +26,10 @@ public FSharpBraceMatcher(IFSharpBraceMatcher braceMatcher) _braceMatcher = braceMatcher; } - public async Task FindBracesAsync(Document document, int position, CancellationToken cancellationToken = default) + public async Task FindBracesAsync(Document document, int position, BraceMatchingOptions options, CancellationToken cancellationToken) { var result = await _braceMatcher.FindBracesAsync(document, position, cancellationToken).ConfigureAwait(false); - if (result.HasValue) - { - return new Microsoft.CodeAnalysis.Editor.BraceMatchingResult(result.Value.LeftSpan, result.Value.RightSpan); - } - else - { - return null; - } + return result.HasValue ? new BraceMatchingResult(result.Value.LeftSpan, result.Value.RightSpan) : null; } } } diff --git a/src/Tools/ExternalAccess/OmniSharp/Structure/OmniSharpBlockStructureOptions.cs b/src/Tools/ExternalAccess/OmniSharp/Structure/OmniSharpBlockStructureOptions.cs index e2ea39bb9534c..3a85176e96456 100644 --- a/src/Tools/ExternalAccess/OmniSharp/Structure/OmniSharpBlockStructureOptions.cs +++ b/src/Tools/ExternalAccess/OmniSharp/Structure/OmniSharpBlockStructureOptions.cs @@ -12,8 +12,8 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.Structure { internal static class OmniSharpBlockStructureOptions { - public static readonly PerLanguageOption ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = (PerLanguageOption)BlockStructureOptions.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions; + public static readonly PerLanguageOption ShowBlockStructureGuidesForCommentsAndPreprocessorRegions = (PerLanguageOption)BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCommentsAndPreprocessorRegions; - public static readonly PerLanguageOption ShowOutliningForCommentsAndPreprocessorRegions = (PerLanguageOption)BlockStructureOptions.ShowOutliningForCommentsAndPreprocessorRegions; + public static readonly PerLanguageOption ShowOutliningForCommentsAndPreprocessorRegions = (PerLanguageOption)BlockStructureOptions.Metadata.ShowOutliningForCommentsAndPreprocessorRegions; } } diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index 5a8a867145791..f1e592218aaf3 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Editor.CSharp.SplitStringLiteral; using Microsoft.CodeAnalysis.Editor.Implementation.Suggestions; using Microsoft.CodeAnalysis.Editor.InlineDiagnostics; +using Microsoft.CodeAnalysis.Editor.InlineHints; using Microsoft.CodeAnalysis.Editor.Options; using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions; @@ -76,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.ShowOutliningForDeclarationLevelConstructs, LanguageNames.CSharp); - BindToOption(Show_outlining_for_code_level_constructs, BlockStructureOptions.ShowOutliningForCodeLevelConstructs, LanguageNames.CSharp); - BindToOption(Show_outlining_for_comments_and_preprocessor_regions, BlockStructureOptions.ShowOutliningForCommentsAndPreprocessorRegions, LanguageNames.CSharp); - BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, 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(Fade_out_unused_usings, FadingOptions.FadeOutUnusedImports, LanguageNames.CSharp); BindToOption(Fade_out_unreachable_code, FadingOptions.FadeOutUnreachableCode, LanguageNames.CSharp); - BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.CSharp); - BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, 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(GenerateXmlDocCommentsForTripleSlash, DocumentationCommentOptions.Metadata.AutoXmlDocCommentGeneration, LanguageNames.CSharp); BindToOption(InsertSlashSlashAtTheStartOfNewLinesWhenWritingSingleLineComments, SplitStringLiteralOptions.Enabled, LanguageNames.CSharp); @@ -124,22 +125,22 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(Editor_color_scheme, ColorSchemeOptions.ColorScheme); - BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsOptions.DisplayAllHintsWhilePressingAltF1); - BindToOption(ColorHints, InlineHintsOptions.ColorHints, LanguageNames.CSharp); + BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsViewOptions.DisplayAllHintsWhilePressingAltF1); + BindToOption(ColorHints, InlineHintsViewOptions.ColorHints, LanguageNames.CSharp); - BindToOption(DisplayInlineParameterNameHints, InlineHintsOptions.EnabledForParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForLiterals, InlineHintsOptions.ForLiteralParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForNewExpressions, InlineHintsOptions.ForObjectCreationParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForEverythingElse, InlineHintsOptions.ForOtherParameters, LanguageNames.CSharp); - BindToOption(ShowHintsForIndexers, InlineHintsOptions.ForIndexerParameters, LanguageNames.CSharp); - BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineHintsOptions.SuppressForParametersThatMatchMethodIntent, LanguageNames.CSharp); - BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineHintsOptions.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.CSharp); - BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineHintsOptions.SuppressForParametersThatMatchArgumentName, LanguageNames.CSharp); + BindToOption(DisplayInlineParameterNameHints, InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForLiterals, InlineParameterHintsOptions.Metadata.ForLiteralParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForNewExpressions, InlineParameterHintsOptions.Metadata.ForObjectCreationParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForEverythingElse, InlineParameterHintsOptions.Metadata.ForOtherParameters, LanguageNames.CSharp); + BindToOption(ShowHintsForIndexers, InlineParameterHintsOptions.Metadata.ForIndexerParameters, LanguageNames.CSharp); + BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchMethodIntent, LanguageNames.CSharp); + BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineParameterHintsOptions.Metadata.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.CSharp); + BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchArgumentName, LanguageNames.CSharp); - BindToOption(DisplayInlineTypeHints, InlineHintsOptions.EnabledForTypes, LanguageNames.CSharp); - BindToOption(ShowHintsForVariablesWithInferredTypes, InlineHintsOptions.ForImplicitVariableTypes, LanguageNames.CSharp); - BindToOption(ShowHintsForLambdaParameterTypes, InlineHintsOptions.ForLambdaParameterTypes, LanguageNames.CSharp); - BindToOption(ShowHintsForImplicitObjectCreation, InlineHintsOptions.ForImplicitObjectCreation, LanguageNames.CSharp); + BindToOption(DisplayInlineTypeHints, InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp); + BindToOption(ShowHintsForVariablesWithInferredTypes, InlineTypeHintsOptions.Metadata.ForImplicitVariableTypes, LanguageNames.CSharp); + BindToOption(ShowHintsForLambdaParameterTypes, InlineTypeHintsOptions.Metadata.ForLambdaParameterTypes, LanguageNames.CSharp); + BindToOption(ShowHintsForImplicitObjectCreation, InlineTypeHintsOptions.Metadata.ForImplicitObjectCreation, LanguageNames.CSharp); // Leave the null converter here to make sure if the option value is get from the storage (if it is null), the feature will be enabled BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.CSharp, () => true); @@ -231,7 +232,7 @@ private void Enable_Razor_pull_diagnostics_experimental_requires_restart_Uncheck private void UpdateInlineHintsOptions() { - var enabledForParameters = this.OptionStore.GetOption(InlineHintsOptions.EnabledForParameters, LanguageNames.CSharp); + var enabledForParameters = this.OptionStore.GetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp); ShowHintsForLiterals.IsEnabled = enabledForParameters; ShowHintsForNewExpressions.IsEnabled = enabledForParameters; ShowHintsForEverythingElse.IsEnabled = enabledForParameters; @@ -240,7 +241,7 @@ private void UpdateInlineHintsOptions() SuppressHintsWhenParameterNamesDifferOnlyBySuffix.IsEnabled = enabledForParameters; SuppressHintsWhenParameterNamesMatchArgumentNames.IsEnabled = enabledForParameters; - var enabledForTypes = this.OptionStore.GetOption(InlineHintsOptions.EnabledForTypes, LanguageNames.CSharp); + var enabledForTypes = this.OptionStore.GetOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp); ShowHintsForVariablesWithInferredTypes.IsEnabled = enabledForTypes; ShowHintsForLambdaParameterTypes.IsEnabled = enabledForTypes; ShowHintsForImplicitObjectCreation.IsEnabled = enabledForTypes; @@ -248,25 +249,25 @@ private void UpdateInlineHintsOptions() private void DisplayInlineParameterNameHints_Checked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineHintsOptions.EnabledForParameters, LanguageNames.CSharp, true); + this.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp, true); UpdateInlineHintsOptions(); } private void DisplayInlineParameterNameHints_Unchecked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineHintsOptions.EnabledForParameters, LanguageNames.CSharp, false); + this.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.CSharp, false); UpdateInlineHintsOptions(); } private void DisplayInlineTypeHints_Checked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineHintsOptions.EnabledForTypes, LanguageNames.CSharp, true); + this.OptionStore.SetOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp, true); UpdateInlineHintsOptions(); } private void DisplayInlineTypeHints_Unchecked(object sender, RoutedEventArgs e) { - this.OptionStore.SetOption(InlineHintsOptions.EnabledForTypes, LanguageNames.CSharp, false); + this.OptionStore.SetOption(InlineTypeHintsOptions.Metadata.EnabledForTypes, LanguageNames.CSharp, false); UpdateInlineHintsOptions(); } } diff --git a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.OnOff.cs b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.OnOff.cs index e05ccaa61e125..5abcbaa9a31cf 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.OnOff.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AutomationObject/AutomationObject.OnOff.cs @@ -62,12 +62,6 @@ public int NavigateToDecompiledSources set { SetBooleanOption(FeatureOnOffOptions.NavigateToDecompiledSources, value); } } - public int UseEnhancedColors - { - get { return GetOption(FeatureOnOffOptions.UseEnhancedColors); } - set { SetOption(FeatureOnOffOptions.UseEnhancedColors, value); } - } - public int AddImportsOnPaste { get { return GetBooleanOption(FeatureOnOffOptions.AddImportsOnPaste); } diff --git a/src/VisualStudio/CSharp/Impl/Snippets/SnippetCommandHandler.cs b/src/VisualStudio/CSharp/Impl/Snippets/SnippetCommandHandler.cs index 17f38118ac021..d9437a82a9a0e 100644 --- a/src/VisualStudio/CSharp/Impl/Snippets/SnippetCommandHandler.cs +++ b/src/VisualStudio/CSharp/Impl/Snippets/SnippetCommandHandler.cs @@ -43,7 +43,6 @@ internal sealed class SnippetCommandHandler : IChainedCommandHandler { private readonly ImmutableArray> _argumentProviders; - private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] @@ -55,10 +54,9 @@ public SnippetCommandHandler( SVsServiceProvider serviceProvider, [ImportMany] IEnumerable> argumentProviders, IGlobalOptionService globalOptions) - : base(threadingContext, signatureHelpControllerProvider, editorCommandHandlerServiceFactory, editorAdaptersFactoryService, serviceProvider) + : base(threadingContext, signatureHelpControllerProvider, editorCommandHandlerServiceFactory, editorAdaptersFactoryService, globalOptions, serviceProvider) { _argumentProviders = argumentProviders.ToImmutableArray(); - _globalOptions = globalOptions; } public bool ExecuteCommand(SurroundWithCommandArgs args, CommandExecutionContext context) @@ -131,7 +129,7 @@ protected override AbstractSnippetExpansionClient GetSnippetExpansionClient(ITex EditorCommandHandlerServiceFactory, EditorAdaptersFactoryService, _argumentProviders, - _globalOptions); + GlobalOptions); textView.Properties.AddProperty(typeof(AbstractSnippetExpansionClient), expansionClient); } diff --git a/src/VisualStudio/Core/Def/Implementation/AbstractVsTextViewFilter.cs b/src/VisualStudio/Core/Def/Implementation/AbstractVsTextViewFilter.cs index afc4b032d4ebd..fa726ef13937f 100644 --- a/src/VisualStudio/Core/Def/Implementation/AbstractVsTextViewFilter.cs +++ b/src/VisualStudio/Core/Def/Implementation/AbstractVsTextViewFilter.cs @@ -196,7 +196,8 @@ internal static int GetPairExtentsWorker(ITextView textView, IBraceMatchingServi var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document != null) { - var matchingSpan = braceMatcher.FindMatchingSpanAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken); + var options = BraceMatchingOptions.From(document.Project); + var matchingSpan = braceMatcher.FindMatchingSpanAsync(document, position, options, cancellationToken).WaitAndGetResult(cancellationToken); if (matchingSpan.HasValue) { @@ -230,7 +231,7 @@ internal static int GetPairExtentsWorker(ITextView textView, IBraceMatchingServi if (extendSelection) { // case a. - var closingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.Start, cancellationToken).WaitAndGetResult(cancellationToken); + var closingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.Start, options, cancellationToken).WaitAndGetResult(cancellationToken); var vsClosingSpans = textView.GetSpanInView(closingSpans.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList().First().ToVsTextSpan(); pSpan[0].iEndIndex = vsClosingSpans.iStartIndex; } @@ -247,7 +248,7 @@ internal static int GetPairExtentsWorker(ITextView textView, IBraceMatchingServi pSpan[0].iEndIndex = vsTextSpan.iStartIndex; // case b. - var openingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.End, cancellationToken).WaitAndGetResult(cancellationToken); + var openingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.End, options, cancellationToken).WaitAndGetResult(cancellationToken); var vsOpeningSpans = textView.GetSpanInView(openingSpans.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList().First().ToVsTextSpan(); pSpan[0].iStartIndex = vsOpeningSpans.iStartIndex; } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/FindUsagesOptions.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/FindUsagesOptions.cs index a30dce5d12181..dd7b8b5a02dab 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/FindUsagesOptions.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/FindUsagesOptions.cs @@ -11,8 +11,18 @@ namespace Microsoft.VisualStudio.LanguageServices.FindUsages { - internal static class FindUsagesOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class FindUsagesOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public FindUsagesOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + DefinitionGroupingPriority); + private const string LocalRegistryPath = @"Roslyn\Internal\FindUsages\"; /// @@ -25,17 +35,4 @@ internal static class FindUsagesOptions nameof(FindUsagesOptions), nameof(DefinitionGroupingPriority), defaultValue: -1, storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(DefinitionGroupingPriority))); } - - [ExportOptionProvider, Shared] - internal class FindUsagesOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public FindUsagesOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - FindUsagesOptions.DefinitionGroupingPriority); - } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/StreamingFindUsagesPresenter.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/StreamingFindUsagesPresenter.cs index 93373fa08fbe9..d6fc09bc08aa1 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/StreamingFindUsagesPresenter.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/StreamingFindUsagesPresenter.cs @@ -44,7 +44,7 @@ internal partial class StreamingFindUsagesPresenter : public readonly IClassificationFormatMap ClassificationFormatMap; private readonly Workspace _workspace; - private readonly IGlobalOptionService _optionService; + private readonly IGlobalOptionService _globalOptions; private readonly HashSet _currentContexts = new(); @@ -55,7 +55,7 @@ internal partial class StreamingFindUsagesPresenter : public StreamingFindUsagesPresenter( IThreadingContext threadingContext, VisualStudioWorkspace workspace, - IGlobalOptionService optionService, + IGlobalOptionService globalOptions, Shell.SVsServiceProvider serviceProvider, ClassificationTypeMap typeMap, IEditorFormatMapService formatMapService, @@ -65,7 +65,7 @@ public StreamingFindUsagesPresenter( : this(workspace, threadingContext, serviceProvider, - optionService, + globalOptions, typeMap, formatMapService, classificationFormatMapService, @@ -105,7 +105,7 @@ private StreamingFindUsagesPresenter( : base(threadingContext, assertIsForeground: false) { _workspace = workspace; - _optionService = optionService; + _globalOptions = optionService; _serviceProvider = serviceProvider; TypeMap = typeMap; FormatMapService = formatMapService; @@ -184,7 +184,7 @@ private AbstractTableDataSourceFindUsagesContext StartSearchWorker( // We need this because we disable the Definition column when we're not showing references // (i.e. GoToImplementation/GoToDef). However, we want to restore the user's choice if they // then do another FindAllReferences. - var desiredGroupingPriority = _optionService.GetOption(FindUsagesOptions.DefinitionGroupingPriority); + var desiredGroupingPriority = _globalOptions.GetOption(FindUsagesOptions.DefinitionGroupingPriority); if (desiredGroupingPriority < 0) { StoreCurrentGroupingPriority(window); @@ -226,7 +226,7 @@ private AbstractTableDataSourceFindUsagesContext StartSearchWithoutReferences( private void StoreCurrentGroupingPriority(IFindAllReferencesWindow window) { - _optionService.SetGlobalOption(FindUsagesOptions.DefinitionGroupingPriority, window.GetDefinitionColumn().GroupingPriority); + _globalOptions.SetGlobalOption(FindUsagesOptions.DefinitionGroupingPriority, window.GetDefinitionColumn().GroupingPriority); } private void SetDefinitionGroupingPriority(IFindAllReferencesWindow window, int priority) diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactory.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactory.cs index af42774be7869..9478357d8298d 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactory.cs @@ -30,6 +30,7 @@ internal sealed class InheritanceGlyphFactory : IGlyphFactory private readonly IUIThreadOperationExecutor _operationExecutor; private readonly IWpfTextView _textView; private readonly IAsynchronousOperationListener _listener; + private readonly IGlobalOptionService _globalOptions; public InheritanceGlyphFactory( IThreadingContext threadingContext, @@ -38,6 +39,7 @@ public InheritanceGlyphFactory( IClassificationFormatMap classificationFormatMap, IUIThreadOperationExecutor operationExecutor, IWpfTextView textView, + IGlobalOptionService globalOptions, IAsynchronousOperationListener listener) { _threadingContext = threadingContext; @@ -46,6 +48,7 @@ public InheritanceGlyphFactory( _classificationFormatMap = classificationFormatMap; _operationExecutor = operationExecutor; _textView = textView; + _globalOptions = globalOptions; _listener = listener; } @@ -56,20 +59,17 @@ public InheritanceGlyphFactory( return null; } - var workspace = _textView.TextBuffer.GetWorkspace(); - if (workspace == null) - { - return null; - } - - var optionService = workspace.Services.GetRequiredService(); // The life cycle of the glyphs in Indicator Margin is controlled by the editor, // so in order to get the glyphs removed when FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin is off, // we need // 1. Generate tags when this option changes. // 2. Always return null here to force the editor to remove the glyphs. - var combineWithIndicatorMargin = optionService.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin); - if (!combineWithIndicatorMargin) + if (!_globalOptions.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin)) + { + return null; + } + + if (_textView.TextBuffer.GetWorkspace() == null) { return null; } diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactoryProvider.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactoryProvider.cs index 03b8279c6da8f..be933b4210f90 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactoryProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceGlyphFactoryProvider.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; @@ -30,6 +31,7 @@ internal class InheritanceGlyphFactoryProvider : IGlyphFactoryProvider private readonly IClassificationFormatMapService _classificationFormatMapService; private readonly IUIThreadOperationExecutor _operationExecutor; private readonly IAsynchronousOperationListener _listener; + private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] @@ -39,6 +41,7 @@ public InheritanceGlyphFactoryProvider( ClassificationTypeMap classificationTypeMap, IClassificationFormatMapService classificationFormatMapService, IUIThreadOperationExecutor operationExecutor, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) { _threadingContext = threadingContext; @@ -46,6 +49,7 @@ public InheritanceGlyphFactoryProvider( _classificationTypeMap = classificationTypeMap; _classificationFormatMapService = classificationFormatMapService; _operationExecutor = operationExecutor; + _globalOptions = globalOptions; _listener = listenerProvider.GetListener(FeatureAttribute.InheritanceMargin); } @@ -58,6 +62,7 @@ public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margi _classificationFormatMapService.GetClassificationFormatMap("tooltip"), _operationExecutor, view, + _globalOptions, _listener); } } diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginTaggerProvider.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginTaggerProvider.cs index edd2f0b92773c..6aef7dbc06c96 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginTaggerProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginTaggerProvider.cs @@ -19,6 +19,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.InheritanceMargin; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Text; @@ -39,8 +40,10 @@ internal sealed class InheritanceMarginTaggerProvider : AsynchronousViewTaggerPr [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public InheritanceMarginTaggerProvider( IThreadingContext threadingContext, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) : base( threadingContext, + globalOptions, listenerProvider.GetListener(FeatureAttribute.InheritanceMargin)) { } @@ -87,11 +90,7 @@ protected override async Task ProduceTagsAsync( return; } - var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); - var optionValue = optionSet.GetOption(FeatureOnOffOptions.ShowInheritanceMargin); - - var shouldDisableFeature = optionValue == false; - if (shouldDisableFeature) + if (GlobalOptions.GetOption(FeatureOnOffOptions.ShowInheritanceMargin, document.Project.Language) == false) { return; } diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMargin.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMargin.cs index fadbd524d390c..04510b2a84ee7 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMargin.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMargin.cs @@ -28,7 +28,7 @@ internal class InheritanceMarginViewMargin : ForegroundThreadAffinitizedObject, private const double HeightAndWidthOfMargin = 18; private readonly IWpfTextView _textView; private readonly ITagAggregator _tagAggregator; - private readonly IOptionService _optionService; + private readonly IGlobalOptionService _globalOptions; private readonly InheritanceGlyphManager _glyphManager; private readonly string _languageName; private readonly Grid _grid; @@ -49,13 +49,13 @@ public InheritanceMarginViewMargin(IWpfTextView textView, ClassificationTypeMap classificationTypeMap, ITagAggregator tagAggregator, IEditorFormatMap editorFormatMap, - IOptionService optionService, + IGlobalOptionService globalOptions, IAsynchronousOperationListener listener, string languageName) : base(threadingContext) { _textView = textView; _tagAggregator = tagAggregator; - _optionService = optionService; + _globalOptions = globalOptions; _languageName = languageName; _mainCanvas = new Canvas { ClipToBounds = true, Width = HeightAndWidthOfMargin }; _grid = new Grid(); @@ -77,7 +77,7 @@ public InheritanceMarginViewMargin(IWpfTextView textView, _tagAggregator.BatchedTagsChanged += OnTagsChanged; _textView.LayoutChanged += OnLayoutChanged; _textView.ZoomLevelChanged += OnZoomLevelChanged; - _optionService.OptionChanged += OnRoslynOptionChanged; + _globalOptions.OptionChanged += OnGlobalOptionChanged; _grid.LayoutTransform = new ScaleTransform( scaleX: _textView.ZoomLevel / 100, @@ -95,7 +95,7 @@ void IDisposable.Dispose() _tagAggregator.BatchedTagsChanged -= OnTagsChanged; _textView.LayoutChanged -= OnLayoutChanged; _textView.ZoomLevelChanged -= OnZoomLevelChanged; - _optionService.OptionChanged -= OnRoslynOptionChanged; + _globalOptions.OptionChanged -= OnGlobalOptionChanged; _tagAggregator.Dispose(); ((IDisposable)_glyphManager).Dispose(); } @@ -124,9 +124,10 @@ private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e) _refreshAllGlyphs = false; } - private void OnRoslynOptionChanged(object sender, OptionChangedEventArgs e) + private void OnGlobalOptionChanged(object sender, OptionChangedEventArgs e) { - if (e.Option.Equals(FeatureOnOffOptions.ShowInheritanceMargin) || e.Option.Equals(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin)) + if (e.Option.Equals(FeatureOnOffOptions.ShowInheritanceMargin) || + e.Option.Equals(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin)) { UpdateMarginVisibility(); } @@ -134,18 +135,9 @@ private void OnRoslynOptionChanged(object sender, OptionChangedEventArgs e) private void UpdateMarginVisibility() { - var featureEnabled = _optionService.GetOption(FeatureOnOffOptions.ShowInheritanceMargin, _languageName) ?? true; - if (featureEnabled) - { - var showMargin = !_optionService.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin); - if (showMargin) - { - _mainCanvas.Visibility = Visibility.Visible; - return; - } - } - - _mainCanvas.Visibility = Visibility.Collapsed; + _mainCanvas.Visibility = + (_globalOptions.GetOption(FeatureOnOffOptions.ShowInheritanceMargin, _languageName) ?? true) && + !_globalOptions.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin) ? Visibility.Visible : Visibility.Collapsed; } private void OnTagsChanged(object sender, BatchedTagsChangedEventArgs e) @@ -185,7 +177,7 @@ private void OnTagsChanged(object sender, BatchedTagsChangedEventArgs e) private void RefreshGlyphsOver(ITextViewLine textViewLine) { - if (!_optionService.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin)) + if (!_globalOptions.GetOption(FeatureOnOffOptions.InheritanceMarginCombinedWithIndicatorMargin)) { foreach (var mappingTagSpan in _tagAggregator.GetTags(textViewLine.ExtentAsMappingSpan)) { diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMarginProvider.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMarginProvider.cs index 268f69c6ea35b..2567d62e415e1 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMarginProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/InheritanceMarginViewMarginProvider.cs @@ -35,6 +35,7 @@ internal class InheritanceMarginViewMarginProvider : IWpfTextViewMarginProvider private readonly IUIThreadOperationExecutor _operationExecutor; private readonly IEditorFormatMapService _editorFormatMapService; private readonly IAsynchronousOperationListenerProvider _listenerProvider; + private readonly IGlobalOptionService _globalOptions; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] @@ -46,6 +47,7 @@ public InheritanceMarginViewMarginProvider( IUIThreadOperationExecutor operationExecutor, IViewTagAggregatorFactoryService tagAggregatorFactoryService, IEditorFormatMapService editorFormatMapService, + IGlobalOptionService globalOptions, IAsynchronousOperationListenerProvider listenerProvider) { _threadingContext = threadingContext; @@ -55,6 +57,7 @@ public InheritanceMarginViewMarginProvider( _operationExecutor = operationExecutor; _tagAggregatorFactoryService = tagAggregatorFactoryService; _editorFormatMapService = editorFormatMapService; + _globalOptions = globalOptions; _listenerProvider = listenerProvider; } @@ -70,7 +73,6 @@ public InheritanceMarginViewMarginProvider( return null; } - var optionService = document.Project.Solution.Workspace.Services.GetRequiredService(); var listener = _listenerProvider.GetListener(FeatureAttribute.InheritanceMargin); return new InheritanceMarginViewMargin( textView, @@ -81,7 +83,7 @@ public InheritanceMarginViewMarginProvider( _classificationTypeMap, tagAggregator, editorFormatMap, - optionService, + _globalOptions, listener, document.Project.Language); } diff --git a/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetDetector.cs b/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetDetector.cs index 4b0b0e6a11806..b041b015aab18 100644 --- a/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetDetector.cs +++ b/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetDetector.cs @@ -62,7 +62,7 @@ internal sealed class KeybindingResetDetector : ForegroundThreadAffinitizedObjec KeybindingResetOptions.ReSharperStatus, KeybindingResetOptions.NeedsReset); - private readonly IGlobalOptionService _optionService; + private readonly IGlobalOptionService _globalOptions; private readonly System.IServiceProvider _serviceProvider; private readonly VisualStudioInfoBarService _infoBarService; @@ -90,12 +90,12 @@ internal sealed class KeybindingResetDetector : ForegroundThreadAffinitizedObjec [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public KeybindingResetDetector( IThreadingContext threadingContext, - IGlobalOptionService optionService, + IGlobalOptionService globalOptions, VisualStudioInfoBarService infoBarService, SVsServiceProvider serviceProvider) : base(threadingContext) { - _optionService = optionService; + _globalOptions = globalOptions; _infoBarService = infoBarService; _serviceProvider = serviceProvider; } @@ -103,7 +103,7 @@ public KeybindingResetDetector( public Task InitializeAsync() { // Immediately bail if the user has asked to never see this bar again. - if (_optionService.GetOption(KeybindingResetOptions.NeverShowAgain)) + if (_globalOptions.GetOption(KeybindingResetOptions.NeverShowAgain)) { return Task.CompletedTask; } @@ -115,7 +115,7 @@ private void InitializeCore() { AssertIsForeground(); - if (!_optionService.GetOption(KeybindingResetOptions.EnabledFeatureFlag)) + if (!_globalOptions.GetOption(KeybindingResetOptions.EnabledFeatureFlag)) { return; } @@ -171,7 +171,7 @@ private void StartUpdateStateMachine() private async Task UpdateStateMachineWorkerAsync(CancellationToken cancellationToken) { - var options = _optionService.GetOptions(s_statusOptions); + var options = _globalOptions.GetOptions(s_statusOptions); var lastStatus = (ReSharperStatus)options[0]; var needsReset = (bool)options[1]; @@ -216,7 +216,7 @@ private async Task UpdateStateMachineWorkerAsync(CancellationToken cancellationT break; } - _optionService.SetGlobalOptions(s_statusOptions, ImmutableArray.Create(currentStatus, needsReset)); + _globalOptions.SetGlobalOptions(s_statusOptions, ImmutableArray.Create(currentStatus, needsReset)); if (needsReset) { @@ -353,7 +353,7 @@ private void RestoreVsKeybindings() KeybindingsResetLogger.Log("KeybindingsReset"); - _optionService.SetGlobalOption(KeybindingResetOptions.NeedsReset, false); + _globalOptions.SetGlobalOption(KeybindingResetOptions.NeedsReset, false); } private void OpenExtensionsHyperlink() @@ -363,13 +363,13 @@ private void OpenExtensionsHyperlink() VisualStudioNavigateToLinkService.StartBrowser(KeybindingsFwLink); KeybindingsResetLogger.Log("ExtensionsLink"); - _optionService.SetGlobalOption(KeybindingResetOptions.NeedsReset, false); + _globalOptions.SetGlobalOption(KeybindingResetOptions.NeedsReset, false); } private void NeverShowAgain() { - _optionService.SetGlobalOption(KeybindingResetOptions.NeverShowAgain, true); - _optionService.SetGlobalOption(KeybindingResetOptions.NeedsReset, false); + _globalOptions.SetGlobalOption(KeybindingResetOptions.NeverShowAgain, true); + _globalOptions.SetGlobalOption(KeybindingResetOptions.NeedsReset, false); KeybindingsResetLogger.Log("NeverShowAgain"); // The only external references to this object are as callbacks, which are removed by the Shutdown method. diff --git a/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetOptions.cs b/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetOptions.cs index 5c18f2a35087e..29d0239a7ff93 100644 --- a/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetOptions.cs +++ b/src/VisualStudio/Core/Def/Implementation/KeybindingReset/KeybindingResetOptions.cs @@ -11,7 +11,7 @@ namespace Microsoft.VisualStudio.LanguageServices.KeybindingReset { - [ExportOptionProvider, Shared] + [ExportGlobalOptionProvider, Shared] internal sealed class KeybindingResetOptions : IOptionProvider { private const string LocalRegistryPath = @"Roslyn\Internal\KeybindingsStatus\"; diff --git a/src/VisualStudio/Core/Def/Implementation/Log/LoggerOptions.cs b/src/VisualStudio/Core/Def/Implementation/Log/LoggerOptions.cs index bd4aeae27c3d7..8eee7e1f931b7 100644 --- a/src/VisualStudio/Core/Def/Implementation/Log/LoggerOptions.cs +++ b/src/VisualStudio/Core/Def/Implementation/Log/LoggerOptions.cs @@ -13,8 +13,20 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation { - internal static class LoggerOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class LoggerOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public LoggerOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + EtwLoggerKey, + TraceLoggerKey, + OutputWindowLoggerKey); + private const string LocalRegistryPath = @"Roslyn\Internal\Performance\Logger\"; public static readonly Option EtwLoggerKey = new(nameof(LoggerOptions), nameof(EtwLoggerKey), defaultValue: true, @@ -26,19 +38,4 @@ internal static class LoggerOptions public static readonly Option OutputWindowLoggerKey = new(nameof(LoggerOptions), nameof(OutputWindowLoggerKey), defaultValue: false, storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "OutputWindowLogger")); } - - [ExportOptionProvider, Shared] - internal class LoggerOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public LoggerOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - LoggerOptions.EtwLoggerKey, - LoggerOptions.TraceLoggerKey, - LoggerOptions.OutputWindowLoggerKey); - } } diff --git a/src/VisualStudio/Core/Def/Implementation/Options/XamlOptions.cs b/src/VisualStudio/Core/Def/Implementation/Options/XamlOptions.cs index e0c8c6d944d45..6415d2f04e12a 100644 --- a/src/VisualStudio/Core/Def/Implementation/Options/XamlOptions.cs +++ b/src/VisualStudio/Core/Def/Implementation/Options/XamlOptions.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.Editor.Xaml /// Currently GlobalOptionService.CreateLazySerializableOptionsByLanguage loads all IOptionProvider types eagerly to determine whether or not they contribute to solution options. /// This is causing RPS regression. /// - [ExportOptionProvider, Shared] + [ExportGlobalOptionProvider, Shared] internal sealed class XamlOptions : IOptionProvider { private const string FeatureName = "XamlOptions"; diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs index 8c85f49d5df99..3a5bcbee39896 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs @@ -58,6 +58,7 @@ internal abstract partial class VisualStudioWorkspaceImpl : VisualStudioWorkspac private readonly IThreadingContext _threadingContext; private readonly ITextBufferFactoryService _textBufferFactoryService; private readonly IProjectionBufferFactoryService _projectionBufferFactoryService; + private readonly IGlobalOptionService _globalOptions; [Obsolete("This is a compatibility shim for TypeScript; please do not use it.")] private readonly Lazy _projectFactory; @@ -118,6 +119,7 @@ public VisualStudioWorkspaceImpl(ExportProvider exportProvider, IAsyncServicePro : base(VisualStudioMefHostServices.Create(exportProvider)) { _threadingContext = exportProvider.GetExportedValue(); + _globalOptions = exportProvider.GetExportedValue(); _textBufferCloneService = exportProvider.GetExportedValue(); _textBufferFactoryService = exportProvider.GetExportedValue(); _projectionBufferFactoryService = exportProvider.GetExportedValue(); @@ -206,7 +208,7 @@ public async Task InitializeUIAffinitizedServicesAsync(IAsyncServiceProvider asy _openFileTracker = openFileTracker; } - var memoryListener = await VirtualMemoryNotificationListener.CreateAsync(this, _threadingContext, asyncServiceProvider, _threadingContext.DisposalToken).ConfigureAwait(true); + var memoryListener = await VirtualMemoryNotificationListener.CreateAsync(this, _threadingContext, asyncServiceProvider, _globalOptions, _threadingContext.DisposalToken).ConfigureAwait(true); // Update our fields first, so any asynchronous work that needs to use these is able to see the service. lock (_gate) diff --git a/src/VisualStudio/Core/Def/Implementation/Snippets/AbstractSnippetCommandHandler.cs b/src/VisualStudio/Core/Def/Implementation/Snippets/AbstractSnippetCommandHandler.cs index 2ba1133b85d7b..de2729e0c7fb7 100644 --- a/src/VisualStudio/Core/Def/Implementation/Snippets/AbstractSnippetCommandHandler.cs +++ b/src/VisualStudio/Core/Def/Implementation/Snippets/AbstractSnippetCommandHandler.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Commanding; @@ -40,16 +41,24 @@ internal abstract class AbstractSnippetCommandHandler : protected readonly IEditorCommandHandlerServiceFactory EditorCommandHandlerServiceFactory; protected readonly IVsEditorAdaptersFactoryService EditorAdaptersFactoryService; protected readonly SVsServiceProvider ServiceProvider; + protected readonly IGlobalOptionService GlobalOptions; public string DisplayName => FeaturesResources.Snippets; - public AbstractSnippetCommandHandler(IThreadingContext threadingContext, SignatureHelpControllerProvider signatureHelpControllerProvider, IEditorCommandHandlerServiceFactory editorCommandHandlerServiceFactory, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, SVsServiceProvider serviceProvider) + public AbstractSnippetCommandHandler( + IThreadingContext threadingContext, + SignatureHelpControllerProvider signatureHelpControllerProvider, + IEditorCommandHandlerServiceFactory editorCommandHandlerServiceFactory, + IVsEditorAdaptersFactoryService editorAdaptersFactoryService, + IGlobalOptionService globalOptions, + SVsServiceProvider serviceProvider) : base(threadingContext) { - this.SignatureHelpControllerProvider = signatureHelpControllerProvider; - this.EditorCommandHandlerServiceFactory = editorCommandHandlerServiceFactory; - this.EditorAdaptersFactoryService = editorAdaptersFactoryService; - this.ServiceProvider = serviceProvider; + SignatureHelpControllerProvider = signatureHelpControllerProvider; + EditorCommandHandlerServiceFactory = editorCommandHandlerServiceFactory; + EditorAdaptersFactoryService = editorAdaptersFactoryService; + ServiceProvider = serviceProvider; + GlobalOptions = globalOptions; } protected abstract AbstractSnippetExpansionClient GetSnippetExpansionClient(ITextView textView, ITextBuffer subjectBuffer); @@ -324,7 +333,7 @@ protected bool TryGetExpansionManager(out IVsExpansionManager expansionManager) return expansionManager != null; } - protected static bool AreSnippetsEnabled(EditorCommandArgs args) + protected bool AreSnippetsEnabled(EditorCommandArgs args) { // Don't execute in cloud environment, should be handled by LSP if (args.SubjectBuffer.IsInLspEditorContext()) @@ -332,7 +341,7 @@ protected static bool AreSnippetsEnabled(EditorCommandArgs args) return false; } - return args.SubjectBuffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.Snippets) && + return GlobalOptions.GetOption(InternalFeatureOnOffOptions.Snippets) && // TODO (https://github.com/dotnet/roslyn/issues/5107): enable in interactive !(Workspace.TryGetWorkspace(args.SubjectBuffer.AsTextContainer(), out var workspace) && workspace.Kind == WorkspaceKind.Interactive); } diff --git a/src/VisualStudio/Core/Def/Implementation/UnusedReferences/RemoveUnusedReferencesCommandHandler.cs b/src/VisualStudio/Core/Def/Implementation/UnusedReferences/RemoveUnusedReferencesCommandHandler.cs index 11ac15537a541..f71c6d0415b66 100644 --- a/src/VisualStudio/Core/Def/Implementation/UnusedReferences/RemoveUnusedReferencesCommandHandler.cs +++ b/src/VisualStudio/Core/Def/Implementation/UnusedReferences/RemoveUnusedReferencesCommandHandler.cs @@ -34,6 +34,7 @@ internal sealed class RemoveUnusedReferencesCommandHandler private readonly Lazy _lazyReferenceCleanupService; private readonly RemoveUnusedReferencesDialogProvider _unusedReferenceDialogProvider; private readonly VisualStudioWorkspace _workspace; + private readonly IGlobalOptionService _globalOptions; private readonly IUIThreadOperationExecutor _threadOperationExecutor; private IServiceProvider? _serviceProvider; @@ -42,11 +43,13 @@ internal sealed class RemoveUnusedReferencesCommandHandler public RemoveUnusedReferencesCommandHandler( RemoveUnusedReferencesDialogProvider unusedReferenceDialogProvider, IUIThreadOperationExecutor threadOperationExecutor, - VisualStudioWorkspace workspace) + VisualStudioWorkspace workspace, + IGlobalOptionService globalOptions) { _unusedReferenceDialogProvider = unusedReferenceDialogProvider; _threadOperationExecutor = threadOperationExecutor; _workspace = workspace; + _globalOptions = globalOptions; _lazyReferenceCleanupService = new(() => workspace.Services.GetRequiredService()); } @@ -70,8 +73,8 @@ private void OnRemoveUnusedReferencesForSelectedProjectStatus(object sender, Eve var command = (OleMenuCommand)sender; // If the option hasn't been expicitly set then fallback to whether this is enabled as part of an experiment. - var isOptionEnabled = _workspace.Options.GetOption(FeatureOnOffOptions.OfferRemoveUnusedReferences) - ?? _workspace.Options.GetOption(FeatureOnOffOptions.OfferRemoveUnusedReferencesFeatureFlag); + var isOptionEnabled = _globalOptions.GetOption(FeatureOnOffOptions.OfferRemoveUnusedReferences) + ?? _globalOptions.GetOption(FeatureOnOffOptions.OfferRemoveUnusedReferencesFeatureFlag); var isDotNetCpsProject = VisualStudioCommandHandlerHelpers.TryGetSelectedProjectHierarchy(_serviceProvider, out var hierarchy) && hierarchy.IsCapabilityMatch("CPS") && diff --git a/src/VisualStudio/Core/Def/Implementation/VirtualMemoryNotificationListener.cs b/src/VisualStudio/Core/Def/Implementation/VirtualMemoryNotificationListener.cs index 53fe68931691a..67d3b6710f620 100644 --- a/src/VisualStudio/Core/Def/Implementation/VirtualMemoryNotificationListener.cs +++ b/src/VisualStudio/Core/Def/Implementation/VirtualMemoryNotificationListener.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis.Extensions; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Options; using Microsoft.CodeAnalysis.SolutionCrawler; using Microsoft.VisualStudio.LanguageServices.Implementation; @@ -32,18 +33,21 @@ internal sealed class VirtualMemoryNotificationListener : ForegroundThreadAffini // low vm more info page link private const string LowVMMoreInfoLink = "https://go.microsoft.com/fwlink/?LinkID=799402&clcid=0x409"; - + private readonly IGlobalOptionService _globalOptions; private readonly VisualStudioWorkspace _workspace; private readonly WorkspaceCacheService? _workspaceCacheService; private bool _alreadyLogged; + private bool _infoBarShown; private VirtualMemoryNotificationListener( IThreadingContext threadingContext, IVsShell shell, + IGlobalOptionService globalOptions, VisualStudioWorkspace workspace) : base(threadingContext, assertIsForeground: true) { + _globalOptions = globalOptions; _workspace = workspace; _workspaceCacheService = workspace.Services.GetService() as WorkspaceCacheService; @@ -60,14 +64,19 @@ private VirtualMemoryNotificationListener( ErrorHandler.ThrowOnFailure(shell.AdviseBroadcastMessages(this, out var cookie)); } - public static async Task CreateAsync(VisualStudioWorkspace workspace, IThreadingContext threadingContext, IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken) + public static async Task CreateAsync( + VisualStudioWorkspace workspace, + IThreadingContext threadingContext, + IAsyncServiceProvider serviceProvider, + IGlobalOptionService globalOptions, + CancellationToken cancellationToken) { await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var shell = (IVsShell?)await serviceProvider.GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true); Assumes.Present(shell); - return new VirtualMemoryNotificationListener(threadingContext, shell, workspace); + return new VirtualMemoryNotificationListener(threadingContext, shell, globalOptions, workspace); } /// @@ -129,7 +138,7 @@ private bool ShouldDisableBackgroundAnalysis(long availableMemory) return availableMemory < MemoryThreshold && !SolutionCrawlerOptions.LowMemoryForcedMinimalBackgroundAnalysis && - _workspace.Options.GetOption(InternalFeatureOnOffOptions.BackgroundAnalysisMemoryMonitor); + _globalOptions.GetOption(InternalFeatureOnOffOptions.BackgroundAnalysisMemoryMonitor); } private void DisableBackgroundAnalysis() @@ -146,9 +155,8 @@ private void RenableBackgroundAnalysis() private void ShowInfoBarIfRequired() { - if (_workspace.Options.GetOption(RuntimeOptions.BackgroundAnalysisSuspendedInfoBarShown)) + if (_infoBarShown) { - // Info bar already shown. return; } @@ -160,9 +168,7 @@ private void ShowInfoBarIfRequired() new InfoBarUI(ServicesVSResources.Learn_more, InfoBarUI.UIKind.HyperLink, () => VisualStudioNavigateToLinkService.StartBrowser(new Uri(LowVMMoreInfoLink)), closeAfterAction: false)); - // Update info bar shown state. - _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options - .WithChangedOption(RuntimeOptions.BackgroundAnalysisSuspendedInfoBarShown, true))); + _infoBarShown = true; } private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) @@ -173,8 +179,7 @@ private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) } // For newly opened solution, reset the info bar state. - _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options - .WithChangedOption(RuntimeOptions.BackgroundAnalysisSuspendedInfoBarShown, false))); + _infoBarShown = false; } } } diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptions.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptions.cs index c785ba3c2cae2..06fc6d936684c 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptions.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptions.cs @@ -2,12 +2,27 @@ // 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.VisualStudio.LanguageServices.Implementation { - internal static class VisualStudioNavigationOptions + [ExportGlobalOptionProvider, Shared] + internal sealed class VisualStudioNavigationOptions : IOptionProvider { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public VisualStudioNavigationOptions() + { + } + + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + NavigateToObjectBrowser); + public static readonly PerLanguageOption2 NavigateToObjectBrowser = new(nameof(VisualStudioNavigationOptions), nameof(NavigateToObjectBrowser), defaultValue: false, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NavigateToObjectBrowser")); } diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptionsProvider.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptionsProvider.cs deleted file mode 100644 index 1322aed6e124d..0000000000000 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioNavigationOptionsProvider.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. - -#nullable disable - -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.VisualStudio.LanguageServices.Implementation -{ - [ExportOptionProvider, Shared] - internal class VisualStudioNavigationOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public VisualStudioNavigationOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - VisualStudioNavigationOptions.NavigateToObjectBrowser); - } -} diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 2ca76ec9402c4..9944ea1467559 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -115,7 +115,7 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet? opti } // Generate new source or retrieve existing source for the symbol in question - var allowDecompilation = project.Solution.Workspace.Options.GetOption(FeatureOnOffOptions.NavigateToDecompiledSources); + var allowDecompilation = _globalOptions.GetOption(FeatureOnOffOptions.NavigateToDecompiledSources); var result = _metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, signaturesOnly: false, allowDecompilation, cancellationToken).WaitAndGetResult(cancellationToken); var vsRunningDocumentTable4 = IServiceProviderExtensions.GetService(_serviceProvider); diff --git a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs index 7231d9ed9e5a7..3253218dd95a8 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,7 +107,8 @@ public PackageInstallerService( [Import(AllowDefault = true)] Lazy? packageSourceProvider) : base(threadingContext, workspace, - SymbolSearchOptions.Enabled, + globalOptions, + SymbolSearchGlobalOptions.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..d470c975da03a 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, SymbolSearchGlobalOptions.Enabled, + SymbolSearchOptions.SuggestForTypesInReferenceAssemblies, SymbolSearchOptions.SuggestForTypesInNuGetPackages) { _workspace = workspace; _installerService = workspace.Services.GetService(); diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/Workspace/WorkspaceBase.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/Workspace/WorkspaceBase.cs index b481269f5abf1..57a1a90f2d097 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/Workspace/WorkspaceBase.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/Workspace/WorkspaceBase.cs @@ -92,7 +92,6 @@ Sub M(p As Object) End Sub End Module"); VisualStudio.Editor.PlaceCaret("(x)", charsOffset: -1); - VisualStudio.Workspace.SetQuickInfo(true); var project = new ProjectUtils.Project(ProjectName); VisualStudio.Workspace.SetOptionInfer(project.Name, true); VisualStudio.Editor.InvokeQuickInfo(); diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs index 8907cd099de1e..745766fdf8cc4 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs @@ -26,6 +26,7 @@ internal class VisualStudioWorkspace_InProc : InProcComponent { private static readonly Guid RoslynPackageId = new Guid("6cf2e545-6109-4730-8883-cf43d7aec3e1"); private readonly VisualStudioWorkspace _visualStudioWorkspace; + private readonly IGlobalOptionService _globalOptions; private VisualStudioWorkspace_InProc() { @@ -33,6 +34,7 @@ private VisualStudioWorkspace_InProc() GetWaitingService().Enable(true); _visualStudioWorkspace = GetComponentModelService(); + _globalOptions = GetComponentModelService(); } public static VisualStudioWorkspace_InProc Create() @@ -52,13 +54,12 @@ private EnvDTE.Project GetProject(string nameOrFileName) || string.Compare(p.Name, nameOrFileName, StringComparison.OrdinalIgnoreCase) == 0); public bool IsPrettyListingOn(string languageName) - => _visualStudioWorkspace.Options.GetOption(FeatureOnOffOptions.PrettyListing, languageName); + => _globalOptions.GetOption(FeatureOnOffOptions.PrettyListing, languageName); public void SetPrettyListing(string languageName, bool value) => InvokeOnUIThread(cancellationToken => { - _visualStudioWorkspace.SetOptions(_visualStudioWorkspace.Options.WithChangedOption( - FeatureOnOffOptions.PrettyListing, languageName, value)); + _globalOptions.SetGlobalOption(new OptionKey(FeatureOnOffOptions.PrettyListing, languageName), value); }); public void SetFileScopedNamespaces(bool value) @@ -72,13 +73,6 @@ public void SetFileScopedNamespaces(bool value) NotificationOption2.Suggestion))); }); - public void EnableQuickInfo(bool value) - => InvokeOnUIThread(cancellationToken => - { - _visualStudioWorkspace.SetOptions(_visualStudioWorkspace.Options.WithChangedOption( - InternalFeatureOnOffOptions.QuickInfo, value)); - }); - public void SetPerLanguageOption(string optionName, string feature, string language, object value) { var option = GetOption(optionName, feature); diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs index f339e18ab4166..6d7a73c7eafbc 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs @@ -57,9 +57,6 @@ public void ResetOptions() public void CleanUpWaitingService() => _inProc.CleanUpWaitingService(); - public void SetQuickInfo(bool value) - => _inProc.EnableQuickInfo(value); - public void SetImportCompletionOption(bool value) { SetPerLanguageOption( diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 9c2e1d3ae9c44..8706bdcbbc9db 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -12,6 +12,7 @@ Imports Microsoft.CodeAnalysis.Editing Imports Microsoft.CodeAnalysis.Editor.Implementation.SplitComment Imports Microsoft.CodeAnalysis.Editor.Implementation.Suggestions Imports Microsoft.CodeAnalysis.Editor.InlineDiagnostics +Imports Microsoft.CodeAnalysis.Editor.InlineHints Imports Microsoft.CodeAnalysis.Editor.Options Imports Microsoft.CodeAnalysis.Editor.Shared.Options Imports Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions @@ -79,17 +80,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.ShowOutliningForDeclarationLevelConstructs, LanguageNames.VisualBasic) - BindToOption(Show_outlining_for_code_level_constructs, BlockStructureOptions.ShowOutliningForCodeLevelConstructs, LanguageNames.VisualBasic) - BindToOption(Show_outlining_for_comments_and_preprocessor_regions, BlockStructureOptions.ShowOutliningForCommentsAndPreprocessorRegions, LanguageNames.VisualBasic) - BindToOption(Collapse_regions_when_collapsing_to_definitions, BlockStructureOptions.CollapseRegionsWhenCollapsingToDefinitions, 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) ' Fading BindToOption(Fade_out_unused_imports, FadingOptions.FadeOutUnusedImports, LanguageNames.VisualBasic) ' Block structure guides - BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptions.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic) - BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptions.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic) + BindToOption(Show_guides_for_declaration_level_constructs, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForDeclarationLevelConstructs, LanguageNames.VisualBasic) + BindToOption(Show_guides_for_code_level_constructs, BlockStructureOptions.Metadata.ShowBlockStructureGuidesForCodeLevelConstructs, LanguageNames.VisualBasic) ' Comments BindToOption(GenerateXmlDocCommentsForTripleApostrophes, DocumentationCommentOptions.Metadata.AutoXmlDocCommentGeneration, LanguageNames.VisualBasic) @@ -132,17 +133,17 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(prefer_auto_properties, ImplementTypeOptions.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties, LanguageNames.VisualBasic) ' Inline hints - BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsOptions.DisplayAllHintsWhilePressingAltF1) - BindToOption(ColorHints, InlineHintsOptions.ColorHints, LanguageNames.VisualBasic) - - BindToOption(DisplayInlineParameterNameHints, InlineHintsOptions.EnabledForParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForLiterals, InlineHintsOptions.ForLiteralParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForNewExpressions, InlineHintsOptions.ForObjectCreationParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForEverythingElse, InlineHintsOptions.ForOtherParameters, LanguageNames.VisualBasic) - BindToOption(ShowHintsForIndexers, InlineHintsOptions.ForIndexerParameters, LanguageNames.VisualBasic) - BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineHintsOptions.SuppressForParametersThatMatchMethodIntent, LanguageNames.VisualBasic) - BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineHintsOptions.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.VisualBasic) - BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineHintsOptions.SuppressForParametersThatMatchArgumentName, LanguageNames.VisualBasic) + BindToOption(DisplayAllHintsWhilePressingAltF1, InlineHintsViewOptions.DisplayAllHintsWhilePressingAltF1) + BindToOption(ColorHints, InlineHintsViewOptions.ColorHints, LanguageNames.VisualBasic) + + BindToOption(DisplayInlineParameterNameHints, InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForLiterals, InlineParameterHintsOptions.Metadata.ForLiteralParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForNewExpressions, InlineParameterHintsOptions.Metadata.ForObjectCreationParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForEverythingElse, InlineParameterHintsOptions.Metadata.ForOtherParameters, LanguageNames.VisualBasic) + BindToOption(ShowHintsForIndexers, InlineParameterHintsOptions.Metadata.ForIndexerParameters, LanguageNames.VisualBasic) + BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchMethodIntent, LanguageNames.VisualBasic) + BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineParameterHintsOptions.Metadata.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.VisualBasic) + BindToOption(SuppressHintsWhenParameterNamesMatchArgumentNames, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchArgumentName, LanguageNames.VisualBasic) BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.VisualBasic, Function() @@ -168,7 +169,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Sub Private Sub UpdateInlineHintsOptions() - Dim enabledForParameters = Me.OptionStore.GetOption(InlineHintsOptions.EnabledForParameters, LanguageNames.VisualBasic) <> False + Dim enabledForParameters = Me.OptionStore.GetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic) <> False ShowHintsForLiterals.IsEnabled = enabledForParameters ShowHintsForNewExpressions.IsEnabled = enabledForParameters ShowHintsForEverythingElse.IsEnabled = enabledForParameters @@ -179,12 +180,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Sub Private Sub DisplayInlineParameterNameHints_Checked() - Me.OptionStore.SetOption(InlineHintsOptions.EnabledForParameters, LanguageNames.VisualBasic, True) + Me.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic, True) UpdateInlineHintsOptions() End Sub Private Sub DisplayInlineParameterNameHints_Unchecked() - Me.OptionStore.SetOption(InlineHintsOptions.EnabledForParameters, LanguageNames.VisualBasic, False) + Me.OptionStore.SetOption(InlineParameterHintsOptions.Metadata.EnabledForParameters, LanguageNames.VisualBasic, False) UpdateInlineHintsOptions() End Sub End Class diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb index ff9d104fd458a..fe1756617703b 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb @@ -87,15 +87,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Set End Property - Public Property UseEnhancedColorsForManagedLanguages As Integer - Get - Return GetOption(FeatureOnOffOptions.UseEnhancedColors) - End Get - Set(value As Integer) - SetOption(FeatureOnOffOptions.UseEnhancedColors, value) - End Set - End Property - Public Property AddImportsOnPaste As Integer Get Return GetBooleanOption(FeatureOnOffOptions.AddImportsOnPaste) diff --git a/src/VisualStudio/VisualBasic/Impl/Snippets/SnippetCommandHandler.vb b/src/VisualStudio/VisualBasic/Impl/Snippets/SnippetCommandHandler.vb index a34555f6c7170..1e9ef697064bd 100644 --- a/src/VisualStudio/VisualBasic/Impl/Snippets/SnippetCommandHandler.vb +++ b/src/VisualStudio/VisualBasic/Impl/Snippets/SnippetCommandHandler.vb @@ -39,7 +39,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Snippets Inherits AbstractSnippetCommandHandler Private ReadOnly _argumentProviders As ImmutableArray(Of Lazy(Of ArgumentProvider, OrderableLanguageMetadata)) - Private ReadOnly _globalOptions As IGlobalOptionService @@ -51,9 +50,8 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Snippets serviceProvider As SVsServiceProvider, argumentProviders As IEnumerable(Of Lazy(Of ArgumentProvider, OrderableLanguageMetadata)), globalOptions As IGlobalOptionService) - MyBase.New(threadingContext, signatureHelpControllerProvider, editorCommandHandlerServiceFactory, editorAdaptersFactoryService, serviceProvider) + MyBase.New(threadingContext, signatureHelpControllerProvider, editorCommandHandlerServiceFactory, editorAdaptersFactoryService, globalOptions, serviceProvider) _argumentProviders = argumentProviders.ToImmutableArray() - _globalOptions = globalOptions End Sub Protected Overrides Function IsSnippetExpansionContext(document As Document, startPosition As Integer, cancellationToken As CancellationToken) As Boolean @@ -65,7 +63,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Snippets End Function Protected Overrides Function GetSnippetExpansionClient(textView As ITextView, subjectBuffer As ITextBuffer) As AbstractSnippetExpansionClient - Return SnippetExpansionClient.GetSnippetExpansionClient(ThreadingContext, textView, subjectBuffer, SignatureHelpControllerProvider, EditorCommandHandlerServiceFactory, EditorAdaptersFactoryService, _argumentProviders, _globalOptions) + Return SnippetExpansionClient.GetSnippetExpansionClient(ThreadingContext, textView, subjectBuffer, SignatureHelpControllerProvider, EditorCommandHandlerServiceFactory, EditorAdaptersFactoryService, _argumentProviders, GlobalOptions) End Function Protected Overrides Function TryInvokeInsertionUI(textView As ITextView, subjectBuffer As ITextBuffer, Optional surroundWith As Boolean = False) As Boolean diff --git a/src/VisualStudio/VisualStudioDiagnosticsToolWindow/OptionPages/PerformanceLoggersPage.cs b/src/VisualStudio/VisualStudioDiagnosticsToolWindow/OptionPages/PerformanceLoggersPage.cs index e2b91f6da4cbe..f1a556cde5dea 100644 --- a/src/VisualStudio/VisualStudioDiagnosticsToolWindow/OptionPages/PerformanceLoggersPage.cs +++ b/src/VisualStudio/VisualStudioDiagnosticsToolWindow/OptionPages/PerformanceLoggersPage.cs @@ -26,17 +26,17 @@ namespace Roslyn.VisualStudio.DiagnosticsWindow.OptionsPages [Guid(Guids.RoslynOptionPagePerformanceLoggersIdString)] internal class PerformanceLoggersPage : AbstractOptionPage { - private IGlobalOptionService _optionService; + private IGlobalOptionService _globalOptions; private IThreadingContext _threadingContext; private HostWorkspaceServices _workspaceServices; protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider, OptionStore optionStore) { - if (_optionService == null) + if (_globalOptions == null) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); - _optionService = componentModel.GetService(); + _globalOptions = componentModel.GetService(); _threadingContext = componentModel.GetService(); var workspace = componentModel.GetService(); @@ -50,15 +50,15 @@ protected override void OnApply(PageApplyEventArgs e) { base.OnApply(e); - SetLoggers(_optionService, _threadingContext, _workspaceServices); + SetLoggers(_globalOptions, _threadingContext, _workspaceServices); } - public static void SetLoggers(IGlobalOptionService optionService, IThreadingContext threadingContext, HostWorkspaceServices workspaceServices) + public static void SetLoggers(IGlobalOptionService globalOptions, IThreadingContext threadingContext, HostWorkspaceServices workspaceServices) { - var loggerTypeNames = GetLoggerTypes(optionService).ToImmutableArray(); + var loggerTypeNames = GetLoggerTypes(globalOptions).ToImmutableArray(); // update loggers in VS - var isEnabled = Logger.GetLoggingChecker(optionService); + var isEnabled = Logger.GetLoggingChecker(globalOptions); SetRoslynLogger(loggerTypeNames, () => new EtwLogger(isEnabled)); SetRoslynLogger(loggerTypeNames, () => new TraceLogger(isEnabled)); @@ -76,19 +76,19 @@ public static void SetLoggers(IGlobalOptionService optionService, IThreadingCont } } - private static IEnumerable GetLoggerTypes(IGlobalOptionService optionService) + private static IEnumerable GetLoggerTypes(IGlobalOptionService globalOptions) { - if (optionService.GetOption(LoggerOptions.EtwLoggerKey)) + if (globalOptions.GetOption(LoggerOptions.EtwLoggerKey)) { yield return nameof(EtwLogger); } - if (optionService.GetOption(LoggerOptions.TraceLoggerKey)) + if (globalOptions.GetOption(LoggerOptions.TraceLoggerKey)) { yield return nameof(TraceLogger); } - if (optionService.GetOption(LoggerOptions.OutputWindowLoggerKey)) + if (globalOptions.GetOption(LoggerOptions.OutputWindowLoggerKey)) { yield return nameof(OutputWindowLogger); } diff --git a/src/Workspaces/CSharp/Portable/CodeStyle/CSharpCodeStyleOptionsProvider.cs b/src/Workspaces/CSharp/Portable/CodeStyle/CSharpCodeStyleOptionsProvider.cs index 82b0f5997ba56..44b158c2af7fc 100644 --- a/src/Workspaces/CSharp/Portable/CodeStyle/CSharpCodeStyleOptionsProvider.cs +++ b/src/Workspaces/CSharp/Portable/CodeStyle/CSharpCodeStyleOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,8 +11,8 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeStyle { - [ExportOptionProvider(LanguageNames.CSharp), Shared] - internal class CSharpCodeStyleOptionsProvider : IOptionProvider + [ExportSolutionOptionProvider(LanguageNames.CSharp), Shared] + internal sealed class CSharpCodeStyleOptionsProvider : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] diff --git a/src/Workspaces/CSharp/Portable/Formatting/CSharpFormattingOptionsProvider.cs b/src/Workspaces/CSharp/Portable/Formatting/CSharpFormattingOptionsProvider.cs index 7e7293ea6e2a6..132e6f6ce31ee 100644 --- a/src/Workspaces/CSharp/Portable/Formatting/CSharpFormattingOptionsProvider.cs +++ b/src/Workspaces/CSharp/Portable/Formatting/CSharpFormattingOptionsProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Formatting { - [ExportOptionProvider(LanguageNames.CSharp), Shared] + [ExportSolutionOptionProvider(LanguageNames.CSharp), Shared] internal sealed class CSharpFormattingOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs b/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs index ce46a5eab102a..40053f93113e9 100644 --- a/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs +++ b/src/Workspaces/Core/Portable/Classification/ClassificationOptions.cs @@ -17,7 +17,7 @@ internal readonly record struct ClassificationOptions( [property: DataMember(Order = 0)] bool ClassifyReassignedVariables, [property: DataMember(Order = 1)] bool ColorizeRegexPatterns) { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class Metadata : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptionsProvider.cs b/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptionsProvider.cs index 6085064b89743..48fdb34347c20 100644 --- a/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptionsProvider.cs +++ b/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.CodeStyle { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class CodeStyleOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/Editing/GenerationOptionsProvider.cs b/src/Workspaces/Core/Portable/Editing/GenerationOptionsProvider.cs index 825e673d2264a..566b90519a29f 100644 --- a/src/Workspaces/Core/Portable/Editing/GenerationOptionsProvider.cs +++ b/src/Workspaces/Core/Portable/Editing/GenerationOptionsProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Editing { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class GenerationOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaOptions.cs b/src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaOptions.cs index d0af7bd136bfd..d8fc85227e522 100644 --- a/src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaOptions.cs +++ b/src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaOptions.cs @@ -26,7 +26,7 @@ internal static class PythiaOptions storageLocation: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(RemoveRecommendationLimit))); } - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class PythiaOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/Fading/FadingOptionsProvider.cs b/src/Workspaces/Core/Portable/Fading/FadingOptionsProvider.cs deleted file mode 100644 index 17d20522fc3b4..0000000000000 --- a/src/Workspaces/Core/Portable/Fading/FadingOptionsProvider.cs +++ /dev/null @@ -1,25 +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.Fading -{ - [ExportOptionProvider, Shared] - internal class FadingOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public FadingOptionsProvider() - { - } - - public ImmutableArray Options { get; } = FadingOptions.AllOptions.As(); - } -} diff --git a/src/Workspaces/Core/Portable/Formatting/FormattingBehaviorOptions.cs b/src/Workspaces/Core/Portable/Formatting/FormattingBehaviorOptions.cs index dc01a9b1c64d1..3c9cdbd7e6f52 100644 --- a/src/Workspaces/Core/Portable/Formatting/FormattingBehaviorOptions.cs +++ b/src/Workspaces/Core/Portable/Formatting/FormattingBehaviorOptions.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Formatting /// internal sealed class FormattingBehaviorOptions { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class Provider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/Options/Providers/ExportOptionProviderAttribute.cs b/src/Workspaces/Core/Portable/Options/Providers/ExportOptionProviderAttribute.cs index b5509921ebe38..b27133100b4bc 100644 --- a/src/Workspaces/Core/Portable/Options/Providers/ExportOptionProviderAttribute.cs +++ b/src/Workspaces/Core/Portable/Options/Providers/ExportOptionProviderAttribute.cs @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Options.Providers { [MetadataAttribute] [AttributeUsage(AttributeTargets.Class)] - internal sealed class ExportOptionProviderAttribute : ExportAttribute + internal abstract class ExportOptionProviderAttribute : ExportAttribute { /// /// Optional source language for language specific option providers. See . @@ -18,23 +18,48 @@ internal sealed class ExportOptionProviderAttribute : ExportAttribute public string Language { get; } /// - /// Constructor for language agnostic option providers. - /// Use overload for language specific option providers. + /// True if the option is a client global option provided by . /// - public ExportOptionProviderAttribute() + public bool IsGlobal { get; } + + public ExportOptionProviderAttribute(string language, bool isGlobal) : base(typeof(IOptionProvider)) { - this.Language = string.Empty; + Language = language; + IsGlobal = isGlobal; } + } - /// - /// Constructor for language specific option providers. - /// Use overload for language agnostic option providers. - /// - public ExportOptionProviderAttribute(string language) - : base(typeof(IOptionProvider)) + /// + /// Global client-only options. + /// + internal sealed class ExportGlobalOptionProviderAttribute : ExportOptionProviderAttribute + { + public ExportGlobalOptionProviderAttribute() + : this(language: string.Empty) + { + } + + public ExportGlobalOptionProviderAttribute(string language) + : base(language, isGlobal: true) + { + } + } + + /// + /// Options that are part of the solution snapshot. + /// Some of these options may be configurable per document via editorconfig. + /// + internal sealed class ExportSolutionOptionProviderAttribute : ExportOptionProviderAttribute + { + public ExportSolutionOptionProviderAttribute() + : this(language: string.Empty) + { + } + + public ExportSolutionOptionProviderAttribute(string language) + : base(language, isGlobal: false) { - this.Language = language ?? throw new ArgumentNullException(nameof(language)); } } } diff --git a/src/Workspaces/Core/Portable/Shared/RuntimeOptions.cs b/src/Workspaces/Core/Portable/Shared/RuntimeOptions.cs deleted file mode 100644 index 095a0a257752c..0000000000000 --- a/src/Workspaces/Core/Portable/Shared/RuntimeOptions.cs +++ /dev/null @@ -1,18 +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. - -#nullable disable - -using Microsoft.CodeAnalysis.Options; - -namespace Microsoft.CodeAnalysis.Shared.Options -{ - /// - /// Options that aren't persisted. options here will be reset to default on new process. - /// - internal static class RuntimeOptions - { - public static readonly Option BackgroundAnalysisSuspendedInfoBarShown = new(nameof(RuntimeOptions), "FullSolutionAnalysisInfoBarShown", defaultValue: false); - } -} diff --git a/src/Workspaces/Core/Portable/Shared/RuntimeOptionsProvider.cs b/src/Workspaces/Core/Portable/Shared/RuntimeOptionsProvider.cs deleted file mode 100644 index a8d049f0a1360..0000000000000 --- a/src/Workspaces/Core/Portable/Shared/RuntimeOptionsProvider.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. - -#nullable disable - -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.Shared.Options -{ - [ExportOptionProvider, Shared] - internal class RuntimeOptionsProvider : IOptionProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public RuntimeOptionsProvider() - { - } - - public ImmutableArray Options { get; } = ImmutableArray.Create( - RuntimeOptions.BackgroundAnalysisSuspendedInfoBarShown); - } -} diff --git a/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs b/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs index ffa5ca24f116a..53b2205fe5064 100644 --- a/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs +++ b/src/Workspaces/Core/Portable/Simplification/SimplificationOptionProvider.cs @@ -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.Collections.Immutable; using System.Composition; @@ -13,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Simplification { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class SimplificationOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/SolutionCrawler/SolutionCrawlerOnOffOptionsProvider.cs b/src/Workspaces/Core/Portable/SolutionCrawler/SolutionCrawlerOnOffOptionsProvider.cs index d5a014f0c71c9..2139857a98735 100644 --- a/src/Workspaces/Core/Portable/SolutionCrawler/SolutionCrawlerOnOffOptionsProvider.cs +++ b/src/Workspaces/Core/Portable/SolutionCrawler/SolutionCrawlerOnOffOptionsProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.SolutionCrawler { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class SolutionCrawlerOnOffOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/Storage/StorageOptions.cs b/src/Workspaces/Core/Portable/Storage/StorageOptions.cs index 5d147b2db6035..e086112f7d23f 100644 --- a/src/Workspaces/Core/Portable/Storage/StorageOptions.cs +++ b/src/Workspaces/Core/Portable/Storage/StorageOptions.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Storage { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class StorageOptions : IOptionProvider { internal const string LocalRegistryPath = @"Roslyn\Internal\OnOff\Features\"; 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 a6fd41a19eaa5..0000000000000 --- a/src/Workspaces/Core/Portable/SymbolSearch/SymbolSearchOptionsProvider.cs +++ /dev/null @@ -1,30 +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. - -#nullable disable - -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 -{ - [ExportOptionProvider, 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); - } -} diff --git a/src/Workspaces/Core/Portable/TodoComments/TodoCommentOptions.cs b/src/Workspaces/Core/Portable/TodoComments/TodoCommentOptions.cs index 7192c322c6ec2..03952bfeae543 100644 --- a/src/Workspaces/Core/Portable/TodoComments/TodoCommentOptions.cs +++ b/src/Workspaces/Core/Portable/TodoComments/TodoCommentOptions.cs @@ -11,21 +11,18 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.TodoComments { - internal static class TodoCommentOptions - { - public static readonly Option TokenList = new(nameof(TodoCommentOptions), nameof(TokenList), defaultValue: ""); - } - - [ExportOptionProvider, Shared] - internal class TodoCommentOptionsProvider : IOptionProvider + [ExportSolutionOptionProvider, Shared] + internal sealed class TodoCommentOptions : IOptionProvider { [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public TodoCommentOptionsProvider() + public TodoCommentOptions() { } - public ImmutableArray Options { get; } = ImmutableArray.Create( - TodoCommentOptions.TokenList); + ImmutableArray IOptionProvider.Options { get; } = ImmutableArray.Create( + TokenList); + + public static readonly Option TokenList = new(nameof(TodoCommentOptions), nameof(TokenList), defaultValue: ""); } } diff --git a/src/Workspaces/Core/Portable/Workspace/FileTextLoader.cs b/src/Workspaces/Core/Portable/Workspace/FileTextLoader.cs index 46a51b43a1010..c36c00aa2ae9c 100644 --- a/src/Workspaces/Core/Portable/Workspace/FileTextLoader.cs +++ b/src/Workspaces/Core/Portable/Workspace/FileTextLoader.cs @@ -34,7 +34,7 @@ internal static class FileTextLoaderOptions storageLocation: new LocalUserProfileStorageLocation(@"Roslyn\Internal\Performance\Text\FileLengthThreshold")); } - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class FileTextLoaderOptionsProvider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/Core/Portable/Workspace/WorkspaceConfigurationOptions.cs b/src/Workspaces/Core/Portable/Workspace/WorkspaceConfigurationOptions.cs index 7bb32659d19f9..2192bd7abac94 100644 --- a/src/Workspaces/Core/Portable/Workspace/WorkspaceConfigurationOptions.cs +++ b/src/Workspaces/Core/Portable/Workspace/WorkspaceConfigurationOptions.cs @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis { - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal class WorkspaceConfigurationOptions : IOptionProvider { /// diff --git a/src/Workspaces/CoreTest/WorkspaceServiceTests/OptionServiceTests.cs b/src/Workspaces/CoreTest/WorkspaceServiceTests/OptionServiceTests.cs index 045ee0186d62e..a6c0a7df2396b 100644 --- a/src/Workspaces/CoreTest/WorkspaceServiceTests/OptionServiceTests.cs +++ b/src/Workspaces/CoreTest/WorkspaceServiceTests/OptionServiceTests.cs @@ -314,7 +314,7 @@ public void TestChangedTodoCommentOptions() using var workspace = new AdhocWorkspace(hostServices); var option = TodoCommentOptions.TokenList; - var provider = ((IMefHostExportProvider)hostServices).GetExportedValues().OfType().FirstOrDefault(); + var provider = ((IMefHostExportProvider)hostServices).GetExportedValues().OfType().FirstOrDefault(); var optionService = TestOptionService.GetService(workspace, provider); var optionSet = optionService.GetOptions(); var optionKey = new OptionKey(option); @@ -349,7 +349,7 @@ public void TestPersistedTodoCommentOptions() Assert.True(persister.TryFetch(option, out var persistedValue)); Assert.Equal(newOptionValue, persistedValue); - var provider = ((IMefHostExportProvider)hostServices).GetExportedValues().OfType().FirstOrDefault(); + var provider = ((IMefHostExportProvider)hostServices).GetExportedValues().OfType().FirstOrDefault(); var persisterProvider = new TestOptionService.TestOptionsPersisterProvider(persister); var optionService = TestOptionService.GetService(workspace, provider, persisterProvider); var optionSet = optionService.GetOptions(); diff --git a/src/Workspaces/Remote/Core/RemoteHostOptions.cs b/src/Workspaces/Remote/Core/RemoteHostOptions.cs index c7d404a1a4727..b773722a0e20b 100644 --- a/src/Workspaces/Remote/Core/RemoteHostOptions.cs +++ b/src/Workspaces/Remote/Core/RemoteHostOptions.cs @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Remote { - [ExportOptionProvider, Shared] + [ExportGlobalOptionProvider, Shared] internal sealed class RemoteHostOptions : IOptionProvider { private const string LocalRegistryPath = StorageOptions.LocalRegistryPath; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems index f616833480ad6..bd5474dd5ac2a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems @@ -234,7 +234,6 @@ - diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Fading/FadingOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Fading/FadingOptions.cs deleted file mode 100644 index 9d5a11b0f9c7d..0000000000000 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Fading/FadingOptions.cs +++ /dev/null @@ -1,24 +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.Collections.Immutable; -using Microsoft.CodeAnalysis.Options; - -namespace Microsoft.CodeAnalysis.Fading -{ - internal static class FadingOptions - { - public static readonly PerLanguageOption2 FadeOutUnusedImports = new( - nameof(FadingOptions), nameof(FadeOutUnusedImports), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(FadeOutUnusedImports)}")); - - public static readonly PerLanguageOption2 FadeOutUnreachableCode = new( - nameof(FadingOptions), nameof(FadeOutUnreachableCode), defaultValue: true, - storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(FadeOutUnreachableCode)}")); - - public static readonly ImmutableArray AllOptions = ImmutableArray.Create( - FadeOutUnusedImports, - FadeOutUnreachableCode); - } -} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs index 5b3cad8dbd23b..13282f2a3e29b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs @@ -22,7 +22,7 @@ namespace Microsoft.CodeAnalysis.Formatting internal sealed class FormattingOptions2 { #if !CODE_STYLE - [ExportOptionProvider, Shared] + [ExportSolutionOptionProvider, Shared] internal sealed class Provider : IOptionProvider { [ImportingConstructor] diff --git a/src/Workspaces/VisualBasic/Portable/CodeStyle/VisualBasicCodeStyleOptionsProvider.vb b/src/Workspaces/VisualBasic/Portable/CodeStyle/VisualBasicCodeStyleOptionsProvider.vb index a07cf3e014694..a62b4cd1515cc 100644 --- a/src/Workspaces/VisualBasic/Portable/CodeStyle/VisualBasicCodeStyleOptionsProvider.vb +++ b/src/Workspaces/VisualBasic/Portable/CodeStyle/VisualBasicCodeStyleOptionsProvider.vb @@ -9,7 +9,7 @@ Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Options.Providers Namespace Microsoft.CodeAnalysis.VisualBasic.CodeStyle - + Friend NotInheritable Class VisualBasicCodeStyleOptionsProvider Implements IOptionProvider