提交 4ad33373 编写于 作者: C CyrusNajmabadi

Show all source locations for a source item.

上级 90661187
......@@ -52,8 +52,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
Dim actualDefinitions = GetFileNamesAndSpans(
context.Definitions.Where(AddressOf context.ShouldShow).
OfType(Of DefinitionItem.DocumentLocationDefinitionItem).
SelectMany(Function(d) d.AdditionalLocations.Concat(d.Location)))
SelectMany(Function(d) d.SourceLocations))
Assert.Equal(expectedDefinitions, actualDefinitions)
......
......@@ -14,25 +14,21 @@ internal partial class DefinitionItem
// internal for testing purposes.
internal sealed class DocumentLocationDefinitionItem : DefinitionItem
{
public readonly DocumentLocation Location;
internal override bool IsExternal => false;
public DocumentLocationDefinitionItem(
ImmutableArray<string> tags,
ImmutableArray<TaggedText> displayParts,
ImmutableArray<DocumentLocation> additionalLocations,
bool displayIfNoReferences,
DocumentLocation location)
ImmutableArray<DocumentLocation> sourceLocations,
bool displayIfNoReferences)
: base(tags, displayParts,
ImmutableArray.Create(new TaggedText(TextTags.Text, location.Document.Project.Name)),
additionalLocations, displayIfNoReferences)
ImmutableArray.Create(new TaggedText(TextTags.Text, sourceLocations[0].Document.Project.Name)),
sourceLocations, displayIfNoReferences)
{
Location = location;
}
public override bool CanNavigateTo() => Location.CanNavigateTo();
public override bool TryNavigateTo() => Location.TryNavigateTo();
public override bool CanNavigateTo() => SourceLocations[0].CanNavigateTo();
public override bool TryNavigateTo() => SourceLocations[0].TryNavigateTo();
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Completion;
......@@ -38,7 +39,7 @@ internal abstract partial class DefinitionItem
/// Additional locations to present in the UI. A definition may have multiple locations
/// for cases like partial types/members.
/// </summary>
public ImmutableArray<DocumentLocation> AdditionalLocations { get; }
public ImmutableArray<DocumentLocation> SourceLocations { get; }
/// <summary>
/// Whether or not this definition should be presented if we never found any references to
......@@ -58,13 +59,13 @@ internal abstract partial class DefinitionItem
ImmutableArray<string> tags,
ImmutableArray<TaggedText> displayParts,
ImmutableArray<TaggedText> originationParts = default(ImmutableArray<TaggedText>),
ImmutableArray<DocumentLocation> additionalLocations = default(ImmutableArray<DocumentLocation>),
ImmutableArray<DocumentLocation> sourceLocations = default(ImmutableArray<DocumentLocation>),
bool displayIfNoReferences = true)
{
Tags = tags;
DisplayParts = displayParts;
OriginationParts = originationParts.NullToEmpty();
AdditionalLocations = additionalLocations.NullToEmpty();
SourceLocations = sourceLocations.NullToEmpty();
DisplayIfNoReferences = displayIfNoReferences;
}
......@@ -74,12 +75,25 @@ internal abstract partial class DefinitionItem
public static DefinitionItem Create(
ImmutableArray<string> tags,
ImmutableArray<TaggedText> displayParts,
DocumentLocation location,
ImmutableArray<DocumentLocation> additionalLocations = default(ImmutableArray<DocumentLocation>),
DocumentLocation sourceLocation,
bool displayIfNoReferences = true)
{
return Create(tags, displayParts, ImmutableArray.Create(sourceLocation), displayIfNoReferences);
}
public static DefinitionItem Create(
ImmutableArray<string> tags,
ImmutableArray<TaggedText> displayParts,
ImmutableArray<DocumentLocation> sourceLocations,
bool displayIfNoReferences = true)
{
if (sourceLocations.Length == 0)
{
throw new ArgumentException($"{nameof(sourceLocations)} cannot be empty.");
}
return new DocumentLocationDefinitionItem(
tags, displayParts, additionalLocations, displayIfNoReferences, location);
tags, displayParts, sourceLocations, displayIfNoReferences);
}
internal static DefinitionItem CreateMetadataDefinition(
......
......@@ -154,8 +154,7 @@ internal static class DefinitionItemExtensions
var tags = GlyphTags.GetTags(definition.GetGlyph());
var displayIfNoReferences = definition.ShouldShowWithNoReferenceLocations();
var additionalLocations = ImmutableArray.CreateBuilder<DocumentLocation>();
DocumentLocation? mainLocation = null;
var sourceLocations = ImmutableArray.CreateBuilder<DocumentLocation>();
// If it's a namespace, don't create any normal lcoation. Namespaces
// come from many different sources, but we'll only show a single
......@@ -175,16 +174,16 @@ internal static class DefinitionItemExtensions
if (document != null)
{
var documentLocation = new DocumentLocation(document, location.SourceSpan);
if (mainLocation == null)
if (sourceLocations.Count == 0)
{
mainLocation = documentLocation;
sourceLocations.Add(documentLocation);
}
else
{
if (uniqueLocations == null ||
uniqueLocations.Add(documentLocation))
{
additionalLocations.Add(documentLocation);
sourceLocations.Add(documentLocation);
}
}
}
......@@ -192,7 +191,7 @@ internal static class DefinitionItemExtensions
}
}
if (mainLocation == null)
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.
......@@ -203,8 +202,7 @@ internal static class DefinitionItemExtensions
}
return DefinitionItem.Create(
tags, displayParts, mainLocation.Value,
additionalLocations.ToImmutable(), displayIfNoReferences);
tags, displayParts, sourceLocations.ToImmutable(), displayIfNoReferences);
}
public static SourceReferenceItem TryCreateSourceReferenceItem(
......
......@@ -26,10 +26,12 @@ public void PresentDefinitionsAndReferences(DefinitionsAndReferences definitions
DefinitionsAndReferences definitionsAndReferences)
{
var definitionDocuments =
definitionsAndReferences.Definitions.SelectMany(d => d.AdditionalLocations)
definitionsAndReferences.Definitions.SelectMany(d => d.SourceLocations)
.Select(loc => loc.Document);
var referenceDocuments = definitionsAndReferences.References.Select(r => r.Location.Document);
var referenceDocuments =
definitionsAndReferences.References
.Select(r => r.Location.Document);
var allDocuments = definitionDocuments.Concat(referenceDocuments).WhereNotNull().ToSet();
var commonPathElements = CountCommonPathElements(allDocuments);
......@@ -51,8 +53,9 @@ public void PresentDefinitionsAndReferences(DefinitionsAndReferences definitions
var definitionGlyph = definitionItem.Tags.GetGlyph();
// Skip the first definition. We'll present it in the definition item.
var definitionLocationsAndGlyphs =
from loc in definitionItem.AdditionalLocations
from loc in definitionItem.SourceLocations.Skip(1)
select ValueTuple.Create(loc, definitionGlyph);
var referenceLocationsAndGlyphs =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册