-
Notifications
You must be signed in to change notification settings - Fork 4k
/
SymbolFinder_FindReferences_Legacy.cs
127 lines (118 loc) · 5.95 KB
/
SymbolFinder_FindReferences_Legacy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.FindSymbols
{
// This file contains the legacy FindReferences APIs. The APIs are legacy because they
// do not contain enough information for us to effectively remote them over to the OOP
// process to do the work. Specifically, they lack the "current project context" necessary
// to be able to effectively serialize symbols to/from the remote process.
public static partial class SymbolFinder
{
/// <summary>
/// Finds all references to a symbol throughout a solution
/// </summary>
/// <param name="symbol">The symbol to find references to.</param>
/// <param name="solution">The solution to find references within.</param>
/// <param name="cancellationToken">A cancellation token.</param>
public static Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
CancellationToken cancellationToken = default)
{
if (symbol is null)
throw new System.ArgumentNullException(nameof(symbol));
if (solution is null)
throw new System.ArgumentNullException(nameof(solution));
return FindReferencesAsync(symbol, solution, FindReferencesSearchOptions.Default, cancellationToken);
}
internal static async Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
var progressCollector = new StreamingProgressCollector();
await FindReferencesAsync(
symbol, solution, progressCollector,
documents: null, options, cancellationToken).ConfigureAwait(false);
return progressCollector.GetReferencedSymbols();
}
/// <summary>
/// Finds all references to a symbol throughout a solution
/// </summary>
/// <param name="symbol">The symbol to find references to.</param>
/// <param name="solution">The solution to find references within.</param>
/// <param name="documents">A set of documents to be searched. If documents is null, then that means "all documents".</param>
/// <param name="cancellationToken">A cancellation token.</param>
public static Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
IImmutableSet<Document>? documents,
CancellationToken cancellationToken = default)
{
if (symbol is null)
throw new System.ArgumentNullException(nameof(symbol));
if (solution is null)
throw new System.ArgumentNullException(nameof(solution));
return FindReferencesAsync(symbol, solution, progress: null, documents: documents, cancellationToken: cancellationToken);
}
/// <summary>
/// Finds all references to a symbol throughout a solution
/// </summary>
/// <param name="symbol">The symbol to find references to.</param>
/// <param name="solution">The solution to find references within.</param>
/// <param name="progress">An optional progress object that will receive progress
/// information as the search is undertaken.</param>
/// <param name="documents">An optional set of documents to be searched. If documents is null, then that means "all documents".</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
public static async Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
IFindReferencesProgress? progress,
IImmutableSet<Document>? documents,
CancellationToken cancellationToken = default)
{
if (symbol is null)
throw new System.ArgumentNullException(nameof(symbol));
if (solution is null)
throw new System.ArgumentNullException(nameof(solution));
return await FindReferencesAsync(
symbol, solution, progress, documents,
FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false);
}
internal static async Task<ImmutableArray<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
IFindReferencesProgress? progress,
IImmutableSet<Document>? documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
progress ??= NoOpFindReferencesProgress.Instance;
var streamingProgress = new StreamingProgressCollector(
new StreamingFindReferencesProgressAdapter(progress));
await FindReferencesAsync(
symbol, solution, streamingProgress, documents,
options, cancellationToken).ConfigureAwait(false);
return streamingProgress.GetReferencedSymbols();
}
internal static class TestAccessor
{
internal static Task<ImmutableArray<ReferencedSymbol>> FindReferencesAsync(
ISymbol symbol,
Solution solution,
IFindReferencesProgress progress,
IImmutableSet<Document> documents,
FindReferencesSearchOptions options,
CancellationToken cancellationToken)
{
return SymbolFinder.FindReferencesAsync(symbol, solution, progress, documents, options, cancellationToken);
}
}
}
}