mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 23:18:33 +00:00
startup: wait for embedder before executing startup commands and files
Give embeders a chance to set up nvim, by processing a request before startup. This allows an external UI to show messages and prompts from --cmd and buffer loading (e.g. swap files)
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
static PMap(cstr_t) *event_strings = NULL;
|
||||
static msgpack_sbuffer out_buffer;
|
||||
|
||||
static bool got_stdio_request = false;
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "msgpack_rpc/channel.c.generated.h"
|
||||
#endif
|
||||
@@ -329,6 +331,9 @@ static void handle_request(Channel *channel, msgpack_object *request)
|
||||
send_error(channel, request_id, error.msg);
|
||||
api_clear_error(&error);
|
||||
api_free_array(args);
|
||||
if (channel->id == CHAN_STDIO) {
|
||||
got_stdio_request = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -344,6 +349,9 @@ static void handle_request(Channel *channel, msgpack_object *request)
|
||||
if (is_get_mode && !input_blocking()) {
|
||||
// Defer the event to a special queue used by os/input.c. #6247
|
||||
multiqueue_put(ch_before_blocking_events, on_request_event, 1, evdata);
|
||||
if (channel->id == CHAN_STDIO) {
|
||||
got_stdio_request = true;
|
||||
}
|
||||
} else {
|
||||
// Invoke immediately.
|
||||
on_request_event((void **)&evdata);
|
||||
@@ -378,6 +386,11 @@ static void on_request_event(void **argv)
|
||||
channel_decref(channel);
|
||||
xfree(e);
|
||||
api_clear_error(&error);
|
||||
bool is_api_info = handler.fn == handle_nvim_get_api_info;
|
||||
// api info is used to initiate client library, ignore it
|
||||
if (channel->id == CHAN_STDIO && !is_api_info) {
|
||||
got_stdio_request = true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool channel_write(Channel *channel, WBuffer *buffer)
|
||||
@@ -744,3 +757,16 @@ static void log_msg_close(FILE *f, msgpack_object msg)
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Wait until embedder has done a request
|
||||
void rpc_wait_for_request(void)
|
||||
{
|
||||
Channel *channel = find_rpc_channel(CHAN_STDIO);
|
||||
if (!channel) {
|
||||
// this function should only be called in --embed mode, stdio channel
|
||||
// can be assumed.
|
||||
abort();
|
||||
}
|
||||
|
||||
LOOP_PROCESS_EVENTS_UNTIL(&main_loop, channel->events, -1, got_stdio_request);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user