Esempio n. 1
0
        internal static void FindReferrers(this SemanticContext context, ISymbol symbol, Predicate <ISymbol> definitionFilter = null, Predicate <SyntaxNode> nodeFilter = null)
        {
            var referrers = SyncHelper.RunSync(() => symbol.FindReferrersAsync(context.Document.Project, definitionFilter, nodeFilter));

            if (referrers == null)
            {
                return;
            }
            var m = new SymbolMenu(context, SymbolListType.SymbolReferrers);

            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true)
            .Append(R.T_Referrers);
            var containerType = symbol.ContainingType;

            foreach (var(referrer, occurance) in referrers)
            {
                var s = referrer;
                var i = m.Menu.Add(s, false);
                i.Location = occurance.FirstOrDefault().Item2.Location;
                foreach (var item in occurance)
                {
                    i.Usage |= item.Item1;
                }
                if (s.ContainingType != containerType)
                {
                    i.Hint = (s.ContainingType ?? s).ToDisplayString(CodeAnalysisHelper.MemberNameFormat);
                }
            }
            m.Menu.ExtIconProvider = ExtIconProvider.Default.GetExtIconsWithUsage;
            m.Show();
        }
Esempio n. 2
0
        internal static void FindImplementations(this SemanticContext context, ISymbol symbol)
        {
            var implementations = new List <ISymbol>(SyncHelper.RunSync(() => SymbolFinder.FindImplementationsAsync(symbol, context.Document.Project.Solution, null, default)));

            implementations.Sort((a, b) => a.Name.CompareTo(b.Name));
            var m = new SymbolMenu(context);

            if (symbol.Kind == SymbolKind.NamedType)
            {
                foreach (var impl in implementations)
                {
                    m.Menu.Add(impl, false);
                }
            }
            else
            {
                foreach (var impl in implementations)
                {
                    m.Menu.Add(impl, impl.ContainingSymbol);
                }
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true)
            .Append(R.T_Implementations)
            .Append(implementations.Count.ToString());
            m.Show();
        }
