Beispiel #1
0
        /// <summary>Displays numbers about selected characters and lines in quick info.</summary>
        static SnapshotSpan ShowSelectionInfo(IQuickInfoSession session, IList <object> qiContent, SnapshotPoint point)
        {
            var selection  = session.TextView.Selection;
            var activeSpan = default(SnapshotSpan);

            if (selection.IsEmpty)
            {
                return(activeSpan);
            }
            var p1 = selection.Start.Position;
            var p2 = selection.End.Position;

            if (p1 > point || point > p2)
            {
                var tes = session.TextView.GetTextElementSpan(point);
                if (tes.Contains(p1) == false)
                {
                    return(activeSpan);
                }
            }
            var c = 0;

            foreach (var item in selection.SelectedSpans)
            {
                c += item.Length;
                if (item.Contains(point))
                {
                    activeSpan = item;
                }
            }
            if (c == 1)
            {
                var ch = point.Snapshot.GetText(p1, 1);
                qiContent.Add(new ThemedTipText {
                    Name = Name
                }
                              .Append("Selected character: \"", true)
                              .Append(ch)
                              .Append("\" (Unicode: 0x" + ((int)ch[0]).ToString("X2") + ")")
                              );
                return(activeSpan);
            }
            var lines = selection.StreamSelectionSpan.SnapshotSpan.GetLineSpan();
            var info  = new ThemedTipText()
            {
                Name = Name
            }.Append("Selection: ", true).Append(c.ToString()).Append(" characters");

            if (lines.Length > 0)
            {
                info.Append(", " + (lines.Length + 1).ToString() + " lines");
            }
            qiContent.Add(info);
            return(activeSpan);
        }
        /// <summary>Displays numbers about selected characters and lines in quick info.</summary>
        static QuickInfoItem ShowSelectionInfo(IAsyncQuickInfoSession session, SnapshotPoint point)
        {
            var selection = session.TextView.Selection;

            if (selection.IsEmpty)
            {
                return(null);
            }
            var p1 = selection.Start.Position;

            if (p1 > point || point > selection.End.Position)
            {
                var tes = session.TextView.GetTextElementSpan(point);
                if (tes.Contains(p1) == false)
                {
                    return(null);
                }
            }
            var          c          = 0;
            var          lines      = selection.SelectedSpans.Count;
            SnapshotSpan activeSpan = default;

            foreach (var item in selection.SelectedSpans)
            {
                c += item.Length;
                if (item.Contains(point))
                {
                    activeSpan = item;
                }
            }
            if (activeSpan.IsEmpty)
            {
                activeSpan = selection.SelectedSpans[0];
            }
            ThemedTipText info;

            if (c == 1)
            {
                var ch = point.Snapshot.GetText(p1, 1);
                info = new ThemedTipText {
                    Name = Name
                }
                .Append(R.T_SelectedCharacter + "\"", true)
                .Append(ch)
                .Append("\" (Unicode: 0x" + ((int)ch[0]).ToString("X2") + ")");
                goto RETURN;
            }
            info = new ThemedTipText()
            {
                Name = Name
            }
            .Append(R.T_Selection, true)
            .Append(c.ToString() + R.T_Characters);
            if (lines > 1)
            {
                info.Append(", " + lines + R.T_Spans);
            }
            else
            {
                lines = selection.StreamSelectionSpan.SnapshotSpan.GetLineSpan().Length;
                if (lines > 0)
                {
                    info.Append(", " + (lines + 1).ToString() + R.T_Lines);
                }
            }
RETURN:
            return(new QuickInfoItem(activeSpan.ToTrackingSpan(), info.SetGlyph(ThemeHelper.GetImage(IconIds.SelectCode))));
        }
Beispiel #3
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);
        }