fix(messages): truncate warning messages only in display (#38901)

For now, add a private "_truncate" flag to nvim_echo, using a truncation
method similar to showmode().
This commit is contained in:
zeertzjq
2026-04-09 12:11:32 +08:00
committed by GitHub
parent 3a4a66017b
commit 9c5fba5df0
9 changed files with 117 additions and 22 deletions

View File

@@ -780,7 +780,8 @@ do
vim.v.swapchoice = 'e' -- Choose "(E)dit".
vim.notify(
('W325: Ignoring swapfile from Nvim process %d'):format(info.pid),
vim.log.levels.WARN
vim.log.levels.WARN,
{ _truncate = true }
)
end,
})
@@ -991,7 +992,8 @@ do
then
vim.notify(
'defaults.lua: Did not detect DSR response from terminal. This results in a slower startup time.',
vim.log.levels.WARN
vim.log.levels.WARN,
{ _truncate = true }
)
end
end

View File

@@ -547,7 +547,11 @@ end
---@diagnostic disable-next-line: unused-local
function vim.notify(msg, level, opts) -- luacheck: no unused args
local chunks = { { msg, level == vim.log.levels.WARN and 'WarningMsg' or nil } }
vim.api.nvim_echo(chunks, true, { err = level == vim.log.levels.ERROR })
vim.api.nvim_echo(
chunks,
true,
{ err = level == vim.log.levels.ERROR, _truncate = opts and opts._truncate }
)
end
do
@@ -1213,9 +1217,7 @@ end
do
local function truncated_echo(msg)
-- Truncate message to avoid hit-enter-prompt
local max_width = vim.o.columns * math.max(vim.o.cmdheight - 1, 0) + vim.v.echospace
local msg_truncated = string.sub(msg, 1, max_width)
vim.api.nvim_echo({ { msg_truncated, 'WarningMsg' } }, true, {})
vim.api.nvim_echo({ { msg, 'WarningMsg' } }, true, { _truncate = true })
end
local notified = false

View File

@@ -239,6 +239,7 @@ error('Cannot require a meta file')
--- @class vim.api.keyset.echo_opts
--- @field err? boolean
--- @field verbose? boolean
--- @field _truncate? boolean
--- @field kind? string
--- @field id? integer|string
--- @field title? string