aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/vim.c2
-rw-r--r--src/nvim/main.c103
-rw-r--r--src/nvim/main.h2
3 files changed, 106 insertions, 1 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index ebf4f65c91..b691dee2ef 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1997,7 +1997,7 @@ Array nvim_get_proc_children(Integer pid, Error *err)
DLOG("fallback to vim._os_proc_children()");
Array a = ARRAY_DICT_INIT;
ADD(a, INTEGER_OBJ(pid));
- String s = cstr_to_string("return vim._os_proc_children(select(1, ...))");
+ String s = cstr_to_string("return vim._os_proc_children(...)");
Object o = nlua_exec(s, a, err);
api_free_string(s);
api_free_array(a);
diff --git a/src/nvim/main.c b/src/nvim/main.c
index a575aba50a..230be9d9b9 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -268,6 +268,10 @@ int main(int argc, char **argv)
}
server_init(params.listen_addr);
+ if (params.remote) {
+ handle_remote_client(&params, params.remote,
+ params.server_addr, argc, argv);
+ }
if (GARGCOUNT > 0) {
fname = get_fname(&params, cwd);
@@ -803,6 +807,91 @@ static void init_locale(void)
}
#endif
+/// Handle remote subcommands
+static void handle_remote_client(mparm_T *params, int remote_args,
+ char *server_addr, int argc, char **argv)
+{
+ Object rvobj = OBJECT_INIT;
+ rvobj.data.dictionary = (Dictionary)ARRAY_DICT_INIT;
+ rvobj.type = kObjectTypeDictionary;
+ CallbackReader on_data = CALLBACK_READER_INIT;
+ const char *connect_error = NULL;
+ uint64_t rc_id = 0;
+ if (server_addr != NULL) {
+ rc_id = channel_connect(false, server_addr, true, on_data, 50, &connect_error);
+ }
+
+ int t_argc = remote_args;
+ Array args = ARRAY_DICT_INIT;
+ String arg_s;
+ for (; t_argc < argc; t_argc++) {
+ arg_s = cstr_to_string(argv[t_argc]);
+ ADD(args, STRING_OBJ(arg_s));
+ }
+
+ Error err = ERROR_INIT;
+ Array a = ARRAY_DICT_INIT;
+ ADD(a, INTEGER_OBJ((int)rc_id));
+ ADD(a, CSTR_TO_OBJ(server_addr));
+ ADD(a, CSTR_TO_OBJ(connect_error));
+ ADD(a, ARRAY_OBJ(args));
+ String s = STATIC_CSTR_AS_STRING("return vim._cs_remote(...)");
+ Object o = nlua_exec(s, a, &err);
+ api_free_array(a);
+ if (ERROR_SET(&err)) {
+ mch_errmsg(err.msg);
+ mch_errmsg("\n");
+ os_exit(2);
+ }
+
+ if (o.type == kObjectTypeDictionary) {
+ rvobj.data.dictionary = o.data.dictionary;
+ } else {
+ mch_errmsg("vim._cs_remote returned unexpected value\n");
+ os_exit(2);
+ }
+
+ TriState should_exit = kNone;
+ TriState tabbed = kNone;
+
+ for (size_t i = 0; i < rvobj.data.dictionary.size ; i++) {
+ if (strcmp(rvobj.data.dictionary.items[i].key.data, "errmsg") == 0) {
+ if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) {
+ mch_errmsg("vim._cs_remote returned an unexpected type for 'errmsg'\n");
+ os_exit(2);
+ }
+ mch_errmsg(rvobj.data.dictionary.items[i].value.data.string.data);
+ mch_errmsg("\n");
+ os_exit(2);
+ } else if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) {
+ if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) {
+ mch_errmsg("vim._cs_remote returned an unexpected type for 'tabbed'\n");
+ os_exit(2);
+ }
+ tabbed = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse;
+ } else if (strcmp(rvobj.data.dictionary.items[i].key.data, "should_exit") == 0) {
+ if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) {
+ mch_errmsg("vim._cs_remote returned an unexpected type for 'should_exit'\n");
+ os_exit(2);
+ }
+ should_exit = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse;
+ }
+ }
+ if (should_exit == kNone || tabbed == kNone) {
+ mch_errmsg("vim._cs_remote didn't return a value for should_exit or tabbed, bailing\n");
+ os_exit(2);
+ }
+ api_free_object(o);
+
+ if (should_exit == kTrue) {
+ os_exit(0);
+ }
+ if (tabbed == kTrue) {
+ params->window_count = argc - remote_args - 1;
+ params->window_layout = WIN_TABS;
+ }
+}
+
/// Decides whether text (as opposed to commands) will be read from stdin.
/// @see EDIT_STDIN
static bool edit_stdin(bool explicit, mparm_T *parmp)
@@ -868,6 +957,8 @@ static void command_line_scan(mparm_T *parmp)
// "--version" give version message
// "--noplugin[s]" skip plugins
// "--cmd <cmd>" execute cmd before vimrc
+ // "--remote" execute commands remotey on a server
+ // "--server" name of vim server to send remote commands to
if (STRICMP(argv[0] + argv_idx, "help") == 0) {
usage();
os_exit(0);
@@ -906,6 +997,11 @@ static void command_line_scan(mparm_T *parmp)
argv_idx += 6;
} else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
// Do nothing: file args are always literal. #7679
+ } else if (STRNICMP(argv[0] + argv_idx, "remote", 6) == 0) {
+ parmp->remote = parmp->argc - argc;
+ } else if (STRNICMP(argv[0] + argv_idx, "server", 6) == 0) {
+ want_argument = true;
+ argv_idx += 6;
} else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) {
p_lpl = false;
} else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) {
@@ -1137,6 +1233,9 @@ static void command_line_scan(mparm_T *parmp)
} else if (strequal(argv[-1], "--listen")) {
// "--listen {address}"
parmp->listen_addr = argv[0];
+ } else if (strequal(argv[-1], "--server")) {
+ // "--server {address}"
+ parmp->server_addr = argv[0];
}
// "--startuptime <file>" already handled
break;
@@ -1291,6 +1390,8 @@ static void init_params(mparm_T *paramp, int argc, char **argv)
paramp->use_debug_break_level = -1;
paramp->window_count = -1;
paramp->listen_addr = NULL;
+ paramp->server_addr = NULL;
+ paramp->remote = 0;
}
/// Initialize global startuptime file if "--startuptime" passed as an argument.
@@ -2041,6 +2142,8 @@ static void usage(void)
mch_msg(_(" --headless Don't start a user interface\n"));
mch_msg(_(" --listen <address> Serve RPC API from this address\n"));
mch_msg(_(" --noplugin Don't load plugins\n"));
+ mch_msg(_(" --remote[-subcommand] Execute commands remotely on a server\n"));
+ mch_msg(_(" --server <address> Specify RPC server to send commands to\n"));
mch_msg(_(" --startuptime <file> Write startup timing messages to <file>\n"));
mch_msg(_("\nSee \":help startup-options\" for all options.\n"));
}
diff --git a/src/nvim/main.h b/src/nvim/main.h
index f73af5c288..e55bef6e33 100644
--- a/src/nvim/main.h
+++ b/src/nvim/main.h
@@ -39,6 +39,8 @@ typedef struct {
int diff_mode; // start with 'diff' set
char *listen_addr; // --listen {address}
+ int remote; // --remote-[subcmd] {file1} {file2}
+ char *server_addr; // --server {address}
} mparm_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS