Skip to content

Commit 31c2de5

Browse files
Single doc
1 parent 0c2c306 commit 31c2de5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Features/CSharp/Portable/Completion/CompletionProviders/AwaitCompletionProvider.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,21 @@ async ValueTask<bool> IsMethodUsedAsEventHandlerAsync()
114114
if (containingType is null)
115115
return false;
116116

117-
// Get the syntax root for the containing type
118-
var documents = containingType.DeclaringSyntaxReferences.Select(r => solution.GetDocument(r.SyntaxTree)).WhereNotNull().ToImmutableHashSet();
117+
// For perf, only search for usages of the containing method within the same file. This may miss something
118+
// in the case of a partial type, but it allows us to easily scope this to a single document.
119+
var document = solution.GetDocument(containingType.DeclaringSyntaxReferences.FirstOrDefault(r => r.SyntaxTree == methodDeclaration.SyntaxTree)?.SyntaxTree);
120+
if (document is null)
121+
return false;
122+
119123
var references = await SymbolFinder.FindReferencesAsync(
120-
methodSymbol, solution, documents, cancellationToken).ConfigureAwait(false);
124+
methodSymbol, solution, [document], cancellationToken).ConfigureAwait(false);
121125

122126
foreach (var group in references.SelectMany(r => r.Locations).GroupBy(l => l.Location.SourceTree))
123127
{
124128
var tree = group.Key;
125-
var document = solution.GetDocument(tree);
126-
if (document is null)
129+
if (tree != methodDeclaration.SyntaxTree)
127130
continue;
128131

129-
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
130132
foreach (var location in group)
131133
{
132134
var node = location.Location.FindNode(cancellationToken) as ExpressionSyntax;

0 commit comments

Comments
 (0)