Skip to content

Add additional properties callback in Inspector Serialization Delegate - #45531

Merged
albertusdev merged 8 commits into
flutter:masterfrom
albertusdev:add-additional-properties-callback-widget-inspector-delegate
Nov 26, 2019
Merged

albertusdev merged 8 commits into
flutter:masterfrom
albertusdev:add-additional-properties-callback-widget-inspector-delegate

Conversation

@albertusdev

@albertusdev albertusdev commented Nov 25, 2019 •

Copy link
Copy Markdown
Contributor

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 addAdditionalPropertiesCallback

Checklist

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@albertusdev
albertusdev requested a review from jacob314 November 25, 2019 09:09
@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 25, 2019
@fluttergithubbot

Copy link
Copy Markdown
Contributor

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.

Comment thread packages/flutter/lib/src/widgets/widget_inspector.dart Outdated

@jacob314 jacob314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@albertusdev albertusdev changed the title [WIP] Add additional properties callback in Inspector Serialization Delegate Add additional properties callback in Inspector Serialization Delegate Nov 25, 2019
@albertusdev
albertusdev force-pushed the add-additional-properties-callback-widget-inspector-delegate branch from 4f5b9aa to 6d46ed1 Compare November 25, 2019 22:32
@albertusdev

Copy link
Copy Markdown
Contributor Author

@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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unsafeDelegate to emptyDelegate.

@jacob314 jacob314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@jacob314
jacob314 requested a review from goderbauer November 26, 2019 01:08

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[RenderObject]

/// 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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Element]

///
/// The following code samples demonstrates adding the RenderObject associated
/// with an Element to the serialized data for all elements in the tree:
/// ```dart

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really document what this property is for.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I agree.


final List<DiagnosticsNode> _nodesCreatedByLocalProject = <DiagnosticsNode>[];

/// Whether the Inspector is interactive or not

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what it means to be interactive?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this!

/// ) {
/// return _nodeToJson(
/// root,
/// InspectorSerializationDelegate(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would I run this code? InspectorSerializationDelegate is marked as visibleForTesting, so would this only be in test code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@albertusdev

Copy link
Copy Markdown
Contributor Author

@goderbauer ready for another round of review after improving the docs :-)

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@albertusdev
albertusdev merged commit e1512b4 into flutter:master Nov 26, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants