Skip to content

[dart_tooling_mcp_server] add tool for getting the selected widget #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 17, 2025

Conversation

kenzieschmoll
Copy link
Contributor

This PR adds a tool that gets the selected widget from the Widget Inspector for a running Flutter app. In its current form, this tool calls the ext.flutter.inspector.getSelectedSummaryWidget service extension. I opted to use getSelectedSummaryWidget instead of getSelectedWidget because this tool will likely be useful in the context of the user's code.

Copy link

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

final isolateId = vm.isolates!.first.id;
try {
final result = await vmService.callServiceExtension(
'$_inspectorServiceExtensionPrefix.getSelectedSummaryWidget',
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this determine what things are "user code"? Do we need to call addPubRootDirectories? Or do we assume something else is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Dart Code extension / Flutter IntelliJ plugin already do this today. Otherwise we assume the pub root directories is the root of the running app. CC @elliette to confirm this is how things still work today.

Choose a reason for hiding this comment

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

Yes, that matches my understanding. Though it looks like the call to addPubRootDirectories was removed from the IntelliJ plugin: flutter/flutter-intellij@1c1389f

FYI @pq @jwren this is another piece of code that might need to be added back

);
}
return CallToolResult(
content: [TextContent(text: widget.toString())],
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do this instead?

Suggested change
content: [TextContent(text: widget.toString())],
content: [TextContent(text: jsonEncode(widget)],

Or maybe even:

Suggested change
content: [TextContent(text: widget.toString())],
content: [TextContent(text: JsonEncoder.withIndent(' ').encode(widget)],

Copy link
Contributor Author

@kenzieschmoll kenzieschmoll Apr 16, 2025

Choose a reason for hiding this comment

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

Used jsonEncode. Will the added new lines caused by using .withIndent have any impact on the LLM trying to parse this information? In terms of using up more tokens than necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

It probably is just a waste of tokens yes, no idea how it might affect its ability to reason about it either positively or negatively 🤷‍♂️ .

Just jsonEncode SGTM though

Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

LGTM with some nits - should we also add enabling/disabling the widget inspector?

@kenzieschmoll
Copy link
Contributor Author

should we also add enabling/disabling the widget inspector

Good question. It's not immediately clear to me what the use case for this would be. Do you have one in mind?

@kenzieschmoll kenzieschmoll requested a review from jakemac53 April 16, 2025 22:22
@jakemac53
Copy link
Contributor

jakemac53 commented Apr 17, 2025

Good question. It's not immediately clear to me what the use case for this would be. Do you have one in mind?

Basically the idea is it would give the LLM the ability to decide that it should be asking the user to select a widget based on some query, and handle enabling the inspector for them and then prompt them to select the widget.

It also could enable some more "no code" scenarios, where a user doesn't have a full IDE or DevTools available but they could still enable the widget inspector via chat.

@kenzieschmoll kenzieschmoll merged commit 7e07e62 into main Apr 17, 2025
13 checks passed
@kenzieschmoll kenzieschmoll deleted the getSelectedWidget branch April 17, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants