public void TryConvert_TagHelperAttribute_ReturnsTrue() { // Arrange var completionItem = new RazorCompletionItem("format", "format", RazorCompletionItemKind.TagHelperAttribute); completionItem.SetTagHelperAttributeDescriptionInfo(new AttributeDescriptionInfo(Array.Empty <TagHelperAttributeDescriptionInfo>())); // Act var result = RazorCompletionEndpoint.TryConvert(completionItem, out var converted); // Assert Assert.True(result); Assert.Equal(completionItem.DisplayText, converted.Label); Assert.Equal(completionItem.InsertText, converted.InsertText); Assert.Equal(completionItem.InsertText, converted.FilterText); Assert.Equal(completionItem.InsertText, converted.SortText); Assert.Null(converted.Detail); Assert.Null(converted.Documentation); Assert.Null(converted.Command); var descriptionInfo = completionItem.GetTagHelperAttributeDescriptionInfo(); Assert.NotNull(descriptionInfo); }
// Internal for testing internal static bool TryConvert(RazorCompletionItem razorCompletionItem, out CompletionItem completionItem) { if (razorCompletionItem is null) { throw new ArgumentNullException(nameof(razorCompletionItem)); } switch (razorCompletionItem.Kind) { case RazorCompletionItemKind.Directive: { // There's not a lot of calculation needed for Directives, go ahead and store the documentation // on the completion item. var descriptionInfo = razorCompletionItem.GetDirectiveCompletionDescription(); var directiveCompletionItem = new VSLspCompletionItem() { Label = razorCompletionItem.DisplayText, InsertText = razorCompletionItem.InsertText, FilterText = razorCompletionItem.DisplayText, SortText = razorCompletionItem.DisplayText, Documentation = descriptionInfo.Description, Kind = CompletionItemKind.Struct, }; if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0) { directiveCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters); } if (razorCompletionItem == DirectiveAttributeTransitionCompletionItemProvider.TransitionCompletionItem) { directiveCompletionItem.Command = RetriggerCompletionCommand; directiveCompletionItem.Kind = CompletionItemKind.TypeParameter; directiveCompletionItem.Icon = VSLspCompletionItemIcons.TagHelper; } directiveCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind); completionItem = directiveCompletionItem; return(true); } case RazorCompletionItemKind.DirectiveAttribute: { var descriptionInfo = razorCompletionItem.GetAttributeCompletionDescription(); var directiveAttributeCompletionItem = new VSLspCompletionItem() { Label = razorCompletionItem.DisplayText, InsertText = razorCompletionItem.InsertText, FilterText = razorCompletionItem.InsertText, SortText = razorCompletionItem.InsertText, Kind = CompletionItemKind.TypeParameter, Icon = VSLspCompletionItemIcons.TagHelper, }; if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0) { directiveAttributeCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters); } directiveAttributeCompletionItem.SetDescriptionInfo(descriptionInfo); directiveAttributeCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind); completionItem = directiveAttributeCompletionItem; return(true); } case RazorCompletionItemKind.DirectiveAttributeParameter: { var descriptionInfo = razorCompletionItem.GetAttributeCompletionDescription(); var parameterCompletionItem = new VSLspCompletionItem() { Label = razorCompletionItem.DisplayText, InsertText = razorCompletionItem.InsertText, FilterText = razorCompletionItem.InsertText, SortText = razorCompletionItem.InsertText, Kind = CompletionItemKind.TypeParameter, Icon = VSLspCompletionItemIcons.TagHelper, }; parameterCompletionItem.SetDescriptionInfo(descriptionInfo); parameterCompletionItem.SetRazorCompletionKind(razorCompletionItem.Kind); completionItem = parameterCompletionItem; return(true); } case RazorCompletionItemKind.MarkupTransition: { var descriptionInfo = razorCompletionItem.GetMarkupTransitionCompletionDescription(); var markupTransitionCompletionItem = new VSLspCompletionItem() { Label = razorCompletionItem.DisplayText, InsertText = razorCompletionItem.InsertText, FilterText = razorCompletionItem.DisplayText, SortText = razorCompletionItem.DisplayText, Documentation = descriptionInfo.Description, Kind = CompletionItemKind.TypeParameter, Icon = VSLspCompletionItemIcons.TagHelper, }; if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0) { markupTransitionCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters); } completionItem = markupTransitionCompletionItem; return(true); } case RazorCompletionItemKind.TagHelperElement: { var tagHelperElementCompletionItem = new VSLspCompletionItem() { Label = razorCompletionItem.DisplayText, InsertText = razorCompletionItem.InsertText, FilterText = razorCompletionItem.InsertText, SortText = razorCompletionItem.InsertText, Kind = CompletionItemKind.TypeParameter, Icon = VSLspCompletionItemIcons.TagHelper, }; if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0) { tagHelperElementCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters); } var descriptionInfo = razorCompletionItem.GetTagHelperElementDescriptionInfo(); tagHelperElementCompletionItem.SetDescriptionInfo(descriptionInfo); completionItem = tagHelperElementCompletionItem; return(true); } case RazorCompletionItemKind.TagHelperAttribute: { var tagHelperAttributeCompletionItem = new VSLspCompletionItem() { Label = razorCompletionItem.DisplayText, InsertText = razorCompletionItem.InsertText, FilterText = razorCompletionItem.InsertText, SortText = razorCompletionItem.InsertText, Kind = CompletionItemKind.TypeParameter, Icon = VSLspCompletionItemIcons.TagHelper, }; if (razorCompletionItem.CommitCharacters != null && razorCompletionItem.CommitCharacters.Count > 0) { tagHelperAttributeCompletionItem.CommitCharacters = new Container <string>(razorCompletionItem.CommitCharacters); } var descriptionInfo = razorCompletionItem.GetTagHelperAttributeDescriptionInfo(); tagHelperAttributeCompletionItem.SetDescriptionInfo(descriptionInfo); completionItem = tagHelperAttributeCompletionItem; return(true); } } completionItem = null; return(false); }