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

Code before:
      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;
}

// Returns true if the 'connect' event was successfully sent to the UI
void remote_ui_connect(uint64_t channel_id, char *server_address, Error *err)
{
  RemoteUI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
  if (!ui) {
    api_set_error(err, kErrorTypeException,
                  "UI not attached to channel: %" PRId64, channel_id);
    return;
  }

  MAXSIZE_TEMP_ARRAY(args, 1);
  ADD_C(args, CSTR_AS_OBJ(server_address));

  push_call(ui, "connect", args);
}

// 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
{
  RemoteUI *ui = get_ui_or_err(channel_id, err);
  if (!ui) {
    return;
  }

  if (width <= 0 || height <= 0) {
    api_set_error(err, kErrorTypeValidation, "Expected width > 0 and height > 0");
    return;
  }

  ui->width = (int)width;

Review comment (suggestion):
Something to think about later. Because this address is passed along without modification, users can `:connect <local>` even if they are currently connected to a remote machine. And that's good.

But something we need to think about for the "remote ssh", is can we present a useful menu that shows both local and remote addresses, even when connected to a remote machine? One way to do this might be for the UI to pass along locally-discovered addresses when it first connects to a remote.

Code after:
      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));
    }
  });
  ADD_C(args, ARRAY_OBJ(argv));

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

// Send a connect UI event to the UI on the given channel
void remote_ui_connect(uint64_t channel_id, char *server_addr, Error *err)
{
  RemoteUI *ui = get_ui_or_err(channel_id, err);
  if (!ui) {
    return;
  }

  MAXSIZE_TEMP_ARRAY(args, 1);
  ADD_C(args, CSTR_AS_OBJ(server_addr));

  push_call(ui, "connect", args);
}

// 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