📄 core/src/CompilationsExtensions.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;

namespace Cfa;

internal static class CompilationsExtensions
{
    public static SemanticModel GetSemanticModel(this IEnumerable<Compilation> compilations, SyntaxTree syntaxTree) =>
        compilations.FirstOrDefault(c => c.ContainsSyntaxTree(syntaxTree))?.GetSemanticModel(syntaxTree)
        ?? throw new InvalidOperationException(
            $"Unable to get semantic model for syntax tree at {syntaxTree.FilePath}"
        );
}