updateDtdWorkspaceRoots static method

  1. @visibleForTesting
Future<Response> updateDtdWorkspaceRoots(
  1. DTDConnectionInfo dtd, {
  2. required Uri rootFromVmService,
  3. required bool connected,
  4. required ServerApi api,
})

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();
  }
}