Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Feb 4, 2022
1 parent a7b9674 commit 7a090c9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Options settable by integration tests.
///
/// TODO: Options are currently explicitly listed since <see cref="OptionKey"/> is not serializable.
/// https://github.com/dotnet/roslyn/issues/59267
/// </summary>
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);
}
}

0 comments on commit 7a090c9

Please sign in to comment.