Skip to content

Commit

Permalink
Update to vs-extension-testing 0.1.127-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Feb 16, 2022
1 parent 939970d commit cfdb64a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 54 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RoslynDiagnosticsNugetPackageVersion>3.3.3-beta1.21105.3</RoslynDiagnosticsNugetPackageVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-rc1.21366.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisTestingVersion>1.1.1-beta1.22081.4</MicrosoftCodeAnalysisTestingVersion>
<MicrosoftVisualStudioExtensibilityTestingVersion>0.1.124-beta</MicrosoftVisualStudioExtensibilityTestingVersion>
<MicrosoftVisualStudioExtensibilityTestingVersion>0.1.127-beta</MicrosoftVisualStudioExtensibilityTestingVersion>
<!-- CodeStyleAnalyzerVersion should we updated together with version of dotnet-format in dotnet-tools.json -->
<CodeStyleAnalyzerVersion>4.0.1</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>16.10.230</VisualStudioEditorPackagesVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,20 @@
// 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.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.UnitTests;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using IAsyncDisposable = System.IAsyncDisposable;
using IOleCommandTarget = Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget;
using OLECMDEXECOPT = Microsoft.VisualStudio.OLE.Interop.OLECMDEXECOPT;

namespace Microsoft.VisualStudio.Extensibility.Testing
{
internal partial class ShellInProcess
{
public async Task<(Guid commandGroup, uint commandId)> PrepareCommandAsync(string command, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var commandWindow = await GetRequiredGlobalServiceAsync<SVsCommandWindow, IVsCommandWindow>(cancellationToken);
var result = new PREPARECOMMANDRESULT[1];
ErrorHandler.ThrowOnFailure(commandWindow.PrepareCommand(command, out var commandGroup, out var commandId, out var cmdArg, result));

if (cmdArg != IntPtr.Zero)
{
throw new NotSupportedException("Unable to create a disposable wrapper for command arguments (VARIANT).");
}

return (commandGroup, commandId);
}

public async Task ExecuteCommandAsync(string command, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var (commandGuid, commandId) = await PrepareCommandAsync(command, cancellationToken);
await ExecuteCommandAsync(commandGuid, commandId, cancellationToken);
}

public Task ExecuteCommandAsync<TEnum>(TEnum command, CancellationToken cancellationToken)
where TEnum : struct, Enum
{
var commandGuid = command switch
{
EditorConstants.EditorCommandID => EditorConstants.EditorCommandSet,
_ => typeof(TEnum).GUID,
};

return ExecuteCommandAsync(commandGuid, Convert.ToUInt32(command), cancellationToken);
}

public Task ExecuteCommandAsync((Guid commandGuid, uint commandId) command, CancellationToken cancellationToken)
=> ExecuteCommandAsync(command.commandGuid, command.commandId, cancellationToken);

public async Task ExecuteCommandAsync(Guid commandGuid, uint commandId, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var dispatcher = await TestServices.Shell.GetRequiredGlobalServiceAsync<SUIHostCommandDispatcher, IOleCommandTarget>(cancellationToken);
ErrorHandler.ThrowOnFailure(dispatcher.Exec(commandGuid, commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero));
}

public async Task<PauseFileChangesRestorer> PauseFileChangesAsync(CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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.

using System;
using System.ComponentModel.Design;
using Microsoft.VisualStudio;

namespace Roslyn.VisualStudio.IntegrationTests
Expand All @@ -11,7 +11,7 @@ internal static class WellKnownCommands
{
public static class Edit
{
public static readonly (Guid commandGroup, uint commandId) RemoveAndSort = (VSConstants.CMDSETID.CSharpGroup_guid, 6419);
public static readonly CommandID RemoveAndSort = new(VSConstants.CMDSETID.CSharpGroup_guid, 6419);
}
}
}

0 comments on commit cfdb64a

Please sign in to comment.