Esempio n. 3
0
        void FindMembers(ISymbol symbol)
        {
            var type = symbol as INamedTypeSymbol;
            var m    = new SymbolMenu(this);
            var c    = AddSymbolMembers(this, m.Menu, symbol, null);
            int mi   = 0;

            if (type != null)
            {
                if (type.TypeKind == TypeKind.Class)
                {
                    while ((type = type.BaseType) != null && type.IsCommonClass() == false)
                    {
                        mi += AddSymbolMembers(this, m.Menu, type, type.ToDisplayString(WpfHelper.MemberNameFormat));
                    }
                }
                else if (type.TypeKind == TypeKind.Interface)
                {
                    foreach (var item in type.AllInterfaces)
                    {
                        mi += AddSymbolMembers(this, m.Menu, item, item.ToDisplayString(WpfHelper.MemberNameFormat));
                    }
                }
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(" members: ")
            .Append(c + " (" + mi + " inherited)");
            m.Show();
        }
Esempio n. 4
0
        void FindImplementations(CommandContext context, ISymbol symbol)
        {
            var implementations = new List <ISymbol>(ThreadHelper.JoinableTaskFactory.Run(() => SymbolFinder.FindImplementationsAsync(symbol, _Context.Document.Project.Solution, null, context.CancellationToken)));

            implementations.Sort((a, b) => a.Name.CompareTo(b.Name));
            var m = new SymbolMenu(this);

            if (symbol.Kind == SymbolKind.NamedType)
            {
                foreach (var impl in implementations)
                {
                    m.Menu.Add(impl, _Context, false);
                }
            }
            else
            {
                foreach (var impl in implementations)
                {
                    m.Menu.Add(impl, _Context, impl.ContainingSymbol);
                }
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(" implementations: ")
            .Append(implementations.Count.ToString());
            m.Show();
        }
Esempio n. 5
0
        internal static void ShowLocations(this SemanticContext context, ISymbol symbol, ICollection <SyntaxReference> locations, UIElement positionElement = null)
        {
            var m    = new SymbolMenu(context, SymbolListType.Locations);
            var locs = new SortedList <(string, string, int), Location>();

            foreach (var item in locations)
            {
                locs[(System.IO.Path.GetDirectoryName(item.SyntaxTree.FilePath), System.IO.Path.GetFileName(item.SyntaxTree.FilePath), item.Span.Start)] = item.ToLocation();
Esempio n. 6
0
        void FindCallers(CommandContext context, ISymbol source)
        {
            var doc  = _Context.Document;
            var docs = System.Collections.Immutable.ImmutableHashSet.CreateRange(doc.Project.GetRelatedProjectDocuments());
            List <SymbolCallerInfo> callers;

            switch (source.Kind)
            {
            case SymbolKind.Method:
            case SymbolKind.Property:
            case SymbolKind.Event:
                callers = ThreadHelper.JoinableTaskFactory.Run(() => SymbolFinder.FindCallersAsync(source, doc.Project.Solution, docs, context.CancellationToken)).ToList();
                break;

            case SymbolKind.NamedType:
                var tempResults = new HashSet <SymbolCallerInfo>(SymbolCallerInfoComparer.Instance);
                ThreadHelper.JoinableTaskFactory.Run(async() => {
                    foreach (var item in (source as INamedTypeSymbol).InstanceConstructors)
                    {
                        foreach (var c in await SymbolFinder.FindCallersAsync(item, doc.Project.Solution, docs, context.CancellationToken))
                        {
                            tempResults.Add(c);
                        }
                    }
                });
                (callers = new List <SymbolCallerInfo>(tempResults.Count)).AddRange(tempResults);
                break;

            default: return;
            }
            callers.Sort((a, b) => CodeAnalysisHelper.CompareSymbol(a.CallingSymbol, b.CallingSymbol));
            var m = new SymbolMenu(this);

            m.Title.SetGlyph(ThemeHelper.GetImage(source.GetImageId()))
            .Append(source.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(" callers");
            var containerType = source.ContainingType;

            foreach (var caller in callers)
            {
                var s = caller.CallingSymbol;
                var i = m.Menu.Add(s, _Context, false);
                i.Location = caller.Locations.FirstOrDefault();
                if (s.ContainingType != containerType)
                {
                    i.Hint = s.ContainingType.ToDisplayString(WpfHelper.MemberNameFormat);
                }
            }
            m.Show();
        }
Esempio n. 7
0
        internal static void FindOverrides(this SemanticContext context, ISymbol symbol)
        {
            var m = new SymbolMenu(context);
            int c = 0;

            foreach (var ov in SyncHelper.RunSync(() => SymbolFinder.FindOverridesAsync(symbol, context.Document.Project.Solution, null, default)))
            {
                m.Menu.Add(ov, ov.ContainingType);
                ++c;
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true)
            .Append(R.T_Overrides)
            .Append(c.ToString());
            m.Show();
        }
Esempio n. 8
0
        void FindOverrides(CommandContext context, ISymbol symbol)
        {
            var m = new SymbolMenu(this);
            int c = 0;

            foreach (var ov in ThreadHelper.JoinableTaskFactory.Run(() => SymbolFinder.FindOverridesAsync(symbol, _Context.Document.Project.Solution, null, context.CancellationToken)))
            {
                m.Menu.Add(ov, _Context, ov.ContainingType);
                ++c;
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(" overrides: ")
            .Append(c.ToString());
            m.Show();
        }
Esempio n. 9
0
        void FindReferencedSymbols(CommandContext context, ISymbol symbol)
        {
            var m = new SymbolMenu(this);
            var c = 0;

            foreach (var item in _Context.Node.FindReferencingSymbols(_Context.SemanticModel, true))
            {
                var member = item.Key;
                var i      = m.Menu.Add(member, _Context, true);
                if (item.Value > 1)
                {
                    i.Hint = "* " + item.Value.ToString();
                }
                ++c;
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(" referenced members: ")
            .Append(c.ToString());
            m.Show();
        }
Esempio n. 10
0
        void ShowSymbolMenuForResult(ISymbol source, List <ISymbol> members, string suffix, bool groupByType)
        {
            members.Sort(CodeAnalysisHelper.CompareSymbol);
            var m = new SymbolMenu(this);

            m.Title.SetGlyph(ThemeHelper.GetImage(source.GetImageId()))
            .Append(source.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(suffix);
            ITypeSymbol containingType = null;

            foreach (var item in members)
            {
                if (groupByType && item.ContainingType != containingType)
                {
                    m.Menu.Add((containingType = item.ContainingType), _Context, false)
                    .Type = SymbolItemType.Container;
                }
                m.Menu.Add(item, _Context, false);
            }
            m.Show();
        }
Esempio n. 11
0
        internal static void FindMembers(this SemanticContext context, ISymbol symbol, UIElement positionElement = null)
        {
            var m = new SymbolMenu(context, symbol.Kind == SymbolKind.Namespace ? SymbolListType.TypeList : SymbolListType.None);

            var(count, external) = m.Menu.AddSymbolMembers(symbol);
            if (m.Menu.IconProvider == null)
            {
                if (symbol.Kind == SymbolKind.NamedType)
                {
                    switch (((INamedTypeSymbol)symbol).TypeKind)
                    {
                    case TypeKind.Interface:
                        m.Menu.ExtIconProvider = ExtIconProvider.InterfaceMembers.GetExtIcons; break;

                    case TypeKind.Class:
                    case TypeKind.Struct:
                        m.Menu.ExtIconProvider = ExtIconProvider.Default.GetExtIcons; break;
                    }
                }
                else
                {
                    m.Menu.ExtIconProvider = ExtIconProvider.Default.GetExtIcons;
                }
            }
            m.Title.SetGlyph(ThemeHelper.GetImage(symbol.GetImageId()))
            .Append(symbol.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true);
            if (symbol.Kind != SymbolKind.Namespace)
            {
                m.Title.Append(R.T_Members.Replace("{count}", count.ToString()).Replace("{inherited}", external.ToString()));
            }
            else
            {
                m.Title.Append(R.T_NamespaceMembers.Replace("{count}", count.ToString()));
            }
            m.Show(positionElement);
        }