diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs index cf9a396e59..4b85393079 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs @@ -194,8 +194,11 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { foreach (var completionTagName in elementCompletions.Keys) { - if (completionTagName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) + if (elementCompletions[completionTagName].Count > 0 || + !string.IsNullOrEmpty(prefix) && completionTagName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { + // The current completion either has other TagHelper's associated with it or is prefixed with a non-empty + // TagHelper prefix. UpdateCompletions(completionTagName, catchAllDescriptor); } } diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs index 70f98ed3fc..a430fa90cb 100644 --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs +++ b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs @@ -509,7 +509,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor } [Fact] - public void GetElementCompletions_CatchAllsApplyToAllCompletions() + public void GetElementCompletions_CatchAllsApplyToOnlyTagHelperCompletions() { // Arrange var documentDescriptors = new[] @@ -523,8 +523,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor }; var expectedCompletions = ElementCompletionResult.Create(new Dictionary>() { - ["superli"] = new HashSet { documentDescriptors[0], documentDescriptors[1] }, - ["li"] = new HashSet { documentDescriptors[1] }, + ["superli"] = new HashSet() { documentDescriptors[0], documentDescriptors[1] }, + ["li"] = new HashSet(), }); var existingCompletions = new[] { "li" }; @@ -541,6 +541,40 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor AssertCompletionsAreEquivalent(expectedCompletions, completions); } + [Fact] + public void GetElementCompletions_CatchAllsApplyToNonTagHelperCompletionsIfStartsWithTagHelperPrefix() + { + // Arrange + var documentDescriptors = new[] + { + TagHelperDescriptorBuilder.Create("SuperLiTagHelper", "TestAssembly") + .TagMatchingRule(rule => rule.RequireTagName("superli")) + .Build(), + TagHelperDescriptorBuilder.Create("CatchAll", "TestAssembly") + .TagMatchingRule(rule => rule.RequireTagName("*")) + .Build(), + }; + var expectedCompletions = ElementCompletionResult.Create(new Dictionary>() + { + ["th:superli"] = new HashSet() { documentDescriptors[0], documentDescriptors[1] }, + ["th:li"] = new HashSet() { documentDescriptors[1] }, + }); + + var existingCompletions = new[] { "th:li" }; + var completionContext = BuildElementCompletionContext( + documentDescriptors, + existingCompletions, + containingTagName: "ul", + tagHelperPrefix: "th:"); + var service = CreateTagHelperCompletionFactsService(); + + // Act + var completions = service.GetElementCompletions(completionContext); + + // Assert + AssertCompletionsAreEquivalent(expectedCompletions, completions); + } + [Fact] public void GetElementCompletions_AllowsMultiTargetingTagHelpers() {