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

Code before:
{
  remote_ui_disconnect(channel_id, err, false);
}

/// Sends a "restart" UI event to the UI on the given channel.
///
/// @return  false if there is no UI on the channel, otherwise true
bool remote_ui_restart(uint64_t channel_id, Error *err)
{
  RemoteUI *ui = get_ui_or_err(channel_id, err);
  if (!ui) {
    return false;
  }

  MAXSIZE_TEMP_ARRAY(args, 2);

  ADD_C(args, CSTR_AS_OBJ(get_vim_var_str(VV_PROGPATH)));

  Arena arena = ARENA_EMPTY;
  const list_T *l = get_vim_var_list(VV_ARGV);
  int argc = tv_list_len(l);
  assert(argc > 0);
  Array argv = arena_array(&arena, (size_t)argc + 1);
  bool had_minmin = false;
  TV_LIST_ITER_CONST(l, li, {
    const char *arg = tv_get_string(TV_LIST_ITEM_TV(li));
    if (argv.size > 0 && !had_minmin && strequal(arg, "--")) {
      had_minmin = true;
    }
    // Exclude --embed/--headless from `argv`, as the client may start the server in a
    // different way than how the server was originally started.
    if (argv.size == 0 || had_minmin
        || (!strequal(arg, "--embed") && !strequal(arg, "--headless"))) {
      ADD_C(argv, CSTR_AS_OBJ(arg));
    }
  });
  ADD_C(args, ARRAY_OBJ(argv));

  push_call(ui, "restart", args);
  arena_mem_free(arena_finish(&arena));
  return true;
}

// TODO(bfredl): use me to detach a specific ui from the server
void remote_ui_stop(RemoteUI *ui)
{
}

void nvim_ui_try_resize(uint64_t channel_id, Integer width, Integer height, Error *err)
  FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{

Review comment (suggestion):
@sathya-pramodh do you recall why this logic is in ui.c instead of in `ex_restart` ? Seems more obvious if we just fixup `v:argv` in one place (`ex_restart`), instead of patching in `ex_restart` and later skipping stuff in `ui.c`. 

(I am looking at this for https://github.com/neovim/neovim/pull/37846 )

Code after:
{
  remote_ui_disconnect(channel_id, err, false);
}

/// Sends a "restart" UI event to the UI on the given channel.
///
/// @return  false if there is no UI on the channel, otherwise true
bool remote_ui_restart(uint64_t channel_id, Error *err)
{
  RemoteUI *ui = get_ui_or_err(channel_id, err);
  if (!ui) {
    return false;
  }

  MAXSIZE_TEMP_ARRAY(args, 2);

  ADD_C(args, CSTR_AS_OBJ(get_vim_var_str(VV_PROGPATH)));

  Arena arena = ARENA_EMPTY;
  const list_T *l = get_vim_var_list(VV_ARGV);
  int argc = tv_list_len(l);
  assert(argc > 0);
  Array argv = arena_array(&arena, (size_t)argc + 1);
  bool had_minmin = false;
  bool skipping_minc = false;  // Skip -c <cmd> from argv.
  bool first_minc = true;  // Avoid skipping the first -c <cmd> from argv.
  TV_LIST_ITER_CONST(l, li, {
    const char *arg = tv_get_string(TV_LIST_ITEM_TV(li));
    if (argv.size > 0 && !had_minmin && strequal(arg, "--")) {
      had_minmin = true;
      skipping_minc = false;
    }
    bool startswith_min = strlen(arg) > 0 && arg[0] == '-';
    bool startswith_minmin = strlen(arg) > 1 && arg[0] == '-' && arg[1] == '-';
    if (skipping_minc && (startswith_min || startswith_minmin)) {
      skipping_minc = false;
    }
    if (!had_minmin && !skipping_minc && strequal(arg, "-c")) {
      if (!first_minc) {
        skipping_minc = true;
        continue;
      }
      first_minc = false;
    }
    // Exclude --embed/--headless/-c <cmd> from `argv`, as the client may start the server in a
    // different way than how the server was originally started.
    // Eg: 'nvim -c foo -c bar --embed --headless -- example.txt' would be parsed as { 'nvim', '-c', 'foo', '--', 'example.txt' }.
    if (argv.size == 0 || had_minmin
        || (!strequal(arg, "--embed") && !strequal(arg, "--headless") && !skipping_minc)) {
      ADD_C(argv, CSTR_AS_OBJ(arg));
    }