Description
Background
The Dart Tooling Daemon (DTD) is either started by DDS / DevTools server, in the case where an app is started from the CLI, or an IDE plugin / extension (VS Code, Android Studio, or IntelliJ), in the case where an app is started from the IDE. This means that DTD may be connected to a development workflow that has one or many running apps.
For DTD clients like DevTools and the new Dart Tooling MCP Server, a client may need to fetch the list of active debug sessions (the running Dart / Flutter apps). In the case where DTD is started from a 1P supported IDE (VS Code or Android Studio / IntelliJ), the IDE provides an EditorService from which a client can get the list of active debug sessions, and therefore the list of the active VM Service URIs. However, in the case where a 1P supported IDE did NOT start DTD, this service will be unavailable and there is no way to get the VM service URI of the running app(s).
The following is a proposed solution to this problem, allowing DTD to have awareness of the connected Dart & Flutter applications that the DTD clients are interacting with.
Proposed solution
Create a new service ConnectedAppService directly in DTD that provides the methods:
- [Protected]
void registerVmService(String uri)
List<String> getVmServiceUris()
[Protected] here means that the only DTD client that started DTD (either the IDE or DDS / DevTools server) should be able to call this method. We can use the same client secret that we require for the setIDEWorkspaceRoots
method.
The ConnectedAppService
can maintain a set of VmService
objects for the VM service URIs that have been registered, which will allow the service to automatically clean up VmService
instances when they are shutdown.
[OPTIONAL] Instead of (or in addition to) getVmServiceUris()
, we could implement a stream for the VM Service URIs that DTD clients can subscribe to. Upon a client subscribing to this stream, all the current VM Service URIs should be sent. The stream should be updated with vmServiceRegistered
and vmServiceShutdown
events so that the client can update its set of URIs. This may not be necessary since the client can just request getVmServiceUris()
whenever an operation needs to know about the current set of VM service instances.
Implementation plan
- Build the
ConnectedAppService
in DTD. CC @bkonyi - [DDS] For the case of an app started from the CLI (dart or flutter), call the new method
ConnectedAppService.registerVmService
. This should be called whenever DDS (or DevTools server inside DDS) is responsible for starting DTD. - [Dart-Code extension] Call the new method
ConnectedAppService.registerVmService
when a new debug session is started. CC @DanTup - [IntelliJ Plugin] Call the new method
ConnectedAppService.registerVmService
when a new debug session is started. CC @jwren @pq - In the Dart Tooling MCP Server (the first DTD client that will be using this new service), initially call
ConnectedAppService.getVmServiceUris
only when theEditorService.getDebugSessions
method is not available. This will ensure that the Dart Tooling MCP Server is backwards compatible with older IDE plugin / extension versions. After some safe time period (12-18 months?), switch over to usingConnectedAppService.getVmServiceUris
exclusively. CC @jakemac53