Skip to content

Commit dbcedb5

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 396e8b3 commit dbcedb5

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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)]
@@ -103,6 +105,9 @@ public static SessionEvent FromJson(string json) =>
103105

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

108113
/// <summary>

scripts/codegen/csharp.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ function generateSessionEventsCode(schema: JSONSchema7): string {
396396
// Generated code does not have XML doc comments; suppress CS1591 to avoid warnings.
397397
#pragma warning disable CS1591
398398
399+
using System.Diagnostics;
399400
using System.Text.Json;
400401
using System.Text.Json.Serialization;
401402
@@ -406,6 +407,7 @@ namespace GitHub.Copilot.SDK;
406407
lines.push(`/// <summary>`);
407408
lines.push(`/// Base class for all session events with polymorphic JSON serialization.`);
408409
lines.push(`/// </summary>`);
410+
lines.push(`[DebuggerDisplay("{DebuggerDisplay,nq}")]`);
409411
lines.push(`[JsonPolymorphic(`, ` TypeDiscriminatorPropertyName = "type",`, ` UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]`);
410412
for (const variant of [...variants].sort((a, b) => a.typeName.localeCompare(b.typeName))) {
411413
lines.push(`[JsonDerivedType(typeof(${variant.className}), "${variant.typeName}")]`);
@@ -417,7 +419,8 @@ namespace GitHub.Copilot.SDK;
417419
lines.push(` /// <summary>`, ` /// The event type discriminator.`, ` /// </summary>`);
418420
lines.push(` [JsonIgnore]`, ` public abstract string Type { get; }`, "");
419421
lines.push(` public static SessionEvent FromJson(string json) =>`, ` JsonSerializer.Deserialize(json, SessionEventsJsonContext.Default.SessionEvent)!;`, "");
420-
lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, `}`, "");
422+
lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, "");
423+
lines.push(` [DebuggerBrowsable(DebuggerBrowsableState.Never)]`, ` private string DebuggerDisplay => ToJson();`, `}`, "");
421424

422425
// Event classes with XML docs
423426
for (const variant of variants) {

0 commit comments

Comments
 (0)