From bfe42c84de053abe125f7a61116bc8a97ec32cde Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Fri, 27 Jun 2025 15:54:32 +0200 Subject: perf(extui): delay creating windows, buffers and parser (#34665) Problem: vim._extui unconditionally creates windows, buffers and the Vimscript cmdline highlighter when it is first loaded. Solution: Schedule first creation of the window so that first redraw happens sooner (still need to create at least the cmdline window asap as it can have a different highlight through hl-MsgArea; thus further delaying until the first event that needs a particular target seems redundant). Load the cmdline highlighter on the first cmdline_show event. --- runtime/lua/vim/_extui/cmdline.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/_extui/cmdline.lua') diff --git a/runtime/lua/vim/_extui/cmdline.lua b/runtime/lua/vim/_extui/cmdline.lua index 38050eb74f..c257d07ebb 100644 --- a/runtime/lua/vim/_extui/cmdline.lua +++ b/runtime/lua/vim/_extui/cmdline.lua @@ -30,7 +30,7 @@ local function win_config(win, hide, height) end end -local cmdbuff ---@type string Stored cmdline used to calculate translation offset. +local cmdbuff = '' ---@type string Stored cmdline used to calculate translation offset. local promptlen = 0 -- Current length of the prompt, stored for use in "cmdline_pos" --- Concatenate content chunks and set the text for the current row in the cmdline buffer. --- @@ -57,6 +57,10 @@ end ---@param hl_id integer function M.cmdline_show(content, pos, firstc, prompt, indent, level, hl_id) M.level, M.indent, M.prompt = level, indent, M.prompt or #prompt > 0 + if M.highlighter == nil then + local parser = assert(vim.treesitter.get_parser(ext.bufs.cmd, 'vim', {})) + M.highlighter = vim.treesitter.highlighter.new(parser) + end -- Only enable TS highlighter for Ex commands (not search or filter commands). M.highlighter.active[ext.bufs.cmd] = firstc == ':' and M.highlighter or nil if ext.msg.cmd.msg_row ~= -1 then -- cgit