Skip to content

Commit b660bc6

Browse files
committed
Add DebuggerDisplay to SessionEvent for better debugging
Added [DebuggerDisplay] attribute to SessionEvent base class to show JSON in debugger views.
1 parent 11dde6e commit b660bc6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

dotnet/src/Generated/SessionEvents.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Generated code does not have XML doc comments; suppress CS1591 to avoid warnings.
99
#pragma warning disable CS1591
1010

11+
using System.Diagnostics;
1112
using System.Text.Json;
1213
using System.Text.Json.Serialization;
1314

@@ -16,6 +17,7 @@ namespace GitHub.Copilot.SDK;
1617
/// <summary>
1718
/// Base class for all session events with polymorphic JSON serialization.
1819
/// </summary>
20+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1921
[JsonPolymorphic(
2022
TypeDiscriminatorPropertyName = "type",
2123
UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]
@@ -104,6 +106,9 @@ public static SessionEvent FromJson(string json) =>
104106

105107
public string ToJson() =>
106108
JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);
109+
110+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
111+
private string DebuggerDisplay => ToJson();
107112
}
108113

109114
/// <summary>

scripts/codegen/csharp.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ function generateSessionEventsCode(schema: JSONSchema7): string {
428428
// Generated code does not have XML doc comments; suppress CS1591 to avoid warnings.
429429
#pragma warning disable CS1591
430430
431+
using System.Diagnostics;
431432
using System.Text.Json;
432433
using System.Text.Json.Serialization;
433434
@@ -438,6 +439,7 @@ namespace GitHub.Copilot.SDK;
438439
lines.push(`/// <summary>`);
439440
lines.push(`/// Base class for all session events with polymorphic JSON serialization.`);
440441
lines.push(`/// </summary>`);
442+
lines.push(`[DebuggerDisplay("{DebuggerDisplay,nq}")]`);
441443
lines.push(`[JsonPolymorphic(`, ` TypeDiscriminatorPropertyName = "type",`, ` UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]`);
442444
for (const variant of [...variants].sort((a, b) => a.typeName.localeCompare(b.typeName))) {
443445
lines.push(`[JsonDerivedType(typeof(${variant.className}), "${variant.typeName}")]`);
@@ -449,7 +451,8 @@ namespace GitHub.Copilot.SDK;
449451
lines.push(` /// <summary>`, ` /// The event type discriminator.`, ` /// </summary>`);
450452
lines.push(` [JsonIgnore]`, ` public abstract string Type { get; }`, "");
451453
lines.push(` public static SessionEvent FromJson(string json) =>`, ` JsonSerializer.Deserialize(json, SessionEventsJsonContext.Default.SessionEvent)!;`, "");
452-
lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, `}`, "");
454+
lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, "");
455+
lines.push(` [DebuggerBrowsable(DebuggerBrowsableState.Never)]`, ` private string DebuggerDisplay => ToJson();`, `}`, "");
453456

454457
// Event classes with XML docs
455458
for (const variant of variants) {

0 commit comments

Comments
 (0)