Esempio n. 1
0
        public override Task OnDefinitionFoundAsync(DefinitionItem definition)
        {
            lock (_gate)
            {
                _definitionItems.Add(definition);
            }

            return SpecializedTasks.EmptyTask;
        }
Esempio n. 2
0
        public DefinitionTreeItem(
            DefinitionItem definitionItem,
            ImmutableArray<SourceReferenceTreeItem> referenceItems)
            : base(definitionItem.Tags.GetGlyph().GetGlyphIndex())
        {
            _definitionItem = definitionItem;

            this.Children.AddRange(referenceItems);
            this.DisplayText = CreateDisplayText();
        }
 public RoslynDefinitionBucket(
     StreamingFindUsagesPresenter presenter,
     TableDataSourceFindUsagesContext context,
     DefinitionItem definitionItem)
     : base(name: definitionItem.DisplayParts.JoinText() + " " + definitionItem.GetHashCode(),
            sourceTypeIdentifier: context.SourceTypeIdentifier,
            identifier: context.Identifier)
 {
     _presenter = presenter;
     _context = context;
     DefinitionItem = definitionItem;
 }
        private ImmutableArray<SourceReferenceTreeItem> CreateReferenceItems(
            DefinitionItem definitionItem,
            DefinitionsAndReferences definitionsAndReferences,
            int commonPathElements)
        {
            var result = ImmutableArray.CreateBuilder<SourceReferenceTreeItem>();

            var definitionGlyph = definitionItem.Tags.GetGlyph();

            // Skip the first definition.  We'll present it in the definition item.
            var definitionLocationsAndGlyphs =
                from loc in definitionItem.SourceSpans.Skip(1)
                select ValueTuple.Create(loc, definitionGlyph);

            var referenceLocationsAndGlyphs =
                from r in definitionsAndReferences.References
                where r.Definition == definitionItem
                select ValueTuple.Create(r.SourceSpan, Glyph.Reference);

            var allLocationsAndGlyphs = definitionLocationsAndGlyphs.Concat(referenceLocationsAndGlyphs);

            foreach (var locationAndGlyph in allLocationsAndGlyphs)
            {
                var documentLocation = locationAndGlyph.Item1;
                var glyph = locationAndGlyph.Item2;
                result.Add(new SourceReferenceTreeItem(
                    documentLocation.Document,
                    documentLocation.SourceSpan,
                    glyph.GetGlyphIndex(),
                    commonPathElements));
            }

            var linkedReferences = result.GroupBy(r => r.DisplayText.ToLowerInvariant()).Where(g => g.Count() > 1).SelectMany(g => g);
            foreach (var linkedReference in linkedReferences)
            {
                linkedReference.AddProjectNameDisambiguator();
            }

            result.Sort();
            return result.ToImmutable();
        }
            private async Task AddDeclarationEntriesAsync(DefinitionItem definition)
            {
                CancellationToken.ThrowIfCancellationRequested();

                // Don't do anything if we already have declaration entries for this definition 
                // (i.e. another thread beat us to this).
                if (HasDeclarationEntries(definition))
                {
                    return;
                }

                var definitionBucket = GetOrCreateDefinitionBucket(definition);

                // We could do this inside the lock.  but that would mean async activity in a 
                // lock, and i'd like to avoid that.  That does mean that we might do extra
                // work if multiple threads end up down htis path.  But only one of them will
                // win when we access the lock below.
                var declarations = ArrayBuilder<Entry>.GetInstance();
                foreach (var declarationLocation in definition.SourceSpans)
                {
                    var definitionEntry = await CreateDocumentLocationEntryAsync(
                        definitionBucket, declarationLocation, isDefinitionLocation: true).ConfigureAwait(false);
                    if (definitionEntry != null)
                    {
                        declarations.Add(definitionEntry);
                    }
                }

                lock (_gate)
                {
                    // Do one final check to ensure that no other thread beat us here.
                    if (!HasDeclarationEntries(definition))
                    {
                        // We only include declaration entries in the entries we show when 
                        // not grouping by definition.
                        _entriesWithDeclarations = _entriesWithDeclarations.AddRange(declarations);
                        CurrentVersionNumber++;
                    }
                }

                declarations.Free();

                // Let all our subscriptions know that we've updated.
                _tableDataSink.FactorySnapshotChanged(this);
            }
 private bool HasDeclarationEntries(DefinitionItem definition)
 {
     lock (_gate)
     {
         return _entriesWithDeclarations.Any(e => e.DefinitionBucket.DefinitionItem == definition);
     }
 }
            public override async Task OnDefinitionFoundAsync(DefinitionItem definition)
            {
                lock (_gate)
                {
                    _definitions.Add(definition);
                }

                // If this is a definition we always want to show, then create entries
                // for all the declaration locations immediately.  Otherwise, we'll 
                // create them on demand when we hear about references for this definition.
                if (definition.DisplayIfNoReferences)
                {
                    await AddDeclarationEntriesAsync(definition).ConfigureAwait(false);
                }
            }
 // Used by TypeScript
 internal SourceReferenceItem(DefinitionItem definition, DocumentSpan sourceSpan, SymbolUsageInfo symbolUsageInfo)
     : this(definition, sourceSpan, symbolUsageInfo, additionalProperties : ImmutableDictionary <string, string> .Empty)
 {
 }
        public static SourceReferenceItem TryCreateSourceReferenceItem(
            this ReferenceLocation referenceLocation,
            DefinitionItem definitionItem,
            bool includeHiddenLocations)
        {
            var location = referenceLocation.Location;

            Debug.Assert(location.IsInSource);
            if (!location.IsVisibleSourceLocation() &&
                !includeHiddenLocations)
            {
                return null;
            }

            return new SourceReferenceItem(definitionItem, 
                new DocumentSpan(referenceLocation.Document, location.SourceSpan));
        }
