Unverified Commit 853415dd authored by Devon Carew's avatar Devon Carew Committed by GitHub

send back Widget class name information in the widget rebuild/repaint count events (#84804)

send back Widget class name information in the widget rebuild/repaint count event
parent 3ee1d46d
......@@ -1527,10 +1527,10 @@ mixin WidgetInspectorService {
}
bool _isLocalCreationLocation(_Location? location) {
if (location == null || location.file == null) {
if (location == null) {
return false;
}
final String file = Uri.parse(location.file!).path;
final String file = Uri.parse(location.file).path;
// By default check whether the creation location was within package:flutter.
if (_pubRootDirectories == null) {
......@@ -2127,16 +2127,32 @@ class _ElementLocationStatsTracker {
final Map<String, List<int>> locationsJson = <String, List<int>>{};
for (final _LocationCount entry in newLocations) {
final _Location location = entry.location;
if (location.file != null) {
final List<int> jsonForFile = locationsJson.putIfAbsent(
location.file!,
location.file,
() => <int>[],
);
jsonForFile..add(entry.id)..add(location.line)..add(location.column);
}
}
json['newLocations'] = locationsJson;
}
// Add in a data structure for the location names.
if (newLocations.isNotEmpty) {
final Map<String, Map<int, String>> namesJson = <String, Map<int, String>>{};
for (final _LocationCount entry in newLocations) {
final _Location location = entry.location;
final Map<int, String> jsonForFile = namesJson.putIfAbsent(
location.file,
() => <int, String>{},
);
final String? name = location.name;
if (name != null) {
jsonForFile[entry.id] = name;
}
}
json['newLocationsNames'] = namesJson;
}
resetCounts();
newLocations.clear();
return json;
......@@ -2852,23 +2868,20 @@ class _Location {
required this.line,
required this.column,
this.name,
this.parameterLocations,
});
/// File path of the location.
final String? file;
final String file;
/// 1-based line number.
final int line;
/// 1-based column number.
final int column;
/// Optional name of the parameter or function at this location.
final String? name;
/// Optional locations of the parameters of the member at this location.
final List<_Location>? parameterLocations;
Map<String, Object?> toJsonMap() {
final Map<String, Object?> json = <String, Object?>{
'file': file,
......@@ -2878,11 +2891,6 @@ class _Location {
if (name != null) {
json['name'] = name;
}
if (parameterLocations != null) {
json['parameterLocations'] = parameterLocations!.map<Map<String, Object?>>(
(_Location location) => location.toJsonMap(),
).toList();
}
return json;
}
......@@ -2892,9 +2900,7 @@ class _Location {
if (name != null) {
parts.add(name!);
}
if (file != null) {
parts.add(file!);
}
parts.add(file);
parts..add('$line')..add('$column');
return parts.join(':');
}
......
......@@ -134,17 +134,19 @@ class CyclicDiagnostic extends DiagnosticableTree {
}
class _CreationLocation {
const _CreationLocation({
_CreationLocation({
required this.file,
required this.line,
required this.column,
required this.id,
this.name,
});
final String file;
final int line;
final int column;
final int id;
String? name;
}
typedef InspectorServiceExtensionCallback = FutureOr<Map<String, Object>> Function(Map<String, String> parameters);
......@@ -943,6 +945,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final String fileA = creationLocationA['file']! as String;
final int lineA = creationLocationA['line']! as int;
final int columnA = creationLocationA['column']! as int;
final String nameA = creationLocationA['name']! as String;
expect(nameA, equals('Text'));
service.setSelection(elementB, 'my-group');
final Map<String, Object?> jsonB = json.decode(service.getSelectedWidget(null, 'my-group')) as Map<String, Object?>;
......@@ -951,6 +955,8 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final String fileB = creationLocationB['file']! as String;
final int lineB = creationLocationB['line']! as int;
final int columnB = creationLocationB['column']! as int;
final String? nameB = creationLocationB['name'] as String?;
expect(nameB, equals('Text'));
expect(fileA, endsWith('widget_inspector_test.dart'));
expect(fileA, equals(fileB));
// We don't hardcode the actual lines the widgets are created on as that
......@@ -1919,6 +1925,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(newLocations, isNotNull);
expect(newLocations.length, equals(1));
expect(newLocations.keys.first, equals(file));
final Map<String, Map<int, String>> newLocationsNames = event['newLocationsNames']! as Map<String, Map<int, String>>;
expect(newLocationsNames, isNotNull);
expect(newLocationsNames.length, equals(1));
expect(newLocationsNames.keys.first, equals(file));
final List<int> locationsForFile = newLocations[file]!;
expect(locationsForFile.length, equals(21));
final int numLocationEntries = locationsForFile.length ~/ 3;
......@@ -1928,6 +1938,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
_addToKnownLocationsMap(
knownLocations: knownLocations,
newLocations: newLocations,
newLocationsNames: newLocationsNames,
);
int totalCount = 0;
int maxCount = 0;
......@@ -1956,6 +1967,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
data = event['events']! as List<int>;
// No new locations were rebuilt.
expect(event, isNot(contains('newLocations')));
expect(event, isNot(contains('newLocationsNames')));
// There were two rebuilds: one for the ClockText element itself and one
// for its child.
......@@ -1967,6 +1979,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// ClockText widget.
expect(location.line, equals(53));
expect(location.column, equals(9));
expect(location.name, equals('ClockText'));
expect(count, equals(1));
id = data[2];
......@@ -1976,6 +1989,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// Text widget in _ClockTextState build method.
expect(location.line, equals(91));
expect(location.column, equals(12));
expect(location.name, equals('Text'));
expect(count, equals(1));
// Update 3 of the clocks;
......@@ -1992,6 +2006,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
data = event['events']! as List<int>;
// No new locations were rebuilt.
expect(event, isNot(contains('newLocations')));
expect(event, isNot(contains('newLocationsNames')));
expect(data.length, equals(4));
id = data[0];
......@@ -2001,6 +2016,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// ClockText widget.
expect(location.line, equals(53));
expect(location.column, equals(9));
expect(location.name, equals('ClockText'));
expect(count, equals(3)); // 3 clock widget instances rebuilt.
id = data[2];
......@@ -2010,6 +2026,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
// Text widget in _ClockTextState build method.
expect(location.line, equals(91));
expect(location.column, equals(12));
expect(location.name, equals('Text'));
expect(count, equals(3)); // 3 clock widget instances rebuilt.
// Update one clock 3 times.
......@@ -2026,6 +2043,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
data = event['events']! as List<int>;
// No new locations were rebuilt.
expect(event, isNot(contains('newLocations')));
expect(event, isNot(contains('newLocationsNames')));
expect(data.length, equals(4));
id = data[0];
......@@ -2053,6 +2071,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
_addToKnownLocationsMap(
knownLocations: knownLocations,
newLocations: newLocations,
newLocationsNames: newLocationsNames,
);
// Verify the rebuild location was included in the newLocations data.
expect(knownLocations, contains(id));
......@@ -2117,6 +2136,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(newLocations, isNotNull);
expect(newLocations.length, equals(1));
expect(newLocations.keys.first, equals(file));
final Map<String, Map<int, String>> newLocationsNames = event['newLocationsNames']! as Map<String, Map<int, String>>;
expect(newLocationsNames, isNotNull);
expect(newLocationsNames.length, equals(1));
expect(newLocationsNames.keys.first, equals(file));
final List<int> locationsForFile = newLocations[file]!;
expect(locationsForFile.length, equals(27));
final int numLocationEntries = locationsForFile.length ~/ 3;
......@@ -2127,6 +2150,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
_addToKnownLocationsMap(
knownLocations: knownLocations,
newLocations: newLocations,
newLocationsNames: newLocationsNames,
);
int totalCount = 0;
int maxCount = 0;
......@@ -2155,6 +2179,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
data = event['events']! as List<int>;
// No new locations were rebuilt.
expect(event, isNot(contains('newLocations')));
expect(event, isNot(contains('newLocationsNames')));
// Triggering a rebuild of one widget in this app causes the whole app
// to repaint.
......@@ -3008,6 +3033,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
void _addToKnownLocationsMap({
required Map<int, _CreationLocation> knownLocations,
required Map<String, List<int>> newLocations,
required Map<String, Map<int, String>> newLocationsNames,
}) {
newLocations.forEach((String file, List<int> entries) {
assert(entries.length % 3 == 0);
......@@ -3020,4 +3046,9 @@ void _addToKnownLocationsMap({
_CreationLocation(file: file, line: line, column: column, id: id);
}
});
newLocationsNames.forEach((String file, Map<int, String> namesInfo) {
namesInfo.forEach((int id, String name) {
knownLocations[id]!.name = name;
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment