Exemple #1
0
        public static ThemedToolTip CreateToolTip(ISymbol symbol, bool forMemberList, Compilation compilation)
        {
            var tip = new ThemedToolTip();

            if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.CodeWindow) != 0)
            {
                WpfHelper.SetUITextRenderOptions(tip, true);
            }
            tip.Title
            .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + symbol.GetSymbolKindName() + " ")
            .Append(symbol.Name, true)
            .Append(symbol.GetParameterString());
            var content = tip.Content;
            var t       = symbol.GetReturnType();

            if (t != null)
            {
                content.Append("member type: ")
                .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true);
            }
            t = symbol.ContainingType;
            if (t != null)
            {
                if (content.Inlines.FirstInline != null)
                {
                    content.AppendLine();
                }
                content.Append(t.GetSymbolKindName() + ": ")
                .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true);
            }
            if (content.Inlines.FirstInline != null)
            {
                content.AppendLine();
            }
            content.Append("namespace: " + symbol.ContainingNamespace?.ToString())
            .Append("\nassembly: " + symbol.GetAssemblyModuleName());

            if (forMemberList == false)
            {
                var f = symbol as IFieldSymbol;
                if (f != null && f.IsConst)
                {
                    content.Append("\nconst: " + f.ConstantValue?.ToString());                     // sometimes the const value could be null
                }
            }
            foreach (var attr in symbol.GetAttributes())
            {
                SymbolFormatter.Empty.ToUIText(content.AppendLine().Inlines, attr);
            }
            var doc     = new XmlDoc(symbol, compilation);
            var summary = doc.Summary ?? (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromInheritDoc) ? doc.ExplicitInheritDoc?.Summary : null);

            if (summary != null)
            {
                var docContent = ThemedToolTip.CreateContentBlock();
                new XmlDocRenderer(compilation, SymbolFormatter.Empty, symbol).Render(summary, docContent);
                tip.Children.Add(docContent);
                tip.MaxWidth = Config.Instance.QuickInfoMaxWidth;
            }
            return(tip);
        }
Exemple #2
0
        public ThemedTipDocument RenderXmlDoc(ISymbol symbol, XmlDoc doc)
        {
            var    tip             = new ThemedTipDocument();
            var    summary         = doc.GetDescription(symbol);
            XmlDoc inheritDoc      = null;
            bool   showSummaryIcon = true;

            #region Summary
            if (summary == null &&
                Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromBaseType))
            {
                summary = doc.GetInheritedDescription(symbol, out inheritDoc);
                if (inheritDoc != null && summary != null)
                {
                    tip.Append(new ThemedTipParagraph(IconIds.ReferencedXmlDoc, new ThemedTipText()
                                                      .Append(R.T_DocumentationFrom)
                                                      .AddSymbol(inheritDoc.Symbol.ContainingSymbol, false, _SymbolFormatter)
                                                      .Append(".")
                                                      .AddSymbol(inheritDoc.Symbol, true, _SymbolFormatter)
                                                      .Append(":"))
                               );
                    showSummaryIcon = false;
                }
            }
            if (summary != null &&
                (summary.Name.LocalName != XmlDocNodeName || Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.TextOnlyDoc)))
            {
                ParagraphCount = 0;
                Render(summary, tip, showSummaryIcon);
                if (inheritDoc == null)
                {
                    tip.Tag = ParagraphCount;
                }
            }
            #endregion
            #region Type parameter
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.TypeParameters) &&
                (symbol.Kind == SymbolKind.Method || symbol.Kind == SymbolKind.NamedType))
            {
                var typeParams = symbol.GetTypeParameters();
                if (typeParams.IsDefaultOrEmpty == false)
                {
                    var para = new ThemedTipParagraph(IconIds.TypeParameters);
                    foreach (var param in typeParams)
                    {
                        var p = doc.GetTypeParameter(param.Name);
                        if (p == null)
                        {
                            continue;
                        }
                        if (para.Content.Inlines.FirstInline != null)
                        {
                            para.Content.AppendLine();
                        }
                        para.Content
                        .Append(param.Name, _SymbolFormatter.TypeParameter)
                        .Append(": ")
                        .AddXmlDoc(p, this);
                    }
                    if (para.Content.Inlines.FirstInline != null)
                    {
                        tip.Append(para);
                    }
                }
            }
            #endregion
            #region Returns
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.ReturnsDoc) &&
                (symbol.Kind == SymbolKind.Method ||
                 symbol.Kind == SymbolKind.NamedType && ((INamedTypeSymbol)symbol).TypeKind == TypeKind.Delegate))
            {
                var returns = doc.Returns ?? doc.ExplicitInheritDoc?.Returns ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.Returns != null)?.Returns;
                if (returns != null && returns.FirstNode != null)
                {
                    tip.Append(new ThemedTipParagraph(IconIds.Return, new ThemedTipText()
                                                      .Append(R.T_Returns, true)
                                                      .Append(returns == doc.Returns ? ": " : (R.T_Inherited + ": "))
                                                      .AddXmlDoc(returns, this))
                               );
                }
            }
            #endregion
            #region Remarks
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.RemarksDoc) &&
                symbol.Kind != SymbolKind.Parameter &&
                symbol.Kind != SymbolKind.TypeParameter)
            {
                var remarks = doc.Remarks ?? doc.ExplicitInheritDoc?.Remarks ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.Remarks != null)?.Remarks;
                if (remarks != null && remarks.FirstNode != null)
                {
                    tip.Append(new ThemedTipParagraph(IconIds.RemarksXmlDoc, new ThemedTipText()
                                                      .Append(R.T_Remarks, true)
                                                      .Append(remarks == doc.Remarks ? ": " : (R.T_Inherited + ": "))
                                                      ))
                    .Append(new ThemedTipParagraph(new ThemedTipText().AddXmlDoc(remarks, this)));
                }
            }
            #endregion
            #region SeeAlso
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.SeeAlsoDoc))
            {
                var seeAlsos = doc.SeeAlso ?? doc.ExplicitInheritDoc?.SeeAlso ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.SeeAlso != null)?.SeeAlso;
                if (seeAlsos != null)
                {
                    var seeAlso = new ThemedTipText()
                                  .Append(R.T_SeeAlso, true)
                                  .Append(seeAlsos == doc.SeeAlso ? ": " : (R.T_Inherited + ": "));
                    bool hasItem = false;
                    foreach (var item in seeAlsos)
                    {
                        if (hasItem)
                        {
                            seeAlso.Append(", ");
                        }
                        RenderXmlDocSymbol(item.Attribute("cref").Value, seeAlso.Inlines, SymbolKind.Alias);
                        hasItem = true;
                    }
                    tip.Append(new ThemedTipParagraph(IconIds.SeeAlsoXmlDoc, seeAlso));
                }
            }
            #endregion
            var example = doc.Example ?? doc.ExplicitInheritDoc?.Example ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.Example != null)?.Example;
            if (example != null)
            {
                tip.Append(new ThemedTipParagraph(IconIds.ExampleXmlDoc, new ThemedTipText()
                                                  .Append(R.T_Example, true)
                                                  .Append(example == doc.Example ? ": " : (R.T_Inherited + ": "))
                                                  ))
                .Append(new ThemedTipParagraph(new ThemedTipText().AddXmlDoc(example, this)));
            }
            return(tip);
        }