Ejemplo n.º 1
0
 static ClassifiedTextElement GetDeprecationMessage(ISymbol info)
 {
     if (info is VariableInfo val && val.IsDeprecated)
     {
         var msg = string.IsNullOrEmpty(val.DeprecationMessage) ? "Deprecated" : $"Deprecated: {val.DeprecationMessage}";
         return(new ClassifiedTextElement(new ClassifiedTextRun("syntax error", msg)));
     }
     return(null);
 }
Ejemplo n.º 2
0
        public async Task <object> GetInfoTooltipElement(ITextBuffer buffer, MSBuildRootDocument doc, ISymbol info, MSBuildResolveResult rr, CancellationToken token)
        {
            object nameElement = GetNameElement(info);

            if (nameElement == null)
            {
                return(null);
            }

            var imageElement = GetImageElement(info);

            if (imageElement != null)
            {
                nameElement = new ContainerElement(
                    ContainerElementStyle.Wrapped | ContainerElementStyle.VerticalPadding,
                    imageElement, nameElement
                    );
            }

            var elements = new List <object> {
                nameElement
            };

            switch (info.Description.DisplayElement)
            {
            case IRoslynSymbol symbol:
                await AddSymbolDescriptionElements(symbol, elements.Add, token);

                break;

            case object obj:
                elements.Add(obj);
                break;

            default:
                var descStr = DescriptionFormatter.GetDescription(info, doc, rr);
                if (!string.IsNullOrEmpty(descStr))
                {
                    elements.Add(new ClassifiedTextElement(FormatDescriptionText(descStr)));
                }
                break;
            }

            if (info is VariableInfo vi && !string.IsNullOrEmpty(vi.DefaultValue))
            {
                elements.Add(
                    new ClassifiedTextElement(
                        new ClassifiedTextRun(PredefinedClassificationTypeNames.NaturalLanguage, $"Default value: "),
                        new ClassifiedTextRun(PredefinedClassificationTypeNames.String, vi.DefaultValue)
                        )
                    );
            }

            var seenIn = GetSeenInElement(buffer, rr, info, doc);

            if (seenIn != null)
            {
                elements.Add(seenIn);
            }

            var deprecationMessage = GetDeprecationMessage(info);

            if (deprecationMessage != null)
            {
                elements.Add(deprecationMessage);
            }

            return(elements.Count == 1
                                ? elements[0]
                                : new ContainerElement(ContainerElementStyle.Stacked | ContainerElementStyle.VerticalPadding, elements));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public ClassifiedTextElement GetNameElement(ISymbol info)
        {
            var label = DescriptionFormatter.GetTitle(info);

            if (label.kind == null)
            {
                return(null);
            }

            var runs = new List <ClassifiedTextRun> ();

            runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, label.kind));
            runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.WhiteSpace, " "));
            runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, label.name));

            string typeInfo = null;

            if (info is VariableInfo vi)
            {
                var tdesc = vi.GetTypeDescription();
                if (tdesc.Count > 0)
                {
                    typeInfo = string.Join(" ", tdesc);
                }
            }

            if (info is FunctionInfo fi)
            {
                typeInfo = fi.ReturnTypeString;
                if (!fi.IsProperty)
                {
                    runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "("));

                    bool first = true;
                    foreach (var p in fi.Parameters)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, ", "));
                        }

                        runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.SymbolReference, p.Name));
                        runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, " : "));
                        runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Type, p.Type));
                    }
                    runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, ")"));
                }
            }

            if (typeInfo != null)
            {
                runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, " : "));
                runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Type, typeInfo));
            }

            return(new ClassifiedTextElement(runs));
        }