mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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:
		| @@ -1094,17 +1094,6 @@ nvim_load_context({dict})                                *nvim_load_context()* | |||||||
|     Parameters: ~ |     Parameters: ~ | ||||||
|       • {dict}  |Context| map. |       • {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()* | nvim_open_term({buffer}, {opts})                            *nvim_open_term()* | ||||||
|     Open a terminal instance in a buffer |     Open a terminal instance in a buffer | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,6 +16,7 @@ Deprecated features | |||||||
| DEPRECATED IN 0.11					*deprecated-0.11* | DEPRECATED IN 0.11					*deprecated-0.11* | ||||||
|  |  | ||||||
| API | API | ||||||
|  | • nvim_notify()		Use |nvim_echo()| or `nvim_exec_lua("vim.notify(...)", ...)` instead. | ||||||
| • nvim_subscribe()	Plugins must maintain their own "multicast" channels list. | • nvim_subscribe()	Plugins must maintain their own "multicast" channels list. | ||||||
| • nvim_unsubscribe()	Plugins must maintain their own "multicast" channels list. | • nvim_unsubscribe()	Plugins must maintain their own "multicast" channels list. | ||||||
| • nvim_out_write()	Use |nvim_echo()|. | • nvim_out_write()	Use |nvim_echo()|. | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								runtime/lua/vim/_meta/api.lua
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										12
									
								
								runtime/lua/vim/_meta/api.lua
									
									
									
										generated
									
									
									
								
							| @@ -1647,14 +1647,10 @@ function vim.api.nvim_list_wins() end | |||||||
| --- @return any | --- @return any | ||||||
| function vim.api.nvim_load_context(dict) end | function vim.api.nvim_load_context(dict) end | ||||||
|  |  | ||||||
| --- Notify the user with a message | --- @deprecated | ||||||
| --- | --- @param msg string | ||||||
| --- Relays the call to vim.notify . By default forwards your message in the | --- @param log_level integer | ||||||
| --- echo area but can be overridden to trigger desktop notifications. | --- @param opts table<string,any> | ||||||
| --- |  | ||||||
| --- @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. |  | ||||||
| --- @return any | --- @return any | ||||||
| function vim.api.nvim_notify(msg, log_level, opts) end | function vim.api.nvim_notify(msg, log_level, opts) end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,3 +1,5 @@ | |||||||
|  | // Island of misfit toys. | ||||||
|  |  | ||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| @@ -896,3 +898,22 @@ void nvim_err_writeln(String str) | |||||||
| { | { | ||||||
|   write_msg(str, true, true); |   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); | ||||||
|  | } | ||||||
|   | |||||||
| @@ -516,26 +516,6 @@ Object nvim_exec_lua(String code, Array args, Arena *arena, Error *err) | |||||||
|   return nlua_exec(code, args, kRetObject, arena, 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`. | /// Calculates the number of display cells occupied by `text`. | ||||||
| /// Control characters including [<Tab>] count as one cell. | /// Control characters including [<Tab>] count as one cell. | ||||||
| /// | /// | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								test/functional/api/deprecated_spec.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								test/functional/api/deprecated_spec.lua
									
									
									
									
									
										Normal 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) | ||||||
| @@ -781,18 +781,6 @@ describe('API', function() | |||||||
|     end) |     end) | ||||||
|   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() |   describe('nvim_input', function() | ||||||
|     it('Vimscript error: does NOT fail, updates v:errmsg', function() |     it('Vimscript error: does NOT fail, updates v:errmsg', function() | ||||||
|       local status, _ = pcall(api.nvim_input, ':call bogus_fn()<CR>') |       local status, _ = pcall(api.nvim_input, ':call bogus_fn()<CR>') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes