refactor(api): deprecate nvim_notify #31938

Problem:
The `nvim_notify` API (note: unrelated to `vim.notify()` Lua API) was
not given any real motivation in https://github.com/neovim/neovim/pull/13843

There are, and were, idiomatic and ergonomic alternatives already.

Solution:
Deprecate `nvim_notify`.
This commit is contained in:
Justin M. Keyes 2025-01-10 11:42:04 -08:00 committed by GitHub
parent b06f42b502
commit 0717dfbfaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 47 additions and 51 deletions

View File

@ -1094,17 +1094,6 @@ nvim_load_context({dict}) *nvim_load_context()*
Parameters: ~
• {dict} |Context| map.
nvim_notify({msg}, {log_level}, {opts}) *nvim_notify()*
Notify the user with a message
Relays the call to vim.notify . By default forwards your message in the
echo area but can be overridden to trigger desktop notifications.
Parameters: ~
• {msg} Message to display to the user
• {log_level} The log level
• {opts} Reserved for future use.
nvim_open_term({buffer}, {opts}) *nvim_open_term()*
Open a terminal instance in a buffer

View File

@ -16,6 +16,7 @@ Deprecated features
DEPRECATED IN 0.11 *deprecated-0.11*
API
• nvim_notify() Use |nvim_echo()| or `nvim_exec_lua("vim.notify(...)", ...)` instead.
• nvim_subscribe() Plugins must maintain their own "multicast" channels list.
• nvim_unsubscribe() Plugins must maintain their own "multicast" channels list.
• nvim_out_write() Use |nvim_echo()|.

View File

@ -1647,14 +1647,10 @@ function vim.api.nvim_list_wins() end
--- @return any
function vim.api.nvim_load_context(dict) end
--- Notify the user with a message
---
--- Relays the call to vim.notify . By default forwards your message in the
--- echo area but can be overridden to trigger desktop notifications.
---
--- @param msg string Message to display to the user
--- @param log_level integer The log level
--- @param opts table<string,any> Reserved for future use.
--- @deprecated
--- @param msg string
--- @param log_level integer
--- @param opts table<string,any>
--- @return any
function vim.api.nvim_notify(msg, log_level, opts) end

View File

@ -1,3 +1,5 @@
// Island of misfit toys.
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
@ -896,3 +898,22 @@ void nvim_err_writeln(String str)
{
write_msg(str, true, true);
}
/// @deprecated
///
/// Use `nvim_echo` or `nvim_exec_lua("vim.notify(...)", ...)` instead.
///
/// @param msg Message to display to the user
/// @param log_level The log level
/// @param opts Reserved for future use.
/// @param[out] err Error details, if any
Object nvim_notify(String msg, Integer log_level, Dict opts, Arena *arena, Error *err)
FUNC_API_SINCE(7) FUNC_API_DEPRECATED_SINCE(13)
{
MAXSIZE_TEMP_ARRAY(args, 3);
ADD_C(args, STRING_OBJ(msg));
ADD_C(args, INTEGER_OBJ(log_level));
ADD_C(args, DICT_OBJ(opts));
return NLUA_EXEC_STATIC("return vim.notify(...)", args, kRetObject, arena, err);
}

View File

@ -516,26 +516,6 @@ Object nvim_exec_lua(String code, Array args, Arena *arena, Error *err)
return nlua_exec(code, args, kRetObject, arena, err);
}
/// Notify the user with a message
///
/// Relays the call to vim.notify . By default forwards your message in the
/// echo area but can be overridden to trigger desktop notifications.
///
/// @param msg Message to display to the user
/// @param log_level The log level
/// @param opts Reserved for future use.
/// @param[out] err Error details, if any
Object nvim_notify(String msg, Integer log_level, Dict opts, Arena *arena, Error *err)
FUNC_API_SINCE(7)
{
MAXSIZE_TEMP_ARRAY(args, 3);
ADD_C(args, STRING_OBJ(msg));
ADD_C(args, INTEGER_OBJ(log_level));
ADD_C(args, DICT_OBJ(opts));
return NLUA_EXEC_STATIC("return vim.notify(...)", args, kRetObject, arena, err);
}
/// Calculates the number of display cells occupied by `text`.
/// Control characters including [<Tab>] count as one cell.
///

View File

@ -0,0 +1,21 @@
-- Island of misfit toys.
--- @diagnostic disable: deprecated
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
describe('deprecated', function()
before_each(n.clear)
describe('nvim_notify', function()
it('can notify a info message', function()
n.api.nvim_notify('hello world', 2, {})
end)
it('can be overridden', function()
n.command('lua vim.notify = function(...) return 42 end')
t.eq(42, n.api.nvim_exec_lua("return vim.notify('Hello world')", {}))
n.api.nvim_notify('hello world', 4, {})
end)
end)
end)

View File

@ -781,18 +781,6 @@ describe('API', function()
end)
end)
describe('nvim_notify', function()
it('can notify a info message', function()
api.nvim_notify('hello world', 2, {})
end)
it('can be overridden', function()
command('lua vim.notify = function(...) return 42 end')
eq(42, api.nvim_exec_lua("return vim.notify('Hello world')", {}))
api.nvim_notify('hello world', 4, {})
end)
end)
describe('nvim_input', function()
it('Vimscript error: does NOT fail, updates v:errmsg', function()
local status, _ = pcall(api.nvim_input, ':call bogus_fn()<CR>')