From 72f8613e97e3ab4e375a1b9dd20c847f7148acf2 Mon Sep 17 00:00:00 2001 From: notomo Date: Mon, 7 Nov 2022 10:20:27 +0900 Subject: [PATCH] fix(ui-ext): correct message kind in history before vim.ui_attach() --- src/nvim/message.c | 1 + test/functional/lua/ui_event_spec.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/nvim/message.c b/src/nvim/message.c index fa1c8036e6..e42fd42d46 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -3151,6 +3151,7 @@ int msg_end(void) void msg_ext_ui_flush(void) { if (!ui_has(kUIMessages)) { + msg_ext_kind = NULL; return; } diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 57ffcf7b4e..6481da900e 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -117,4 +117,31 @@ describe('vim.ui_attach', function() }) eq(0, helpers.eval('v:shell_error')) end) + + it('can receive accurate message kinds even if they are history', function() + exec_lua([[ + vim.cmd.echomsg("'message1'") + print('message2') + vim.ui_attach(ns, { ext_messages = true }, on_event) + vim.cmd.echomsg("'message3'") + ]]) + feed(':messages') + feed('') + + local actual = exec_lua([[ + return vim.tbl_filter(function (event) + return event[1] == "msg_history_show" + end, events) + ]]) + eq({ + { + 'msg_history_show', + { + { 'echomsg', { { 0, 'message1' } } }, + { '', { { 0, 'message2' } } }, + { 'echomsg', { { 0, 'message3' } } }, + }, + }, + }, actual, inspect(actual)) + end) end)