-
Notifications
You must be signed in to change notification settings - Fork 6
[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
Conversation
PR HealthChangelog Entry ✔️
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())], |
There was a problem hiding this comment.
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?
content: [TextContent(text: widget.toString())], | |
content: [TextContent(text: jsonEncode(widget)], |
Or maybe even:
content: [TextContent(text: widget.toString())], | |
content: [TextContent(text: JsonEncoder.withIndent(' ').encode(widget)], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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?
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. |
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 usegetSelectedSummaryWidget
instead ofgetSelectedWidget
because this tool will likely be useful in the context of the user's code.