Esempio n. 10
0
 public SourceReferenceItem(DefinitionItem definition, DocumentSpan sourceSpan)
 {
     Definition = definition;
     SourceSpan = sourceSpan;
 }
            public override async Task OnDefinitionFoundAsync(DefinitionItem definition)
            {
                lock (_gate)
                {
                    _definitions.Add(definition);
                }

                // If this is a definition we always want to show, then create entries
                // for all the definition locations immediately.
                if (definition.DisplayIfNoReferences)
                {
                    await AddDefinitionEntriesAsync(definition).ConfigureAwait(false);
                }
            }
Esempio n. 12
0
 public virtual Task OnDefinitionFoundAsync(DefinitionItem definition) => Task.CompletedTask;
Esempio n. 13
0
 public virtual Task OnDefinitionFoundAsync(DefinitionItem definition) => SpecializedTasks.EmptyTask;
Esempio n. 14
0
 public FindLiteralsProgressAdapter(
     IFindUsagesContext context, DefinitionItem definition)
 {
     _context    = context;
     _definition = definition;
 }
 internal SourceReferenceItem(DefinitionItem definition, DocumentSpan sourceSpan, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary <string, string> additionalProperties)
     : this(definition, sourceSpan, symbolUsageInfo, additionalProperties, isWrittenTo : symbolUsageInfo.IsWrittenTo())
 {
 }
            private async Task OnEntryFoundAsync(
                DefinitionItem definition,
                Func<RoslynDefinitionBucket, Task<Entry>> createEntryAsync,
                bool addToEntriesWithDeclarations,
                bool addToEntriesWithoutDeclarations)
            {
                Debug.Assert(addToEntriesWithDeclarations || addToEntriesWithoutDeclarations);
                CancellationToken.ThrowIfCancellationRequested();

                // First find the bucket corresponding to our definition.
                var definitionBucket = GetOrCreateDefinitionBucket(definition);

                var entry = await createEntryAsync(definitionBucket).ConfigureAwait(false);

                // Ok, we got a *reference* to some definition item.  This may have been
                // a reference for some definition that we haven't created any declaration
                // entries for (i.e. becuase it had DisplayIfNoReferences = false).  Because
                // we've now found a reference, we want to make sure all its declaration
                // entries are added.
                await AddDeclarationEntriesAsync(definition).ConfigureAwait(false);

                lock (_gate)
                {
                    // Once we can make the new entry, add it to the appropriate list.
                    if (addToEntriesWithDeclarations)
                    {
                        _entriesWithDeclarations = _entriesWithDeclarations.Add(entry);
                    }

                    if (addToEntriesWithoutDeclarations)
                    {
                        _entriesWithoutDeclarations = _entriesWithoutDeclarations.Add(entry);
                    }

                    CurrentVersionNumber++;
                }

                // Let all our subscriptions know that we've updated.
                _tableDataSink.FactorySnapshotChanged(this);
            }
            private RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem definition)
            {
                lock (_gate)
                {
                    if (!_definitionToBucket.TryGetValue(definition, out var bucket))
                    {
                        bucket = new RoslynDefinitionBucket(Presenter, this, definition);
                        _definitionToBucket.Add(definition, bucket);
                    }

                    return bucket;
                }
            }
            private async Task AddDefinitionEntriesAsync(DefinitionItem definition)
            {
                CancellationToken.ThrowIfCancellationRequested();

                // Don't do anything if we already have entries for this definition 
                // (i.e. another thread beat us to this).
                if (HasEntriesForDefinition(definition))
                {
                    return;
                }

                // First find the bucket corresponding to our definition. If we can't find/create 
                // one, then don't do anything for this reference.
                var definitionBucket = GetOrCreateDefinitionBucket(definition);
                if (definitionBucket == null)
                {
                    return;
                }

                // We could do this inside the lock.  but that would mean async activity in a 
                // lock, and i'd like to avoid that.  That does mean that we might do extra
                // work if multiple threads end up down htis path.  But only one of them will
                // win when we access the lock below.
                var builder = ImmutableArray.CreateBuilder<Entry>();
                foreach (var definitionLocation in definition.SourceSpans)
                {
                    var definitionEntry = await CreateDocumentLocationEntryAsync(
                        definitionBucket, definitionLocation, isDefinitionLocation: true).ConfigureAwait(false);
                    if (definitionEntry != null)
                    {
                        builder.Add(definitionEntry);
                    }
                }

                lock (_gate)
                {
                    // Do one final check to ensure that no other thread beat us here.
                    if (!HasEntriesForDefinition(definition))
                    {
                        _entries = _entries.AddRange(builder);
                        CurrentVersionNumber++;
                    }
                }

                // Let all our subscriptions know that we've updated.
                _tableDataSink.FactorySnapshotChanged(this);
            }
            private async Task OnEntryFoundAsync(
                DefinitionItem definition,
                Func<RoslynDefinitionBucket, Task<Entry>> createEntryAsync)
            {
                CancellationToken.ThrowIfCancellationRequested();

                // First find the bucket corresponding to our definition. If we can't find/create 
                // one, then don't do anything for this reference.
                var definitionBucket = GetOrCreateDefinitionBucket(definition);
                if (definitionBucket == null)
                {
                    return;
                }

                var entry = await createEntryAsync(definitionBucket).ConfigureAwait(false);
                if (entry == null)
                {
                    return;
                }

                // Ok, we got a *reference* to some definition item.  This may have been
                // a reference for some definition that we haven't created any definition
                // entries for (i.e. becuase it had DisplayIfNoReferences = false).  Because
                // we've now found a reference, we want to make sure all tis definition
                // entries are added.
                await AddDefinitionEntriesAsync(definition).ConfigureAwait(false);

                lock (_gate)
                {
                    // Once we can make the new entry, add it to our list.
                    _entries = _entries.Add(entry);
                    CurrentVersionNumber++;
                }

                // Let all our subscriptions know that we've updated.
                _tableDataSink.FactorySnapshotChanged(this);
            }
 private bool HasEntriesForDefinition(DefinitionItem definition)
 {
     lock (_gate)
     {
         return _entries.Any(e => e.DefinitionBucket.DefinitionItem == definition);
     }
 }
        private static void CreateReferences(
            ReferencedSymbol referencedSymbol,
            ArrayBuilder<SourceReferenceItem> references,
            DefinitionItem definitionItem,
            bool includeHiddenLocations,
            HashSet<DocumentSpan> uniqueSpans)
        {
            foreach (var referenceLocation in referencedSymbol.Locations)
            {
                var sourceReferenceItem = referenceLocation.TryCreateSourceReferenceItem(
                    definitionItem, includeHiddenLocations);
                if (sourceReferenceItem == null)
                {
                    continue;
                }

                if (uniqueSpans.Add(sourceReferenceItem.SourceSpan))
                {
                    references.Add(sourceReferenceItem);
                }
            }
        }
            private static string GetMessage(DefinitionItem definition)
            {
                if (definition.IsExternal)
                {
                    return ServicesVisualStudioNextResources.External_reference_found;
                }

                return string.Format(
                    ServicesVisualStudioNextResources.No_references_found_to_0,
                    definition.NameDisplayParts.JoinText());
            }
Esempio n. 23
0
 public virtual Task OnDefinitionFoundAsync(DefinitionItem definition) => SpecializedTasks.EmptyTask;
 // Used by F#
 internal SourceReferenceItem(DefinitionItem definition, DocumentSpan sourceSpan)
     : this(definition, sourceSpan, SymbolUsageInfo.None)
 {
 }