diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 13 | ||||
-rw-r--r-- | src/nvim/eval.c | 47 | ||||
-rw-r--r-- | src/nvim/eval.h | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 16 | ||||
-rw-r--r-- | src/nvim/msgpack_rpc/channel.c | 4 | ||||
-rw-r--r-- | src/nvim/os/input.c | 16 | ||||
-rw-r--r-- | src/nvim/os/job.c | 3 | ||||
-rw-r--r-- | src/nvim/os/rstream.c | 1 |
8 files changed, 62 insertions, 39 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c90e7039ce..9afefd6fa3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -96,6 +96,19 @@ String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, return cstr_as_string(ptr); } +String vim_command_output(String str, Error *err) +{ + do_cmdline_cmd((char_u *)"redir => v:command_output"); + vim_command(str, err); + do_cmdline_cmd((char_u *)"redir END"); + + if (err->set) { + return (String) STRING_INIT; + } + + return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT)); +} + /// Evaluates the expression str using the vim internal expression /// evaluator (see |expression|). /// Dictionaries and lists are recursively expanded. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3fc4104258..59fb82134d 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -424,7 +424,8 @@ static struct vimvar { {VV_NAME("oldfiles", VAR_LIST), 0}, {VV_NAME("windowid", VAR_NUMBER), VV_RO}, {VV_NAME("progpath", VAR_STRING), VV_RO}, - {VV_NAME("job_data", VAR_LIST), 0} + {VV_NAME("job_data", VAR_LIST), 0}, + {VV_NAME("command_output", VAR_STRING), 0} }; /* shorthand */ @@ -448,9 +449,8 @@ static dictitem_T vimvars_var; /* variable used for v: */ // Memory pool for reusing JobEvent structures typedef struct { - Job *job; - RStream *rstream; - char *type; + int id; + char *name, *type, *received; } JobEvent; #define JobEventFreer(x) KMEMPOOL_INIT(JobEventPool, JobEvent, JobEventFreer) @@ -19527,8 +19527,15 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags) #define push_job_event(j, r, t) \ do { \ JobEvent *event_data = kmp_alloc(JobEventPool, job_event_pool); \ - event_data->job = j; \ - event_data->rstream = r; \ + event_data->received = NULL; \ + if (r) { \ + size_t read_count = rstream_pending(r); \ + event_data->received = xmalloc(read_count + 1); \ + rstream_read(r, event_data->received, read_count); \ + event_data->received[read_count] = NUL; \ + } \ + event_data->id = job_id(j); \ + event_data->name = job_data(j); \ event_data->type = t; \ event_push((Event) { \ .handler = on_job_event, \ @@ -19552,39 +19559,28 @@ static void on_job_stderr(RStream *rstream, void *data, bool eof) static void on_job_exit(Job *job, void *data) { - push_job_event(data, NULL, "exit"); + push_job_event(job, NULL, "exit"); } static void on_job_event(Event event) { JobEvent *data = event.data; - Job *job = data->job; - char *str = NULL; - - if (data->rstream) { - // Read event - size_t read_count = rstream_pending(data->rstream); - str = xmalloc(read_count + 1); - - rstream_read(data->rstream, str, read_count); - str[read_count] = NUL; - } - apply_job_autocmds(job, job_data(job), data->type, str); + apply_job_autocmds(data->id, data->name, data->type, data->received); kmp_free(JobEventPool, job_event_pool, data); } -static void apply_job_autocmds(Job *job, char *name, char *type, char *str) +static void apply_job_autocmds(int id, char *name, char *type, char *received) { // Create the list which will be set to v:job_data list_T *list = list_alloc(); - list_append_number(list, job_id(job)); + list_append_number(list, id); list_append_string(list, (uint8_t *)type, -1); - if (str) { + if (received) { listitem_T *str_slot = listitem_alloc(); str_slot->li_tv.v_type = VAR_STRING; str_slot->li_tv.v_lock = 0; - str_slot->li_tv.vval.v_string = (uint8_t *)str; + str_slot->li_tv.vval.v_string = (uint8_t *)received; list_append(list, str_slot); } @@ -19592,6 +19588,11 @@ static void apply_job_autocmds(Job *job, char *name, char *type, char *str) set_vim_var_list(VV_JOB_DATA, list); // Call JobActivity autocommands apply_autocmds(EVENT_JOBACTIVITY, (uint8_t *)name, NULL, TRUE, NULL); + + if (!received) { + // This must be the exit event. Free the name. + free(name); + } } static void script_host_eval(char *method, typval_T *argvars, typval_T *rettv) diff --git a/src/nvim/eval.h b/src/nvim/eval.h index 2f36a46f70..e96106dfb3 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -64,6 +64,7 @@ enum { VV_WINDOWID, VV_PROGPATH, VV_JOB_DATA, + VV_COMMAND_OUTPUT, VV_LEN, /* number of v: vars */ }; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5db950f120..f5fa16a139 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5908,12 +5908,13 @@ void ex_sign(exarg_T *eap) arg = skipwhite(arg); if (idx == SIGNCMD_UNPLACE && *arg == NUL) { - /* ":sign unplace {id}": remove placed sign by number */ - FOR_ALL_BUFFERS(buf) { - if ((lnum = buf_delsign(buf, id)) != 0) - update_debug_sign(buf, lnum); - return; - } + // ":sign unplace {id}": remove placed sign by number + FOR_ALL_BUFFERS(buf) { + if ((lnum = buf_delsign(buf, id)) != 0) { + update_debug_sign(buf, lnum); + } + } + return; } } } @@ -5923,7 +5924,7 @@ void ex_sign(exarg_T *eap) * Leave "arg" pointing to {fname}. */ - buf_T *buf = NULL; + buf_T *buf = NULL; for (;;) { if (STRNCMP(arg, "line=", 5) == 0) @@ -6343,3 +6344,4 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) } } +// vim: tabstop=8 diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 3325b294dd..43bed54b2c 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -338,6 +338,8 @@ static void parse_msgpack(RStream *rstream, void *data, bool eof) if (eof) { close_channel(channel); + call_set_error(channel, "Channel was closed by the client"); + return; } size_t count = rstream_pending(rstream); @@ -730,7 +732,7 @@ static WBuffer *serialize_response(uint64_t channel_id, } #if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL -#define REQ "[response] " +#define REQ "[request] " #define RES "[response] " #define NOT "[notification] " diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 2c8026d099..e4501aeb82 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <string.h> #include <stdint.h> #include <stdbool.h> @@ -237,18 +238,23 @@ static void convert_input(void) if (convert) { // Perform input conversion according to `input_conv` - size_t unconverted_length; + size_t unconverted_length = 0; data = (char *)string_convert_ext(&input_conv, (uint8_t *)data, (int *)&converted_length, (int *)&unconverted_length); - data_length = rbuffer_pending(read_buffer) - unconverted_length; + data_length -= unconverted_length; } - // Write processed data to input buffer - size_t consumed = rbuffer_write(input_buffer, data, data_length); + // The conversion code will be gone eventually, for now assume `input_buffer` + // always has space for the converted data(it's many times the size of + // `read_buffer`, so it's hard to imagine a scenario where the converted data + // doesn't fit) + assert(converted_length <= rbuffer_available(input_buffer)); + // Write processed data to input buffer. + (void)rbuffer_write(input_buffer, data, converted_length); // Adjust raw buffer pointers - rbuffer_consumed(read_buffer, consumed); + rbuffer_consumed(read_buffer, data_length); if (convert) { // data points to memory allocated by `string_convert_ext`, free it. diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index caada5616b..9a11ecd1fd 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -216,9 +216,6 @@ Job *job_start(char **argv, // Spawn the job if (uv_spawn(uv_default_loop(), &job->proc, &job->proc_opts) != 0) { - close_job_in(job); - close_job_out(job); - close_job_err(job); *status = -1; return NULL; } diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index d96b3d931c..beff404fd0 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -396,6 +396,7 @@ static void close_cb(uv_handle_t *handle) static void rbuffer_relocate(RBuffer *rbuffer) { + assert(rbuffer->rpos <= rbuffer->wpos); // Move data ... memmove( rbuffer->data, // ...to the beginning of the buffer(rpos 0) |