Skip to content

Commit

Permalink
Stabilize InvokeCodeActionListAsync prior to 17.1 Preview 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Nov 17, 2021
1 parent c97882e commit 72ee59c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ public async Task InvokeCodeActionListAsync(CancellationToken cancellationToken)
await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.SolutionCrawler, cancellationToken);
await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.DiagnosticService, cancellationToken);

if (Version.Parse("17.1.31916.450") > await TestServices.Shell.GetVersionAsync(cancellationToken))
{
// Workaround for extremely unstable async lightbulb prior to:
// https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/361759
await TestServices.Input.SendAsync(new KeyPress(VirtualKey.Period, ShiftState.Ctrl));
await Task.Delay(5000, cancellationToken);

await TestServices.Editor.DismissLightBulbSessionAsync(cancellationToken);
await Task.Delay(5000, cancellationToken);
}

await ShowLightBulbAsync(cancellationToken);
await TestServices.Workspace.WaitForAsyncOperationsAsync(FeatureAttribute.LightBulb, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell.Interop;

namespace Roslyn.VisualStudio.IntegrationTests.InProcess
{
internal class ShellInProcess : InProcComponent
{
public ShellInProcess(TestServices testServices)
: base(testServices)
{
}

public async Task<Version> GetVersionAsync(CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var shell = await GetRequiredGlobalServiceAsync<SVsShell, IVsShell>(cancellationToken);
shell.GetProperty((int)__VSSPROPID5.VSSPROPID_ReleaseVersion, out var versionProperty);

var fullVersion = versionProperty?.ToString() ?? "";
var firstSpace = fullVersion.IndexOf(' ');
if (firstSpace >= 0)
{
// e.g. "17.1.31907.60 MAIN"
fullVersion = fullVersion[..firstSpace];
}

if (Version.TryParse(fullVersion, out var version))
return version;

throw new NotSupportedException($"Unexpected version format: {versionProperty}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected TestServices(JoinableTaskFactory joinableTaskFactory)
EditorVerifier = new EditorVerifierInProcess(this);
ErrorList = new ErrorListInProcess(this);
Input = new InputInProcess(this);
Shell = new ShellInProcess(this);
SolutionExplorer = new SolutionExplorerInProcess(this);
SolutionVerifier = new SolutionVerifierInProcess(this);
StateReset = new StateResetInProcess(this);
Expand All @@ -33,6 +34,8 @@ protected TestServices(JoinableTaskFactory joinableTaskFactory)

public InputInProcess Input { get; }

public ShellInProcess Shell { get; }

public SolutionExplorerInProcess SolutionExplorer { get; }

public SolutionVerifierInProcess SolutionVerifier { get; }
Expand Down

0 comments on commit 72ee59c

Please sign in to comment.