mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 10:56:31 +00:00
event: Remove automatic event deferall
This is how asynchronous events are currently handled by Nvim: - Libuv event loop is entered when Nvim blocks for user input(os_inchar is called) - Any event delivered by libuv that is not user input is queued for processing - The `K_EVENT` special key code is returned by os_inchar - `K_EVENT` is returned to a loop that is reading keys for the current Nvim mode, which will be handled by calling event_process() This approach has the advantage of integrating nicely with the current codebase, eg: vimscript code can be executed asynchronously with little surprises(Its the same as if the user typed a key). The problem with using keys to represent any event is that it also interferes with operators, and not every event needs or should do that. For example, consider this scenario: - A msgpack-rpc client calls vim_feedkeys("d") - Nvim processes K_EVENT, pushing "d" to the input queue - Nvim processes "d", entering operator-pending mode to wait for a motion - The client calls vim_feedkeys("w"), expecting Nvim to delete a word - Nvim processes K_EVENT, breaking out of operator-pending and pushing "w" - Nvim processes "w", moving a word This commit fixes the above problem by removing all automatic calls to `event_push`(which is what generates K_EVENT input). Right now this also breaks redrawing initiated by asynchronous events(and possibly other stuff too, Nvim is a complex state machine and we can't simply run vimscript code anywhere). In future commits the calls to `event_push` will be inserted only where it's absolutely necessary to run code in "key reading loops", such as when executing vimscript code or mutating editor data structures in ways that currently can only be done by the user.
This commit is contained in:
@@ -126,8 +126,7 @@ void channel_from_stream(uv_stream_t *stream)
|
||||
// read stream
|
||||
channel->data.streams.read = rstream_new(parse_msgpack,
|
||||
rbuffer_new(CHANNEL_BUFFER_SIZE),
|
||||
channel,
|
||||
NULL);
|
||||
channel);
|
||||
rstream_set_stream(channel->data.streams.read, stream);
|
||||
rstream_start(channel->data.streams.read);
|
||||
// write stream
|
||||
@@ -201,17 +200,12 @@ Object channel_send_call(uint64_t id,
|
||||
// Send the msgpack-rpc request
|
||||
send_request(channel, request_id, method_name, args);
|
||||
|
||||
EventSource channel_source = channel->is_job
|
||||
? job_event_source(channel->data.job)
|
||||
: rstream_event_source(channel->data.streams.read);
|
||||
EventSource sources[] = {channel_source, NULL};
|
||||
|
||||
// Push the frame
|
||||
ChannelCallFrame frame = {request_id, false, false, NIL};
|
||||
kv_push(ChannelCallFrame *, channel->call_stack, &frame);
|
||||
|
||||
do {
|
||||
event_poll(-1, sources);
|
||||
event_poll(-1);
|
||||
} while (!frame.returned);
|
||||
|
||||
(void)kv_pop(channel->call_stack);
|
||||
@@ -286,8 +280,7 @@ static void channel_from_stdio(void)
|
||||
// read stream
|
||||
channel->data.streams.read = rstream_new(parse_msgpack,
|
||||
rbuffer_new(CHANNEL_BUFFER_SIZE),
|
||||
channel,
|
||||
NULL);
|
||||
channel);
|
||||
rstream_set_file(channel->data.streams.read, 0);
|
||||
rstream_start(channel->data.streams.read);
|
||||
// write stream
|
||||
|
Reference in New Issue
Block a user