Skip to content

Commit d73a5cb

Browse files
committed
initial commit
1 parent ad96233 commit d73a5cb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Analyzers/Orchestration/OrchestrationAnalyzer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ public override void Initialize(AnalysisContext context)
141141
case IMethodReferenceOperation methodReferenceOperation:
142142
// use the method reference as the method symbol
143143
methodSymbol = methodReferenceOperation.Method;
144-
methodSyntax = methodReferenceOperation.Method.DeclaringSyntaxReferences.First().GetSyntax();
144+
145+
// Only get syntax for methods in the current project (skip external assemblies)
146+
// If IsEmpty (external method), methodSyntax stays null and we skip analysis below
147+
if (!methodReferenceOperation.Method.DeclaringSyntaxReferences.IsEmpty)
148+
{
149+
methodSyntax = methodReferenceOperation.Method.DeclaringSyntaxReferences.First().GetSyntax();
150+
}
151+
145152
break;
146153
default:
147154
break;

src/Analyzers/RoslynExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ public static bool BaseTypeIsConstructedFrom(this INamedTypeSymbol symbol, IType
115115
/// <returns>The collection of syntax nodes of a given method symbol.</returns>
116116
public static IEnumerable<MethodDeclarationSyntax> GetSyntaxNodes(this IMethodSymbol methodSymbol)
117117
{
118+
// If the method has no syntax references (e.g., extension methods from external assemblies),
119+
// return empty to skip analysis rather than throwing ArgumentException.
120+
if (methodSymbol.DeclaringSyntaxReferences.IsEmpty)
121+
{
122+
return Enumerable.Empty<MethodDeclarationSyntax>();
123+
}
124+
118125
return methodSymbol.DeclaringSyntaxReferences.Select(r => r.GetSyntax()).OfType<MethodDeclarationSyntax>();
119126
}
120127

@@ -155,6 +162,13 @@ public static bool IsEqualTo(this IMethodSymbol methodSymbol, INamedTypeSymbol?
155162
/// <returns>The Diagnostic based on the symbol location.</returns>
156163
public static Diagnostic BuildDiagnostic(DiagnosticDescriptor descriptor, ISymbol symbol, params string[] messageArgs)
157164
{
165+
// If the symbol has no syntax references (e.g., symbols from external assemblies),
166+
// fall back to using the symbol's location directly.
167+
if (symbol.DeclaringSyntaxReferences.IsEmpty)
168+
{
169+
return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault() ?? Location.None, messageArgs);
170+
}
171+
158172
return BuildDiagnostic(descriptor, symbol.DeclaringSyntaxReferences.First().GetSyntax(), messageArgs);
159173
}
160174

0 commit comments

Comments
 (0)