Skip to content

Commit c6c3190

Browse files
authored
Fixing html snippet completion and intergration tests (#11172)
HTML snippet completions were being included when they shouldn't have been
1 parent 6e796fe commit c6c3190

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget_Completion.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ internal partial class RazorCustomMessageTarget
150150
};
151151
}
152152

153-
_snippetCompletionItemProvider.AddSnippetCompletions(request.ProjectedKind, request.Context.InvokeKind, request.Context.TriggerCharacter, ref builder.AsRef());
153+
if (request.ShouldIncludeSnippets)
154+
{
155+
_snippetCompletionItemProvider.AddSnippetCompletions(request.ProjectedKind, request.Context.InvokeKind, request.Context.TriggerCharacter, ref builder.AsRef());
156+
}
157+
154158
completionList.Items = builder.ToArray();
155159

156160
completionList.Data = JsonHelpers.TryConvertFromJObject(completionList.Data);

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/CohostDocumentCompletionEndpointTest.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ The end.
290290
snippetLabels: ["snippet1", "snippet2"]);
291291
}
292292

293+
[Fact]
294+
public async Task HtmlSnippetsCompletion_NotInStartTag()
295+
{
296+
await VerifyCompletionListAsync(
297+
input: """
298+
This is a Razor document.
299+
300+
<div $$></div>
301+
302+
The end.
303+
""",
304+
completionContext: new RoslynVSInternalCompletionContext()
305+
{
306+
InvokeKind = RoslynVSInternalCompletionInvokeKind.Typing,
307+
TriggerCharacter = " ",
308+
TriggerKind = RoslynCompletionTriggerKind.TriggerCharacter
309+
},
310+
expectedItemLabels: ["style", "dir"],
311+
unexpectedItemLabels: ["snippet1", "snippet2"],
312+
delegatedItemLabels: ["style", "dir"],
313+
snippetLabels: ["snippet1", "snippet2"]);
314+
}
315+
293316
// Tests HTML attributes and DirectiveAttributeTransitionCompletionItemProvider
294317
[Fact]
295318
public async Task HtmlAndDirectiveAttributeTransitionNamesCompletion()
@@ -402,6 +425,7 @@ private async Task VerifyCompletionListAsync(
402425
TestCode input,
403426
RoslynVSInternalCompletionContext completionContext,
404427
string[] expectedItemLabels,
428+
string[]? unexpectedItemLabels = null,
405429
string[]? delegatedItemLabels = null,
406430
string[]? delegatedItemCommitCharacters = null,
407431
string[]? snippetLabels = null,
@@ -469,6 +493,14 @@ private async Task VerifyCompletionListAsync(
469493
Assert.Contains(expectedItemLabel, labelSet);
470494
}
471495

496+
if (unexpectedItemLabels is not null)
497+
{
498+
foreach (var unexpectedItemLabel in unexpectedItemLabels)
499+
{
500+
Assert.DoesNotContain(unexpectedItemLabel, labelSet);
501+
}
502+
}
503+
472504
if (!commitElementsWithSpace)
473505
{
474506
Assert.False(result.Items.Any(item => item.CommitCharacters?.First().Contains(" ") ?? false));

0 commit comments

Comments
 (0)