diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index 7430357d63330c0bcca7ea7dd0c923235c91a45c..31650da4aa1c0b9b81b26ae82ef74d18f1112c8c 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 112e722da46159ec91ad8cb1014fb7ba51bf863b..5d642618ffbdcfb1cc43fcb9eb8688bdf3149161 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 c43227cf21fc60bfee5e2573730bf63e5ba9e927..1d6b5b83c6a266d22a3bc6f3e178b69bcaf104d1 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 30c4f2af41ad749a0fef39b54c8dd5e99f92d3e4..687d2e2258698e5bb32fc91a17541e1ef44e3531 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 8231a28e4499dfe19ed4b622d0bd46cf1f92fe3e..c672d0e799ce22e34b794cfeda6144fbdebdb70b 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 af39e580da5c39a3233aa92b7ae0f5fbe62b246e..7e7a485b5e6a06bf6fdde223878c09e9a135b08c 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 24d2d8b67db488b687f327e7c6ee3e5d1244af06..fd77350ba4717f3f116c3526fb6b8de4f5ebe6f7 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 359d6f10b227d15bb6e8fd6f7139a4d2726f8503..a81f183e71686753018f5436d42943e030f3e54b 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 a8fb09614a720662a997f1d5e0f4a1b701e7fd46..e3da0f0508fbb78abbcecc3ec8c2c6d8dff2ca8e 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 353889190367d84899eb9e146bac4b96d0ce596d..ea137e9a551399ccd39a98b99bdc4957ab483863 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 a74bab5d60d888eb7ebce66dfecd01aea84b5e2e..a572f39e31e922e3e25138a0442b2c1a7571e816 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 bcdb9afda0c8544acbbd30661d5aa60ebeeb124a..fc99e3cd03806a76b4a5f28e220f63372f43bc42 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 c74ae796c3fea93098cac4b494a79ab2481efa0b..f1d1565ae75a231f99844884c3dad674372269b5 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 d60cce23d42242ef6cd0dcadc307e1769fb52100..c0d354f4f8f510f0113403459faeb6833e5ba7df 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 75ce5202cd0f1824a8602084c8c1ccff7532ae75..cad205ad77edc52c43071b246e69f6498187dc76 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 ba5f9ad403f3e5e4268227e9b2c37e163f0e8c68..d9c620790d6f0a8bd9f3353b902b3ad4a791b395 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 cc30399e231dd32eacbc88512367bfd6ff0a999e..4bc092e018fcccbcdb43d82daf48148c7097f2e2 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 f9a9ee07c3b5336076bdcf13c7bf2538bd912a92..eeda3c191eb3e40c4f1e984e1748bddc3bb2dd91 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 3048fe5d2298aab16e838e97ea6bb81d5ee1ffb2..7c2569f8306c2f672e223763939978a74a133d68 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 5d72a7d81a40847be072f0b72b9550eda882b0a5..9fed377ad2ee9dce5b0df409dd2d3dfc6ddbb224 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 5f19d61bff5da01e72b118393e090c81af1fdeae..fea9dfda9285b8783e32c1041ceeaf75d1eedc29 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 75376c1831759920a00263c131d76a3ed648e4fc..ce8cc9ec19e9ea5c8a1fc955a2c9cc6f85ff1e17 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 d9bd350bbc80331f321fdb031332a553d925e59e..22b68f320b0bffb709fcd8af79dd669805766c23 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 4781c3236938508f2e0af1a46b66cf8cdf85e5b9..09e87c18307f91830227f7615e28ba5ab7205322 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 03e61905207c2d1870a142d9c8c36e71cd2e9efd..bba734009296f83529aca50e04cc7aa9e0107a6a 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 9d1fd21935fdaa16a7ddee72dbcae8fe063c3770..2b6bb51baec4304b0eb630262bf78d7ec87e50ce 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 9fb6518fd7778aa9f2637fddd560ba5644c1e10a..92eab975e4c8bfbf45391d6f9b35011406173176 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 5379c61650ef82f55d645ac055ba12dd26e8d1bc..33044987bed9cea64647a99b1126af32344d1fbb 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 5c22e25bacc0b7c26cdd31ac765f283861e02a1d..04d12b93a3af80dd748d302c041838ce21a29481 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 3ea04ba5c7dc14e68bd3e16126399df78cf0c511..9a315ec3a91aa204335c16a14b1c2d52d09dd97c 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 943c6ef071647fb9857eac87eae6496417af9cdb..9c04256a30d19d1888bd5430df8828f4db3e5f10 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 17b8304ea9a1a357b9a44a288a4532a47fd389b0..eaf9f352dd218546e96e871686e2cbc5fb0e272a 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 db8e3da9b5d98ac929ef8a164cea32e299ecf5d3..7326ebb00981bd3ca51e12cb991b34bdbb57539d 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 c174cf0955ea306aaf5735c3b032973b164a9294..a8035dd17899bcd800f29cc49911db042be7acdb 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 9380c88a1a4449fb8c7321886d26afd71322acab..e062796c0577d6093ef5d427ebbdbdd475fa1228 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 fdeacc659affb527e4f8c38d7a4e294fdecc0410..e2b32430845bd05eb059da151ab5d411d397862e 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 c6e13314fbba720474458b20eaffca1c055f2bdf..80d646a022c1a807b2ccfb5c58197d5d011b65bd 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 590ed8072cc2b53895b4e206df05e818c047928c..c04ca8e2ef360a75246448c71a300a7fb4afdd3a 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); }