using System; using System.Collections.Generic; using Newtonsoft.Json; namespace Unity.Pipeline.Models { /// /// Response from code evaluation commands containing results, output, and diagnostics. /// [Serializable] class EvalResponse :CommandExecutionResponse { /// /// Console output captured during execution. /// [JsonProperty("output")] public string Output { get; set; } /// /// Compilation diagnostics (errors, warnings) from Roslyn. /// [JsonProperty("diagnostics")] public List Diagnostics { get; set; } = new List(); /// /// Create a successful evaluation response. /// /// The evaluated expression's result. /// Console output captured during execution. /// How long execution took, in milliseconds. /// Compilation diagnostics (errors, warnings) from Roslyn. /// A successful response wrapping . public static EvalResponse EvalSuccess(object result, string output = null, long executionTimeMs = 0, List diagnostics = null) { return new EvalResponse { Success = true, Command = "eval", Result = result, Output = output, ExecutionTimeMs = executionTimeMs, Diagnostics = diagnostics ?? new List(), ExecutedAt = DateTime.UtcNow }; } /// /// Create a failed evaluation response. /// /// Error message. /// Additional error details for debugging. /// How long execution took, in milliseconds. /// Compilation diagnostics (errors, warnings) from Roslyn. /// A failed response. public static EvalResponse EvalFailure(string error, string errorDetails = null, long executionTimeMs = 0, List diagnostics = null) { return new EvalResponse { Success = false, Command = "eval", Error = error, ErrorDetails = errorDetails, ExecutionTimeMs = executionTimeMs, Diagnostics = diagnostics ?? new List(), ExecutedAt = DateTime.UtcNow }; } } /// /// Compilation diagnostic information from Roslyn. /// [Serializable] public class DiagnosticInfo { /// /// Severity level: "error", "warning", "info". /// [JsonProperty("severity")] public string Severity { get; set; } /// /// Diagnostic message text. /// [JsonProperty("message")] public string Message { get; set; } /// /// Line number (0-based). /// [JsonProperty("line")] public int Line { get; set; } /// /// Column number (0-based). /// [JsonProperty("column")] public int Column { get; set; } /// /// Diagnostic identifier (e.g., "CS1002"). /// [JsonProperty("id")] public string Id { get; set; } /// /// User source file the diagnostic maps to through a #line directive, or null when /// the compiled source carries no mapping (eval snippets, generated scaffolding). /// [JsonProperty("file", NullValueHandling = NullValueHandling.Ignore)] public string File { get; set; } /// /// 1-based line in ; null when is null. /// [JsonProperty("fileLine", NullValueHandling = NullValueHandling.Ignore)] public int? FileLine { get; set; } /// /// Trimmed text of the compiled source line the diagnostic points at. For code reload that /// is the generated override source, which is what actually failed to compile. /// [JsonProperty("source", NullValueHandling = NullValueHandling.Ignore)] public string Source { get; set; } } }