/// <summary> /// Reference locations are deduplicated across the entire find references result set /// Order the definitions so that references to multiple definitions appear under the /// desired definition (e.g. constructor references should prefer the constructor method /// over the type definition). Note that this does not change the order in which /// definitions are displayed in Find Symbol Results, it only changes which definition /// a given reference should appear under when its location is a reference to multiple /// definitions. /// </summary> private static int GetPrecedence(ReferencedSymbol referencedSymbol) { switch (referencedSymbol.Definition.Kind) { case SymbolKind.Event: case SymbolKind.Field: case SymbolKind.Label: case SymbolKind.Local: case SymbolKind.Method: case SymbolKind.Parameter: case SymbolKind.Property: case SymbolKind.RangeVariable: return 0; case SymbolKind.ArrayType: case SymbolKind.DynamicType: case SymbolKind.ErrorType: case SymbolKind.NamedType: case SymbolKind.PointerType: return 1; default: return 2; } }
private void ProcessReferencedSymbol( Solution solution, ReferencedSymbol referencedSymbol, ImmutableArray<DefinitionItem>.Builder definitions, ImmutableArray<SourceReferenceItem>.Builder references, HashSet<DocumentSpan> uniqueSpans) { // See if this is a symbol we even want to present to the user. If not, // ignore it entirely (including all its reference locations). if (!referencedSymbol.ShouldShow()) { return; } var definitionItem = referencedSymbol.Definition.ToDefinitionItem(solution, uniqueSpans); definitions.Add(definitionItem); // Now, create the SourceReferenceItems for all the reference locations // for this definition. CreateReferences(referencedSymbol, references, definitionItem, uniqueSpans); // Finally, see if there are any third parties that want to add their // own result to our collection. var thirdPartyItem = GetThirdPartyDefinitionItem(solution, referencedSymbol.Definition); if (thirdPartyItem != null) { definitions.Add(thirdPartyItem); } }
private bool IncludeDefinition(ReferencedSymbol reference) { var definition = reference.Definition; // Don't include parameters to property accessors if (definition is IParameterSymbol && definition.ContainingSymbol is IMethodSymbol && ((IMethodSymbol)definition.ContainingSymbol).AssociatedSymbol is IPropertySymbol) { return false; } return true; }
private static bool ShouldKeep(ReferencedSymbol r) { if (r.Locations.Any()) { return true; } if (r.Definition.IsImplicitlyDeclared) { return false; } if (r.Definition.IsPropertyAccessor()) { return false; } return true; }
private static void Verify(ReferencedSymbol reference, HashSet<int> expectedMatchedLines) { System.Action<Location> verifier = (location) => Assert.True(expectedMatchedLines.Remove(location.GetLineSpan().StartLinePosition.Line)); foreach (var location in reference.Locations) { verifier(location.Location); } foreach (var location in reference.Definition.Locations) { verifier(location); } }
public TestAccessor(ReferencedSymbol referencedSymbol) => _referencedSymbol = referencedSymbol;
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 DefinitionItem CreateDefinitionItem( Solution solution, ReferencedSymbol referencedSymbol, HashSet<DocumentLocation> uniqueLocations) { var definition = referencedSymbol.Definition; var displayParts = definition.ToDisplayParts(s_definitionDisplayFormat).ToTaggedText(); return CreateDefinitionItem( GlyphTags.GetTags(definition.GetGlyph()), displayParts, definition.ShouldShowWithNoReferenceLocations(), solution, definition, uniqueLocations); }
private static void CreateReferences( ReferencedSymbol referencedSymbol, ImmutableArray<SourceReferenceItem>.Builder references, DefinitionItem definitionItem, HashSet<DocumentLocation> uniqueLocations) { foreach (var referenceLocation in referencedSymbol.Locations) { var location = referenceLocation.Location; Debug.Assert(location.IsInSource); var document = referenceLocation.Document; var sourceSpan = location.SourceSpan; var documentLocation = new DocumentLocation(document, sourceSpan); if (!documentLocation.CanNavigateTo()) { continue; } if (uniqueLocations.Add(documentLocation)) { references.Add(new SourceReferenceItem(definitionItem, documentLocation)); } } }
private AbstractTreeItem ConvertToDefinitionItem( Solution solution, ReferencedSymbol referencedSymbol, Location location, Glyph glyph) { if (!location.IsInSource) { return referencedSymbol.Locations.Any() ? new MetadataDefinitionTreeItem( solution.Workspace, referencedSymbol.Definition, referencedSymbol.Locations.First().Document.Project.Id, glyph.GetGlyphIndex()) : null; } var document = solution.GetDocument(location.SourceTree); var sourceSpan = location.SourceSpan; if (!IsValidSourceLocation(document, sourceSpan)) { return null; } return new SourceDefinitionTreeItem(document, sourceSpan, referencedSymbol.Definition, glyph.GetGlyphIndex()); }
private static void CreateReferences( ReferencedSymbol referencedSymbol, ImmutableArray<SourceReferenceItem>.Builder references, DefinitionItem definitionItem, HashSet<DocumentLocation> uniqueLocations) { foreach (var referenceLocation in referencedSymbol.Locations) { var sourceReferenceItem = referenceLocation.TryCreateSourceReferenceItem(definitionItem); if (sourceReferenceItem == null) { continue; } if (uniqueLocations.Add(sourceReferenceItem.Location)) { references.Add(sourceReferenceItem); } } }
private static bool ShouldShow(ReferencedSymbol referencedSymbol) { // If the reference has any locations then we will present it. if (referencedSymbol.Locations.Any()) { return true; } return referencedSymbol.Definition.ShouldShowWithNoReferenceLocations(); }