Skip to content

Commit a6e1a8a

Browse files
CopilotYunchuWang
andauthored
Fix "SyntaxTree is not part of the compilation" exception in orchestration analyzers (#588)
* Initial plan * Fix SyntaxTree is not part of the compilation exception in analyzers Co-authored-by: YunchuWang <[email protected]> * Improve comment accuracy based on code review feedback Co-authored-by: YunchuWang <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: YunchuWang <[email protected]> Co-authored-by: wangbill <[email protected]>
1 parent caa632c commit a6e1a8a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Analyzers/Orchestration/OrchestrationAnalyzer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,15 @@ void FindInvokedMethods(
330330
{
331331
// Since the syntax tree of the callee method might be different from the caller method, we need to get the correct semantic model,
332332
// avoiding the exception 'Syntax node is not within syntax tree'.
333+
// We also need to check if the syntax tree is part of the compilation to avoid 'SyntaxTree is not part of the compilation' exception.
334+
if (!this.Compilation.ContainsSyntaxTree(calleeSyntax.SyntaxTree))
335+
{
336+
// Skip this syntax tree if it's not part of the current compilation context (e.g., from referenced projects or source generators)
337+
continue;
338+
}
339+
333340
SemanticModel sm = semanticModel.SyntaxTree == calleeSyntax.SyntaxTree ?
334-
semanticModel : semanticModel.Compilation.GetSemanticModel(calleeSyntax.SyntaxTree);
341+
semanticModel : this.Compilation.GetSemanticModel(calleeSyntax.SyntaxTree);
335342

336343
this.FindInvokedMethods(sm, calleeSyntax, calleeMethodSymbol, rootOrchestration, reportDiagnostic);
337344
}

0 commit comments

Comments
 (0)