From 7a090c9fe86119f8abe24fedb36112380e3e3ca9 Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Thu, 3 Feb 2022 20:05:05 -0800 Subject: [PATCH] Fix integration tests --- .../InProcess/VisualStudioWorkspace_InProc.cs | 9 +++-- .../VisualStudioWorkspace_OutOfProc.cs | 19 +++++----- .../TestUtilities/WellKnownGlobalOptions.cs | 38 +++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/VisualStudio/IntegrationTest/TestUtilities/WellKnownGlobalOptions.cs diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs index 36cbf82166394..e7276d7c72659 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/VisualStudioWorkspace_InProc.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Immutable; using System.ComponentModel; using System.Linq; using System.Runtime.InteropServices; @@ -89,15 +90,15 @@ public void SetOption(string optionName, string feature, object value) SetOption(optionKey, result); } - public object? GetGlobalOption(string feature, string optionName, string? language) + public object? GetGlobalOption(WellKnownGlobalOption option, string? language) { object? result = null; - InvokeOnUIThread(_ => result = _globalOptions.GetOption(new OptionKey(GetOption(optionName, feature), language))); + InvokeOnUIThread(_ => result = _globalOptions.GetOption(option.GetKey(language))); return result; } - public void SetGlobalOption(string feature, string optionName, string? language, object? value) - => InvokeOnUIThread(_ => _globalOptions.SetGlobalOption(new OptionKey(GetOption(optionName, feature), language), value)); + public void SetGlobalOption(WellKnownGlobalOption option, string? language, object? value) + => InvokeOnUIThread(_ => _globalOptions.SetGlobalOption(option.GetKey(language), value)); private static object GetValue(object value, IOption option) { diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs index f05eafc3fac37..5411f6e5cb2b4 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/VisualStudioWorkspace_OutOfProc.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.SolutionCrawler; using Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess; @@ -59,8 +60,8 @@ public void CleanUpWaitingService() public void SetImportCompletionOption(bool value) { - SetGlobalOption("CompletionOptions", "ShowItemsFromUnimportedNamespaces", LanguageNames.CSharp, value); - SetGlobalOption("CompletionOptions", "ShowItemsFromUnimportedNamespaces", LanguageNames.VisualBasic, value); + SetGlobalOption(WellKnownGlobalOption.CompletionOptions_ShowItemsFromUnimportedNamespaces, LanguageNames.CSharp, value); + SetGlobalOption(WellKnownGlobalOption.CompletionOptions_ShowItemsFromUnimportedNamespaces, LanguageNames.VisualBasic, value); } public void SetEnableDecompilationOption(bool value) @@ -70,12 +71,12 @@ public void SetEnableDecompilationOption(bool value) public void SetArgumentCompletionSnippetsOption(bool value) { - SetGlobalOption("CompletionOptions", "EnableArgumentCompletionSnippets", LanguageNames.CSharp, value); - SetGlobalOption("CompletionOptions", "EnableArgumentCompletionSnippets", LanguageNames.VisualBasic, value); + SetGlobalOption(WellKnownGlobalOption.CompletionViewOptions_EnableArgumentCompletionSnippets, LanguageNames.CSharp, value); + SetGlobalOption(WellKnownGlobalOption.CompletionViewOptions_EnableArgumentCompletionSnippets, LanguageNames.VisualBasic, value); } public void SetTriggerCompletionInArgumentLists(bool value) - => SetGlobalOption("CompletionOptions", "TriggerInArgumentLists", LanguageNames.CSharp, value); + => SetGlobalOption(WellKnownGlobalOption.CompletionOptions_TriggerInArgumentLists, LanguageNames.CSharp, value); public void SetFullSolutionAnalysis(bool value) { @@ -106,11 +107,11 @@ public void SetEnableOpeningSourceGeneratedFilesInWorkspaceExperiment(bool value public void SetFeatureOption(string feature, string optionName, string language, string? valueString) => _inProc.SetFeatureOption(feature, optionName, language, valueString); - public object? GetGlobalOption(string feature, string optionName, string? language) - => _inProc.GetGlobalOption(feature, optionName, language); + public object? GetGlobalOption(WellKnownGlobalOption option, string? language) + => _inProc.GetGlobalOption(option, language); - public void SetGlobalOption(string feature, string optionName, string? language, object? value) - => _inProc.SetGlobalOption(feature, optionName, language, value); + public void SetGlobalOption(WellKnownGlobalOption option, string? language, object? value) + => _inProc.SetGlobalOption(option, language, value); public string? GetWorkingFolder() => _inProc.GetWorkingFolder(); } diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/WellKnownGlobalOptions.cs b/src/VisualStudio/IntegrationTest/TestUtilities/WellKnownGlobalOptions.cs new file mode 100644 index 0000000000000..cab93355e0a2c --- /dev/null +++ b/src/VisualStudio/IntegrationTest/TestUtilities/WellKnownGlobalOptions.cs @@ -0,0 +1,38 @@ +// 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.Completion; +using Microsoft.CodeAnalysis.Options; +using Roslyn.Utilities; + +namespace Microsoft.VisualStudio.IntegrationTest.Utilities +{ + /// + /// Options settable by integration tests. + /// + /// TODO: Options are currently explicitly listed since is not serializable. + /// https://github.com/dotnet/roslyn/issues/59267 + /// + public enum WellKnownGlobalOption + { + CompletionOptions_ShowItemsFromUnimportedNamespaces, + CompletionViewOptions_EnableArgumentCompletionSnippets, + CompletionOptions_TriggerInArgumentLists, + } + + public static class WellKnownGlobalOptions + { + public static IOption GetOption(this WellKnownGlobalOption option) + => option switch + { + WellKnownGlobalOption.CompletionOptions_ShowItemsFromUnimportedNamespaces => CompletionOptionsStorage.ShowItemsFromUnimportedNamespaces, + WellKnownGlobalOption.CompletionOptions_TriggerInArgumentLists => CompletionOptionsStorage.TriggerInArgumentLists, + WellKnownGlobalOption.CompletionViewOptions_EnableArgumentCompletionSnippets => CompletionViewOptions.EnableArgumentCompletionSnippets, + _ => throw ExceptionUtilities.Unreachable + }; + + public static OptionKey GetKey(this WellKnownGlobalOption option, string? language) + => new OptionKey(GetOption(option), language); + } +}