CodeBase some Roslyn assemblies and fix Integration test failures

This commit is contained in:
Ryan Brandenburg 2022-10-25 17:26:25 -07:00
Родитель 1fa572208c
Коммит fbd5c12cfe
7 изменённых файлов: 157 добавлений и 6 удалений

Просмотреть файл

@ -80,6 +80,7 @@
<package pattern="humanizer.core" /> <package pattern="humanizer.core" />
<package pattern="iced" /> <package pattern="iced" />
<package pattern="icsharpcode.decompiler" /> <package pattern="icsharpcode.decompiler" />
<package pattern="inputsimulatorplus" />
<package pattern="mediatr" /> <package pattern="mediatr" />
<package pattern="messagepack" /> <package pattern="messagepack" />
<package pattern="messagepack.annotations" /> <package pattern="messagepack.annotations" />

Просмотреть файл

@ -84,6 +84,8 @@
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>$(RoslynPackageVersion)</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion> <MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>$(RoslynPackageVersion)</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Manual"> <PropertyGroup Label="Manual">
<InputSimulatorPlusVersion>1.0.7</InputSimulatorPlusVersion>
<!-- dotnet/runtime packages --> <!-- dotnet/runtime packages -->
<MicrosoftExtensionsPackageVersion>6.0.0</MicrosoftExtensionsPackageVersion> <MicrosoftExtensionsPackageVersion>6.0.0</MicrosoftExtensionsPackageVersion>
<SystemCollectionsImmutablePackageVersion>6.0.0</SystemCollectionsImmutablePackageVersion> <SystemCollectionsImmutablePackageVersion>6.0.0</SystemCollectionsImmutablePackageVersion>

Просмотреть файл

