aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/ui.c15
-rw-r--r--src/nvim/channel.c2
-rw-r--r--src/nvim/main.c21
-rw-r--r--src/nvim/msgpack_rpc/channel.c27
4 files changed, 26 insertions, 39 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 509032892b..4971753854 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -58,6 +58,21 @@ void remote_ui_disconnect(uint64_t channel_id)
xfree(ui);
}
+/// Wait until ui has connected on stdio channel.
+void remote_ui_wait_for_attach(void)
+ FUNC_API_NOEXPORT
+{
+ Channel *channel = find_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,
+ pmap_has(uint64_t)(connected_uis, CHAN_STDIO));
+}
+
void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
Dictionary options, Error *err)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index 36423d0aa1..259f1cc600 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -432,7 +432,7 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
const char **error)
FUNC_ATTR_NONNULL_ALL
{
- if (!headless_mode) {
+ if (!headless_mode && !embedded_mode) {
*error = _("can only be opened in headless mode");
return 0;
}
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 192e7d2907..4b838a837c 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -65,6 +65,7 @@
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/msgpack_rpc/server.h"
#include "nvim/msgpack_rpc/channel.h"
+#include "nvim/api/ui.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/handle.h"
@@ -304,6 +305,7 @@ int main(int argc, char **argv)
// Read ex-commands if invoked with "-es".
//
bool reading_tty = !headless_mode
+ && !embedded_mode
&& !silent_mode
&& (params.input_isatty || params.output_isatty
|| params.err_isatty);
@@ -348,18 +350,16 @@ int main(int argc, char **argv)
// startup. This allows an external UI to show messages and prompts from
// --cmd and buffer loading (e.g. swap files)
bool early_ui = false;
- if (embedded_mode) {
+ if (embedded_mode && !headless_mode) {
TIME_MSG("waiting for embedder to make request");
- rpc_wait_for_request();
+ remote_ui_wait_for_attach();
TIME_MSG("done waiting for embedder");
- if (ui_active()) {
- // prepare screen now, so external UIs can display messages
- starting = NO_BUFFERS;
- screenclear();
- early_ui = true;
- TIME_MSG("initialized screen early for embedder");
- }
+ // prepare screen now, so external UIs can display messages
+ starting = NO_BUFFERS;
+ screenclear();
+ early_ui = true;
+ TIME_MSG("initialized screen early for embedder");
}
// Execute --cmd arguments.
@@ -467,7 +467,7 @@ int main(int argc, char **argv)
wait_return(true);
}
- if (!headless_mode && !silent_mode) {
+ if (!headless_mode && !embedded_mode && !silent_mode) {
input_stop(); // Stop reading input, let the UI take over.
ui_builtin_start();
}
@@ -848,7 +848,6 @@ static void command_line_scan(mparm_T *parmp)
headless_mode = true;
} else if (STRICMP(argv[0] + argv_idx, "embed") == 0) {
embedded_mode = true;
- headless_mode = true;
const char *err;
if (!channel_from_stdio(true, CALLBACK_READER_INIT, &err)) {
abort();
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index c6cfb1a9ce..3356cdc61e 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -40,8 +40,6 @@
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
@@ -331,9 +329,6 @@ 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;
}
@@ -349,9 +344,6 @@ 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);
@@ -387,11 +379,6 @@ 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)
@@ -757,17 +744,3 @@ static void log_msg_close(FILE *f, msgpack_object msg)
log_unlock();
}
#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);
-}
-