public async Task OnReferenceFoundAsync(Document document, TextSpan span) { var documentSpan = await ClassifiedSpansAndHighlightSpan.GetClassifiedDocumentSpanAsync( document, span, _context.CancellationToken).ConfigureAwait(false); await _context.OnReferenceFoundAsync(new SourceReferenceItem( _definition, documentSpan, isWrittenTo: false)).ConfigureAwait(false); }
public static async Task <SourceReferenceItem> TryCreateSourceReferenceItemAsync( this ReferenceLocation referenceLocation, DefinitionItem definitionItem, bool includeHiddenLocations, CancellationToken cancellationToken) { var location = referenceLocation.Location; Debug.Assert(location.IsInSource); if (!location.IsVisibleSourceLocation() && !includeHiddenLocations) { return(null); } var document = referenceLocation.Document; var sourceSpan = location.SourceSpan; var documentSpan = await ClassifiedSpansAndHighlightSpan.GetClassifiedDocumentSpanAsync( document, sourceSpan, cancellationToken).ConfigureAwait(false); return(new SourceReferenceItem(definitionItem, documentSpan, referenceLocation.IsWrittenTo)); }
private static async Task <DefinitionItem> ToDefinitionItemAsync( this ISymbol definition, Solution solution, bool includeHiddenLocations, bool includeClassifiedSpans, CancellationToken cancellationToken) { // Ensure we're working with the original definition for the symbol. I.e. When we're // creating definition items, we want to create them for types like Dictionary<TKey,TValue> // not some random instantiation of that type. // // This ensures that the type will both display properly to the user, as well as ensuring // that we can accurately resolve the type later on when we try to navigate to it. definition = definition.OriginalDefinition; var displayParts = definition.ToDisplayParts(GetFormat(definition)).ToTaggedText(); var nameDisplayParts = definition.ToDisplayParts(s_namePartsFormat).ToTaggedText(); var tags = GlyphTags.GetTags(definition.GetGlyph()); var displayIfNoReferences = definition.ShouldShowWithNoReferenceLocations( showMetadataSymbolsWithoutReferences: false); var sourceLocations = ArrayBuilder <DocumentSpan> .GetInstance(); var properties = GetProperties(definition); // If it's a namespace, don't create any normal location. 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, nameDisplayParts, solution, definition, properties, displayIfNoReferences)); } else if (location.IsInSource) { if (!location.IsVisibleSourceLocation() && !includeHiddenLocations) { continue; } var document = solution.GetDocument(location.SourceTree); if (document != null) { var documentLocation = !includeClassifiedSpans ? new DocumentSpan(document, location.SourceSpan) : await ClassifiedSpansAndHighlightSpan.GetClassifiedDocumentSpanAsync( document, location.SourceSpan, cancellationToken).ConfigureAwait(false); 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), properties, displayIfNoReferences)); } return(DefinitionItem.Create( tags, displayParts, sourceLocations.ToImmutableAndFree(), nameDisplayParts, properties, displayIfNoReferences)); }