Repository: neovim/neovim
File: src/nvim/ui_client.c (C)

Code before:

void ui_client_event_grid_line(Array args)
  FUNC_ATTR_NORETURN
{
  abort();  // unreachable
}

void ui_client_event_raw_line(GridLineEvent *g)
{
  int grid = g->args[0];
  int row = g->args[1];
  int startcol = g->args[2];
  Integer endcol = startcol + g->coloff;
  Integer clearcol = endcol + g->clear_width;
  LineFlags lineflags = g->wrap ? kLineFlagWrap : 0;

  tui_raw_line(tui, grid, row, startcol, endcol, clearcol, g->cur_attr, lineflags,
               (const schar_T *)grid_line_buf_char, grid_line_buf_attr);
}

static Array restart_args = ARRAY_DICT_INIT;

void ui_client_event_restart(Array args)
{
  // NB: don't send nvim_ui_detach to server, as it may have already exited.
  // ui_client_detach();

  // Save the arguments for ui_client_do_restart() later.
  api_free_array(restart_args);
  restart_args = copy_array(args, NULL);
  ui_client_pending_restart = true;
}

void ui_client_do_restart(void)
{
  ui_client_pending_restart = false;

  size_t argc;
  char **argv = NULL;
  if (restart_args.size < 2
      || restart_args.items[0].type != kObjectTypeString
      || restart_args.items[1].type != kObjectTypeArray
      || (argc = restart_args.items[1].data.array.size) < 1) {
    ELOG("Error handling ui event 'restart'");
    goto cleanup;
  }

  // 1. Get executable path and command-line arguments.
  const char *exepath = restart_args.items[0].data.string.data;
  argv = xcalloc(argc + 1, sizeof(char *));
  for (size_t i = 0; i < argc; i++) {

Review comment (suggestion):
the docstring is worth having, no? 

    /// Handles the "restart" UI event.
    ///
    /// @param args CLI args to restart Nvim.

Code after:

void ui_client_event_grid_line(Array args)
  FUNC_ATTR_NORETURN
{
  abort();  // unreachable
}

void ui_client_event_raw_line(GridLineEvent *g)
{
  int grid = g->args[0];
  int row = g->args[1];
  int startcol = g->args[2];
  Integer endcol = startcol + g->coloff;
  Integer clearcol = endcol + g->clear_width;
  LineFlags lineflags = g->wrap ? kLineFlagWrap : 0;

  tui_raw_line(tui, grid, row, startcol, endcol, clearcol, g->cur_attr, lineflags,
               (const schar_T *)grid_line_buf_char, grid_line_buf_attr);
}

/// When a "restart" UI event is received, its arguments are saved here when
/// waiting for the server to exit.
static Array restart_args = ARRAY_DICT_INIT;
static bool restart_pending = false;

void ui_client_event_restart(Array args)
{
  // NB: don't send nvim_ui_detach to server, as it may have already exited.
  // ui_client_detach();

  // Save the arguments for ui_client_may_restart_server() later.
  api_free_array(restart_args);
  restart_args = copy_array(args, NULL);
  restart_pending = true;
}

/// Called when the current server has exited.
void ui_client_may_restart_server(void)
{
  if (!restart_pending) {
    return;
  }
  restart_pending = false;

  size_t argc;
  char **argv = NULL;
  if (restart_args.size < 2
      || restart_args.items[0].type != kObjectTypeString
      || restart_args.items[1].type != kObjectTypeArray
      || (argc = restart_args.items[1].data.array.size) < 1) {
    ELOG("Error handling ui event 'restart'");