aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKillTheMule <KillTheMule@users.noreply.github.com>2018-01-26 15:49:35 +0100
committerKillTheMule <KillTheMule@users.noreply.github.com>2018-05-23 22:07:27 +0200
commitbafae1c427cb1eeb52e4caa641ad134c1e062e8e (patch)
tree5fa3bce5bd51eae937c41a06c8de67b87358f457 /src
parent9e97f14de2e693a204db39331d59778f1b4802a6 (diff)
downloadrneovim-bafae1c427cb1eeb52e4caa641ad134c1e062e8e.tar.gz
rneovim-bafae1c427cb1eeb52e4caa641ad134c1e062e8e.tar.bz2
rneovim-bafae1c427cb1eeb52e4caa641ad134c1e062e8e.zip
Add argument to not send a buffers content when updates are enabled
Add a test.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/buffer.c3
-rw-r--r--src/nvim/liveupdate.c26
-rw-r--r--src/nvim/liveupdate.h2
3 files changed, 17 insertions, 14 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 159683db9e..e594e4975c 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -87,6 +87,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
Boolean nvim_buf_live_updates(uint64_t channel_id,
Buffer buffer,
Boolean enabled,
+ Boolean send_buffer,
Error *err)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY
{
@@ -97,7 +98,7 @@ Boolean nvim_buf_live_updates(uint64_t channel_id,
}
if (enabled) {
- return liveupdate_register(buf, channel_id);
+ return liveupdate_register(buf, channel_id, send_buffer);
}
liveupdate_unregister(buf, channel_id);
diff --git a/src/nvim/liveupdate.c b/src/nvim/liveupdate.c
index 953c5b52b3..9679d72569 100644
--- a/src/nvim/liveupdate.c
+++ b/src/nvim/liveupdate.c
@@ -6,7 +6,7 @@
// Register a channel. Return True if the channel was added, or already added.
// Return False if the channel couldn't be added because the buffer is
// unloaded.
-bool liveupdate_register(buf_T *buf, uint64_t channel_id)
+bool liveupdate_register(buf_T *buf, uint64_t channel_id, bool send_buffer)
{
// must fail if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) {
@@ -27,21 +27,23 @@ bool liveupdate_register(buf_T *buf, uint64_t channel_id)
// append the channelid to the list
kv_push(buf->liveupdate_channels, channel_id);
- // send through the full channel contents now
Array linedata = ARRAY_DICT_INIT;
- size_t line_count = 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;
+ if (send_buffer) {
+ // collect buffer contents
+ size_t line_count = 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));
+ const char *bufstr = (char *)ml_get_buf(buf, lnum, false);
+ Object str = STRING_OBJ(cstr_to_string(bufstr));
- // Vim represents NULs as NLs, but this may confuse clients.
- strchrsub(str.data.string.data, '\n', '\0');
+ // Vim represents NULs as NLs, but this may confuse clients.
+ strchrsub(str.data.string.data, '\n', '\0');
- linedata.items[i] = str;
+ linedata.items[i] = str;
+ }
}
Array args = ARRAY_DICT_INIT;
diff --git a/src/nvim/liveupdate.h b/src/nvim/liveupdate.h
index bbee4b3766..77fb420bf0 100644
--- a/src/nvim/liveupdate.h
+++ b/src/nvim/liveupdate.h
@@ -3,7 +3,7 @@
#include "nvim/buffer_defs.h"
-bool liveupdate_register(buf_T *buf, uint64_t channel_id);
+bool liveupdate_register(buf_T *buf, uint64_t channel_id, bool send_buffer);
void liveupdate_unregister(buf_T *buf, uint64_t channel_id);
void liveupdate_unregister_all(buf_T *buf);
void liveupdate_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,