diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/buffer.c | 4 | ||||
-rw-r--r-- | src/nvim/buffer_updates.c | 50 |
2 files changed, 30 insertions, 24 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 756367f801..12d1feb370 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -80,7 +80,9 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// /// @param buffer The buffer handle /// @param send_buffer Set to true if the initial notification should contain -/// the whole buffer +/// the whole buffer. If so, the first notification will be a +/// `nvim_buf_lines_event`. Otherwise, the first notification will be +/// a `nvim_buf_changedtick_event` /// @param[out] err Details of an error that may have occurred /// @return False when updates couldn't be enabled because the buffer isn't /// loaded; otherwise True. diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index 71ca800ee5..2852561ce0 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -28,20 +28,20 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, bool send_buffer) // append the channelid to the list kv_push(buf->update_channels, channel_id); - Array args = ARRAY_DICT_INIT; - args.size = 6; - args.items = xcalloc(sizeof(Object), args.size); - - // the first argument is always the buffer handle - args.items[0] = BUFFER_OBJ(buf->handle); - args.items[1] = INTEGER_OBJ(buf->b_changedtick); - // the first line that changed (zero-indexed) - args.items[2] = INTEGER_OBJ(-1); - // the last line that was changed - args.items[3] = INTEGER_OBJ(-1); - Array linedata = ARRAY_DICT_INIT; - if (send_buffer) { + Array args = ARRAY_DICT_INIT; + args.size = 6; + args.items = xcalloc(sizeof(Object), args.size); + + // the first argument is always the buffer handle + args.items[0] = BUFFER_OBJ(buf->handle); + args.items[1] = INTEGER_OBJ(buf->b_changedtick); + // the first line that changed (zero-indexed) + args.items[2] = INTEGER_OBJ(0); + // the last line that was changed + args.items[3] = INTEGER_OBJ(-1); + Array linedata = ARRAY_DICT_INIT; + // collect buffer contents // True now, but a compile time reminder for future systems we support @@ -50,8 +50,6 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, bool send_buffer) size_t line_count = (size_t)buf->b_ml.ml_line_count; if (line_count >= 1) { - args.items[2] = INTEGER_OBJ(0); - linedata.size = line_count; linedata.items = xcalloc(sizeof(Object), line_count); for (size_t i = 0; i < line_count; i++) { @@ -66,12 +64,15 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, bool send_buffer) linedata.items[i] = str; } } - } - args.items[4] = ARRAY_OBJ(linedata); - args.items[5] = BOOLEAN_OBJ(false); + args.items[4] = ARRAY_OBJ(linedata); + args.items[5] = BOOLEAN_OBJ(false); + + rpc_send_event(channel_id, "nvim_buf_lines_event", args); + } else { + buf_updates_changedtick_single(buf, channel_id); + } - rpc_send_event(channel_id, "nvim_buf_lines_event", args); return true; } @@ -207,9 +208,13 @@ void buf_updates_changedtick(buf_T *buf) { // notify each of the active channels for (size_t i = 0; i < kv_size(buf->update_channels); i++) { - uint64_t channelid = kv_A(buf->update_channels, i); + uint64_t channel_id = kv_A(buf->update_channels, i); + buf_updates_changedtick_single(buf, channel_id); + } +} - // send through the changes now channel contents now +void buf_updates_changedtick_single(buf_T *buf, uint64_t channel_id) +{ Array args = ARRAY_DICT_INIT; args.size = 2; args.items = xcalloc(sizeof(Object), args.size); @@ -221,6 +226,5 @@ void buf_updates_changedtick(buf_T *buf) args.items[1] = INTEGER_OBJ(buf->b_changedtick); // don't try and clean up dead channels here - rpc_send_event(channelid, "nvim_buf_changedtick", args); - } + rpc_send_event(channel_id, "nvim_buf_changedtick_event", args); } |