зеркало из https://github.com/dotnet/razor.git
Fixing HTML attribute commit (#10897)
* Fixing HTML attribute commit * PR feedback
This commit is contained in:
Родитель
4b3e4096e8
Коммит
53dae17245
|
@ -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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче