diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs index a2d7941879..bf81b9161f 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperCompletionService.cs @@ -62,11 +62,13 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { addRuleCompletions = true; } - else if (outputHint != null && elementCompletions.ContainsKey(outputHint)) + else if (outputHint != null) { - // If the possible descriptors final output tag already exists in our list of completions, we should add every representation - // of that descriptor to the possible element completions. - addRuleCompletions = true; + // If the current descriptor has an output hint we need to make sure it shows up only when its output hint would normally show up. + // Example: We have a MyTableTagHelper that has an output hint of "table" and a MyTrTagHelper that has an output hint of "tr". + // If we try typing in a situation like this:
| + // We'd expect to only get "my-table" as a completion because the "body" tag doesn't allow "tr" tags. + addRuleCompletions = elementCompletions.ContainsKey(outputHint); } else if (!completionContext.InHTMLSchema(rule.TagName)) { diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs index 0dbc538240..c16b9eca9f 100644 --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs +++ b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/DefaultTagHelperCompletionServiceTest.cs @@ -10,6 +10,42 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { public class DefaultTagHelperCompletionServiceTest { + [Fact] + public void GetElementCompletions_TagOutputHintDoesNotFallThroughToSchemaCheck() + { + // Arrange + var documentDescriptors = new[] + { + TagHelperDescriptorBuilder.Create("MyTableTagHelper", "TestAssembly") + .TagMatchingRule(rule => rule.RequireTagName("my-table")) + .TagOutputHint("table") + .Build(), + TagHelperDescriptorBuilder.Create("MyTrTagHelper", "TestAssembly") + .TagMatchingRule(rule => rule.RequireTagName("my-tr")) + .TagOutputHint("tr") + .Build(), + }; + var expectedCompletions = ElementCompletionResult.Create(new Dictionary