public ContainerElement GetSeenInElement(BaseInfo info, MSBuildRootDocument doc)
        {
            var seenIn = doc.GetFilesSeenIn(info).ToList();

            if (seenIn.Count == 0)
            {
                return(null);
            }

            Func <string, (string prefix, string remaining)?> shorten = null;

            var elements = new List <ClassifiedTextElement> ();

            int count = 0;

            foreach (var s in seenIn)
            {
                if (count == 5)
                {
                    elements.Add(new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "[more in Find References]")));
                    break;
                }
                count++;

                //factor out some common prefixes into variables
                //we do this instead of using the original string, as the result is simpler
                //and easier to understand
                shorten = shorten ?? CreateFilenameShortener(doc.RuntimeInformation);
                var replacement = shorten(s);
                if (!replacement.HasValue)
                {
                    elements.Add(new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, s)));
                    continue;
                }

                elements.Add(new ClassifiedTextElement(
                                 new ClassifiedTextRun(PredefinedClassificationTypeNames.SymbolReference, replacement.Value.prefix),
                                 new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, replacement.Value.remaining, () => OpenFile(s), s)
                                 ));
            }

            if (elements.Count == 0)
            {
                return(null);
            }

            elements.Insert(0, new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "Seen in:")));
            return(new ContainerElement(ContainerElementStyle.Stacked, elements));
        }
Ejemplo n.º 2
0
        public DisplayText AppendSeenInMarkup(BaseInfo info, string baseDesc)
        {
            IEnumerable <string> seenIn = doc.GetFilesSeenIn(info);
            StringBuilder        sb     = null;

            Func <string, (string prefix, string remaining)?> shorten = null;

            int count = 0;

            foreach (var s in seenIn)
            {
                if (count++ == 0)
                {
                    sb      = new StringBuilder();
                    shorten = CreateFilenameShortener(doc.RuntimeInformation);
                    if (!string.IsNullOrEmpty(baseDesc))
                    {
                        sb.AppendLine(baseDesc);
                        sb.AppendLine();
                    }
                    sb.Append("Seen in:");
                }
                sb.AppendLine();

                if (count == 5)
                {
                    sb.Append("[more in Find References]");
                    sb.AppendLine();
                    break;
                }

                //factor out some common prefixes into variables
                //we do this instead of using the original string, as the result is simpler
                //and easier to understand
                var replacement = shorten(s);
                if (!replacement.HasValue)
                {
                    sb.Append("<i>");
                    sb.Append(Escape(s));
                    sb.Append("</i>");
                    continue;
                }
                sb.Append("<i>");
                sb.Append($"<span foreground=\"{GetColor(varColorID)}\">{Escape (replacement.Value.prefix)}</span>");
                sb.Append(Escape(replacement.Value.remaining));
                sb.Append("</i>");
            }
            return(new DisplayText(sb?.ToString() ?? baseDesc, true));
        }
Ejemplo n.º 3
0
        public string AppendSeenInMarkup(BaseInfo info, string baseDesc)
        {
            IEnumerable <string> seenIn = doc.GetFilesSeenIn(info);
            StringBuilder        sb     = null;

            List <(string prefix, string subst)> prefixes = null;

            int count = 0;

            foreach (var s in seenIn)
            {
                if (count++ == 0)
                {
                    sb       = new StringBuilder();
                    prefixes = GetPrefixes(doc.RuntimeInformation);
                    if (!string.IsNullOrEmpty(baseDesc))
                    {
                        sb.AppendLine(baseDesc);
                        sb.AppendLine();
                    }
                    sb.Append("Seen in:");
                }
                sb.AppendLine();

                if (count == 5)
                {
                    sb.Append("[more in Find References]");
                    sb.AppendLine();
                    break;
                }

                //factor out some common prefixes into variables
                //we do this instead of using the original string, as the result is simpler
                //and easier to understand
                var replacement = GetLongestReplacement(s, prefixes);
                if (!replacement.HasValue)
                {
                    sb.Append("<i>");
                    sb.Append(Escape(s));
                    sb.Append("</i>");
                    continue;
                }
                sb.Append("<i>");
                sb.Append($"<span foreground=\"{GetColor(varColorID)}\">{Escape (replacement.Value.subst)}</span>");
                sb.Append(Escape(s.Substring(replacement.Value.prefix.Length)));
                sb.Append("</i>");
            }
            return(sb?.ToString() ?? baseDesc);
        }
Ejemplo n.º 4
0
        ContainerElement GetSeenInElement(ITextBuffer buffer, MSBuildResolveResult rr, ISymbol info, MSBuildRootDocument doc)
        {
            var seenIn = doc.GetFilesSeenIn(info).ToList();

            if (seenIn.Count == 0)
            {
                return(null);
            }

            Func <string, (string prefix, string remaining)?> shorten = null;

            var elements = new List <ClassifiedTextElement> ();

            int count = 0;

            foreach (var s in seenIn)
            {
                if (count == 5)
                {
                    elements.Add(new ClassifiedTextElement(
                                     new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "["),
                                     new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "more in Find References", () => {
                        NavigationService.FindReferences(buffer, rr);
                    }),
                                     new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "]")
                                     ));
                    break;
                }
                count++;

                // collapse any .. segments
                string path = System.IO.Path.GetFullPath(s);

                //factor out some common prefixes into variables
                //we do this instead of using the original string, as the result is simpler
                //and easier to understand
                shorten ??= CreateFilenameShortener(doc.RuntimeInformation);
                var replacement = shorten(path);
                if (!replacement.HasValue)
                {
                    elements.Add(
                        new ClassifiedTextElement(
                            new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, path, () => OpenFile(path), path)
                            )
                        );
                    continue;
                }

                elements.Add(new ClassifiedTextElement(
                                 new ClassifiedTextRun(PredefinedClassificationTypeNames.SymbolReference, replacement.Value.prefix),
                                 new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, replacement.Value.remaining, () => OpenFile(path), path)
                                 ));
            }

            if (elements.Count == 0)
            {
                return(null);
            }

            elements.Insert(0, new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "Seen in:")));
            return(new ContainerElement(ContainerElementStyle.Stacked, elements));
        }