Skip to content

Add DebuggerDisplay to SessionEvent for better debugging#726

Open
stephentoub wants to merge 1 commit intomainfrom
stoub/debuggerdisplay
Open

Add DebuggerDisplay to SessionEvent for better debugging#726
stephentoub wants to merge 1 commit intomainfrom
stoub/debuggerdisplay

Conversation

@stephentoub
Copy link
Collaborator

@stephentoub stephentoub commented Mar 8, 2026

Adds [DebuggerDisplay] to the generated SessionEvent base class so that hovering over an event in the debugger shows its JSON representation.

Changes:

  • scripts/codegen/csharp.ts: Updated the C# code generator to emit using System.Diagnostics;, the [DebuggerDisplay] attribute, and a DebuggerDisplay property on the SessionEvent base class.
  • dotnet/src/Generated/SessionEvents.cs: Regenerated output reflecting the generator changes.

Before:
image

After:
image

@stephentoub stephentoub requested a review from a team as a code owner March 8, 2026 15:03
Copilot AI review requested due to automatic review settings March 8, 2026 15:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a .NET debugging convenience to the generated SessionEvent model so developers can quickly inspect session events as JSON in the debugger, aligning with the SDK’s generated-model workflow.

Changes:

  • Update the C# session-events code generator to emit using System.Diagnostics; and a [DebuggerDisplay] attribute on SessionEvent.
  • Add a hidden DebuggerDisplay property that returns ToJson() for debugger visualization.
  • Regenerate dotnet/src/Generated/SessionEvents.cs to reflect the new attribute/property.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
scripts/codegen/csharp.ts Emits DebuggerDisplay/DebuggerBrowsable annotations and required System.Diagnostics using for generated session-event models.
dotnet/src/Generated/SessionEvents.cs Regenerated output: SessionEvent now shows JSON via debugger display and hides the helper property from property lists.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Cross-SDK Consistency Review

This PR adds a [DebuggerDisplay] attribute to the .NET SDK's generated SessionEvent base class, which improves the debugging experience by showing the event's JSON representation when hovering over an event instance in the Visual Studio debugger.

Analysis

This is a language-specific developer experience enhancement that leverages .NET's debugging infrastructure. While this is a valuable improvement for .NET developers, similar debugging enhancements could be considered for other language SDKs to maintain feature parity in developer experience:

Python

The Python SDK uses @dataclass for SessionEvent (in python/copilot/generated/session_events.py), which auto-generates a basic __repr__. However, it could benefit from a custom __repr__ method that returns the JSON representation for easier debugging:

def __repr__(self) -> str:
    import json
    return json.dumps(self.to_dict(), default=str)

This would need to be added to the Python code generator (scripts/codegen/python.ts).

Go

The Go SDK has a Marshal() method on SessionEvent but doesn't implement the fmt.Stringer interface. Adding a String() method would improve debugging output in tools like Delve:

func (r SessionEvent) String() string {
    b, _ := r.Marshal()
    return string(b)
}

This would need to be added to the Go code generator (scripts/codegen/go.ts).

TypeScript/Node.js

The TypeScript SDK uses union types for SessionEvent, which don't support method definitions. JavaScript/TypeScript objects already display reasonably in debuggers, so this is less critical. However, if SessionEvent were a class, a toString() method could be added.

Recommendation

This PR is good to merge as-is since it's a valid .NET-specific enhancement. However, I suggest considering follow-up issues to add equivalent debugging enhancements to the other SDKs for consistency in developer experience:

  • Python: Add custom __repr__ to SessionEvent dataclass
  • Go: Implement String() method on SessionEvent
  • TypeScript: Evaluate if class-based events with toString() would be beneficial (lower priority)

These enhancements would ensure all SDK users get a similarly great debugging experience regardless of their language choice.


Summary: ✅ No blocking consistency issues. This is a language-appropriate enhancement. Consider adding similar debugging aids to other SDKs in future work.

Generated by SDK Consistency Review Agent for issue #726 ·

Added [DebuggerDisplay] attribute to SessionEvent base class to show JSON in debugger views.
@stephentoub stephentoub force-pushed the stoub/debuggerdisplay branch from dbcedb5 to b660bc6 Compare March 10, 2026 02:20
@github-actions
Copy link
Contributor

✅ Cross-SDK Consistency Review: No Issues Found

I've reviewed this PR for consistency across all four SDK implementations (Node.js/TypeScript, Python, Go, and .NET).

Summary

This PR adds a .NET-specific debugging enhancement using the [DebuggerDisplay] attribute. This is appropriate and does not require changes to other SDKs because:

  1. Language-Specific Debugging Tool: The [DebuggerDisplay] attribute is a .NET-specific feature that integrates with Visual Studio and .NET debuggers. It has no direct equivalent in other languages.

  2. Current State Across SDKs:

    • TypeScript/Node.js: Uses plain TypeScript types (discriminated unions). Debuggers naturally show object properties via util.inspect() or standard JSON serialization.
    • Python: Uses @dataclass which provides default __repr__() output showing all fields. Python debuggers work well with this default representation.
    • Go: Uses quicktype-generated structs. Go debuggers (like Delve) display struct fields natively without needing custom String() methods.
    • .NET: Previously lacked good debugging representation; this PR fixes that.
  3. Idiomatic for Each Language:

    • Each SDK follows its language's conventions for debugging
    • TypeScript types don't have class methods (they're interfaces/type aliases)
    • Python dataclasses provide built-in repr functionality
    • Go uses standard struct field inspection
    • .NET benefits from [DebuggerDisplay] for rich Visual Studio integration
  4. Implementation is Consistent with Codegen Patterns: The change correctly updates both the C# code generator (scripts/codegen/csharp.ts) and the generated output, maintaining the repo's architecture.

Recommendation

Approve this PR. The debugging enhancement is language-appropriate and maintains the SDK design principle of following each language's idioms rather than forcing identical implementations across all platforms.

Generated by SDK Consistency Review Agent for issue #726 ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants