private void TryLinkToRealReference(ISymbol typeSymbol, DocumentData documentData, ReferenceLocation refLocation) { if (typeSymbol.Kind != SymbolKind.NamedType) { return; } // A cref/nameof can be on a method or type trivia but we get always the type symbol var typeData = documentData.GetAllTypeDatas(o => o.Symbol.Equals(typeSymbol)).FirstOrDefault(); if (typeData == null) { return; } // Try to find the real node where the cref/nameof is located var referenceNameNode = typeData.Node.GetSimpleName(refLocation.Location.SourceSpan, true); var referenceSymbolInfo = documentData.SemanticModel.GetSymbolInfo(referenceNameNode); var data = documentData.GetNearestNodeData(referenceNameNode.Parent, referenceNameNode.IsInsideCref()); if (referenceSymbolInfo.Symbol is IMethodSymbol methodSymbol) { if (!referenceNameNode.IsInsideCref()) { return; } var referenceData = ProjectData.GetFunctionData(methodSymbol); var reference = new CrefFunctionDataReference(data, refLocation, referenceNameNode, methodSymbol, referenceData, false); data.References.TryAdd(reference); referenceData?.SelfReferences.TryAdd(reference); } else if (referenceNameNode.IsInsideNameOf()) // GetSymbolInfo will never return a concrete symbol for nameof only candidates { var referencedFuncs = new Dictionary <IMethodSymbol, FunctionData>(); foreach (var candidateSymbol in referenceSymbolInfo.CandidateSymbols.OfType <IMethodSymbol>()) { var nameofReferenceData = ProjectData.GetFunctionData(candidateSymbol); referencedFuncs.Add(candidateSymbol, nameofReferenceData); } var nameofReference = new NameofFunctionDataReference(data, refLocation, referenceNameNode, referencedFuncs, false); data.References.TryAdd(nameofReference); foreach (var referencedFun in referencedFuncs.Values.Where(o => o != null)) { referencedFun.SelfReferences.TryAdd(nameofReference); } } }