提交 96f0c6d8 编写于 作者: C Cyrus Najmabadi

Add a new FindReferencesOptions types and thread it through our platform.

上级 6da27094
......@@ -49,6 +49,7 @@ private class FindReferencesProgressAdapter : ForegroundThreadAffinitizedObject,
{
private readonly Solution _solution;
private readonly IFindUsagesContext _context;
private readonly FindReferencesSearchOptions _options;
/// <summary>
/// We will hear about definition symbols many times while performing FAR. We'll
......@@ -65,10 +66,12 @@ private class FindReferencesProgressAdapter : ForegroundThreadAffinitizedObject,
private readonly SemaphoreSlim _gate = new SemaphoreSlim(initialCount: 1);
public FindReferencesProgressAdapter(Solution solution, IFindUsagesContext context)
public FindReferencesProgressAdapter(
Solution solution, IFindUsagesContext context, FindReferencesSearchOptions options)
{
_solution = solution;
_context = context;
_options = options;
}
// Do nothing functions. The streaming far service doesn't care about
......@@ -93,7 +96,8 @@ private async Task<DefinitionItem> GetDefinitionItemAsync(SymbolAndProjectId def
if (!_definitionToItem.TryGetValue(definition.Symbol, out var definitionItem))
{
definitionItem = await definition.Symbol.ToClassifiedDefinitionItemAsync(
_solution.GetProject(definition.ProjectId), includeHiddenLocations: false, cancellationToken: _context.CancellationToken).ConfigureAwait(false);
_solution.GetProject(definition.ProjectId), includeHiddenLocations: false,
FindReferencesSearchOptions.Default, _context.CancellationToken).ConfigureAwait(false);
_definitionToItem[definition.Symbol] = definitionItem;
}
......
......@@ -44,7 +44,8 @@ internal abstract partial class AbstractFindUsagesService : IFindUsagesService
foreach (var implementation in tuple.Value.implementations)
{
var definitionItem = await implementation.ToClassifiedDefinitionItemAsync(
project, includeHiddenLocations: false, cancellationToken: cancellationToken).ConfigureAwait(false);
project, includeHiddenLocations: false,
FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false);
await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false);
}
}
......@@ -132,7 +133,9 @@ internal abstract partial class AbstractFindUsagesService : IFindUsagesService
{
await context.SetSearchTitleAsync(string.Format(EditorFeaturesResources._0_references,
FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false);
var progressAdapter = new FindReferencesProgressAdapter(project.Solution, context);
var options = FindReferencesSearchOptions.Default;
var progressAdapter = new FindReferencesProgressAdapter(project.Solution, context, options);
// Now call into the underlying FAR engine to find reference. The FAR
// engine will push results into the 'progress' instance passed into it.
......@@ -143,6 +146,7 @@ internal abstract partial class AbstractFindUsagesService : IFindUsagesService
project.Solution,
progressAdapter,
documents: null,
options: options,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
......
......@@ -48,18 +48,21 @@ internal static class DefinitionItemExtensions
// to actually do async work. This is because the only asynchrony is when we are trying
// to compute the classified spans for the locations of the definition. So it's totally
// fine to pass in CancellationToken.None and block on the result.
return ToDefinitionItemAsync(definition, project, includeHiddenLocations,
includeClassifiedSpans: false, cancellationToken: CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
return ToDefinitionItemAsync(
definition, project, includeHiddenLocations, includeClassifiedSpans: false,
options: FindReferencesSearchOptions.Default, cancellationToken: CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
}
public static Task<DefinitionItem> ToClassifiedDefinitionItemAsync(
this ISymbol definition,
Project project,
bool includeHiddenLocations,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return ToDefinitionItemAsync(definition, project,
includeHiddenLocations, includeClassifiedSpans: true, cancellationToken: cancellationToken);
includeHiddenLocations, includeClassifiedSpans: true,
options, cancellationToken);
}
private static async Task<DefinitionItem> ToDefinitionItemAsync(
......@@ -67,6 +70,7 @@ internal static class DefinitionItemExtensions
Project project,
bool includeHiddenLocations,
bool includeClassifiedSpans,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// Ensure we're working with the original definition for the symbol. I.e. When we're
......@@ -82,7 +86,7 @@ internal static class DefinitionItemExtensions
var tags = GlyphTags.GetTags(definition.GetGlyph());
var displayIfNoReferences = definition.ShouldShowWithNoReferenceLocations(
showMetadataSymbolsWithoutReferences: false);
options, showMetadataSymbolsWithoutReferences: false);
var sourceLocations = ArrayBuilder<DocumentSpan>.GetInstance();
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Editor.FindUsages
......@@ -160,14 +161,19 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
End Function
End Class
Private Async Function TestAPI(definition As XElement, Optional searchSingleFileOnly As Boolean = False, Optional uiVisibleOnly As Boolean = False) As Task
Await TestAPI(definition, searchSingleFileOnly, uiVisibleOnly, outOfProcess:=False)
Await TestAPI(definition, searchSingleFileOnly, uiVisibleOnly, outOfProcess:=True)
Private Async Function TestAPI(
definition As XElement,
Optional searchSingleFileOnly As Boolean = False,
Optional uiVisibleOnly As Boolean = False,
Optional options As FindReferencesSearchOptions = Nothing) As Task
Await TestAPI(definition, searchSingleFileOnly, uiVisibleOnly, options, outOfProcess:=False)
Await TestAPI(definition, searchSingleFileOnly, uiVisibleOnly, options, outOfProcess:=True)
End Function
Private Async Function TestAPI(definition As XElement,
searchSingleFileOnly As Boolean,
uiVisibleOnly As Boolean,
options As FindReferencesSearchOptions,
outOfProcess As Boolean) As Task
Using workspace = TestWorkspace.Create(definition)
workspace.Options = workspace.Options.WithChangedOption(RemoteHostOptions.RemoteHostTest, outOfProcess).
......@@ -188,11 +194,15 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
Dim scope = If(searchSingleFileOnly, ImmutableHashSet.Create(Of Document)(document), Nothing)
result = result.Concat(Await SymbolFinder.FindReferencesAsync(symbol, document.Project.Solution, progress:=Nothing, documents:=scope))
Dim project = document.Project
result = result.Concat(
Await SymbolFinder.FindReferencesAsync(
symbol, project.Solution,
progress:=Nothing, documents:=scope, options, CancellationToken.None))
End If
Dim actualDefinitions =
result.FilterToItemsToShow().
result.FilterToItemsToShow(options).
Where(Function(s) Not IsImplicitNamespace(s)).
SelectMany(Function(r) r.Definition.GetDefinitionLocationsToShow()).
Where(Function(loc) IsInSource(workspace, loc, uiVisibleOnly)).
......@@ -214,7 +224,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
Next
Dim actualReferences =
result.FilterToItemsToShow().
result.FilterToItemsToShow(options).
SelectMany(Function(r) r.Locations.Select(Function(loc) loc.Location)).
Where(Function(loc) IsInSource(workspace, loc, uiVisibleOnly)).
Distinct().
......
......@@ -468,6 +468,7 @@ private static async Task<(ITypeSymbol, RefKind)> GetArgumentTypeAndRefKindAsync
solution: invocationDocument.Project.Solution,
documents: null,
progress: progress,
options: FindReferencesSearchOptions.Default,
cancellationToken: cancellationToken).ConfigureAwait(false);
var referencedSymbols = progress.GetReferencedSymbols();
return referencedSymbols.Select(referencedSymbol => referencedSymbol.Definition)
......
......@@ -187,6 +187,7 @@ internal ChangeSignatureResult ChangeSignatureWithContext(ChangeSignatureAnalyze
documents,
ReferenceFinders.DefaultReferenceFinders.Add(DelegateInvokeMethodReferenceFinder.DelegateInvokeMethod),
streamingProgress,
FindReferencesSearchOptions.Default,
cancellationToken);
await engine.FindReferencesAsync(symbolAndProjectId).ConfigureAwait(false);
......
......@@ -35,6 +35,7 @@ protected override bool CanFind(IMethodSymbol symbol)
SymbolAndProjectId<IMethodSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var result = ImmutableArray.CreateBuilder<SymbolAndProjectId>();
......@@ -64,6 +65,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return Task.FromResult(project.Documents.ToImmutableArray());
......@@ -73,6 +75,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol methodSymbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// FAR on the Delegate type and use those results to find Invoke calls
......
......@@ -110,13 +110,15 @@ private static async Task<ISymbol> GetSymbolToSearchAsync(Document document, int
{
var progress = new StreamingProgressCollector(
StreamingFindReferencesProgress.Instance);
var options = FindReferencesSearchOptions.Default;
await SymbolFinder.FindReferencesAsync(
symbolAndProjectId, document.Project.Solution, progress,
documentsToSearch, cancellationToken).ConfigureAwait(false);
documentsToSearch, options, cancellationToken).ConfigureAwait(false);
return await FilterAndCreateSpansAsync(
progress.GetReferencedSymbols(), document, documentsToSearch,
symbol, cancellationToken).ConfigureAwait(false);
symbol, options, cancellationToken).ConfigureAwait(false);
}
return ImmutableArray<DocumentHighlights>.Empty;
......@@ -149,11 +151,11 @@ private static bool ShouldConsiderSymbol(ISymbol symbol)
private async Task<ImmutableArray<DocumentHighlights>> FilterAndCreateSpansAsync(
IEnumerable<ReferencedSymbol> references, Document startingDocument,
IImmutableSet<Document> documentsToSearch, ISymbol symbol,
CancellationToken cancellationToken)
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
var solution = startingDocument.Project.Solution;
references = references.FilterToItemsToShow();
references = references.FilterToItemsToShow(options);
references = references.FilterNonMatchingMethodNames(solution, symbol);
references = references.FilterToAliasMatches(symbol as IAliasSymbol);
......
......@@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindSymbols.Finders;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Roslyn.Utilities;
......@@ -17,6 +18,16 @@ namespace Microsoft.CodeAnalysis.FindSymbols
{
using ProjectToDocumentMap = Dictionary<Project, MultiDictionary<Document, (SymbolAndProjectId symbolAndProjectId, IReferenceFinder finder)>>;
internal class FindReferencesSearchOptions
{
public static readonly FindReferencesSearchOptions Default =
new FindReferencesSearchOptions();
public FindReferencesSearchOptions()
{
}
}
internal partial class FindReferencesSearchEngine
{
private readonly Solution _solution;
......@@ -26,6 +37,7 @@ internal partial class FindReferencesSearchEngine
private readonly IStreamingFindReferencesProgress _progress;
private readonly CancellationToken _cancellationToken;
private readonly ProjectDependencyGraph _dependencyGraph;
private readonly FindReferencesSearchOptions _options;
/// <summary>
/// Mapping from a document to the list of reference locations found in it. Kept around so
......@@ -40,6 +52,7 @@ internal partial class FindReferencesSearchEngine
IImmutableSet<Document> documents,
ImmutableArray<IReferenceFinder> finders,
IStreamingFindReferencesProgress progress,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
_documents = documents;
......@@ -48,6 +61,7 @@ internal partial class FindReferencesSearchEngine
_progress = progress;
_cancellationToken = cancellationToken;
_dependencyGraph = solution.GetProjectDependencyGraph();
_options = options;
_progressTracker = new StreamingProgressTracker(progress.ReportProgressAsync);
}
......
......@@ -57,7 +57,8 @@ internal partial class FindReferencesSearchEngine
{
try
{
var references = await finder.FindReferencesInDocumentAsync(symbolAndProjectId, document, semanticModel, _cancellationToken).ConfigureAwait(false);
var references = await finder.FindReferencesInDocumentAsync(
symbolAndProjectId, document, semanticModel, _options, _cancellationToken).ConfigureAwait(false);
foreach (var location in references)
{
await HandleLocationAsync(symbolAndProjectId, location).ConfigureAwait(false);
......
......@@ -38,7 +38,8 @@ private async Task<ProjectToDocumentMap> CreateProjectToDocumentMapAsync(Project
var symbol = symbolAndProjectId.Symbol;
var finder = symbolAndFinder.finder;
var documents = await finder.DetermineDocumentsToSearchAsync(symbol, project, _documents, _cancellationToken).ConfigureAwait(false);
var documents = await finder.DetermineDocumentsToSearchAsync(
symbol, project, _documents, _options, _cancellationToken).ConfigureAwait(false);
foreach (var document in documents.Distinct().WhereNotNull())
{
if (_documents == null || _documents.Contains(document))
......@@ -125,7 +126,7 @@ private async Task<ProjectMap> CreateProjectMapAsync(ConcurrentSet<SymbolAndProj
_cancellationToken.ThrowIfCancellationRequested();
List<Task> finderTasks = new List<Task>();
var finderTasks = new List<Task>();
foreach (var f in _finders)
{
finderTasks.Add(Task.Run(async () =>
......@@ -133,7 +134,7 @@ private async Task<ProjectMap> CreateProjectMapAsync(ConcurrentSet<SymbolAndProj
var symbolTasks = new List<Task>();
var symbols = await f.DetermineCascadedSymbolsAsync(
searchSymbolAndProjectId, _solution, projects, _cancellationToken).ConfigureAwait(false);
searchSymbolAndProjectId, _solution, projects, _options, _cancellationToken).ConfigureAwait(false);
AddSymbolTasks(result, symbols, symbolTasks);
// Defer to the language to see if it wants to cascade here in some special way.
......
......@@ -24,6 +24,7 @@ protected sealed override bool CanFind(TSymbol symbol)
TSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var location = symbol.Locations.FirstOrDefault();
......@@ -50,6 +51,7 @@ protected sealed override bool CanFind(TSymbol symbol)
TSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var container = GetContainer(symbol);
......
// 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 System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
......@@ -21,6 +19,7 @@ protected AbstractMethodOrPropertyOrEventSymbolReferenceFinder()
SymbolAndProjectId<TSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// Static methods can't cascade.
......
......@@ -17,10 +17,17 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal abstract partial class AbstractReferenceFinder : IReferenceFinder
{
public abstract Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet<Project> projects, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(
SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet<Project> projects,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<Project>> DetermineProjectsToSearchAsync(ISymbol symbol, Solution solution, IImmutableSet<Project> projects, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(ISymbol symbol, Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(
ISymbol symbol, Project project, IImmutableSet<Document> documents, FindReferencesSearchOptions options, CancellationToken cancellationToken);
public abstract Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, FindReferencesSearchOptions options, CancellationToken cancellationToken);
protected static bool TryGetNameWithoutAttributeSuffix(
string name,
......@@ -506,8 +513,14 @@ internal abstract partial class AbstractReferenceFinder<TSymbol> : AbstractRefer
where TSymbol : ISymbol
{
protected abstract bool CanFind(TSymbol symbol);
protected abstract Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(TSymbol symbol, Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(TSymbol symbol, Document document, SemanticModel semanticModel, CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(
TSymbol symbol, Project project, IImmutableSet<Document> documents,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
TSymbol symbol, Document document, SemanticModel semanticModel,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
public override Task<ImmutableArray<Project>> DetermineProjectsToSearchAsync(ISymbol symbol, Solution solution, IImmutableSet<Project> projects, CancellationToken cancellationToken)
{
......@@ -516,31 +529,35 @@ public override Task<ImmutableArray<Project>> DetermineProjectsToSearchAsync(ISy
: SpecializedTasks.EmptyImmutableArray<Project>();
}
public override Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(ISymbol symbol, Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken)
public override Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(
ISymbol symbol, Project project, IImmutableSet<Document> documents,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return symbol is TSymbol && CanFind((TSymbol)symbol)
? DetermineDocumentsToSearchAsync((TSymbol)symbol, project, documents, cancellationToken)
? DetermineDocumentsToSearchAsync((TSymbol)symbol, project, documents, options, cancellationToken)
: SpecializedTasks.EmptyImmutableArray<Document>();
}
public override Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken)
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
var symbol = symbolAndProjectId.Symbol;
return symbol is TSymbol && CanFind((TSymbol)symbol)
? FindReferencesInDocumentAsync((TSymbol)symbol, document, semanticModel, cancellationToken)
? FindReferencesInDocumentAsync((TSymbol)symbol, document, semanticModel, options, cancellationToken)
: SpecializedTasks.EmptyImmutableArray<ReferenceLocation>();
}
public override Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects, CancellationToken cancellationToken)
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
var symbol = symbolAndProjectId.Symbol;
if (symbol is TSymbol && CanFind((TSymbol)symbol))
{
return DetermineCascadedSymbolsAsync(
symbolAndProjectId.WithSymbol((TSymbol)symbol),
solution, projects, cancellationToken);
solution, projects, options, cancellationToken);
}
return SpecializedTasks.EmptyImmutableArray<SymbolAndProjectId>();
......@@ -554,7 +571,8 @@ public override Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(I
}
protected virtual Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(
SymbolAndProjectId<TSymbol> symbolAndProject, Solution solution, IImmutableSet<Project> projects, CancellationToken cancellationToken)
SymbolAndProjectId<TSymbol> symbolAndProject, Solution solution, IImmutableSet<Project> projects,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<SymbolAndProjectId>();
}
......
// 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.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
......@@ -23,6 +21,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindDocumentsAsync(project, documents, async (d, c) =>
......@@ -54,6 +53,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol methodSymbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var syntaxFactsService = document.GetLanguageService<ISyntaxFactsService>();
......
......@@ -29,6 +29,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var typeName = symbol.ContainingType.Name;
......@@ -58,6 +59,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol methodSymbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindAllReferencesInDocumentAsync(methodSymbol, document, semanticModel, cancellationToken);
......
// 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 System.Threading;
using System.Threading.Tasks;
......@@ -19,6 +18,7 @@ protected override bool CanFind(IMethodSymbol symbol)
SymbolAndProjectId<IMethodSymbol> symbol,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<SymbolAndProjectId>();
......@@ -28,6 +28,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<Document>();
......@@ -37,6 +38,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol methodSymbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<ReferenceLocation>();
......
......@@ -21,9 +21,11 @@ protected override bool CanFind(IEventSymbol symbol)
SymbolAndProjectId<IEventSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var baseSymbols = await base.DetermineCascadedSymbolsAsync(symbolAndProjectId, solution, projects, cancellationToken).ConfigureAwait(false);
var baseSymbols = await base.DetermineCascadedSymbolsAsync(
symbolAndProjectId, solution, projects, options, cancellationToken).ConfigureAwait(false);
var symbol = symbolAndProjectId.Symbol;
var backingFields = symbol.ContainingType.GetMembers()
......@@ -45,6 +47,7 @@ protected override bool CanFind(IEventSymbol symbol)
IEventSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindDocumentsAsync(project, documents, cancellationToken, symbol.Name);
......@@ -54,6 +57,7 @@ protected override bool CanFind(IEventSymbol symbol)
IEventSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindReferencesInDocumentUsingSymbolNameAsync(symbol, document, semanticModel, cancellationToken);
......
......@@ -20,6 +20,7 @@ protected override bool CanFind(IMethodSymbol symbol)
SymbolAndProjectId<IMethodSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// An explicit interface method will cascade to all the methods that it implements.
......@@ -32,6 +33,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// An explicit method can't be referenced anywhere.
......@@ -42,6 +44,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// An explicit method can't be referenced anywhere.
......
// 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 System.Threading;
using System.Threading.Tasks;
......@@ -19,6 +18,7 @@ protected override bool CanFind(IFieldSymbol symbol)
SymbolAndProjectId<IFieldSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var symbol = symbolAndProjectId.Symbol;
......@@ -37,6 +37,7 @@ protected override bool CanFind(IFieldSymbol symbol)
IFieldSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindDocumentsAsync(project, documents, cancellationToken, symbol.Name);
......@@ -46,6 +47,7 @@ protected override bool CanFind(IFieldSymbol symbol)
IFieldSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindReferencesInDocumentUsingSymbolNameAsync(symbol, document, semanticModel, cancellationToken);
......
......@@ -24,7 +24,8 @@ internal interface IReferenceFinder
/// Implementations of this method must be thread-safe.
/// </summary>
Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(
SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet<Project> projects, CancellationToken cancellationToken);
SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet<Project> projects,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
/// <summary>
/// Called by the find references search engine to determine which projects should be
......@@ -55,7 +56,8 @@ internal interface IReferenceFinder
/// Implementations of this method must be thread-safe.
/// </summary>
Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(
ISymbol symbol, Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken);
ISymbol symbol, Project project, IImmutableSet<Document> documents,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
/// <summary>
/// Called by the find references search engine to determine the set of reference locations
......@@ -65,6 +67,7 @@ internal interface IReferenceFinder
/// Implementations of this method must be thread-safe.
/// </summary>
Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken);
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel,
FindReferencesSearchOptions options, CancellationToken cancellationToken);
}
}
......@@ -12,7 +12,8 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders
internal class LinkedFileReferenceFinder : IReferenceFinder
{
public async Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default)
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
var linkedSymbols = new HashSet<SymbolAndProjectId>();
......@@ -62,7 +63,9 @@ internal class LinkedFileReferenceFinder : IReferenceFinder
return linkedSymbols.ToImmutableArray();
}
public Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(ISymbol symbol, Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken = default)
public Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(
ISymbol symbol, Project project, IImmutableSet<Document> documents,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<Document>();
}
......@@ -73,7 +76,8 @@ public Task<ImmutableArray<Project>> DetermineProjectsToSearchAsync(ISymbol symb
}
public Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken = default)
SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<ReferenceLocation>();
}
......
......@@ -19,6 +19,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol)
SymbolAndProjectId<ITypeParameterSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var symbol = symbolAndProjectId.Symbol;
......@@ -47,6 +48,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol)
ITypeParameterSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// Type parameters are only found in documents that have both their name, and the name
......@@ -76,6 +78,7 @@ private static string GetMemberNameWithoutInterfaceName(string fullName)
ITypeParameterSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// TODO(cyrusn): Method type parameters are like locals. They are only in scope in
......
......@@ -23,6 +23,7 @@ protected override bool CanFind(INamedTypeSymbol symbol)
SymbolAndProjectId<INamedTypeSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var result = ArrayBuilder<SymbolAndProjectId>.GetInstance();
......@@ -55,6 +56,7 @@ protected override bool CanFind(INamedTypeSymbol symbol)
INamedTypeSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var documentsWithName = await FindDocumentsAsync(project, documents, cancellationToken, symbol.Name).ConfigureAwait(false);
......@@ -81,6 +83,7 @@ protected override bool CanFind(INamedTypeSymbol symbol)
INamedTypeSymbol namedType,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var namedTypereferences = await FindReferencesInDocumentWorker(
......
......@@ -24,6 +24,7 @@ protected override bool CanFind(INamespaceSymbol symbol)
INamespaceSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindDocumentsAsync(project, documents, cancellationToken, GetNamespaceIdentifierName(symbol, project));
......@@ -40,6 +41,7 @@ private static string GetNamespaceIdentifierName(INamespaceSymbol symbol, Projec
INamespaceSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var identifierName = GetNamespaceIdentifierName(symbol, document.Project);
......
......@@ -20,6 +20,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var op = symbol.GetPredefinedOperator();
......@@ -30,6 +31,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
......
......@@ -24,6 +24,7 @@ protected override bool CanFind(IMethodSymbol symbol)
SymbolAndProjectId<IMethodSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// If it's a delegate method, then cascade to the type as well. These guys are
......@@ -37,7 +38,8 @@ protected override bool CanFind(IMethodSymbol symbol)
else
{
var otherPartsOfPartial = GetOtherPartsOfPartial(symbolAndProjectId);
var baseCascadedSymbols = await base.DetermineCascadedSymbolsAsync(symbolAndProjectId, solution, projects, cancellationToken).ConfigureAwait(false);
var baseCascadedSymbols = await base.DetermineCascadedSymbolsAsync(
symbolAndProjectId, solution, projects, options, cancellationToken).ConfigureAwait(false);
if (otherPartsOfPartial == null && baseCascadedSymbols == null)
{
......@@ -71,6 +73,7 @@ protected override bool CanFind(IMethodSymbol symbol)
IMethodSymbol methodSymbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// TODO(cyrusn): Handle searching for IDisposable.Dispose (or an implementation
......@@ -114,6 +117,7 @@ private bool IsDeconstructMethod(IMethodSymbol methodSymbol)
IMethodSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
......
......@@ -24,6 +24,7 @@ protected override bool CanFind(IParameterSymbol symbol)
IParameterSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// TODO(cyrusn): We can be smarter with parameters. They will either be found
......@@ -38,6 +39,7 @@ protected override bool CanFind(IParameterSymbol symbol)
IParameterSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var symbolsMatch = GetParameterSymbolsMatchFunction(
......@@ -98,6 +100,7 @@ protected override bool CanFind(IParameterSymbol symbol)
SymbolAndProjectId<IParameterSymbol> parameterAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var parameter = parameterAndProjectId.Symbol;
......
......@@ -20,10 +20,11 @@ protected override bool CanFind(IMethodSymbol symbol)
SymbolAndProjectId<IMethodSymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var result = await base.DetermineCascadedSymbolsAsync(
symbolAndProjectId, solution, projects, cancellationToken).ConfigureAwait(false);
symbolAndProjectId, solution, projects, options, cancellationToken).ConfigureAwait(false);
var symbol = symbolAndProjectId.Symbol;
if (symbol.AssociatedSymbol != null)
......@@ -34,12 +35,16 @@ protected override bool CanFind(IMethodSymbol symbol)
return result;
}
protected override Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(IMethodSymbol symbol, Project project, IImmutableSet<Document> documents, CancellationToken cancellationToken)
protected override Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsync(
IMethodSymbol symbol, Project project, IImmutableSet<Document> documents,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return FindDocumentsAsync(project, documents, cancellationToken, symbol.Name);
}
protected override Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(IMethodSymbol symbol, Document document, SemanticModel semanticModel, CancellationToken cancellationToken)
protected override Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
IMethodSymbol symbol, Document document, SemanticModel semanticModel,
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return FindReferencesInDocumentUsingSymbolNameAsync(symbol, document, semanticModel, cancellationToken);
}
......
// 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.Linq;
using System.Threading;
......@@ -23,9 +24,11 @@ protected override bool CanFind(IPropertySymbol symbol)
SymbolAndProjectId<IPropertySymbol> symbolAndProjectId,
Solution solution,
IImmutableSet<Project> projects,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var baseSymbols = await base.DetermineCascadedSymbolsAsync(symbolAndProjectId, solution, projects, cancellationToken).ConfigureAwait(false);
var baseSymbols = await base.DetermineCascadedSymbolsAsync(
symbolAndProjectId, solution, projects, options, cancellationToken).ConfigureAwait(false);
var symbol = symbolAndProjectId.Symbol;
var backingFields = symbol.ContainingType.GetMembers()
......@@ -53,6 +56,7 @@ protected override bool CanFind(IPropertySymbol symbol)
IPropertySymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var ordinaryDocuments = await FindDocumentsAsync(project, documents, cancellationToken, symbol.Name).ConfigureAwait(false);
......@@ -83,9 +87,11 @@ private static bool IsForEachProperty(IPropertySymbol symbol)
IPropertySymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var nameReferences = await FindReferencesInDocumentUsingSymbolNameAsync(symbol, document, semanticModel, cancellationToken).ConfigureAwait(false);
var nameReferences = await FindReferencesInDocumentUsingSymbolNameAsync(
symbol, document, semanticModel, cancellationToken).ConfigureAwait(false);
var forEachReferences = IsForEachProperty(symbol)
? await FindReferencesInForEachStatementsAsync(symbol, document, semanticModel, cancellationToken).ConfigureAwait(false)
......
......@@ -18,6 +18,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol)
ITypeParameterSymbol symbol,
Project project,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// Type parameters are only found in documents that have both their name, and the
......@@ -34,6 +35,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol)
ITypeParameterSymbol symbol,
Document document,
SemanticModel semanticModel,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return FindReferencesInDocumentUsingSymbolNameAsync(symbol, document, semanticModel, cancellationToken);
......
......@@ -10,7 +10,10 @@ namespace Microsoft.CodeAnalysis.FindSymbols
{
internal interface IRemoteSymbolFinder
{
Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndProjectIdArg, DocumentId[] documentArgs, CancellationToken cancellationToken);
Task FindReferencesAsync(
SerializableSymbolAndProjectId symbolAndProjectIdArg, DocumentId[] documentArgs,
SerializableFindReferencesSearchOptions options, CancellationToken cancellationToken);
Task FindLiteralReferencesAsync(object value, TypeCode typeCode, CancellationToken cancellationToken);
Task<IList<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
......
......@@ -22,12 +22,14 @@ public static partial class SymbolFinder
Solution solution,
IStreamingFindReferencesProgress progress,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.FindReference, cancellationToken))
{
var handled = await TryFindReferencesInServiceProcessAsync(
symbolAndProjectId, solution, progress, documents, cancellationToken).ConfigureAwait(false);
symbolAndProjectId, solution, progress,
documents, options, cancellationToken).ConfigureAwait(false);
if (handled)
{
return;
......@@ -35,19 +37,20 @@ public static partial class SymbolFinder
// Couldn't effectively search using the OOP process. Just perform the search in-proc.
await FindReferencesInCurrentProcessAsync(
symbolAndProjectId, solution, progress, documents, cancellationToken).ConfigureAwait(false);
symbolAndProjectId, solution, progress,
documents, options, cancellationToken).ConfigureAwait(false);
}
}
internal static Task FindReferencesInCurrentProcessAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution,
IStreamingFindReferencesProgress progress, IImmutableSet<Document> documents,
CancellationToken cancellationToken)
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
var finders = ReferenceFinders.DefaultReferenceFinders;
progress = progress ?? StreamingFindReferencesProgress.Instance;
var engine = new FindReferencesSearchEngine(
solution, documents, finders, progress, cancellationToken);
solution, documents, finders, progress, options, cancellationToken);
return engine.FindReferencesAsync(symbolAndProjectId);
}
......@@ -56,6 +59,7 @@ public static partial class SymbolFinder
Solution solution,
IStreamingFindReferencesProgress progress,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
// If ProjectId is null then this is a call through our old public API. We don't have
......@@ -71,7 +75,12 @@ public static partial class SymbolFinder
RemoteFeatureOptions.SymbolFinderEnabled,
serverCallback,
nameof(IRemoteSymbolFinder.FindReferencesAsync),
new object[] { SerializableSymbolAndProjectId.Dehydrate(symbolAndProjectId), documents?.Select(d => d.Id).ToArray() },
new object[]
{
SerializableSymbolAndProjectId.Dehydrate(symbolAndProjectId),
documents?.Select(d => d.Id).ToArray(),
SerializableFindReferencesSearchOptions.Dehydrate(options),
},
cancellationToken).ConfigureAwait(false);
}
......
......@@ -2,12 +2,8 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindSymbols.Finders;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Remote;
namespace Microsoft.CodeAnalysis.FindSymbols
{
......@@ -32,8 +28,9 @@ public static partial class SymbolFinder
var progressCollector = new StreamingProgressCollector(StreamingFindReferencesProgress.Instance);
await FindReferencesAsync(
SymbolAndProjectId.Create(symbol, projectId: null),
solution, progress: progressCollector,
documents: null, cancellationToken: cancellationToken).ConfigureAwait(false);
solution, progress: progressCollector, documents: null,
options: FindReferencesSearchOptions.Default,
cancellationToken: cancellationToken).ConfigureAwait(false);
return progressCollector.GetReferencedSymbols();
}
......@@ -62,19 +59,33 @@ public static partial class SymbolFinder
/// information as the search is undertaken.</param>
/// <param name="documents">An optional set of documents to be searched. If documents is null, then that means "all documents".</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
public static async Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
public static Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
IFindReferencesProgress progress,
IImmutableSet<Document> documents,
CancellationToken cancellationToken = default)
{
return FindReferencesAsync(
symbol, solution, progress, documents,
FindReferencesSearchOptions.Default, cancellationToken);
}
internal static async Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
IFindReferencesProgress progress,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
progress = progress ?? FindReferencesProgress.Instance;
var streamingProgress = new StreamingProgressCollector(
new StreamingFindReferencesProgressAdapter(progress));
await FindReferencesAsync(
SymbolAndProjectId.Create(symbol, projectId: null),
solution, streamingProgress, documents, cancellationToken).ConfigureAwait(false);
solution, streamingProgress, documents,
options, cancellationToken).ConfigureAwait(false);
return streamingProgress.GetReferencedSymbols();
}
}
......
......@@ -29,6 +29,7 @@ public static partial class SymbolFinder
documents,
ReferenceFinders.DefaultRenameReferenceFinders,
streamingProgress,
FindReferencesSearchOptions.Default,
cancellationToken);
await engine.FindReferencesAsync(symbolAndProjectId).ConfigureAwait(false);
......
......@@ -12,6 +12,21 @@ namespace Microsoft.CodeAnalysis.Remote
{
#region FindReferences
internal class SerializableFindReferencesSearchOptions
{
public static SerializableFindReferencesSearchOptions Dehydrate(FindReferencesSearchOptions options)
{
return new SerializableFindReferencesSearchOptions
{
};
}
public FindReferencesSearchOptions Rehydrate()
{
return new FindReferencesSearchOptions();
}
}
internal class SerializableSymbolAndProjectId : IEquatable<SerializableSymbolAndProjectId>
{
public string SymbolKeyData;
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.LanguageServices;
......@@ -21,12 +22,13 @@ internal static partial class IFindReferencesResultExtensions
}
public static IEnumerable<ReferencedSymbol> FilterToItemsToShow(
this IEnumerable<ReferencedSymbol> result)
this IEnumerable<ReferencedSymbol> result, FindReferencesSearchOptions options)
{
return result.Where(ShouldShow);
return result.Where(r => ShouldShow(r, options));
}
public static bool ShouldShow(this ReferencedSymbol referencedSymbol)
public static bool ShouldShow(
this ReferencedSymbol referencedSymbol, FindReferencesSearchOptions options)
{
// If the reference has any locations then we will present it.
if (referencedSymbol.Locations.Any())
......@@ -35,11 +37,11 @@ public static bool ShouldShow(this ReferencedSymbol referencedSymbol)
}
return referencedSymbol.Definition.ShouldShowWithNoReferenceLocations(
showMetadataSymbolsWithoutReferences: true);
options, showMetadataSymbolsWithoutReferences: true);
}
public static bool ShouldShowWithNoReferenceLocations(
this ISymbol definition, bool showMetadataSymbolsWithoutReferences)
this ISymbol definition, FindReferencesSearchOptions options, bool showMetadataSymbolsWithoutReferences)
{
// If the definition is implicit and we have no references, then we don't want to
// clutter the UI with it.
......@@ -49,7 +51,6 @@ public static bool ShouldShow(this ReferencedSymbol referencedSymbol)
}
// We don't want to clutter the UI with property accessors if there are no direct
// references to them.
if (definition.IsPropertyAccessor())
{
return false;
......
......@@ -15,7 +15,9 @@ namespace Microsoft.CodeAnalysis.Remote
// root level service for all Roslyn services
internal partial class CodeAnalysisService : IRemoteSymbolFinder
{
public Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndProjectIdArg, DocumentId[] documentArgs, CancellationToken cancellationToken)
public Task FindReferencesAsync(
SerializableSymbolAndProjectId symbolAndProjectIdArg, DocumentId[] documentArgs,
SerializableFindReferencesSearchOptions options, CancellationToken cancellationToken)
{
return RunServiceAsync(async token =>
{
......@@ -44,8 +46,8 @@ public Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndProjectI
.ToImmutableHashSet();
await SymbolFinder.FindReferencesInCurrentProcessAsync(
symbolAndProjectId.Value, solution,
progressCallback, documents, token).ConfigureAwait(false);
symbolAndProjectId.Value, solution, progressCallback,
documents, options.Rehydrate(), token).ConfigureAwait(false);
}
}, cancellationToken);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册