Skip to content

Commit 9a0a1a5

Browse files
authored
Add DebuggerDisplay to SessionEvent for better debugging (#726)
Added [DebuggerDisplay] attribute to SessionEvent base class to show JSON in debugger views.
1 parent abfbc9e commit 9a0a1a5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

dotnet/src/Generated/SessionEvents.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// AUTO-GENERATED FILE - DO NOT EDIT
66
// Generated from: session-events.schema.json
77

8+
using System.Diagnostics;
89
using System.Text.Json;
910
using System.Text.Json.Serialization;
1011

@@ -13,6 +14,7 @@ namespace GitHub.Copilot.SDK;
1314
/// <summary>
1415
/// Provides the base class from which all session events derive.
1516
/// </summary>
17+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1618
[JsonPolymorphic(
1719
TypeDiscriminatorPropertyName = "type",
1820
UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]
@@ -107,6 +109,9 @@ public static SessionEvent FromJson(string json) =>
107109
/// <summary>Serializes this event to a JSON string.</summary>
108110
public string ToJson() =>
109111
JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);
112+
113+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
114+
private string DebuggerDisplay => ToJson();
110115
}
111116

112117
/// <summary>Represents the <c>session.start</c> event.</summary>

scripts/codegen/csharp.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ function generateSessionEventsCode(schema: JSONSchema7): string {
509509
// AUTO-GENERATED FILE - DO NOT EDIT
510510
// Generated from: session-events.schema.json
511511
512+
using System.Diagnostics;
512513
using System.Text.Json;
513514
using System.Text.Json.Serialization;
514515
@@ -519,6 +520,7 @@ namespace GitHub.Copilot.SDK;
519520
lines.push(`/// <summary>`);
520521
lines.push(`/// Provides the base class from which all session events derive.`);
521522
lines.push(`/// </summary>`);
523+
lines.push(`[DebuggerDisplay("{DebuggerDisplay,nq}")]`);
522524
lines.push(`[JsonPolymorphic(`, ` TypeDiscriminatorPropertyName = "type",`, ` UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]`);
523525
for (const variant of [...variants].sort((a, b) => a.typeName.localeCompare(b.typeName))) {
524526
lines.push(`[JsonDerivedType(typeof(${variant.className}), "${variant.typeName}")]`);
@@ -537,7 +539,9 @@ namespace GitHub.Copilot.SDK;
537539
lines.push(` /// <summary>Deserializes a JSON string into a <see cref="SessionEvent"/>.</summary>`);
538540
lines.push(` public static SessionEvent FromJson(string json) =>`, ` JsonSerializer.Deserialize(json, SessionEventsJsonContext.Default.SessionEvent)!;`, "");
539541
lines.push(` /// <summary>Serializes this event to a JSON string.</summary>`);
540-
lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, `}`, "");
542+
lines.push(` public string ToJson() =>`, ` JsonSerializer.Serialize(this, SessionEventsJsonContext.Default.SessionEvent);`, "");
543+
lines.push(` [DebuggerBrowsable(DebuggerBrowsableState.Never)]`, ` private string DebuggerDisplay => ToJson();`);
544+
lines.push(`}`, "");
541545

542546
// Event classes with XML docs
543547
for (const variant of variants) {

0 commit comments

Comments
 (0)