Reduce catch all element completion usage.
- This makes it so if you have catch all `TagHelperDescriptor`s their completions don't apply to every existing completion. Instead, they now only apply to already TagHelperified completions and existing completions that are prefixed with a non-empty TagHelperPrefix. - Updated existing test to have new expectations. - Added new test to validate non-empty tag helper prefix case. #1230
This commit is contained in:
parent
5856517be7
commit
8616cf5dd0
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string, HashSet<TagHelperDescriptor>>()
|
||||
{
|
||||
["superli"] = new HashSet<TagHelperDescriptor> { documentDescriptors[0], documentDescriptors[1] },
|
||||
["li"] = new HashSet<TagHelperDescriptor> { documentDescriptors[1] },
|
||||
["superli"] = new HashSet<TagHelperDescriptor>() { documentDescriptors[0], documentDescriptors[1] },
|
||||
["li"] = new HashSet<TagHelperDescriptor>(),
|
||||
});
|
||||
|
||||
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<string, HashSet<TagHelperDescriptor>>()
|
||||
{
|
||||
["th:superli"] = new HashSet<TagHelperDescriptor>() { documentDescriptors[0], documentDescriptors[1] },
|
||||
["th:li"] = new HashSet<TagHelperDescriptor>() { 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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue