From a41cea4ee9fba2b3cf1f749a0136d5ccb748e101 Mon Sep 17 00:00:00 2001 From: "Alex Gavrilov (DEV PROD)" Date: Wed, 6 Nov 2024 10:18:18 -0800 Subject: [PATCH] Fixing html snippet completion and intergration tests HTML snippet completions were being included when they shouldn't have been --- .../RazorCustomMessageTarget_Completion.cs | 6 +++- .../CohostDocumentCompletionEndpointTest.cs | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget_Completion.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget_Completion.cs index 2e5defe68cf..2ab78534f45 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget_Completion.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget_Completion.cs @@ -150,7 +150,11 @@ internal partial class RazorCustomMessageTarget }; } - _snippetCompletionItemProvider.AddSnippetCompletions(request.ProjectedKind, request.Context.InvokeKind, request.Context.TriggerCharacter, ref builder.AsRef()); + if (request.ShouldIncludeSnippets) + { + _snippetCompletionItemProvider.AddSnippetCompletions(request.ProjectedKind, request.Context.InvokeKind, request.Context.TriggerCharacter, ref builder.AsRef()); + } + completionList.Items = builder.ToArray(); completionList.Data = JsonHelpers.TryConvertFromJObject(completionList.Data); diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentCompletionEndpointTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentCompletionEndpointTest.cs index 4f0ef748592..fa1c8d8215f 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentCompletionEndpointTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentCompletionEndpointTest.cs @@ -290,6 +290,29 @@ The end. snippetLabels: ["snippet1", "snippet2"]); } + [Fact] + public async Task HtmlSnippetsCompletion_NotInStartTag() + { + await VerifyCompletionListAsync( + input: """ + This is a Razor document. + +
+ + The end. + """, + completionContext: new RoslynVSInternalCompletionContext() + { + InvokeKind = RoslynVSInternalCompletionInvokeKind.Typing, + TriggerCharacter = " ", + TriggerKind = RoslynCompletionTriggerKind.TriggerCharacter + }, + expectedItemLabels: ["style", "dir"], + unexpectedItemLabels: ["snippet1", "snippet2"], + delegatedItemLabels: ["style", "dir"], + snippetLabels: ["snippet1", "snippet2"]); + } + // Tests HTML attributes and DirectiveAttributeTransitionCompletionItemProvider [Fact] public async Task HtmlAndDirectiveAttributeTransitionNamesCompletion() @@ -402,6 +425,7 @@ private async Task VerifyCompletionListAsync( TestCode input, RoslynVSInternalCompletionContext completionContext, string[] expectedItemLabels, + string[]? unexpectedItemLabels = null, string[]? delegatedItemLabels = null, string[]? delegatedItemCommitCharacters = null, string[]? snippetLabels = null, @@ -469,6 +493,14 @@ private async Task VerifyCompletionListAsync( Assert.Contains(expectedItemLabel, labelSet); } + if (unexpectedItemLabels is not null) + { + foreach (var unexpectedItemLabel in unexpectedItemLabels) + { + Assert.DoesNotContain(unexpectedItemLabel, labelSet); + } + } + if (!commitElementsWithSpace) { Assert.False(result.Items.Any(item => item.CommitCharacters?.First().Contains(" ") ?? false));