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

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

上级 2e1cb224
......@@ -126,7 +126,7 @@ private IStreamingFindUsagesPresenter GetStreamingPresenter()
// 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.
var context = presenter.StartSearch(
EditorFeaturesResources.Find_References, alwaysShowDeclarations: false);
EditorFeaturesResources.Find_References, canShowReferences: true);
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
......
......@@ -3,15 +3,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.CodeAnalysis.Editor.FindReferences;
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.GoToDefinition
......@@ -75,8 +72,7 @@ internal static class GoToDefinitionHelpers
FindUsagesHelpers.GetDisplayName(symbol));
return presenter.TryNavigateToOrPresentItemsAsync(
title, definitions.ToImmutableAndFree(),
alwaysShowDeclarations: true).WaitAndGetResult(cancellationToken);
title, definitions.ToImmutableAndFree()).WaitAndGetResult(cancellationToken);
}
private static IStreamingFindUsagesPresenter GetFindUsagesPresenter(
......
......@@ -136,8 +136,7 @@ public void ExecuteCommand(GoToImplementationCommandArgs args, Action nextHandle
var definitionItems = goToImplContext.GetDefinitions();
streamingPresenter.TryNavigateToOrPresentItemsAsync(
goToImplContext.SearchTitle, definitionItems,
alwaysShowDeclarations: true).Wait(cancellationToken);
goToImplContext.SearchTitle, definitionItems).Wait(cancellationToken);
}
private IStreamingFindUsagesPresenter GetStreamingPresenter()
......
......@@ -21,7 +21,7 @@ internal interface IStreamingFindUsagesPresenter
/// search completes <see cref="FindUsagesContext.OnCompletedAsync"/> should be called.
/// etc. etc.
/// </summary>
FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations);
FindUsagesContext StartSearch(string title, bool canShowReferences);
}
internal static class IStreamingFindUsagesPresenterExtensions
......@@ -31,8 +31,8 @@ internal static class IStreamingFindUsagesPresenterExtensions
/// items to the user.
/// </summary>
public static async Task<bool> TryNavigateToOrPresentItemsAsync(
this IStreamingFindUsagesPresenter presenter, string title,
ImmutableArray<DefinitionItem> items, bool alwaysShowDeclarations)
this IStreamingFindUsagesPresenter presenter,
string title, ImmutableArray<DefinitionItem> items)
{
// Ignore any definitions that we can't navigate to.
var definitions = items.WhereAsArray(d => d.CanNavigateTo());
......@@ -66,7 +66,7 @@ internal static class IStreamingFindUsagesPresenterExtensions
// 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.
var context = presenter.StartSearch(title, alwaysShowDeclarations);
var context = presenter.StartSearch(title, canShowReferences: false);
foreach (var definition in nonExternalItems)
{
await context.OnDefinitionFoundAsync(definition).ConfigureAwait(false);
......
......@@ -27,60 +27,102 @@ namespace Microsoft.VisualStudio.LanguageServices.FindUsages
{
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 bool _isDefinitionLocation;
private readonly object _boxedProjectGuid;
private readonly SourceText _sourceText;
private readonly ClassifiedSpansAndHighlightSpan _classifiedSpans;
protected readonly SourceText _sourceText;
public DocumentSpanEntry(
TableDataSourceFindUsagesContext context,
protected AbstractDocumentSpanEntry(
AbstractTableDataSourceFindUsagesContext context,
RoslynDefinitionBucket definitionBucket,
DocumentSpan documentSpan,
bool isDefinitionLocation,
Guid projectGuid,
SourceText sourceText,
ClassifiedSpansAndHighlightSpan classifiedSpans)
SourceText sourceText)
: base(definitionBucket)
{
_context = context;
_documentSpan = documentSpan;
_isDefinitionLocation = isDefinitionLocation;
_boxedProjectGuid = projectGuid;
_sourceText = sourceText;
_classifiedSpans = classifiedSpans;
}
private StreamingFindUsagesPresenter Presenter => _context.Presenter;
protected StreamingFindUsagesPresenter Presenter => _context.Presenter;
private Document Document => _documentSpan.Document;
private TextSpan SourceSpan => _documentSpan.SourceSpan;
protected Document Document => _documentSpan.Document;
protected TextSpan SourceSpan => _documentSpan.SourceSpan;
protected override object GetValueWorker(string keyName)
{
switch (keyName)
{
case StandardTableKeyNames.DocumentName:
return Document.FilePath;
case StandardTableKeyNames.Line:
return _sourceText.Lines.GetLinePosition(SourceSpan.Start).Line;
case StandardTableKeyNames.Column:
return _sourceText.Lines.GetLinePosition(SourceSpan.Start).Character;
case StandardTableKeyNames.ProjectName:
return Document.Project.Name;
case StandardTableKeyNames.ProjectGuid:
return _boxedProjectGuid;
case StandardTableKeyNames.Text:
return _sourceText.Lines.GetLineFromPosition(SourceSpan.Start).ToString().Trim();
case StandardTableKeyNames.DocumentName:
return Document.FilePath;
case StandardTableKeyNames.Line:
return _sourceText.Lines.GetLinePosition(SourceSpan.Start).Line;
case StandardTableKeyNames.Column:
return _sourceText.Lines.GetLinePosition(SourceSpan.Start).Character;
case StandardTableKeyNames.ProjectName:
return Document.Project.Name;
case StandardTableKeyNames.ProjectGuid:
return _boxedProjectGuid;
case StandardTableKeyNames.Text:
return _sourceText.Lines.GetLineFromPosition(SourceSpan.Start).ToString().Trim();
}
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)
{
......
......@@ -17,13 +17,13 @@ internal partial class StreamingFindUsagesPresenter
private class RoslynDefinitionBucket : DefinitionBucket, ISupportsNavigation
{
private readonly StreamingFindUsagesPresenter _presenter;
private readonly TableDataSourceFindUsagesContext _context;
private readonly AbstractTableDataSourceFindUsagesContext _context;
public readonly DefinitionItem DefinitionItem;
public RoslynDefinitionBucket(
StreamingFindUsagesPresenter presenter,
TableDataSourceFindUsagesContext context,
AbstractTableDataSourceFindUsagesContext context,
DefinitionItem definitionItem)
: base(name: definitionItem.DisplayParts.JoinText() + " " + definitionItem.GetHashCode(),
sourceTypeIdentifier: context.SourceTypeIdentifier,
......
......@@ -60,7 +60,7 @@ internal partial class StreamingFindUsagesPresenter :
_vsFindAllReferencesService = (IFindAllReferencesService)_serviceProvider.GetService(typeof(SVsFindAllReferences));
}
public FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations)
public FindUsagesContext StartSearch(string title, bool canShowReferences)
{
this.AssertIsForeground();
......@@ -68,8 +68,10 @@ public FindUsagesContext StartSearch(string title, bool alwaysShowDeclarations)
var window = _vsFindAllReferencesService.StartSearch(title);
// 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
// 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.
先完成此消息的编辑!
想要评论请 注册