aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKillTheMule <KillTheMule@users.noreply.github.com>2018-05-10 15:47:00 +0200
committerKillTheMule <KillTheMule@users.noreply.github.com>2018-05-23 22:07:27 +0200
commitad151847f179e51d70cbde9440e765c2a451a7f6 (patch)
tree20a3e841f7c571060031973095072e8073a326cb /src
parent8ef3fb4e738c4021a1c779252a1dac53e09324fc (diff)
downloadrneovim-ad151847f179e51d70cbde9440e765c2a451a7f6.tar.gz
rneovim-ad151847f179e51d70cbde9440e765c2a451a7f6.tar.bz2
rneovim-ad151847f179e51d70cbde9440e765c2a451a7f6.zip
Unify updates_start and updates to lines_event
Also rename changedtick -> changedtick_event
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer_updates.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c
index 8eac695efe..71ca800ee5 100644
--- a/src/nvim/buffer_updates.c
+++ b/src/nvim/buffer_updates.c
@@ -28,39 +28,50 @@ 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) {
// collect buffer contents
+
// True now, but a compile time reminder for future systems we support
STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t to small to hold the number of"
" lines in a buffer");
size_t line_count = (size_t)buf->b_ml.ml_line_count;
- linedata.size = line_count;
- linedata.items = xcalloc(sizeof(Object), line_count);
- for (size_t i = 0; i < line_count; i++) {
- linenr_T lnum = 1 + (linenr_T)i;
- const char *bufstr = (char *)ml_get_buf(buf, lnum, false);
- Object str = STRING_OBJ(cstr_to_string(bufstr));
+ 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++) {
+ linenr_T lnum = 1 + (linenr_T)i;
- // Vim represents NULs as NLs, but this may confuse clients.
- strchrsub(str.data.string.data, '\n', '\0');
+ const char *bufstr = (char *)ml_get_buf(buf, lnum, false);
+ Object str = STRING_OBJ(cstr_to_string(bufstr));
- linedata.items[i] = str;
+ // Vim represents NULs as NLs, but this may confuse clients.
+ strchrsub(str.data.string.data, '\n', '\0');
+
+ linedata.items[i] = str;
+ }
}
}
- Array args = ARRAY_DICT_INIT;
- args.size = 4;
- 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);
- args.items[2] = ARRAY_OBJ(linedata);
- args.items[3] = BOOLEAN_OBJ(false);
+ args.items[4] = ARRAY_OBJ(linedata);
+ args.items[5] = BOOLEAN_OBJ(false);
- rpc_send_event(channel_id, "nvim_buf_updates_start", args);
+ rpc_send_event(channel_id, "nvim_buf_lines_event", args);
return true;
}
@@ -137,7 +148,7 @@ void buf_updates_send_changes(buf_T *buf,
// send through the changes now channel contents now
Array args = ARRAY_DICT_INIT;
- args.size = 5;
+ args.size = 6;
args.items = xcalloc(sizeof(Object), args.size);
// the first argument is always the buffer handle
@@ -174,7 +185,8 @@ void buf_updates_send_changes(buf_T *buf,
}
}
args.items[4] = ARRAY_OBJ(linedata);
- if (!rpc_send_event(channelid, "nvim_buf_update", args)) {
+ args.items[5] = BOOLEAN_OBJ(false);
+ if (!rpc_send_event(channelid, "nvim_buf_lines_event", args)) {
// We can't unregister the channel while we're iterating over the
// update_channels array, so we remember its ID to unregister it at
// the end.