feat: Expand multidimensional array and dictionary previews in CapturedVariables#1921
Conversation
…pause-point CapturedVariables The collection preview serializer had two independent bugs affecting CapturedVariables output: 1. Enum values inside arrays/dictionaries serialized as their underlying integer (e.g. [0,null,1]) instead of their name, diverging from the scalar-capture path which already renders enums by name. Fixed by registering StringEnumConverter on the shared primitive JsonSerializer. 2. A T?[,] or Dictionary<K,V> reached two field-access hops deep (e.g. Board._cells) exhausted the remaining preview depth budget before BuildToken ever inspected the collection itself, degrading it to a bare type-name ToString fallback -- reproducing the reported Tetris board symptom exactly. Fixed by exempting arrays/dictionaries whose elements/keys/values are all primitives, enums, or strings from the depth gate, since those leaf values already resolve independent of depth. Collections of non-primitive objects still degrade at the depth limit as before.
📝 WalkthroughWalkthroughThe preview serializer now renders enum names and preserves JSON expansion for primitive arrays and dictionaries at depth limits. New formatter tests cover nullable enum arrays, nested field access, primitive dictionary serialization, and custom-object fallback behavior. ChangesPause point preview serialization
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/PausePoint/SourcePausePointCollectionPreviewSerializer.cs (1)
126-129: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider supporting generic collections (like
List<T>) for primitive JSON expansion at depth limits.Currently, this depth-limit exception explicitly targets
ArrayandIDictionary. This perfectly fulfills the PR's objective, but it means that a primitive list (e.g.,List<int>) nested at the depth limit will still fall throughisPrimitiveElementArrayand degrade to a type-name string fallback.If you want to allow all generic collections of primitives to remain JSON-expandable at depth limits, consider expanding this check to inspect
IEnumerable<T>orICollection<T>to cover common types likeList<T>andHashSet<T>.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Packages/src/Editor/FirstPartyTools/PausePoint/SourcePausePointCollectionPreviewSerializer.cs` around lines 126 - 129, Extend the depth-limit primitive collection detection around isPrimitiveElementArray to recognize generic IEnumerable<T> or ICollection<T> implementations, including List<T> and HashSet<T>, while preserving the existing array and dictionary checks. Ensure the element type is validated with IsJsonPrimitiveElementType so only collections of JSON primitives remain expandable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@Packages/src/Editor/FirstPartyTools/PausePoint/SourcePausePointCollectionPreviewSerializer.cs`:
- Around line 126-129: Extend the depth-limit primitive collection detection
around isPrimitiveElementArray to recognize generic IEnumerable<T> or
ICollection<T> implementations, including List<T> and HashSet<T>, while
preserving the existing array and dictionary checks. Ensure the element type is
validated with IsJsonPrimitiveElementType so only collections of JSON primitives
remain expandable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b2ecd05e-44c3-4cd4-bde6-de560cacb210
📒 Files selected for processing (2)
Assets/Tests/Editor/SourcePausePointCapture/SourcePausePointVariableFormatterTests.csPackages/src/Editor/FirstPartyTools/PausePoint/SourcePausePointCollectionPreviewSerializer.cs
3303491
into
feature/round7-pause-point-improvements
Summary
User Impact
Before this fix, inspecting a captured variable like a Tetris board's
_cellsfield (PieceType?[,]) showed only an opaque type-name string such as"System.Nullable\1[...PieceType][,]"-- no shape, no cell values. NestedDictionary<string, int>fields hit the same problem. Separately, even where a preview did expand, enum elements showed up as raw integers ([0,null,1]`) instead of readable names.After this fix:
Board._cells(and any array/dictionary of primitives, enums, or strings) previews as a realShape/Elements(or key/value) structure at any nesting depth reachable from a captured variable.["Alpha",null,"Beta"]), consistent with how a plain enum-typed local already renders.Changes
SourcePausePointCollectionPreviewSerializer.cs:StringEnumConverteron the shared primitiveJsonSerializerso enum values serialize by name.IsJsonPrimitiveElementType/IsPrimitiveKeyValueDictionaryTypeto detect arrays/dictionaries whose elements (or keys and values) are all primitives, enums, or strings, and exempt those from theremainingDepth <= 0fallback gate.Verification
dist/darwin-arm64/uloop compile --project-path .: 0 errors, 0 warningsdist/darwin-arm64/uloop run-tests --filter-type regex --filter-value "SourcePausePointVariableFormatterTests" --test-mode EditMode: 42/42 passed (6 new tests covering 1D/2D nullable-enum arrays, primitive-value dictionaries, and the two-hop nesting boundary for both, plus a boundary case confirming non-primitive collections still respect the depth limit)dist/darwin-arm64/uloop run-tests --filter-type regex --filter-value "SourcePausePoint" --test-mode EditMode: 124/124 passed, no regressions