Merge #31900 from luukvbaal/nvim_echo

This commit is contained in:
Justin M. Keyes
2025-01-09 06:36:29 -08:00
committed by GitHub
19 changed files with 190 additions and 160 deletions

View File

@@ -224,7 +224,7 @@ do
local function cmd(opts)
local ok, err = pcall(vim.api.nvim_cmd, opts, {})
if not ok then
vim.api.nvim_err_writeln(err:sub(#'Vim:' + 1))
vim.api.nvim_echo({ { err:sub(#'Vim:' + 1) } }, true, { err = true })
end
end

View File

@@ -58,6 +58,7 @@ vim._extra = {
--- @private
vim.log = {
--- @enum vim.log.levels
levels = {
TRACE = 0,
DEBUG = 1,
@@ -620,13 +621,8 @@ end
---@param opts table|nil Optional parameters. Unused by default.
---@diagnostic disable-next-line: unused-local
function vim.notify(msg, level, opts) -- luacheck: no unused args
if level == vim.log.levels.ERROR then
vim.api.nvim_err_writeln(msg)
elseif level == vim.log.levels.WARN then
vim.api.nvim_echo({ { msg, 'WarningMsg' } }, true, {})
else
vim.api.nvim_echo({ { msg } }, true, {})
end
local chunks = { { msg, level == vim.log.levels.WARN and 'WarningMsg' or nil } }
vim.api.nvim_echo(chunks, true, { err = level == vim.log.levels.ERROR })
end
do

View File

@@ -1104,22 +1104,19 @@ function vim.api.nvim_del_var(name) end
--- `hl_group` element can be omitted for no highlight.
--- @param history boolean if true, add to `message-history`.
--- @param opts vim.api.keyset.echo_opts Optional parameters.
--- - err: Treat the message like `:echoerr`. Omitted `hlgroup`
--- uses `hl-ErrorMsg` instead.
--- - verbose: Message is printed as a result of 'verbose' option.
--- If Nvim was invoked with -V3log_file, the message will be
--- redirected to the log_file and suppressed from direct output.
function vim.api.nvim_echo(chunks, history, opts) end
--- Writes a message to the Vim error buffer. Does not append "\n", the
--- message is buffered (won't display) until a linefeed is written.
---
--- @param str string Message
--- @deprecated
--- @param str string
function vim.api.nvim_err_write(str) end
--- Writes a message to the Vim error buffer. Appends "\n", so the buffer is
--- flushed (and displayed).
---
--- @see vim.api.nvim_err_write
--- @param str string Message
--- @deprecated
--- @param str string
function vim.api.nvim_err_writeln(str) end
--- Evaluates a Vimscript `expression`. Dicts and Lists are recursively expanded.
@@ -1859,10 +1856,8 @@ function vim.api.nvim_open_term(buffer, opts) end
--- @return integer # Window handle, or 0 on error
function vim.api.nvim_open_win(buffer, enter, config) end
--- Writes a message to the Vim output buffer. Does not append "\n", the
--- message is buffered (won't display) until a linefeed is written.
---
--- @param str string Message
--- @deprecated
--- @param str string
function vim.api.nvim_out_write(str) end
--- Parse command line.

View File

@@ -88,6 +88,7 @@ error('Cannot require a meta file')
--- @field pattern? string|string[]
--- @class vim.api.keyset.echo_opts
--- @field err? boolean
--- @field verbose? boolean
--- @class vim.api.keyset.empty

View File

@@ -702,14 +702,14 @@ local wait_result_reason = { [-1] = 'timeout', [-2] = 'interrupted', [-3] = 'err
---
--- @param ... string List to write to the buffer
local function err_message(...)
local message = table.concat(vim.iter({ ... }):flatten():totable())
local chunks = { { table.concat({ ... }) } }
if vim.in_fast_event() then
vim.schedule(function()
api.nvim_err_writeln(message)
vim.api.nvim_echo(chunks, true, { err = true })
api.nvim_command('redraw')
end)
else
api.nvim_err_writeln(message)
vim.api.nvim_echo(chunks, true, { err = true })
api.nvim_command('redraw')
end
end

View File

@@ -582,9 +582,8 @@ NSC['window/showMessage'] = function(_, params, ctx)
if message_type == protocol.MessageType.Error then
err_message('LSP[', client_name, '] ', message)
else
--- @type string
local message_type_name = protocol.MessageType[message_type]
api.nvim_out_write(string.format('LSP[%s][%s] %s\n', client_name, message_type_name, message))
message = ('LSP[%s][%s] %s\n'):format(client_name, protocol.MessageType[message_type], message)
api.nvim_echo({ { message } }, true, { err = true })
end
return params
end