提交 799b963c 编写于 作者: C CyrusNajmabadi

Don't group by definition when presenting result for FindImplementations or GoToDef.

上级 2e1cb224
...@@ -126,7 +126,7 @@ private IStreamingFindUsagesPresenter GetStreamingPresenter() ...@@ -126,7 +126,7 @@ private IStreamingFindUsagesPresenter GetStreamingPresenter()
// Let the presented know we're starging a search. It will give us back // Let the presented know we're starging a search. It will give us back
// the context object that the FAR service will push results into. // the context object that the FAR service will push results into.
var context = presenter.StartSearch( var context = presenter.StartSearch(
EditorFeaturesResources.Find_References, alwaysShowDeclarations: false); EditorFeaturesResources.Find_References, canShowReferences: true);
await findUsagesService.FindReferencesAsync(document, caretPosition, context).ConfigureAwait(false); await findUsagesService.FindReferencesAsync(document, caretPosition, context).ConfigureAwait(false);
// Note: we don't need to put this in a finally. The only time we might not hit // Note: we don't need to put this in a finally. The only time we might not hit
......
...@@ -3,15 +3,12 @@ ...@@ -3,15 +3,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis.Editor.FindReferences;
using Microsoft.CodeAnalysis.Editor.FindUsages; using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.GoToDefinition namespace Microsoft.CodeAnalysis.Editor.GoToDefinition
...@@ -75,8 +72,7 @@ internal static class GoToDefinitionHelpers ...@@ -75,8 +72,7 @@ internal static class GoToDefinitionHelpers
FindUsagesHelpers.GetDisplayName(symbol)); FindUsagesHelpers.GetDisplayName(symbol));
return presenter.TryNavigateToOrPresentItemsAsync( return presenter.TryNavigateToOrPresentItemsAsync(
title, definitions.ToImmutableAndFree(), title, definitions.ToImmutableAndFree()).WaitAndGetResult(cancellationToken);
alwaysShowDeclarations: true).WaitAndGetResult(cancellationToken);
} }
private static IStreamingFindUsagesPresenter GetFindUsagesPresenter( private static IStreamingFindUsagesPresenter GetFindUsagesPresenter(
......
...@@ -136,8 +136,7 @@ public void ExecuteCommand(GoToImplementationCommandArgs args, Action nextHandle ...@@ -136,8 +136,7 @@ public void ExecuteCommand(GoToImplementationCommandArgs args, Action nextHandle
var definitionItems = goToImplContext.GetDefinitions(); var definitionItems = goToImplContext.GetDefinitions();
streamingPresenter.TryNavigateToOrPresentItemsAsync( streamingPresenter.TryNavigateToOrPresentItemsAsync(
goToImplContext.SearchTitle, definitionItems, goToImplContext.SearchTitle, definitionItems).Wait(cancellationToken);
alwaysShowDeclarations: true).Wait(cancellationToken);
} }
private IStreamingFindUsagesPresenter GetStreamingPresenter() private IStreamingFindUsagesPresenter GetStreamingPresenter()
......
...@@ -21,7 +21,7 @@ internal interface IStreamingFindUsagesPresenter ...@@ -21,7 +21,7 @@ internal interface IStreamingFindUsagesPresenter
/// search completes <see cref="FindUsagesContext.OnCompletedAsync"/> should be called. /// search completes <see cref="FindUsagesContext.OnCompletedAsync"/> should be called.
/// etc. etc. /// etc. etc.
/// </summary> /// </summary>
FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations); FindUsagesContext StartSearch(string title, bool canShowReferences);
} }
internal static class IStreamingFindUsagesPresenterExtensions internal static class IStreamingFindUsagesPresenterExtensions
...@@ -31,8 +31,8 @@ internal static class IStreamingFindUsagesPresenterExtensions ...@@ -31,8 +31,8 @@ internal static class IStreamingFindUsagesPresenterExtensions
/// items to the user. /// items to the user.
/// </summary> /// </summary>
public static async Task<bool> TryNavigateToOrPresentItemsAsync( public static async Task<bool> TryNavigateToOrPresentItemsAsync(
this IStreamingFindUsagesPresenter presenter, string title, this IStreamingFindUsagesPresenter presenter,
ImmutableArray<DefinitionItem> items, bool alwaysShowDeclarations) string title, ImmutableArray<DefinitionItem> items)
{ {
// Ignore any definitions that we can't navigate to. // Ignore any definitions that we can't navigate to.
var definitions = items.WhereAsArray(d => d.CanNavigateTo()); var definitions = items.WhereAsArray(d => d.CanNavigateTo());
...@@ -66,7 +66,7 @@ internal static class IStreamingFindUsagesPresenterExtensions ...@@ -66,7 +66,7 @@ internal static class IStreamingFindUsagesPresenterExtensions
// We have multiple definitions, or we have definitions with multiple locations. // We have multiple definitions, or we have definitions with multiple locations.
// Present this to the user so they can decide where they want to go to. // Present this to the user so they can decide where they want to go to.
var context = presenter.StartSearch(title, alwaysShowDeclarations); var context = presenter.StartSearch(title, canShowReferences: false);
foreach (var definition in nonExternalItems) foreach (var definition in nonExternalItems)
{ {
await context.OnDefinitionFoundAsync(definition).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definition).ConfigureAwait(false);
......
...@@ -27,39 +27,33 @@ namespace Microsoft.VisualStudio.LanguageServices.FindUsages ...@@ -27,39 +27,33 @@ namespace Microsoft.VisualStudio.LanguageServices.FindUsages
{ {
internal partial class StreamingFindUsagesPresenter internal partial class StreamingFindUsagesPresenter
{ {
private class DocumentSpanEntry : Entry private abstract class AbstractDocumentSpanEntry : Entry
{ {
private readonly TableDataSourceFindUsagesContext _context; private readonly AbstractTableDataSourceFindUsagesContext _context;
private readonly DocumentSpan _documentSpan; private readonly DocumentSpan _documentSpan;
private readonly bool _isDefinitionLocation;
private readonly object _boxedProjectGuid; private readonly object _boxedProjectGuid;
private readonly SourceText _sourceText; protected readonly SourceText _sourceText;
private readonly ClassifiedSpansAndHighlightSpan _classifiedSpans;
public DocumentSpanEntry( protected AbstractDocumentSpanEntry(
TableDataSourceFindUsagesContext context, AbstractTableDataSourceFindUsagesContext context,
RoslynDefinitionBucket definitionBucket, RoslynDefinitionBucket definitionBucket,
DocumentSpan documentSpan, DocumentSpan documentSpan,
bool isDefinitionLocation,
Guid projectGuid, Guid projectGuid,
SourceText sourceText, SourceText sourceText)
ClassifiedSpansAndHighlightSpan classifiedSpans)
: base(definitionBucket) : base(definitionBucket)
{ {
_context = context; _context = context;
_documentSpan = documentSpan; _documentSpan = documentSpan;
_isDefinitionLocation = isDefinitionLocation;
_boxedProjectGuid = projectGuid; _boxedProjectGuid = projectGuid;
_sourceText = sourceText; _sourceText = sourceText;
_classifiedSpans = classifiedSpans;
} }
private StreamingFindUsagesPresenter Presenter => _context.Presenter; protected StreamingFindUsagesPresenter Presenter => _context.Presenter;
private Document Document => _documentSpan.Document; protected Document Document => _documentSpan.Document;
private TextSpan SourceSpan => _documentSpan.SourceSpan; protected TextSpan SourceSpan => _documentSpan.SourceSpan;
protected override object GetValueWorker(string keyName) protected override object GetValueWorker(string keyName)
{ {
...@@ -81,6 +75,54 @@ protected override object GetValueWorker(string keyName) ...@@ -81,6 +75,54 @@ protected override object GetValueWorker(string keyName)
return null; return null;
} }
}
private class DefinitionItemEntry : AbstractDocumentSpanEntry
{
public DefinitionItemEntry(
AbstractTableDataSourceFindUsagesContext context,
RoslynDefinitionBucket definitionBucket,
DocumentSpan documentSpan,
Guid projectGuid,
SourceText sourceText)
: base(context, definitionBucket, documentSpan, projectGuid, sourceText)
{
}
public override bool TryCreateColumnContent(string columnName, out FrameworkElement content)
{
if (columnName == StandardTableColumnDefinitions2.LineText)
{
var inlines = DefinitionBucket.DefinitionItem.DisplayParts.ToInlines(Presenter._typeMap);
var textBlock = inlines.ToTextBlock(Presenter._typeMap, wrap: false);
content = textBlock;
return true;
}
content = null;
return false;
}
}
private class DocumentSpanEntry : AbstractDocumentSpanEntry
{
private readonly bool _isDefinitionLocation;
private readonly ClassifiedSpansAndHighlightSpan _classifiedSpans;
public DocumentSpanEntry(
AbstractTableDataSourceFindUsagesContext context,
RoslynDefinitionBucket definitionBucket,
DocumentSpan documentSpan,
bool isDefinitionLocation,
Guid projectGuid,
SourceText sourceText,
ClassifiedSpansAndHighlightSpan classifiedSpans)
: base(context, definitionBucket, documentSpan, projectGuid, sourceText)
{
_isDefinitionLocation = isDefinitionLocation;
_classifiedSpans = classifiedSpans;
}
public override bool TryCreateColumnContent(string columnName, out FrameworkElement content) public override bool TryCreateColumnContent(string columnName, out FrameworkElement content)
{ {
......
...@@ -17,13 +17,13 @@ internal partial class StreamingFindUsagesPresenter ...@@ -17,13 +17,13 @@ internal partial class StreamingFindUsagesPresenter
private class RoslynDefinitionBucket : DefinitionBucket, ISupportsNavigation private class RoslynDefinitionBucket : DefinitionBucket, ISupportsNavigation
{ {
private readonly StreamingFindUsagesPresenter _presenter; private readonly StreamingFindUsagesPresenter _presenter;
private readonly TableDataSourceFindUsagesContext _context; private readonly AbstractTableDataSourceFindUsagesContext _context;
public readonly DefinitionItem DefinitionItem; public readonly DefinitionItem DefinitionItem;
public RoslynDefinitionBucket( public RoslynDefinitionBucket(
StreamingFindUsagesPresenter presenter, StreamingFindUsagesPresenter presenter,
TableDataSourceFindUsagesContext context, AbstractTableDataSourceFindUsagesContext context,
DefinitionItem definitionItem) DefinitionItem definitionItem)
: base(name: definitionItem.DisplayParts.JoinText() + " " + definitionItem.GetHashCode(), : base(name: definitionItem.DisplayParts.JoinText() + " " + definitionItem.GetHashCode(),
sourceTypeIdentifier: context.SourceTypeIdentifier, sourceTypeIdentifier: context.SourceTypeIdentifier,
......
...@@ -60,7 +60,7 @@ internal partial class StreamingFindUsagesPresenter : ...@@ -60,7 +60,7 @@ internal partial class StreamingFindUsagesPresenter :
_vsFindAllReferencesService = (IFindAllReferencesService)_serviceProvider.GetService(typeof(SVsFindAllReferences)); _vsFindAllReferencesService = (IFindAllReferencesService)_serviceProvider.GetService(typeof(SVsFindAllReferences));
} }
public FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations) public FindUsagesContext StartSearch(string title, bool canShowReferences)
{ {
this.AssertIsForeground(); this.AssertIsForeground();
...@@ -68,8 +68,10 @@ public FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations) ...@@ -68,8 +68,10 @@ public FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations)
var window = _vsFindAllReferencesService.StartSearch(title); var window = _vsFindAllReferencesService.StartSearch(title);
// Make the data source that will feed data into this window. // Make the data source that will feed data into this window.
var dataSource = new TableDataSourceFindUsagesContext(
this, window, alwaysShowDeclarations); var dataSource = canShowReferences
? (AbstractTableDataSourceFindUsagesContext)new WithReferencesFindUsagesContext(this, window)
: new WithoutReferencesFindUsagesContext(this, window);
// And return the data source so that the FindRefs engine can report results // And return the data source so that the FindRefs engine can report results
// which the data source can then create the appropriate presentation items for // which the data source can then create the appropriate presentation items for
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册