提交 13e12415 编写于 作者: C CyrusNajmabadi

Don't add a NonNavigableItem unless we get no definition locations.

上级 fc51a0f8
......@@ -29,6 +29,9 @@ internal class DefaultDefinitionsAndReferencesFactory : IDefinitionsAndReference
var definitions = ImmutableArray.CreateBuilder<DefinitionItem>();
var references = ImmutableArray.CreateBuilder<SourceReferenceItem>();
// Order the symbols by precedence, then create the appropriate
// definition item per symbol and all refernece items for its
// reference locations.
foreach (var referencedSymbol in referencedSymbols.OrderBy(GetPrecedence))
{
ProcessReferencedSymbol(solution, referencedSymbol, definitions, references);
......@@ -78,11 +81,15 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
ImmutableArray<DefinitionItem>.Builder definitions,
ImmutableArray<SourceReferenceItem>.Builder references)
{
// 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;
}
// Try to create an item for this definition. If we can't,
// ignorei it entirely (including all its reference locations).
var definitionItem = CreateDefinitionItem(solution, referencedSymbol);
if (definitionItem == null)
{
......@@ -90,8 +97,13 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
}
definitions.Add(definitionItem);
// Now, create the SourceReferenceItems for all the reference locations
// for this definition.
CreateReferences(referencedSymbol, references, definitionItem);
// 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)
{
......@@ -114,13 +126,16 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
{
var definition = referencedSymbol.Definition;
var locations = FilterDefinitionLocations(definition);
var definitionLocations = ConvertLocations(solution, referencedSymbol, locations);
if (definitionLocations.IsEmpty)
{
return null;
}
// First, determine the set of locations for this symbol that we'll
// want to present to the user. Some symbols (like namespace) may
// have many locations, but we'll only want to show the user a single
// one.
var filteredLocations = FilterDefinitionLocations(definition);
// Convert the filtered set of locations to DefinitionLocation instances.
// If weren't any to, say because the symbol had no locations that we
// could understand (like Location.None), then we skip this item.
var definitionLocations = ConvertLocations(solution, referencedSymbol, filteredLocations);
var displayParts = definition.ToDisplayParts(s_definitionDisplayFormat).ToTaggedText();
return new DefinitionItem(
......@@ -146,11 +161,6 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
result.Add(DefinitionLocation.CreateSymbolLocation(
definition, firstSourceReferenceLocation.Document.Project));
}
else
{
result.Add(DefinitionLocation.CreateNonNavigatingLocation(
DefinitionLocation.GetOriginationParts(definition)));
}
}
else if (location.IsInSource)
{
......@@ -166,6 +176,14 @@ private static int GetPrecedence(ReferencedSymbol referencedSymbol)
}
}
if (result.Count == 0)
{
// If we got no definition locations, then create a sentinel one
// that we can display but which will not allow navigation.
result.Add(DefinitionLocation.CreateNonNavigatingLocation(
DefinitionLocation.GetOriginationParts(definition)));
}
return result.ToImmutable();
}
......
......@@ -20,7 +20,7 @@ internal static partial class IFindReferencesResultExtensions
public static bool ShouldShow(this ReferencedSymbol referencedSymbol)
{
// If the reference has any locations then we will present it.
if (referencedSymbol.Locations.Any(loc => loc.Location.IsInSource))
if (referencedSymbol.Locations.Any())
{
return true;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册