@ -1,13 +1,160 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information. // Licensed under the MIT license. See License.txt in the project root for license information.
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.VisualStudio.Threading;
using System;
using WindowsInput;
using System.Collections.Immutable;
using WindowsInput.Native;
namespace Microsoft.VisualStudio.Extensibility.Testing namespace Microsoft.VisualStudio.Extensibility.Testing
{ {
internal struct InputKey
{
public readonly ImmutableArray<VirtualKeyCode> Modifiers;
public readonly VirtualKeyCode VirtualKeyCode;
public readonly char? Character;
public readonly string? Text;
public InputKey(VirtualKeyCode virtualKeyCode)
{
Modifiers = ImmutableArray<VirtualKeyCode>.Empty;
VirtualKeyCode = virtualKeyCode;
Character = null;
Text = null;
}
public InputKey(VirtualKeyCode virtualKeyCode, ImmutableArray<VirtualKeyCode> modifiers)
{
Modifiers = modifiers;
VirtualKeyCode = virtualKeyCode;
Character = null;
Text = null;
}
public InputKey(char character)
{
Modifiers = ImmutableArray<VirtualKeyCode>.Empty;
VirtualKeyCode = 0;
Character = character;
Text = null;
}
public InputKey(string text)
{
Modifiers = ImmutableArray<VirtualKeyCode>.Empty;
VirtualKeyCode = 0;
Character = null;
Text = text;
}
public static implicit operator InputKey(VirtualKeyCode virtualKeyCode)
=> new(virtualKeyCode);
public static implicit operator InputKey(char character)
=> new(character);
public static implicit operator InputKey(string text)
=> new(text);
public void Apply(IInputSimulator simulator)
{
if (Character is { } c)
{
if (c == '\n')
simulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);
else if (c == '\t')
simulator.Keyboard.KeyPress(VirtualKeyCode.TAB);
else
simulator.Keyboard.TextEntry(c);
return;
}
else if (Text is not null)
{
var offset = 0;
while (offset < Text.Length)
{
if (Text[offset] == '\r' && offset < Text.Length - 1 && Text[offset + 1] == '\n')
{
// Treat \r\n as a single RETURN character
offset++;
continue;
}
else if (Text[offset] == '\n')
{
simulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);
offset++;
continue;
}
else if (Text[offset] == '\t')
{
simulator.Keyboard.KeyPress(VirtualKeyCode.TAB);
offset++;
continue;
}
else
{
var nextSpecial = Text.IndexOfAny(new[] { '\r', '\n', '\t' }, offset);
var endOfCurrentSegment = nextSpecial < 0 ? Text.Length : nextSpecial;
simulator.Keyboard.TextEntry(Text[offset..endOfCurrentSegment]);
offset = endOfCurrentSegment;
}
}
return;
}
if (Modifiers.IsEmpty)
{
simulator.Keyboard.KeyPress(VirtualKeyCode);
}
else
{
simulator.Keyboard.ModifiedKeyStroke(Modifiers, VirtualKeyCode);
}
}
}
[TestService] [TestService]
internal partial class InputInProcess internal partial class InputInProcess
{ {
internal Task SendAsync(InputKey key, CancellationToken cancellationToken)
=> SendAsync(new InputKey[] { key }, cancellationToken);
internal Task SendAsync(InputKey[] keys, CancellationToken cancellationToken)
{
return SendAsync(
simulator =>
{
foreach (var key in keys)
{
key.Apply(simulator);
}
}, cancellationToken);
}
internal async Task SendAsync(Action<IInputSimulator> callback, CancellationToken cancellationToken)
{
// AbstractSendKeys runs synchronously, so switch to a background thread before the call
await TaskScheduler.Default;
TestServices.JoinableTaskFactory.Run(async () =>
{
await TestServices.Editor.ActivateAsync(cancellationToken);
});
callback(new InputSimulator());
TestServices.JoinableTaskFactory.Run(async () =>
{
await WaitForApplicationIdleAsync(cancellationToken);
});
}
internal void Send(string keys) internal void Send(string keys)
{ {
SendKeys.Send(keys); SendKeys.Send(keys);

Просмотреть файл

@ -25,6 +25,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="InputSimulatorPlus" Version="$(InputSimulatorPlusVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Editor" Version="$(MicrosoftVisualStudioEditorPackageVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Editor" Version="$(MicrosoftVisualStudioEditorPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Testing.Xunit" Version="$(MicrosoftVisualStudioExtensibilityTestingXunitVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Extensibility.Testing.Xunit" Version="$(MicrosoftVisualStudioExtensibilityTestingXunitVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Testing.SourceGenerator" Version="$(MicrosoftVisualStudioExtensibilityTestingSourceGeneratorVersion)" /> <PackageReference Include="Microsoft.VisualStudio.Extensibility.Testing.SourceGenerator" Version="$(MicrosoftVisualStudioExtensibilityTestingSourceGeneratorVersion)" />

Просмотреть файл

@ -116,7 +116,7 @@ A
// Act // Act
await TestServices.Editor.PlaceCaretAsync("@onclick='thing'", charsOffset: 1, ControlledHangMitigatingCancellationToken); await TestServices.Editor.PlaceCaretAsync("@onclick='thing'", charsOffset: 1, ControlledHangMitigatingCancellationToken);
TestServices.Input.Send("{ENTER}"); await TestServices.Input.SendAsync(WindowsInput.Native.VirtualKeyCode.RETURN, ControlledHangMitigatingCancellationToken);
// Assert // Assert
await TestServices.Editor.VerifyTextContainsAsync(@" await TestServices.Editor.VerifyTextContainsAsync(@"

Просмотреть файл

@ -1,6 +1,6 @@
0,1,RazorTransition, 0,1,RazorTransition,
1,8,RazorDirective, 1,8,RazorDirective,
10,19,class name, 10,19,identifier,
33,1,HTML Tag Delimiter, 33,1,HTML Tag Delimiter,
34,9,RazorComponentElement, 34,9,RazorComponentElement,
43,1,HTML Tag Delimiter, 43,1,HTML Tag Delimiter,
@ -76,7 +76,7 @@
337,1,HTML Attribute Value, 337,1,HTML Attribute Value,
338,1,HTML Tag Delimiter, 338,1,HTML Tag Delimiter,
353,1,RazorTransition, 353,1,RazorTransition,
354,4,property name, 354,4,identifier,
368,1,HTML Tag Delimiter, 368,1,HTML Tag Delimiter,
369,1,HTML Tag Delimiter, 369,1,HTML Tag Delimiter,
370,7,HTML Element Name, 370,7,HTML Element Name,

Просмотреть файл

@ -24,7 +24,7 @@
89,1,HTML Attribute Value, 89,1,HTML Attribute Value,
90,1,HTML Tag Delimiter, 90,1,HTML Tag Delimiter,
106,1,RazorTransition, 106,1,RazorTransition,
107,12,field name, 107,12,identifier,
119,1,HTML Tag Delimiter, 119,1,HTML Tag Delimiter,
120,1,HTML Tag Delimiter, 120,1,HTML Tag Delimiter,
121,1,HTML Element Name, 121,1,HTML Element Name,
@ -41,7 +41,7 @@
160,7,RazorDirectiveAttribute, 160,7,RazorDirectiveAttribute,
167,1,HTML Operator, 167,1,HTML Operator,
168,1,HTML Attribute Value, 168,1,HTML Attribute Value,
169,14,method name, 169,14,identifier,
183,1,HTML Attribute Value, 183,1,HTML Attribute Value,
184,1,HTML Tag Delimiter, 184,1,HTML Tag Delimiter,
193,1,HTML Tag Delimiter, 193,1,HTML Tag Delimiter,
@ -63,7 +63,7 @@
283,1,punctuation, 283,1,punctuation,
284,1,punctuation, 284,1,punctuation,
291,1,punctuation, 291,1,punctuation,
302,12,field name, 302,12,identifier,
314,2,operator, 314,2,operator,
316,1,punctuation, 316,1,punctuation,
323,1,punctuation, 323,1,punctuation,