Skip to content

Commit 028038b

Browse files
authored
Support Set instance inspection in debugger page (#5323)
1 parent c4601a1 commit 028038b

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart

+17-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ class DartObjectNode extends TreeNode<DartObjectNode> {
243243
(value.kind!.endsWith('List') ||
244244
value.kind == InstanceKind.kList ||
245245
value.kind == InstanceKind.kMap ||
246-
value.kind == InstanceKind.kRecord)) {
246+
value.kind == InstanceKind.kRecord ||
247+
isSet)) {
247248
return value.length ?? 0;
248249
}
249250
}
@@ -253,6 +254,20 @@ class DartObjectNode extends TreeNode<DartObjectNode> {
253254

254255
int? _childCount;
255256

257+
// TODO(elliette): Can remove this workaround once DWDS correctly returns
258+
// InstanceKind.kSet for the kind of `Sets`. See:
259+
// https://github.com/dart-lang/webdev/issues/2001
260+
bool get isSet {
261+
final value = this.value;
262+
if (value is InstanceRef) {
263+
final kind = value.kind ?? '';
264+
if (kind == InstanceKind.kSet) return true;
265+
final name = value.classRef?.name ?? '';
266+
if (name.contains('Set')) return true;
267+
}
268+
return false;
269+
}
270+
256271
bool treeInitializeStarted = false;
257272
bool treeInitializeComplete = false;
258273

@@ -319,6 +334,7 @@ class DartObjectNode extends TreeNode<DartObjectNode> {
319334
// List, Map, Uint8List, Uint16List, etc...
320335
if (kind != null && kind == InstanceKind.kList ||
321336
kind == InstanceKind.kMap ||
337+
kind == InstanceKind.kSet ||
322338
kind!.endsWith('List')) {
323339
// TODO(elliette): Determine the signature from type parameters, see:
324340
// https://api.flutter.dev/flutter/vm_service/ClassRef/typeParameters.html

packages/devtools_app/lib/src/shared/diagnostics/tree_builder.dart

+5
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ Future<void> _addChildrenToInstanceVariable({
259259
default:
260260
break;
261261
}
262+
263+
if (variable.isSet) {
264+
variable.addAllChildren(createVariablesForSets(value, isolateRef));
265+
}
266+
262267
if (value.fields != null && value.kind != InstanceKind.kRecord) {
263268
variable.addAllChildren(
264269
createVariablesForFields(

packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart

+13
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,19 @@ List<DartObjectNode> createVariablesForBytes(
461461
return variables;
462462
}
463463

464+
List<DartObjectNode> createVariablesForSets(
465+
Instance instance,
466+
IsolateRef? isolateRef,
467+
) {
468+
final elements = instance.elements ?? [];
469+
return elements.map((element) {
470+
return DartObjectNode.fromValue(
471+
value: element,
472+
isolateRef: isolateRef,
473+
);
474+
}).toList();
475+
}
476+
464477
List<DartObjectNode> createVariablesForList(
465478
Instance instance,
466479
IsolateRef? isolateRef,

packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ in deeply nested trees - [#5181](https://github.com/flutter/devtools/pull/5181)
2929
* Add support for browser navigation history when navigating using the `File Explorer` [#4906](https://github.com/flutter/devtools/pull/4906).
3030
* Designate positional fields for `Record` types with the getter syntax beginning at `$1` [#5272](https://github.com/flutter/devtools/pull/5272)
3131
* Fix variable inspection for `Map` and `List` instances: [#5320](https://github.com/flutter/devtools/pull/5320)
32+
* Fix variable inspection for `Set` instances: [#5323](https://github.com/flutter/devtools/pull/5323)
3233

3334
## Network profiler updates
3435
* Improve reliability and performance of the Network tab - [#5056](https://github.com/flutter/devtools/pull/5056)

0 commit comments

Comments
 (0)