updateDtdWorkspaceRoots static method
Implementation
@visibleForTesting
static Future<shelf.Response> updateDtdWorkspaceRoots(
DTDConnectionInfo dtd, {
required Uri rootFromVmService,
required bool connected,
required ServerApi api,
}) async {
DartToolingDaemon? dartToolingDaemon;
try {
dartToolingDaemon = await DartToolingDaemon.connect(Uri.parse(dtd.uri!));
final currentRoots = (await dartToolingDaemon.getIDEWorkspaceRoots())
.ideWorkspaceRoots
.toSet();
// Add or remove [rootFromVmService] depending on whether this was a
// connect or disconnect notification.
final newRoots = connected
? (currentRoots..add(rootFromVmService)).toList()
: (currentRoots..remove(rootFromVmService)).toList();
await dartToolingDaemon.setIDEWorkspaceRoots(dtd.secret!, newRoots);
return api.success();
} catch (e) {
return api.serverError('$e');
} finally {
await dartToolingDaemon?.close();
}
}