From 7a490d65c57e72342ad91e00788109d991cac6c1 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Thu, 5 Feb 2026 15:55:11 +0100 Subject: [PATCH] fix(messages): increment message ID without ext_messages #37714 Problem: Message ID is not incremented without ext_messages. Solution: Increment where callstack reaches without ext_messages. There is no clear place marking the end of internal messages without ext_messages so IDs are only incremented with `nvim_echo` calls. Message IDs are currently not exposed anywhere but the msg_show event for this to matter. --- src/nvim/message.c | 6 +++--- test/functional/api/vim_spec.lua | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/nvim/message.c b/src/nvim/message.c index a3f7e37047..fe0af65394 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -365,10 +365,10 @@ MsgID msg_multihl(MsgID id, HlMessage hl_msg, const char *kind, bool history, bo // provide a new id if not given if (id.type == kObjectTypeNil) { - id = INTEGER_OBJ(msg_id_next); + id = INTEGER_OBJ(msg_id_next++); } else if (id.type == kObjectTypeInteger) { - id = id.data.integer > 0 ? id : INTEGER_OBJ(msg_id_next); - msg_id_next = MAX(msg_id_next, id.data.integer); + id = id.data.integer > 0 ? id : INTEGER_OBJ(msg_id_next++); + msg_id_next = MAX(msg_id_next, id.data.integer + 1); } msg_ext_id = id; diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ae0fa4b07d..7bf8295878 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3853,6 +3853,12 @@ describe('API', function() {9:Error}{16:Message} | ]]) end) + + it('increments message ID', function() + eq(1, api.nvim_echo({ { 'foo' } }, false, {})) + eq(4, api.nvim_echo({ { 'foo' } }, false, { id = 4 })) + eq(5, api.nvim_echo({ { 'foo' } }, false, {})) + end) end) describe('nvim_open_term', function()