mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Send changedtick as first event if buffer contents weren't requested
This commit is contained in:
parent
ad151847f1
commit
0bee3925ab
@ -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.
|
||||
|
@ -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);
|
||||
|
||||
rpc_send_event(channel_id, "nvim_buf_lines_event", args);
|
||||
} else {
|
||||
buf_updates_changedtick_single(buf, channel_id);
|
||||
}
|
||||
|
||||
args.items[4] = ARRAY_OBJ(linedata);
|
||||
args.items[5] = BOOLEAN_OBJ(false);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ describe('buffer events', function()
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false})
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_changedtick', {b, tick})
|
||||
expectn('nvim_buf_changedtick_event', {b, tick})
|
||||
command('set autoindent')
|
||||
command('normal! >>')
|
||||
tick = tick + 1
|
||||
@ -356,7 +356,7 @@ describe('buffer events', function()
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', {b, tick, 1, 2, {}, false})
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_changedtick', {b, tick})
|
||||
expectn('nvim_buf_changedtick_event', {b, tick})
|
||||
command('normal! ggOmmm')
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', {b, tick, 0, 0, {"\t"}, false})
|
||||
@ -376,7 +376,7 @@ describe('buffer events', function()
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'Line 1'}, false})
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_changedtick', {b, tick})
|
||||
expectn('nvim_buf_changedtick_event', {b, tick})
|
||||
|
||||
-- change the file directly
|
||||
local f = io.open(filename, 'a')
|
||||
@ -412,7 +412,7 @@ describe('buffer events', function()
|
||||
tick1 = tick1 + 1
|
||||
expectn('nvim_buf_lines_event', {b1, tick1, 0, 1, {'A1'}, false})
|
||||
tick1 = tick1 + 1
|
||||
expectn('nvim_buf_changedtick', {b1, tick1})
|
||||
expectn('nvim_buf_changedtick_event', {b1, tick1})
|
||||
|
||||
command('b'..b2nr)
|
||||
command('normal! x')
|
||||
@ -422,7 +422,7 @@ describe('buffer events', function()
|
||||
tick2 = tick2 + 1
|
||||
expectn('nvim_buf_lines_event', {b2, tick2, 0, 1, {'B1'}, false})
|
||||
tick2 = tick2 + 1
|
||||
expectn('nvim_buf_changedtick', {b2, tick2})
|
||||
expectn('nvim_buf_changedtick_event', {b2, tick2})
|
||||
|
||||
command('b'..b3nr)
|
||||
command('normal! x')
|
||||
@ -432,7 +432,7 @@ describe('buffer events', function()
|
||||
tick3 = tick3 + 1
|
||||
expectn('nvim_buf_lines_event', {b3, tick3, 0, 1, {'C1'}, false})
|
||||
tick3 = tick3 + 1
|
||||
expectn('nvim_buf_changedtick', {b3, tick3})
|
||||
expectn('nvim_buf_changedtick_event', {b3, tick3})
|
||||
end)
|
||||
|
||||
it('doesn\'t get confused when you turn watching on/off many times',
|
||||
@ -514,8 +514,8 @@ describe('buffer events', function()
|
||||
wantn(2, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false})
|
||||
wantn(3, 'nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false})
|
||||
tick = tick + 1
|
||||
wantn(2, 'nvim_buf_changedtick', {b, tick})
|
||||
wantn(3, 'nvim_buf_changedtick', {b, tick})
|
||||
wantn(2, 'nvim_buf_changedtick_event', {b, tick})
|
||||
wantn(3, 'nvim_buf_changedtick_event', {b, tick})
|
||||
|
||||
-- make sure there are no other pending nvim_buf_lines_event messages going to
|
||||
-- channel 1
|
||||
@ -667,7 +667,7 @@ describe('buffer events', function()
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false})
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_changedtick', {b, tick})
|
||||
expectn('nvim_buf_changedtick_event', {b, tick})
|
||||
|
||||
-- close our buffer by creating a new one
|
||||
command('enew')
|
||||
@ -694,7 +694,7 @@ describe('buffer events', function()
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AAA'}, false})
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_changedtick', {b, tick})
|
||||
expectn('nvim_buf_changedtick_event', {b, tick})
|
||||
|
||||
-- close our buffer by creating a new one
|
||||
command('set hidden')
|
||||
@ -733,7 +733,7 @@ describe('buffer events', function()
|
||||
helpers.clear()
|
||||
local b, tick = editoriginal(false)
|
||||
ok(buffer('attach', b, false))
|
||||
expectn('nvim_buf_lines_event', {b, tick, -1, -1, {}, false})
|
||||
expectn('nvim_buf_changedtick_event', {b, tick})
|
||||
end)
|
||||
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user