fix(tui): wait for embedded server's exit code

Uses the undocumented "error_exit" UI event for a different purpose:
When :detach is used on the server, send an "error_exit" with 0 `status`
to indicate that the server shouldn't wait for client exit.
This commit is contained in:
zeertzjq
2025-06-10 14:10:12 +08:00
parent b98eefd803
commit 2dba5abcb2
9 changed files with 104 additions and 39 deletions

View File

@@ -73,12 +73,26 @@ static void remote_ui_destroy(RemoteUI *ui)
xfree(ui);
}
void remote_ui_disconnect(uint64_t channel_id)
/// Removes the client on the given channel from the list of UIs.
///
/// @param err if non-NULL and there is no UI on the channel, set an error
/// @param send_error_exit send an "error_exit" event with 0 status first
void remote_ui_disconnect(uint64_t channel_id, Error *err, bool send_error_exit)
{
RemoteUI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
if (!ui) {
if (err != NULL) {
api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id);
}
return;
}
if (send_error_exit) {
MAXSIZE_TEMP_ARRAY(args, 1);
ADD_C(args, INTEGER_OBJ(0));
push_call(ui, "error_exit", args);
ui_flush_buf(ui);
}
pmap_del(uint64_t)(&connected_uis, channel_id, NULL);
ui_detach_impl(ui, channel_id);
remote_ui_destroy(ui);
@@ -233,12 +247,7 @@ void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error)
void nvim_ui_detach(uint64_t channel_id, Error *err)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{
if (!map_has(uint64_t, &connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id);
return;
}
remote_ui_disconnect(channel_id);
remote_ui_disconnect(channel_id, err, false);
}
/// Sends a "restart" UI event to the UI on the given channel.