Beispiel #1
0
        private static DefinitionItem CreateDefinitionItem(
            ImmutableArray <string> tags,
            ImmutableArray <TaggedText> displayParts,
            bool displayIfNoReferences,
            Solution solution, ISymbol definition,
            HashSet <DocumentLocation> uniqueLocations)
        {
            var additionalLocations       = ImmutableArray.CreateBuilder <DocumentLocation>();
            DocumentLocation?mainLocation = null;

            // If it's a namespace, don't create any normal lcoation.  Namespaces
            // come from many different sources, but we'll only show a single
            // root definition node for it.  That node won't be navigable.
            if (definition.Kind != SymbolKind.Namespace)
            {
                foreach (var location in definition.Locations)
                {
                    if (location.IsInMetadata)
                    {
                        return(DefinitionItem.CreateMetadataDefinition(
                                   tags, displayParts, solution, definition, displayIfNoReferences));
                    }
                    else if (location.IsVisibleSourceLocation())
                    {
                        var document = solution.GetDocument(location.SourceTree);
                        if (document != null)
                        {
                            var documentLocation = new DocumentLocation(document, location.SourceSpan);
                            if (mainLocation == null)
                            {
                                mainLocation = documentLocation;
                            }
                            else
                            {
                                if (uniqueLocations.Add(documentLocation))
                                {
                                    additionalLocations.Add(documentLocation);
                                }
                            }
                        }
                    }
                }
            }

            if (mainLocation == null)
            {
                // If we got no definition locations, then create a sentinel one
                // that we can display but which will not allow navigation.
                return(DefinitionItem.CreateNonNavigableItem(
                           tags, displayParts,
                           DefinitionItem.GetOriginationParts(definition),
                           displayIfNoReferences));
            }

            return(DefinitionItem.Create(
                       tags, displayParts, mainLocation.Value,
                       additionalLocations.ToImmutable(), displayIfNoReferences));
        }
        public static DefinitionItem ToDefinitionItem(
            this ISymbol definition,
            Solution solution,
            HashSet <DocumentSpan> uniqueSpans = null)
        {
            var displayParts = definition.ToDisplayParts(GetFormat(definition)).ToTaggedText();

            var tags = GlyphTags.GetTags(definition.GetGlyph());
            var displayIfNoReferences = definition.ShouldShowWithNoReferenceLocations(
                showMetadataSymbolsWithoutReferences: false);

            var sourceLocations = ArrayBuilder <DocumentSpan> .GetInstance();

            // If it's a namespace, don't create any normal lcoation.  Namespaces
            // come from many different sources, but we'll only show a single
            // root definition node for it.  That node won't be navigable.
            if (definition.Kind != SymbolKind.Namespace)
            {
                foreach (var location in definition.Locations)
                {
                    if (location.IsInMetadata)
                    {
                        return(DefinitionItem.CreateMetadataDefinition(
                                   tags, displayParts, solution, definition, displayIfNoReferences));
                    }
                    else if (location.IsVisibleSourceLocation())
                    {
                        var document = solution.GetDocument(location.SourceTree);
                        if (document != null)
                        {
                            var documentLocation = new DocumentSpan(document, location.SourceSpan);
                            if (sourceLocations.Count == 0)
                            {
                                sourceLocations.Add(documentLocation);
                            }
                            else
                            {
                                if (uniqueSpans == null ||
                                    uniqueSpans.Add(documentLocation))
                                {
                                    sourceLocations.Add(documentLocation);
                                }
                            }
                        }
                    }
                }
            }

            if (sourceLocations.Count == 0)
            {
                // If we got no definition locations, then create a sentinel one
                // that we can display but which will not allow navigation.
                return(DefinitionItem.CreateNonNavigableItem(
                           tags, displayParts,
                           DefinitionItem.GetOriginationParts(definition),
                           displayIfNoReferences));
            }

            return(DefinitionItem.Create(
                       tags, displayParts, sourceLocations.ToImmutableAndFree(), displayIfNoReferences));
        }