Beispiel #1
0
        public bool TryCreateOrUpdate(ITextView textView, SnapshotSpan span, PackageGlyphTag existingTag, out TagSpan <PackageGlyphTag> tag, out Span valueSpan)
        {
            if (!PackageCompletionSource.IsInRangeForPackageCompletion(span.Snapshot, span.Start, out valueSpan, out string name, out string ver, out string type))
            {
                tag = null;
                return(false);
            }

            double?lineHeight;

            try
            {
                lineHeight = textView.LineHeight;
            }
            catch { lineHeight = null; }

            string text = span.Snapshot.GetText();
            int    targetFrameworkElementStartIndex  = text.IndexOf("<TargetFramework>", StringComparison.OrdinalIgnoreCase);
            int    targetFrameworksElementStartIndex = text.IndexOf("<TargetFrameworks>", StringComparison.OrdinalIgnoreCase);
            string tfm = "netcoreapp1.0";

            if (targetFrameworksElementStartIndex > -1)
            {
                int    closeTfms = text.IndexOf("</TargetFrameworks>", targetFrameworksElementStartIndex);
                int    realStart = targetFrameworksElementStartIndex + "<TargetFrameworks>".Length;
                string allTfms   = text.Substring(realStart, closeTfms - realStart);
                tfm = allTfms.Split(';')[0];
            }
            else if (targetFrameworkElementStartIndex > -1)
            {
                int closeTfm  = text.IndexOf("</TargetFramework>", targetFrameworkElementStartIndex);
                int realStart = targetFrameworkElementStartIndex + "<TargetFramework>".Length;
                tfm = text.Substring(realStart, closeTfm - realStart);
            }

            PackageGlyphTag t = existingTag ?? new PackageGlyphTag(PositionAffinity.Predecessor, textView);

            t.PackageIcon.Source = WpfUtil.MonikerToBitmap(KnownMonikers.NuGet, (int)(lineHeight ?? 16));
            IssueIconQuery(name, ver, tfm, t);
            if (lineHeight.HasValue)
            {
                t.Wrapper.Height = lineHeight.Value;
            }
            tag = new TagSpan <PackageGlyphTag>(new SnapshotSpan(span.Snapshot, Span.FromBounds(valueSpan.Start, valueSpan.Start)), t);
            return(true);
        }