disconnectImpl method
Closes and unsets the Dart Tooling Daemon connection, if one is set.
allowReconnect controls whether reconnection is allowed. This is
generally false for an explicit disconnect/dispose, but allowed if we
are called as part of a dropped connection. Reconnecting being allowed
does not necessarily mean it will happen, because there might have been
an explicit disconnect (or dispose) call before we got here.
Implementation
@visibleForTesting
Future<void> disconnectImpl({bool allowReconnect = false}) async {
if (!allowReconnect) {
// If we're not allowed to reconnect, disable this. `allowReconnect` being
// true does NOT mean we can enable this, because we might get here after
// an explicit disconnect.
_automaticallyReconnect = false;
// We only close and clear the connection if we are explicitly
// disconnecting.
//
// In the case where the connection just dropped, we leave it so
// that we can continue to render a page (usually with an overlay), then
// only close it once the new connection is established.
if (_connection.value case final connection?) {
await connection.close();
}
_connection.value = null;
}
_periodicConnectionCheck?.cancel();
_connectionState.value = NotConnectedDTDState();
_uri = null;
_workspaceRoots = null;
_projectRoots = null;
}