Skip to content

Commit 33163e0

Browse files
committed
Don't add explicit generic method invokes twice
1 parent 4d165b9 commit 33163e0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

GenericSymbolWithSyntax.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.CSharp;
23
using Microsoft.CodeAnalysis.CSharp.Syntax;
34
using Microsoft.CodeAnalysis.Operations;
45
using System;
@@ -97,7 +98,7 @@ CancellationToken cancellationToken
9798
{
9899
var symbol = syntaxNode switch
99100
{
100-
GenericNameSyntax => semanticModel.GetSymbolInfo(syntaxNode, cancellationToken).Symbol,
101+
GenericNameSyntax genericNameSyntax => GetSymbol(genericNameSyntax, semanticModel, cancellationToken),
101102
IdentifierNameSyntax or InvocationExpressionSyntax => GetSymbol(syntaxNode, semanticModel, cancellationToken),
102103
_ => null
103104
};
@@ -139,6 +140,24 @@ CancellationToken cancellationToken
139140
return FromSyntaxNodeInternal(syntaxNode, semanticModel, cancellationToken);
140141
}
141142

143+
private static ISymbol? GetSymbol
144+
(
145+
GenericNameSyntax genericNameSyntax,
146+
SemanticModel semanticModel,
147+
CancellationToken cancellationToken
148+
)
149+
{
150+
if ((genericNameSyntax.Parent is InvocationExpressionSyntax) ||
151+
((genericNameSyntax.Parent is MemberAccessExpressionSyntax memberAccessExpressionSyntax) &&
152+
(memberAccessExpressionSyntax.Parent is InvocationExpressionSyntax)))
153+
{
154+
// generic method invocations with an explicit type argument list produce a GenericNameSyntax node
155+
// this node is already added to the tree via the (grand)parent InvocationExpressionSyntax node
156+
return null;
157+
}
158+
return semanticModel.GetSymbolInfo(genericNameSyntax, cancellationToken).Symbol;
159+
}
160+
142161
private static ISymbol? GetSymbol
143162
(
144163
SyntaxNode syntaxNode,

0 commit comments

Comments
 (0)