Repository navigation
Add additional properties callback in Inspector Serialization Delegate - #45531
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
jacob314
left a comment
There was a problem hiding this comment.
Add a test to widget_inspector_test.dart
verifying the callback works as expected. You will find some existing code that tests the service extensions. You could write a test that simulates registering a custom service extension like the one you need to register from DevTools. In widget_inspector_test.dart, the service extension logic is stubbed out so it is easy to trigger service extensions and validate the responses.
4f5b9aa to
6d46ed1
Compare
|
@jacob314 ready for your another round of review before requesting review from Flutter team, might need your suggestion on the docs as well since we make the SerializationDelegate public now |
| /// | ||
| /// Example usage: | ||
| /// | ||
| /// Map<String, Object> getDetailsSubtreeWithRenderObject( |
There was a problem hiding this comment.
wrap this code example with
"```dart"
| /// the following expression to register a VM Service API with a custom serialization | ||
| /// to experiment with visualizing layouts. | ||
| /// | ||
| /// Example usage: |
There was a problem hiding this comment.
Replace "Example usage:" with
The following code samples demonstrates adding the RenderObject associated with an Element to the
serialized data for all elements in the tree.
| /// Callback to add additional experimental serialization properties. | ||
| /// | ||
| /// This callback can be used to customize the serialization of DiagnosticsNode | ||
| /// objects for experimental features. For example, Dart DevTools can evaluate |
There was a problem hiding this comment.
replace
"Dart Devtools"
with
[Dart Devtools](https://github.com/flutter/devtools)
|
|
||
| class _SerializationDelegate implements DiagnosticsSerializationDelegate { | ||
| _SerializationDelegate({ | ||
| /// A delegate that configures how a hierarchy of [DiagnosticsNode]s should be |
There was a problem hiding this comment.
Add a @visibleForTesting annotation.
Tweak the comment to
/// A delegate that configures how a hierarchy of [DiagnosticsNode]s are
/// serialized by the Flutter Inspector.
| delegate.copyWith(subtreeDepth: 0), | ||
| ); | ||
| } | ||
| additionalJson['callbackIsCalled'] = true; |
There was a problem hiding this comment.
nit: callbackIsCalled -->
callbackExecuted
| expect(json['renderObject'], isA<Map<String, dynamic>>()); | ||
| final Map<String, dynamic> renderObjectJson = json['renderObject']; | ||
| expect(renderObjectJson['description'], startsWith('RenderFlex')); | ||
| final InspectorSerializationDelegate unsafeDelegate = |
There was a problem hiding this comment.
nit: add a line break before lin 2652.
| expect(json['renderObject'], isA<Map<String, dynamic>>()); | ||
| final Map<String, dynamic> renderObjectJson = json['renderObject']; | ||
| expect(renderObjectJson['description'], startsWith('RenderFlex')); | ||
| final InspectorSerializationDelegate unsafeDelegate = |
There was a problem hiding this comment.
nit: unsafeDelegate to emptyDelegate.
jacob314
left a comment
There was a problem hiding this comment.
a few minor nits.
This functionality will be really useful for us to experiment with new Flutter Inspector features without landing code changes before the features are proven to be useful!
goderbauer
left a comment
There was a problem hiding this comment.
Looks good. Just some doc nits.
| /// can evaluate the following expression to register a VM Service API | ||
| /// with a custom serialization to experiment with visualizing layouts. | ||
| /// | ||
| /// The following code samples demonstrates adding the RenderObject associated |
| /// with a custom serialization to experiment with visualizing layouts. | ||
| /// | ||
| /// The following code samples demonstrates adding the RenderObject associated | ||
| /// with an Element to the serialized data for all elements in the tree: |
| /// | ||
| /// The following code samples demonstrates adding the RenderObject associated | ||
| /// with an Element to the serialized data for all elements in the tree: | ||
| /// ```dart |
There was a problem hiding this comment.
Add a blank line before this.
| /// Service used by GUI tools to interact with the [WidgetInspector]. | ||
| final WidgetInspectorService service; | ||
|
|
||
| /// The `groupName` parameter is not needed but is specified to regularize the |
There was a problem hiding this comment.
This doesn't really document what this property is for.
There was a problem hiding this comment.
Alright, I agree.
|
|
||
| final List<DiagnosticsNode> _nodesCreatedByLocalProject = <DiagnosticsNode>[]; | ||
|
|
||
| /// Whether the Inspector is interactive or not |
There was a problem hiding this comment.
Can you document what it means to be interactive?
| // that also exist in the summary tree. This ensures that every time | ||
| // you expand a node in the details tree, you expand the entire subtree | ||
| // up until you reach the next nodes shared with the summary tree. | ||
| // up until you reach the next nodes shared with the sum mary tree. |
There was a problem hiding this comment.
Thank you for catching this!
| /// ) { | ||
| /// return _nodeToJson( | ||
| /// root, | ||
| /// InspectorSerializationDelegate( |
There was a problem hiding this comment.
Where would I run this code? InspectorSerializationDelegate is marked as visibleForTesting, so would this only be in test code?
There was a problem hiding this comment.
Debugging tools such as Dart DevTools can access it even if it was still private via the VM Service protocol. It is marked @visibleForTesting so we can test it from widget_inspector_test.dart
There was a problem hiding this comment.
This code is run through the eval in the Dart DevTools.
But currently in the flutter framework yes it is only in the test code.
|
@goderbauer ready for another round of review after improving the docs :-) |
Description
Added callback to add additional experimental serialization properties.
This callback can be used to customize the serialization of DiagnosticsNode objects for experimental features. For example, Dart DevTools can evaluate the following expression to register a VM Service API with a custom serialization to experiment with visualizing layouts.
Related Issues
Tests
I added the following tests:
InspectorSerializationDelegate addAdditionalPropertiesCallbackChecklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?