Example #1
0
        public override bool TryCreateTooltip(AggregateBoundAttributeDescription attributeDescriptionInfo, out MarkupContent tooltipContent)
        {
            if (attributeDescriptionInfo is null)
            {
                throw new ArgumentNullException(nameof(attributeDescriptionInfo));
            }

            var associatedAttributeInfos = attributeDescriptionInfo.DescriptionInfos;

            if (associatedAttributeInfos.Count == 0)
            {
                tooltipContent = null;
                return(false);
            }

            // This generates a markdown description that looks like the following:
            // **ReturnTypeName** SomeTypeName.**SomeProperty**
            //
            // 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 < associatedAttributeInfos.Count; i++)
            {
                var descriptionInfo = associatedAttributeInfos[i];

                if (descriptionBuilder.Length > 0)
                {
                    descriptionBuilder.AppendLine();
                    descriptionBuilder.AppendLine("---");
                }

                StartOrEndBold(descriptionBuilder);
                if (!TypeNameStringResolver.TryGetSimpleName(descriptionInfo.ReturnTypeName, out var returnTypeName))
                {
                    returnTypeName = descriptionInfo.ReturnTypeName;
                }
                var reducedReturnTypeName = ReduceTypeName(returnTypeName);
                descriptionBuilder.Append(reducedReturnTypeName);
                StartOrEndBold(descriptionBuilder);
                descriptionBuilder.Append(" ");
                var tagHelperTypeName        = descriptionInfo.TypeName;
                var reducedTagHelperTypeName = ReduceTypeName(tagHelperTypeName);
                descriptionBuilder.Append(reducedTagHelperTypeName);
                descriptionBuilder.Append(".");
                StartOrEndBold(descriptionBuilder);
                descriptionBuilder.Append(descriptionInfo.PropertyName);
                StartOrEndBold(descriptionBuilder);

                var documentation = descriptionInfo.Documentation;
                if (!TryExtractSummary(documentation, out var summaryContent))
                {
                    continue;
                }

                descriptionBuilder.AppendLine();
                descriptionBuilder.AppendLine();
                var finalSummaryContent = CleanSummaryContent(summaryContent);
                descriptionBuilder.Append(finalSummaryContent);
            }

            tooltipContent = new MarkupContent
            {
                Kind = GetMarkupKind()
            };

            tooltipContent.Value = descriptionBuilder.ToString();
            return(true);
        }
Example #2
0
        public override ContainerElement CreateClassifiedDescription(AggregateBoundAttributeDescription completionDescription)
        {
            if (completionDescription is null)
            {
                throw new ArgumentNullException(nameof(completionDescription));
            }

            var descriptionElements = new List <object>();

            foreach (var descriptionInfo in completionDescription.DescriptionInfos)
            {
                if (descriptionElements.Count > 0)
                {
                    descriptionElements.Add(SeparatorElement);
                }

                var returnTypeClassification = PredefinedClassificationNames.Type;
                if (TypeNameStringResolver.TryGetSimpleName(descriptionInfo.ReturnTypeName, out var returnTypeName))
                {
                    returnTypeClassification = PredefinedClassificationNames.Keyword;
                }
                else
                {
                    returnTypeName = descriptionInfo.ReturnTypeName;
                }

                var tagHelperTypeName       = descriptionInfo.TypeName;
                var tagHelperTypeNamePrefix = string.Empty;
                var tagHelperTypeNameProper = tagHelperTypeName;

                var lastDot = tagHelperTypeName.LastIndexOf('.');
                if (lastDot > 0)
                {
                    var afterLastDot = lastDot + 1;

                    // We're pulling apart the type name so the prefix looks like:
                    //
                    // Microsoft.AspnetCore.Components.
                    tagHelperTypeNamePrefix = tagHelperTypeName.Substring(0, afterLastDot);

                    // And the type name looks like BindBinds
                    tagHelperTypeNameProper = tagHelperTypeName.Substring(afterLastDot);
                }

                descriptionElements.Add(
                    new ContainerElement(
                        ContainerElementStyle.Wrapped,
                        PropertyGlyph,
                        new ClassifiedTextElement(
                            new ClassifiedTextRun(returnTypeClassification, returnTypeName),
                            SpaceLiteral,
                            new ClassifiedTextRun(PredefinedClassificationNames.Literal, tagHelperTypeNamePrefix),
                            new ClassifiedTextRun(PredefinedClassificationNames.Type, tagHelperTypeNameProper),
                            DotLiteral,
                            new ClassifiedTextRun(PredefinedClassificationNames.Identifier, descriptionInfo.PropertyName))));

                if (descriptionInfo.Documentation != null)
                {
                    descriptionElements.Add(
                        new ContainerElement(
                            ContainerElementStyle.Wrapped,
                            new ClassifiedTextElement(
                                new ClassifiedTextRun(PredefinedClassificationNames.NaturalLanguage, descriptionInfo.Documentation))));
                }
            }

            var descriptionContainer = new ContainerElement(ContainerElementStyle.Stacked, descriptionElements);

            return(descriptionContainer);
        }