public void TryCreateDescription_Element_MultipleAssociatedTagHelpers_ReturnsTrue() { // Arrange var descriptionFactory = new DefaultTagHelperDescriptionFactory(); var associatedTagHelperInfos = new[] { new TagHelperDescriptionInfo("Microsoft.AspNetCore.SomeTagHelper", "<summary>Uses <see cref=\"T:System.Collections.List{System.String}\" />s</summary>"), new TagHelperDescriptionInfo("Microsoft.AspNetCore.OtherTagHelper", "<summary>Also uses <see cref=\"T:System.Collections.List{System.String}\" />s</summary>"), }; var elementDescription = new ElementDescriptionInfo(associatedTagHelperInfos); // Act var result = descriptionFactory.TryCreateDescription(elementDescription, out var markdown); // Assert Assert.True(result); Assert.Equal(@"**SomeTagHelper** Uses `List<System.String>`s --- **OtherTagHelper** Also uses `List<System.String>`s ", markdown); }
public static void SetDescriptionInfo(this CompletionItem completion, ElementDescriptionInfo elementDescriptionInfo) { var data = completion.Data ?? new JObject(); data[TagHelperElementDataKey] = JObject.FromObject(elementDescriptionInfo); completion.Data = data; }
public override bool TryCreateDescription(ElementDescriptionInfo elementDescriptionInfo, out MarkupContent tagHelperDescription) { var associatedTagHelperInfos = elementDescriptionInfo.AssociatedTagHelperDescriptions; if (associatedTagHelperInfos.Count == 0) { tagHelperDescription = null; return(false); } // This generates a markdown description that looks like the following: // **SomeTagHelper** // // The Summary documentation text with `CrefTypeValues` in code. // // Additional description infos result in a triple `---` to separate the markdown entries. var descriptionBuilder = new StringBuilder(); for (var i = 0; i < associatedTagHelperInfos.Count; i++) { var descriptionInfo = associatedTagHelperInfos[i]; if (descriptionBuilder.Length > 0) { descriptionBuilder.AppendLine(); descriptionBuilder.AppendLine("---"); } var tagHelperType = descriptionInfo.TagHelperTypeName; var reducedTypeName = ReduceTypeName(tagHelperType); StartOrEndBold(descriptionBuilder); descriptionBuilder.Append(reducedTypeName); StartOrEndBold(descriptionBuilder); var documentation = descriptionInfo.Documentation; if (!TryExtractSummary(documentation, out var summaryContent)) { continue; } descriptionBuilder.AppendLine(); descriptionBuilder.AppendLine(); var finalSummaryContent = CleanSummaryContent(summaryContent); descriptionBuilder.Append(finalSummaryContent); } tagHelperDescription = new MarkupContent { Kind = GetMarkupKind() }; tagHelperDescription.Value = descriptionBuilder.ToString(); return(true); }
private IReadOnlyList <CompletionItem> GetElementCompletions( SyntaxNode containingTag, string containingTagName, IEnumerable <KeyValuePair <string, string> > attributes, RazorCodeDocument codeDocument) { var ancestors = containingTag.Ancestors(); var tagHelperDocumentContext = codeDocument.GetTagHelperContext(); var(ancestorTagName, ancestorIsTagHelper) = _tagHelperFactsService.GetNearestAncestorTagInfo(ancestors); var elementCompletionContext = new ElementCompletionContext( tagHelperDocumentContext, existingCompletions: Enumerable.Empty <string>(), containingTagName, attributes, ancestorTagName, ancestorIsTagHelper, HtmlFactsService.IsHtmlTagName); var completionItems = new List <CompletionItem>(); var completionResult = _razorTagHelperCompletionService.GetElementCompletions(elementCompletionContext); foreach (var completion in completionResult.Completions) { var razorCompletionItem = new CompletionItem() { Label = completion.Key, InsertText = completion.Key, FilterText = completion.Key, SortText = completion.Key, Kind = CompletionItemKind.TypeParameter, CommitCharacters = ElementCommitCharacters, }; var tagHelperDescriptions = completion.Value.Select(tagHelper => new TagHelperDescriptionInfo(tagHelper.GetTypeName(), tagHelper.Documentation)); var elementDescription = new ElementDescriptionInfo(tagHelperDescriptions.ToList()); razorCompletionItem.SetDescriptionInfo(elementDescription); completionItems.Add(razorCompletionItem); } return(completionItems); }
public void TryCreateDescription_Element_SingleAssociatedTagHelper_ReturnsTrue() { // Arrange var descriptionFactory = new DefaultTagHelperDescriptionFactory(LanguageServer); var associatedTagHelperInfos = new[] { new TagHelperDescriptionInfo("Microsoft.AspNetCore.SomeTagHelper", "<summary>Uses <see cref=\"T:System.Collections.List{System.String}\" />s</summary>"), }; var elementDescription = new ElementDescriptionInfo(associatedTagHelperInfos); // Act var result = descriptionFactory.TryCreateDescription(elementDescription, out var markdown); // Assert Assert.True(result); Assert.Equal(@"**SomeTagHelper** Uses `List<System.String>`s", markdown.Value); Assert.Equal(MarkupKind.Markdown, markdown.Kind); }
public void TryCreateDescription_Element_BothPlainTextAndMarkdown_IsBold() { // Arrange var languageServer = LanguageServer; languageServer.ClientSettings.Capabilities.TextDocument.Completion.Value.CompletionItem.DocumentationFormat = new Container <MarkupKind>(MarkupKind.PlainText, MarkupKind.Markdown); var descriptionFactory = new DefaultTagHelperDescriptionFactory(languageServer); var associatedTagHelperInfos = new[] { new TagHelperDescriptionInfo("Microsoft.AspNetCore.SomeTagHelper", "<summary>Uses <see cref=\"T:System.Collections.List{System.String}\" />s</summary>"), }; var elementDescription = new ElementDescriptionInfo(associatedTagHelperInfos); // Act var result = descriptionFactory.TryCreateDescription(elementDescription, out var markdown); // Assert Assert.True(result); Assert.Equal(@"**SomeTagHelper** Uses `List<System.String>`s", markdown.Value); Assert.Equal(MarkupKind.Markdown, markdown.Kind); }
public abstract bool TryCreateDescription(ElementDescriptionInfo descriptionInfos, out MarkupContent markupContent);
public abstract bool TryCreateDescription(ElementDescriptionInfo descriptionInfos, out string markdown);
public static void SetTagHelperElementDescriptionInfo(this RazorCompletionItem completionItem, ElementDescriptionInfo elementDescriptionInfo) { completionItem.Items[TagHelperElementCompletionDescriptionKey] = elementDescriptionInfo; }