From 96f0c6d83f14eadc10eb9dfbfb2de1c315460608 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 30 Jun 2018 20:05:23 -0700 Subject: [PATCH] Add a new FindReferencesOptions types and thread it through our platform. --- ...stractFindUsagesService.ProgressAdapter.cs | 8 +++- .../FindUsages/AbstractFindUsagesService.cs | 8 +++- .../IDefinitionsAndReferencesFactory.cs | 12 ++++-- .../FindReferences/FindReferencesTests.vb | 22 +++++++--- .../AbstractAddParameterCodeFixProvider.cs | 1 + .../AbstractChangeSignatureService.cs | 1 + .../DelegateInvokeMethodReferenceFinder.cs | 3 ++ .../AbstractDocumentHighlightsService.cs | 10 +++-- .../FindReferencesSearchEngine.cs | 14 +++++++ ...ferencesSearchEngine_DocumentProcessing.cs | 3 +- .../FindReferencesSearchEngine_MapCreation.cs | 7 ++-- .../AbstractMemberScopedReferenceFinder.cs | 2 + ...dOrPropertyOrEventSymbolReferenceFinder.cs | 5 +-- .../Finders/AbstractReferenceFinder.cs | 42 +++++++++++++------ ...tructorInitializerSymbolReferenceFinder.cs | 4 +- .../ConstructorSymbolReferenceFinder.cs | 2 + .../DestructorSymbolReferenceFinder.cs | 4 +- .../Finders/EventSymbolReferenceFinder.cs | 8 +++- .../ExplicitInterfaceMethodReferenceFinder.cs | 3 ++ .../Finders/FieldSymbolReferenceFinder.cs | 4 +- .../Finders/IReferenceFinder.cs | 9 ++-- .../Finders/LinkedFileReferenceFinder.cs | 10 +++-- ...ethodTypeParameterSymbolReferenceFinder.cs | 3 ++ .../Finders/NamedTypeSymbolReferenceFinder.cs | 3 ++ .../Finders/NamespaceSymbolReferenceFinder.cs | 2 + .../Finders/OperatorSymbolReferenceFinder.cs | 2 + .../Finders/OrdinaryMethodReferenceFinder.cs | 6 ++- .../Finders/ParameterSymbolReferenceFinder.cs | 3 ++ .../PropertyAccessorSymbolReferenceFinder.cs | 11 +++-- .../Finders/PropertySymbolReferenceFinder.cs | 12 ++++-- .../TypeParameterSymbolReferenceFinder.cs | 2 + .../FindSymbols/IRemoteSymbolFinder.cs | 5 ++- .../SymbolFinder_FindReferences_Current.cs | 19 ++++++--- .../SymbolFinder_FindReferences_Legacy.cs | 27 ++++++++---- .../SymbolFinder_FindRenamableReferences.cs | 1 + .../Core/Portable/Remote/RemoteArguments.cs | 15 +++++++ .../IFindReferencesResultExtensions.cs | 13 +++--- .../CodeAnalysisService_SymbolFinder.cs | 8 ++-- 38 files changed, 235 insertions(+), 79 deletions(-) diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index 7430357d633..31650da4aa1 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -49,6 +49,7 @@ private class FindReferencesProgressAdapter : ForegroundThreadAffinitizedObject, { private readonly Solution _solution; private readonly IFindUsagesContext _context; + private readonly FindReferencesSearchOptions _options; /// /// 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 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; } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs index 112e722da46..5d642618ffb 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs @@ -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); } diff --git a/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs b/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs index c43227cf21f..1d6b5b83c6a 100644 --- a/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs +++ b/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs @@ -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 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 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.GetInstance(); diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index 30c4f2af41a..687d2e22586 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -1,6 +1,7 @@ ' 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(). diff --git a/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs b/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs index 8231a28e449..c672d0e799c 100644 --- a/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs @@ -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) diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index af39e580da5..7e7a485b5e6 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -187,6 +187,7 @@ internal ChangeSignatureResult ChangeSignatureWithContext(ChangeSignatureAnalyze documents, ReferenceFinders.DefaultReferenceFinders.Add(DelegateInvokeMethodReferenceFinder.DelegateInvokeMethod), streamingProgress, + FindReferencesSearchOptions.Default, cancellationToken); await engine.FindReferencesAsync(symbolAndProjectId).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs b/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs index 24d2d8b67db..fd77350ba47 100644 --- a/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs +++ b/src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs @@ -35,6 +35,7 @@ protected override bool CanFind(IMethodSymbol symbol) SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { var result = ImmutableArray.CreateBuilder(); @@ -64,6 +65,7 @@ protected override bool CanFind(IMethodSymbol symbol) IMethodSymbol symbol, Project project, IImmutableSet 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 diff --git a/src/Features/Core/Portable/DocumentHighlighting/AbstractDocumentHighlightsService.cs b/src/Features/Core/Portable/DocumentHighlighting/AbstractDocumentHighlightsService.cs index 359d6f10b22..a81f183e716 100644 --- a/src/Features/Core/Portable/DocumentHighlighting/AbstractDocumentHighlightsService.cs +++ b/src/Features/Core/Portable/DocumentHighlighting/AbstractDocumentHighlightsService.cs @@ -110,13 +110,15 @@ private static async Task 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.Empty; @@ -149,11 +151,11 @@ private static bool ShouldConsiderSymbol(ISymbol symbol) private async Task> FilterAndCreateSpansAsync( IEnumerable references, Document startingDocument, IImmutableSet 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs index a8fb09614a7..e3da0f0508f 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs @@ -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>; + 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; /// /// 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 documents, ImmutableArray 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); } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_DocumentProcessing.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_DocumentProcessing.cs index 35388919036..ea137e9a551 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_DocumentProcessing.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_DocumentProcessing.cs @@ -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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_MapCreation.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_MapCreation.cs index a74bab5d60d..a572f39e31e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_MapCreation.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine_MapCreation.cs @@ -38,7 +38,8 @@ private async Task 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 CreateProjectMapAsync(ConcurrentSet finderTasks = new List(); + var finderTasks = new List(); foreach (var f in _finders) { finderTasks.Add(Task.Run(async () => @@ -133,7 +134,7 @@ private async Task CreateProjectMapAsync(ConcurrentSet(); 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. diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMemberScopedReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMemberScopedReferenceFinder.cs index bcdb9afda0c..fc99e3cd038 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMemberScopedReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMemberScopedReferenceFinder.cs @@ -24,6 +24,7 @@ protected sealed override bool CanFind(TSymbol symbol) TSymbol symbol, Project project, IImmutableSet 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs index c74ae796c3f..f1d1565ae75 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractMethodOrPropertyOrEventSymbolReferenceFinder.cs @@ -1,12 +1,10 @@ // 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 symbolAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { // Static methods can't cascade. diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs index d60cce23d42..c0d354f4f8f 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs @@ -17,10 +17,17 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders { internal abstract partial class AbstractReferenceFinder : IReferenceFinder { - public abstract Task> DetermineCascadedSymbolsAsync(SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet projects, CancellationToken cancellationToken); + public abstract Task> DetermineCascadedSymbolsAsync( + SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken); + public abstract Task> DetermineProjectsToSearchAsync(ISymbol symbol, Solution solution, IImmutableSet projects, CancellationToken cancellationToken); - public abstract Task> DetermineDocumentsToSearchAsync(ISymbol symbol, Project project, IImmutableSet documents, CancellationToken cancellationToken); - public abstract Task> FindReferencesInDocumentAsync(SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken); + + public abstract Task> DetermineDocumentsToSearchAsync( + ISymbol symbol, Project project, IImmutableSet documents, FindReferencesSearchOptions options, CancellationToken cancellationToken); + + public abstract Task> 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 : AbstractRefer where TSymbol : ISymbol { protected abstract bool CanFind(TSymbol symbol); - protected abstract Task> DetermineDocumentsToSearchAsync(TSymbol symbol, Project project, IImmutableSet documents, CancellationToken cancellationToken); - protected abstract Task> FindReferencesInDocumentAsync(TSymbol symbol, Document document, SemanticModel semanticModel, CancellationToken cancellationToken); + + protected abstract Task> DetermineDocumentsToSearchAsync( + TSymbol symbol, Project project, IImmutableSet documents, + FindReferencesSearchOptions options, CancellationToken cancellationToken); + + protected abstract Task> FindReferencesInDocumentAsync( + TSymbol symbol, Document document, SemanticModel semanticModel, + FindReferencesSearchOptions options, CancellationToken cancellationToken); public override Task> DetermineProjectsToSearchAsync(ISymbol symbol, Solution solution, IImmutableSet projects, CancellationToken cancellationToken) { @@ -516,31 +529,35 @@ public override Task> DetermineProjectsToSearchAsync(ISy : SpecializedTasks.EmptyImmutableArray(); } - public override Task> DetermineDocumentsToSearchAsync(ISymbol symbol, Project project, IImmutableSet documents, CancellationToken cancellationToken) + public override Task> DetermineDocumentsToSearchAsync( + ISymbol symbol, Project project, IImmutableSet 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(); } public override Task> 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(); } public override Task> DetermineCascadedSymbolsAsync( - SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet projects, CancellationToken cancellationToken) + SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet 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(); @@ -554,7 +571,8 @@ public override Task> DetermineDocumentsToSearchAsync(I } protected virtual Task> DetermineCascadedSymbolsAsync( - SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet projects, CancellationToken cancellationToken) + SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorInitializerSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorInitializerSymbolReferenceFinder.cs index 75ce5202cd0..cad205ad77e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorInitializerSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorInitializerSymbolReferenceFinder.cs @@ -1,7 +1,5 @@ // 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 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(); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs index ba5f9ad403f..d9c620790d6 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ConstructorSymbolReferenceFinder.cs @@ -29,6 +29,7 @@ protected override bool CanFind(IMethodSymbol symbol) IMethodSymbol symbol, Project project, IImmutableSet 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/DestructorSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/DestructorSymbolReferenceFinder.cs index cc30399e231..4bc092e018f 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/DestructorSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/DestructorSymbolReferenceFinder.cs @@ -1,6 +1,5 @@ // 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 symbol, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); @@ -28,6 +28,7 @@ protected override bool CanFind(IMethodSymbol symbol) IMethodSymbol symbol, Project project, IImmutableSet documents, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); @@ -37,6 +38,7 @@ protected override bool CanFind(IMethodSymbol symbol) IMethodSymbol methodSymbol, Document document, SemanticModel semanticModel, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/EventSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/EventSymbolReferenceFinder.cs index f9a9ee07c3b..eeda3c191eb 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/EventSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/EventSymbolReferenceFinder.cs @@ -20,10 +20,12 @@ protected override bool CanFind(IEventSymbol symbol) protected override async Task> DetermineCascadedSymbolsAsync( SymbolAndProjectId symbolAndProjectId, Solution solution, - IImmutableSet projects, + IImmutableSet 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 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitInterfaceMethodReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitInterfaceMethodReferenceFinder.cs index 3048fe5d229..7c2569f8306 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitInterfaceMethodReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ExplicitInterfaceMethodReferenceFinder.cs @@ -20,6 +20,7 @@ protected override bool CanFind(IMethodSymbol symbol) SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet 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 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. diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/FieldSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/FieldSymbolReferenceFinder.cs index 5d72a7d81a4..9fed377ad2e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/FieldSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/FieldSymbolReferenceFinder.cs @@ -1,6 +1,5 @@ // 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 symbolAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { var symbol = symbolAndProjectId.Symbol; @@ -37,6 +37,7 @@ protected override bool CanFind(IFieldSymbol symbol) IFieldSymbol symbol, Project project, IImmutableSet 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/IReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/IReferenceFinder.cs index 5f19d61bff5..fea9dfda928 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/IReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/IReferenceFinder.cs @@ -24,7 +24,8 @@ internal interface IReferenceFinder /// Implementations of this method must be thread-safe. /// Task> DetermineCascadedSymbolsAsync( - SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet projects, CancellationToken cancellationToken); + SymbolAndProjectId symbolAndProject, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken); /// /// 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. /// Task> DetermineDocumentsToSearchAsync( - ISymbol symbol, Project project, IImmutableSet documents, CancellationToken cancellationToken); + ISymbol symbol, Project project, IImmutableSet documents, + FindReferencesSearchOptions options, CancellationToken cancellationToken); /// /// 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. /// Task> FindReferencesInDocumentAsync( - SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken); + SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, + FindReferencesSearchOptions options, CancellationToken cancellationToken); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/LinkedFileReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/LinkedFileReferenceFinder.cs index 75376c18317..ce8cc9ec19e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/LinkedFileReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/LinkedFileReferenceFinder.cs @@ -12,7 +12,8 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders internal class LinkedFileReferenceFinder : IReferenceFinder { public async Task> DetermineCascadedSymbolsAsync( - SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet projects = null, CancellationToken cancellationToken = default) + SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { var linkedSymbols = new HashSet(); @@ -62,7 +63,9 @@ internal class LinkedFileReferenceFinder : IReferenceFinder return linkedSymbols.ToImmutableArray(); } - public Task> DetermineDocumentsToSearchAsync(ISymbol symbol, Project project, IImmutableSet documents, CancellationToken cancellationToken = default) + public Task> DetermineDocumentsToSearchAsync( + ISymbol symbol, Project project, IImmutableSet documents, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); } @@ -73,7 +76,8 @@ public Task> DetermineProjectsToSearchAsync(ISymbol symb } public Task> FindReferencesInDocumentAsync( - SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, CancellationToken cancellationToken = default) + SymbolAndProjectId symbolAndProjectId, Document document, SemanticModel semanticModel, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyImmutableArray(); } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/MethodTypeParameterSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/MethodTypeParameterSymbolReferenceFinder.cs index d9bd350bbc8..22b68f320b0 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/MethodTypeParameterSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/MethodTypeParameterSymbolReferenceFinder.cs @@ -19,6 +19,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol) SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { var symbol = symbolAndProjectId.Symbol; @@ -47,6 +48,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol) ITypeParameterSymbol symbol, Project project, IImmutableSet 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 diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs index 4781c323693..09e87c18307 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs @@ -23,6 +23,7 @@ protected override bool CanFind(INamedTypeSymbol symbol) SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { var result = ArrayBuilder.GetInstance(); @@ -55,6 +56,7 @@ protected override bool CanFind(INamedTypeSymbol symbol) INamedTypeSymbol symbol, Project project, IImmutableSet 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( diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs index 03e61905207..bba73400929 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamespaceSymbolReferenceFinder.cs @@ -24,6 +24,7 @@ protected override bool CanFind(INamespaceSymbol symbol) INamespaceSymbol symbol, Project project, IImmutableSet 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OperatorSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OperatorSymbolReferenceFinder.cs index 9d1fd21935f..2b6bb51baec 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OperatorSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OperatorSymbolReferenceFinder.cs @@ -20,6 +20,7 @@ protected override bool CanFind(IMethodSymbol symbol) IMethodSymbol symbol, Project project, IImmutableSet 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(); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OrdinaryMethodReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OrdinaryMethodReferenceFinder.cs index 9fb6518fd77..92eab975e4c 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OrdinaryMethodReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OrdinaryMethodReferenceFinder.cs @@ -24,6 +24,7 @@ protected override bool CanFind(IMethodSymbol symbol) SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet 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 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(); diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs index 5379c61650e..33044987bed 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs @@ -24,6 +24,7 @@ protected override bool CanFind(IParameterSymbol symbol) IParameterSymbol symbol, Project project, IImmutableSet 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 parameterAndProjectId, Solution solution, IImmutableSet projects, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { var parameter = parameterAndProjectId.Symbol; diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertyAccessorSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertyAccessorSymbolReferenceFinder.cs index 5c22e25bacc..04d12b93a3a 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertyAccessorSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertyAccessorSymbolReferenceFinder.cs @@ -20,10 +20,11 @@ protected override bool CanFind(IMethodSymbol symbol) SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet 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> DetermineDocumentsToSearchAsync(IMethodSymbol symbol, Project project, IImmutableSet documents, CancellationToken cancellationToken) + protected override Task> DetermineDocumentsToSearchAsync( + IMethodSymbol symbol, Project project, IImmutableSet documents, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return FindDocumentsAsync(project, documents, cancellationToken, symbol.Name); } - protected override Task> FindReferencesInDocumentAsync(IMethodSymbol symbol, Document document, SemanticModel semanticModel, CancellationToken cancellationToken) + protected override Task> FindReferencesInDocumentAsync( + IMethodSymbol symbol, Document document, SemanticModel semanticModel, + FindReferencesSearchOptions options, CancellationToken cancellationToken) { return FindReferencesInDocumentUsingSymbolNameAsync(symbol, document, semanticModel, cancellationToken); } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs index 3ea04ba5c7d..9a315ec3a91 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs @@ -1,5 +1,6 @@ // 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; @@ -22,10 +23,12 @@ protected override bool CanFind(IPropertySymbol symbol) protected override async Task> DetermineCascadedSymbolsAsync( SymbolAndProjectId symbolAndProjectId, Solution solution, - IImmutableSet projects, + IImmutableSet 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 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) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/TypeParameterSymbolReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/TypeParameterSymbolReferenceFinder.cs index 943c6ef0716..9c04256a30d 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/TypeParameterSymbolReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/TypeParameterSymbolReferenceFinder.cs @@ -18,6 +18,7 @@ protected override bool CanFind(ITypeParameterSymbol symbol) ITypeParameterSymbol symbol, Project project, IImmutableSet 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); diff --git a/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinder.cs index 17b8304ea9a..eaf9f352dd2 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/IRemoteSymbolFinder.cs @@ -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> FindAllDeclarationsWithNormalQueryAsync( diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs index db8e3da9b5d..7326ebb0098 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs @@ -22,12 +22,14 @@ public static partial class SymbolFinder Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet 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 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 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); } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Legacy.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Legacy.cs index c174cf0955e..a8035dd1789 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Legacy.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Legacy.cs @@ -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. /// An optional set of documents to be searched. If documents is null, then that means "all documents". /// An optional cancellation token. - public static async Task> FindReferencesAsync( + public static Task> FindReferencesAsync( ISymbol symbol, Solution solution, IFindReferencesProgress progress, IImmutableSet documents, CancellationToken cancellationToken = default) + { + return FindReferencesAsync( + symbol, solution, progress, documents, + FindReferencesSearchOptions.Default, cancellationToken); + } + + internal static async Task> FindReferencesAsync( + ISymbol symbol, + Solution solution, + IFindReferencesProgress progress, + IImmutableSet 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(); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindRenamableReferences.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindRenamableReferences.cs index 9380c88a1a4..e062796c057 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindRenamableReferences.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindRenamableReferences.cs @@ -29,6 +29,7 @@ public static partial class SymbolFinder documents, ReferenceFinders.DefaultRenameReferenceFinders, streamingProgress, + FindReferencesSearchOptions.Default, cancellationToken); await engine.FindReferencesAsync(symbolAndProjectId).ConfigureAwait(false); diff --git a/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs b/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs index fdeacc659af..e2b32430845 100644 --- a/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs +++ b/src/Workspaces/Core/Portable/Remote/RemoteArguments.cs @@ -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 { public string SymbolKeyData; diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs index c6e13314fbb..80d646a022c 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs @@ -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 FilterToItemsToShow( - this IEnumerable result) + this IEnumerable 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; diff --git a/src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs b/src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs index 590ed8072cc..c04ca8e2ef3 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/CodeAnalysisService_SymbolFinder.cs @@ -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); } -- GitLab