Editor/Prism/Compiler/Backends/BackendEmitResult.cs

Defines small immutable record types used by compiler backends in the Editor. GeneratedArtifact represents an extra file a backend wants written alongside the main output. BackendEmitResult represents the primary emitted text, its extension, source map, extra artifacts, and some metadata like backend id and line count.

using Editor.Prism.Core;

namespace Editor.Prism.Compiler.Backends;

/// <summary>
/// An extra file a backend wants written beside its main artifact — a generated texture definition,
/// a reflection sidecar, the Slang prelude module.
/// </summary>
public sealed record GeneratedArtifact( string FileName, string Text )
{
	/// <summary>True when the file should be written beside the saved document rather than to scratch.</summary>
	public bool BesideDocument { get; init; } = true;

	/// <inheritdoc/>
	public override string ToString() => FileName;
}

/// <summary>What a backend produced.</summary>
public sealed record BackendEmitResult(
	string Text,
	string FileExtension,
	SourceMap SourceMap,
	IReadOnlyList<GeneratedArtifact> Extra )
{
	/// <summary>The backend that produced this.</summary>
	public string BackendId { get; init; }

	/// <summary>Number of lines in <see cref="Text"/>, for the status bar and the code panel.</summary>
	public int LineCount { get; init; }

	/// <summary>An empty result, used when a backend bailed out with diagnostics.</summary>
	public static BackendEmitResult Empty( string backendId, string extension ) =>
		new( string.Empty, extension, new SourceMap(), Array.Empty<GeneratedArtifact>() )
		{
			BackendId = backendId
		};

	/// <inheritdoc/>
	public override string ToString() => $"{BackendId}: {LineCount} lines of .{FileExtension}";
}