Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,15 @@ class RemoteDiagnosticsNode extends DiagnosticableTree {
inHideableGroup && !isHideableGroupLeader && groupIsHidden;

bool get inHideableGroup {
final hasAtMostOneChild = childrenNow.length <= 1;
final isOnlyChild = (parent?.childrenNow ?? []).length == 1;
return !isCreatedByLocalProject && hasAtMostOneChild && isOnlyChild;
if (_alwaysVisible(this)) return false;
final parentIsHideable = parent != null && !_alwaysVisible(parent!);
final firstChildIsHideable =
childrenNow.isNotEmpty && !_alwaysVisible(childrenNow.first);

// A widget should only be included in a hideable group if either its parent
// or first child is hideable (if it's the only hideable widget then it's
// not part of a "group").
return parentIsHideable || firstChildIsHideable;
}

bool get isHideableGroupLeader {
Expand Down Expand Up @@ -619,6 +625,16 @@ class RemoteDiagnosticsNode extends DiagnosticableTree {
}
}

bool _alwaysVisible(RemoteDiagnosticsNode node) {
final isRoot = node.parent == null;
final hasMoreThanOneChild = node.hasChildren && node.childrenNow.length > 1;
final hasSiblings = (node.parent?.childrenNow ?? []).length > 1;
return isRoot ||
node.isCreatedByLocalProject ||
hasMoreThanOneChild ||
hasSiblings;
}

Future<void> _computeChildren() async {
_maybePopulateChildren();
if (!hasChildren || _children != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,27 @@ void main() {
});

group('hidden groups', () {
final implementationNodeWithNoChildren = buildNodeJson(
final implementationNodeWithNoChildren = buildImplementationNodeJson(
description: 'ImplementationNodeWithNoChildren',
createdByLocalProject: false,
children: [],
);

final implementationNodeWithSingleChild = buildNodeJson(
final implementationNodeWithSingleChild = buildImplementationNodeJson(
description: 'ImplementationNodeWithSingleChild',
createdByLocalProject: false,
children: [implementationNodeWithNoChildren],
);

final implementationNodeWithMultipleChildren = buildNodeJson(
final implementationNodeWithMultipleChildren =
buildImplementationNodeJson(
description: 'ImplementationNodeWithMultipleChildren',
createdByLocalProject: false,
children: [
implementationNodeWithNoChildren,
implementationNodeWithSingleChild,
],
);

final projectNodeWithSingleChild = buildNodeJson(
final projectNodeWithSingleChild = buildProjectNodeJson(
description: 'ProjectNodeWithSingleChild',
createdByLocalProject: true,
children: [
implementationNodeWithSingleChild,
],
Expand Down Expand Up @@ -147,6 +144,46 @@ void main() {
expect(node.inHideableGroup, isFalse);
});

test(
'if node\'s parent and child are both not hideable, it is not hideable',
() {
// Build the child as a project node (project nodes are NOT
// hideable):
final childJson = buildProjectNodeJson(children: []);
// Build the node as an implementation node (to be hideable, a node must
// be an implementation node):
final nodeJson = buildImplementationNodeJson(children: [childJson]);
// Build the parent as a project node (project nodes are NOT
// hideable):
final parentJson = buildProjectNodeJson(children: [nodeJson]);
final parent = buildNode(parentJson);
final node = buildNode(nodeJson, parent: parent);
final child = buildNode(childJson, parent: node);

expect(parent.inHideableGroup, isFalse);
expect(child.inHideableGroup, isFalse);
expect(node.inHideableGroup, isFalse);
},
);

test(
'if node\'s parent is not hideable and it has no children, it is not hideable',
() {
// Build the node as an implementation node (to be hideable, a node must
// be an implementation node):
final nodeJson = buildImplementationNodeJson(children: []);
// Build the parent as a project node (project nodes are NOT
// hideable):
final parentJson = buildProjectNodeJson(children: [nodeJson]);
final parent = buildNode(parentJson);
final node = buildNode(nodeJson, parent: parent);

expect(parent.inHideableGroup, isFalse);
expect(node.hasChildren, isFalse);
expect(node.inHideableGroup, isFalse);
},
);

test('otherwise, node is hideable', () {
final node = buildHideableNode();
expect(node.inHideableGroup, isTrue);
Expand Down Expand Up @@ -225,6 +262,26 @@ void main() {
});
}

Map<String, dynamic> buildImplementationNodeJson({
required List<Map<String, dynamic>> children,
String? description,
}) =>
buildNodeJson(
description: description ?? 'ImplementationNode',
createdByLocalProject: false,
children: children,
);

Map<String, dynamic> buildProjectNodeJson({
required List<Map<String, dynamic>> children,
String? description,
}) =>
buildNodeJson(
description: description ?? 'ProjectNode',
createdByLocalProject: true,
children: children,
);

Map<String, dynamic> buildNodeJson({
required String description,
required bool createdByLocalProject,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.