提交 7cf4e3b1 编写于 作者: C Cyrus Najmabadi

Allow NavigableItems to have child items.

This will be used by TypeScript so it can display FindRefernces result in a
tree form similar to how C#/VB does it.  i.e. it can show results like:

Decl1
|--Ref1
|--Ref2
Decl2
|--Ref3
|--Ref4
上级 6cc33123
// 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.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Editor.Navigation
......@@ -11,5 +13,7 @@ internal interface INavigableItem
Document Document { get; }
TextSpan SourceSpan { get; }
ImmutableArray<INavigableItem> ChildItems { get; }
}
}
// 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 System.Threading;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.FindSymbols;
......@@ -20,6 +21,7 @@ internal class DeclaredSymbolNavigableItem : INavigableItem
public Glyph Glyph => _lazySymbol.Value?.GetGlyph() ?? Glyph.Error;
public TextSpan SourceSpan => _declaredSymbolInfo.Span;
public ISymbol Symbol => _lazySymbol.Value;
public ImmutableArray<INavigableItem> ChildItems => ImmutableArray<INavigableItem>.Empty;
private readonly DeclaredSymbolInfo _declaredSymbolInfo;
private readonly Lazy<string> _lazyDisplayName;
......
// 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.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
......@@ -76,6 +77,8 @@ public TextSpan SourceSpan
return _location.SourceSpan;
}
}
public ImmutableArray<INavigableItem> ChildItems => ImmutableArray<INavigableItem>.Empty;
}
}
}
......@@ -60,7 +60,7 @@ private IList<AbstractTreeItem> CreateFindReferencesItems(Solution solution, IEn
definitions.Add(definitionItem);
var referenceItems = CreateReferenceItems(solution, uniqueLocations, referencedSymbol.Locations.Select(loc => loc.Location), Glyph.Reference);
definitionItem.Children.AddRange(referenceItems);
(definitionItem as ITreeItemWithReferenceCount)?.SetReferenceCount(referenceItems.Count);
definitionItem.SetReferenceCount(referenceItems.Count);
}
}
......
......@@ -2,10 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Navigation;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library.FindResults
{
......@@ -16,11 +15,24 @@ private IList<AbstractTreeItem> CreateGoToDefinitionItems(IEnumerable<INavigable
var sourceListItems =
from item in items
where IsValidSourceLocation(item.Document, item.SourceSpan)
select (AbstractTreeItem)new SourceReferenceTreeItem(item.Document, item.SourceSpan, item.Glyph.GetGlyphIndex());
select CreateTreeItem(item);
return sourceListItems.ToList();
}
private AbstractTreeItem CreateTreeItem(INavigableItem item)
{
var result = new SourceReferenceTreeItem(item.Document, item.SourceSpan, item.Glyph.GetGlyphIndex());
if (!item.ChildItems.IsEmpty)
{
var childItems = CreateGoToDefinitionItems(item.ChildItems);
result.Children.AddRange(childItems);
result.SetReferenceCount(childItems.Count);
}
return result;
}
public void PresentNavigableItems(string title, IEnumerable<INavigableItem> items)
{
PresentObjectList(title, new ObjectList(CreateGoToDefinitionItems(items), this));
......
......@@ -96,5 +96,9 @@ private static string GetFileLocationsText(string fileName, string projectNameDi
return string.Empty;
}
internal virtual void SetReferenceCount(int referenceCount)
{
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library.FindResults
{
internal interface ITreeItemWithReferenceCount
{
void SetReferenceCount(int referenceCount);
}
}
......@@ -6,7 +6,7 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library.FindResults
{
internal class MetadataDefinitionTreeItem : AbstractTreeItem, ITreeItemWithReferenceCount
internal class MetadataDefinitionTreeItem : AbstractTreeItem
{
private readonly string _assemblyName;
private readonly string _symbolDefinition;
......@@ -40,7 +40,7 @@ public override int GoToSource()
return VSConstants.E_FAIL;
}
public void SetReferenceCount(int referenceCount)
internal override void SetReferenceCount(int referenceCount)
{
var referenceCountDisplay = referenceCount == 1
? string.Format(ServicesVSResources.ReferenceCountSingular, referenceCount)
......
......@@ -5,7 +5,7 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Library.FindResults
{
internal class SourceDefinitionTreeItem : AbstractSourceTreeItem, ITreeItemWithReferenceCount
internal class SourceDefinitionTreeItem : AbstractSourceTreeItem
{
private readonly string _symbolDisplay;
......@@ -17,7 +17,7 @@ public SourceDefinitionTreeItem(Document document, TextSpan sourceSpan, ISymbol
this.DisplayText = $"[{document.Project.Name}] {_symbolDisplay}";
}
public void SetReferenceCount(int referenceCount)
internal override void SetReferenceCount(int referenceCount)
{
var referenceCountDisplay = referenceCount == 1
? string.Format(ServicesVSResources.ReferenceCountSingular, referenceCount)
......
......@@ -24,7 +24,6 @@
<Compile Include="Implementation\CompilationErrorTelemetry\CompilationErrorTelemetryIncrementalAnalyzer.cs" />
<Compile Include="Implementation\Diagnostics\VisualStudioVenusSpanMappingService.cs" />
<Compile Include="Implementation\Library\FindResults\TreeItems\AbstractSourceTreeItem.cs" />
<Compile Include="Implementation\Library\FindResults\TreeItems\ITreeItemWithReferenceCount.cs" />
<Compile Include="Implementation\Library\FindResults\TreeItems\MetadataDefinitionTreeItem.cs" />
<Compile Include="Implementation\Library\FindResults\TreeItems\SourceDefinitionTreeItem.cs" />
<Compile Include="Implementation\Preview\ReferenceChange.MetadataReferenceChange.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册