Support `Set` instance inspection in debugger page (#5323)
diff --git a/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart b/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart index 4acf1f1..333e996 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart
@@ -243,7 +243,8 @@ (value.kind!.endsWith('List') || value.kind == InstanceKind.kList || value.kind == InstanceKind.kMap || - value.kind == InstanceKind.kRecord)) { + value.kind == InstanceKind.kRecord || + isSet)) { return value.length ?? 0; } } @@ -253,6 +254,20 @@ int? _childCount; + // TODO(elliette): Can remove this workaround once DWDS correctly returns + // InstanceKind.kSet for the kind of `Sets`. See: + // https://github.com/dart-lang/webdev/issues/2001 + bool get isSet { + final value = this.value; + if (value is InstanceRef) { + final kind = value.kind ?? ''; + if (kind == InstanceKind.kSet) return true; + final name = value.classRef?.name ?? ''; + if (name.contains('Set')) return true; + } + return false; + } + bool treeInitializeStarted = false; bool treeInitializeComplete = false; @@ -319,6 +334,7 @@ // List, Map, Uint8List, Uint16List, etc... if (kind != null && kind == InstanceKind.kList || kind == InstanceKind.kMap || + kind == InstanceKind.kSet || kind!.endsWith('List')) { // TODO(elliette): Determine the signature from type parameters, see: // https://api.flutter.dev/flutter/vm_service/ClassRef/typeParameters.html
diff --git a/packages/devtools_app/lib/src/shared/diagnostics/tree_builder.dart b/packages/devtools_app/lib/src/shared/diagnostics/tree_builder.dart index b3b8c24..155020e 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/tree_builder.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/tree_builder.dart
@@ -259,6 +259,11 @@ default: break; } + + if (variable.isSet) { + variable.addAllChildren(createVariablesForSets(value, isolateRef)); + } + if (value.fields != null && value.kind != InstanceKind.kRecord) { variable.addAllChildren( createVariablesForFields(
diff --git a/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart b/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart index 0fc789c..14c5d4d 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart
@@ -461,6 +461,19 @@ return variables; } +List<DartObjectNode> createVariablesForSets( + Instance instance, + IsolateRef? isolateRef, +) { + final elements = instance.elements ?? []; + return elements.map((element) { + return DartObjectNode.fromValue( + value: element, + isolateRef: isolateRef, + ); + }).toList(); +} + List<DartObjectNode> createVariablesForList( Instance instance, IsolateRef? isolateRef,
diff --git a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md index 42f7814..a5c6876 100644 --- a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md +++ b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
@@ -29,6 +29,7 @@ * Add support for browser navigation history when navigating using the `File Explorer` [#4906](https://github.com/flutter/devtools/pull/4906). * Designate positional fields for `Record` types with the getter syntax beginning at `$1` [#5272](https://github.com/flutter/devtools/pull/5272) * Fix variable inspection for `Map` and `List` instances: [#5320](https://github.com/flutter/devtools/pull/5320) +* Fix variable inspection for `Set` instances: [#5323](https://github.com/flutter/devtools/pull/5323) ## Network profiler updates * Improve reliability and performance of the Network tab - [#5056](https://github.com/flutter/devtools/pull/5056)