* Fixing HTML attribute commit

* PR feedback
This commit is contained in:
Alex Gavrilov 2024-09-18 10:57:59 -07:00 коммит произвёл GitHub
Родитель 4b3e4096e8
Коммит 53dae17245
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 259 добавлений и 42 удалений

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

@ -36,6 +36,11 @@ internal class RazorCompletionEndpoint(
{
ResolveProvider = true,
TriggerCharacters = _completionListProvider.AggregateTriggerCharacters.ToArray(),
// This is the intersection of C# and HTML commit characters.
// We need to specify it so that platform can correctly calculate ApplicableToSpan in
// https://devdiv.visualstudio.com/DevDiv/_git/VSLanguageServerClient?path=/src/product/RemoteLanguage/Impl/Features/Completion/AsyncCompletionSource.cs&version=GBdevelop&line=855&lineEnd=855&lineStartColumn=9&lineEndColumn=49&lineStyle=plain&_a=contents
// This is needed to fix https://github.com/dotnet/razor/issues/10787 in particular
AllCommitCharacters = [" ", ">", ";", "="]
};
}

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

@ -16,56 +16,261 @@ public class CompletionIntegrationTests(ITestOutputHelper testOutputHelper) : Ab
[IdeFact]
public async Task SnippetCompletion_Html()
{
await VerifyTypeAndCommitCompletionAsync(
input: """
@page "Test"
<PageTitle>Test</PageTitle>
<h1>Test</h1>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
output: """
@page "Test"
<PageTitle>Test</PageTitle>
<h1>Test</h1>
<dl>
<dt></dt>
<dd></dd>
</dl>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
search: "<h1>Test</h1>",
stringsToType: ["{ENTER}", "d", "d"]);
}
[IdeFact, WorkItem("https://github.com/dotnet/razor/issues/10787")]
public async Task CompletionCommit_HtmlAttributeWithoutValue()
{
await VerifyTypeAndCommitCompletionAsync(
input: """
@page "Test"
<PageTitle>Test</PageTitle>
<button></button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
output: """
@page "Test"
<PageTitle>Test</PageTitle>
<button disabled></button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
search: "<button",
stringsToType: [" ", "d", "i", "s"]);
}
[IdeFact]
public async Task CompletionCommit_HtmlAttributeWithValue()
{
await VerifyTypeAndCommitCompletionAsync(
input: """
@page "Test"
<PageTitle>Test</PageTitle>
<button></button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
output: """
@page "Test"
<PageTitle>Test</PageTitle>
<button style=""></button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
search: "<button",
stringsToType: [" ", "s", "t", "y"]);
}
[IdeFact]
public async Task CompletionCommit_HtmlTag()
{
await VerifyTypeAndCommitCompletionAsync(
input: """
@page "Test"
<PageTitle>Test</PageTitle>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
output: """
@page "Test"
<PageTitle>Test</PageTitle>
<span
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
search: "</PageTitle>",
stringsToType: ["{ENTER}", "{ENTER}", "<", "s", "p", "a"]);
}
[IdeFact]
public async Task CompletionCommit_WithAngleBracket_HtmlTag()
{
await VerifyTypeAndCommitCompletionAsync(
input: """
@page "Test"
<PageTitle>Test</PageTitle>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
output: """
@page "Test"
<PageTitle>Test</PageTitle>
<span></span>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
search: "</PageTitle>",
stringsToType: ["{ENTER}", "{ENTER}", "<", "s", "p", "a"],
commitChar: '>');
}
[IdeFact]
public async Task CompletionCommit_CSharp()
{
await VerifyTypeAndCommitCompletionAsync(
input: """
@page "Test"
<PageTitle>Test</PageTitle>
@code {
private int myCurrentCount = 0;
private void IncrementCount()
{
myCurrentCount++;
}
}
""",
output: """
@page "Test"
<PageTitle>Test</PageTitle>
@code {
private int myCurrentCount = 0;
private void IncrementCount()
{
myCurrentCount++;
myCurrentCount
}
}
""",
search: "myCurrentCount++;",
stringsToType: ["{ENTER}", "{ENTER}", "m", "y", "C", "u", "r"]);
}
private async Task VerifyTypeAndCommitCompletionAsync(string input, string output, string search, string[] stringsToType, char? commitChar = null)
{
await TestServices.SolutionExplorer.AddFileAsync(
RazorProjectConstants.BlazorProjectName,
"Test.razor",
"""
@page "Test"
<PageTitle>Test</PageTitle>
<h1>Test</h1>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""",
input,
open: true,
ControlledHangMitigatingCancellationToken);
await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);
await TestServices.Editor.PlaceCaretAsync("<h1>Test</h1>", charsOffset: 1, ControlledHangMitigatingCancellationToken);
TestServices.Input.Send("{ENTER}");
TestServices.Input.Send("d");
TestServices.Input.Send("d");
await TestServices.Editor.PlaceCaretAsync(search, charsOffset: 1, ControlledHangMitigatingCancellationToken);
foreach (var stringToType in stringsToType)
{
TestServices.Input.Send(stringToType);
}
await CommitCompletionAndVerifyAsync("""
@page "Test"
<PageTitle>Test</PageTitle>
<h1>Test</h1>
<dl>
<dt></dt>
<dd></dd>
</dl>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
""");
await CommitCompletionAndVerifyAsync(output, commitChar);
}
[IdeFact]
@ -225,12 +430,19 @@ public class CompletionIntegrationTests(ITestOutputHelper testOutputHelper) : Ab
""");
}
private async Task CommitCompletionAndVerifyAsync(string expected)
private async Task CommitCompletionAndVerifyAsync(string expected, char? commitChar = null)
{
var session = await TestServices.Editor.WaitForCompletionSessionAsync(HangMitigatingCancellationToken);
Assert.NotNull(session);
Assert.True(session.CommitIfUnique(HangMitigatingCancellationToken));
if (commitChar.HasValue)
{
TestServices.Input.Send(commitChar.Value.ToString());
}
else
{
Assert.True(session.CommitIfUnique(HangMitigatingCancellationToken));
}
var textView = await TestServices.Editor.GetActiveTextViewAsync(HangMitigatingCancellationToken);
var text = textView.TextBuffer.CurrentSnapshot.GetText();