diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2016-06-28 21:45:19 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2016-08-31 21:57:06 +0200 |
commit | 1c22cab2fd283db49bfdbeaea490747574a36049 (patch) | |
tree | 65600e870f91250848aab4cf230340978a7a4c4f | |
parent | e536abc1e1f59d1ac012e1be576bf55175e95443 (diff) | |
download | rneovim-1c22cab2fd283db49bfdbeaea490747574a36049.tar.gz rneovim-1c22cab2fd283db49bfdbeaea490747574a36049.tar.bz2 rneovim-1c22cab2fd283db49bfdbeaea490747574a36049.zip |
api: consistently use nvim_ prefix and update documentation
-rw-r--r-- | runtime/doc/api.txt | 33 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 14 | ||||
-rw-r--r-- | runtime/doc/msgpack_rpc.txt | 38 | ||||
-rw-r--r-- | scripts/dispatch_deprecated.lua | 77 | ||||
-rw-r--r-- | scripts/gendispatch.lua | 212 | ||||
-rw-r--r-- | scripts/geneval.lua | 2 | ||||
-rw-r--r-- | src/nvim/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/nvim/api/buffer.c | 118 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.c | 3 | ||||
-rw-r--r-- | src/nvim/api/tabpage.c | 17 | ||||
-rw-r--r-- | src/nvim/api/ui.c | 12 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 82 | ||||
-rw-r--r-- | src/nvim/api/window.c | 30 | ||||
-rw-r--r-- | src/nvim/eval.c | 8 | ||||
-rw-r--r-- | src/nvim/tui/input.c | 4 | ||||
-rw-r--r-- | test/functional/api/buffer_spec.lua | 134 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 5 | ||||
-rw-r--r-- | test/functional/helpers.lua | 33 | ||||
-rw-r--r-- | test/functional/plugin/shada_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/shada/buffers_spec.lua | 4 |
20 files changed, 492 insertions, 348 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index bdeca367b1..c3d7fdb35b 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -14,13 +14,13 @@ C API for Nvim *API* *api* ============================================================================== 1. Introduction *api-intro* -Nvim exposes a public API for external code to interact with the Nvim core. In -the present version of Nvim the API is primarily used by external processes to -interact with Nvim using the msgpack-rpc protocol, see |msgpack-rpc|. The API -will also be used from vimscript to access new Nvim core features, but this is -not implemented yet. Later on, Nvim might be embeddable in C applications as -libnvim, and the application will then control the embedded instance by -calling the C API directly. +Nvim exposes a public API for external code to interact with the Nvim core. +The API is used by external processes to interact with Nvim using the +msgpack-rpc protocol, see |msgpack-rpc|. The API is used from vimscript to +access some new Nvim core features. See |eval-api| for how api functions are +called from vimscript. Later on, Nvim might be embeddable in C applications as +libnvim, and the application will then control the embedded instance by calling +the C API directly. ============================================================================== 2. API Types *api-types* @@ -73,10 +73,10 @@ Another use case are plugins that show output in an append-only buffer, and want to add highlights to the outputs. Highlight data cannot be preserved on writing and loading a buffer to file, nor in undo/redo cycles. -Highlights are registered using the |buffer_add_highlight| function, see the +Highlights are registered using the |nvim_buf_add_highlight| function, see the generated API documentation for details. If an external highlighter plugin is adding a large number of highlights in a batch, performance can be improved by -calling |buffer_add_highlight| as an asynchronous notification, after first +calling |nvim_buf_add_highlight| as an asynchronous notification, after first (synchronously) reqesting a source id. Here is an example using wrapper functions in the python client: > @@ -91,10 +91,19 @@ functions in the python client: buf.clear_highlight(src) < If the highlights don't need to be deleted or updated, just pass -1 as -src_id (this is the default in python). |buffer_clear_highlight| can be used -to clear highligts from a specific source, in a specific line range or the -entire buffer by passing in the line range 0, -1 (the later is the default +src_id (this is the default in python). |nvim_buf_clear_highlight| can be used +to clear highlights from a specific source, in a specific line range or the +entire buffer by passing in the line range 0, -1 (the latter is the default in python as used above). +An example of calling the api from vimscript: > + + call nvim_buf_set_lines(0, 0, 0, v:true, ["test text"]) + let src = nvim_buf_add_highlight(0, 0, "String", 1, 0, 4) + call nvim_buf_add_highlight(0, src, "Identifier", 0, 5, -1) + + " later + call nvim_buf_clear_highlight(0, src, 0, -1) +> ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 03d8f84aa6..92f9a0f656 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2009,6 +2009,7 @@ msgpackdump({list}) List dump a list of objects to msgpack msgpackparse({list}) List parse msgpack to a list of objects nextnonblank({lnum}) Number line nr of non-blank line >= {lnum} nr2char({expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr} +nvim_...({args}...) any call nvim |api| functions or({expr}, {expr}) Number bitwise OR pathshorten({expr}) String shorten directory names in a path pow({x}, {y}) Float {x} to the power of {y} @@ -2208,11 +2209,9 @@ and({expr}, {expr}) *and()* Example: > :let flag = and(bits, 0x80) - api_info() *api_info()* Returns Dictionary of |api-metadata|. - append({lnum}, {expr}) *append()* When {expr} is a |List|: Append each item of the |List| as a text line below line {lnum} in the current buffer. @@ -5172,6 +5171,17 @@ nr2char({expr}[, {utf8}]) *nr2char()* characters. nr2char(0) is a real NUL and terminates the string, thus results in an empty string. +nvim_...({...}) *nvim_...()* *eval-api* + Call nvim |api| functions. The type checking of arguments will + be stricter than for most other builtins. For instance, + if Integer is expected, a |Number| must be passed in, a + |String| will not be autoconverted. + Buffer numbers, as returned by |bufnr()| could be used as + first argument to nvim_buf_... functions. All functions + expecting an object (buffer, window or tabpage) can + also take the numerical value 0 to indicate the current + (focused) object. + or({expr}, {expr}) *or()* Bitwise OR on the two arguments. The arguments are converted to a number. A List, Dict or Float argument causes an error. diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt index 30f68ca942..59e9e44f8f 100644 --- a/runtime/doc/msgpack_rpc.txt +++ b/runtime/doc/msgpack_rpc.txt @@ -47,7 +47,7 @@ instance. There are three ways to obtain API metadata: - 1. Connect to a running Nvim instance and call `vim_get_api_info` via + 1. Connect to a running Nvim instance and call `nvim_get_api_info` via msgpack-rpc. This is best for clients written in dynamic languages which can define functions at runtime. @@ -105,7 +105,7 @@ Nvim instance: require 'msgpack/rpc/transport/unix' nvim = MessagePack::RPC::Client.new(MessagePack::RPC::UNIXTransport.new, ENV['NVIM_LISTEN_ADDRESS']) - result = nvim.call(:vim_command, 'echo "hello world!"') + result = nvim.call(:nvim_command, 'echo "hello world!"') < A better way is to use the Python REPL with the `neovim` package, where API functions can be called interactively: @@ -117,9 +117,9 @@ functions can be called interactively: You can also embed an Nvim instance via |jobstart()|, and communicate using |rpcrequest()| and |rpcnotify()|: > - let vim = jobstart(['nvim', '--embed'], {'rpc': v:true}) - echo rpcrequest(vim, 'vim_eval', '"Hello " . "world!"') - call jobstop(vim) + let nvim = jobstart(['nvim', '--embed'], {'rpc': v:true}) + echo rpcrequest(nvim, 'nvim_eval', '"Hello " . "world!"') + call jobstop(nvim) < ============================================================================== 4. Implementing API clients *rpc-api-client* *api-client* @@ -177,15 +177,20 @@ contains information that makes this task easier (see also |rpc-types|): - Container types may be decorated with type/size constraints, e.g. ArrayOf(Buffer) or ArrayOf(Integer, 2). This can be useful to generate even more strongly-typed APIs. - - Methods that operate on instances of Nvim special types (msgpack EXT) are - prefixed with the type name in lower case, e.g. `buffer_get_line` - represents the `get_line` method of a Buffer instance. - - Global methods are prefixed with `vim`, e.g. `vim_get_buffers`. + - Functions that are considered to be methods that operate on instances of + Nvim special types (msgpack EXT) will have the `"method"` attribute set to + `true`. The reciever type is the type of the first argument. The method + names are prefixed with `nvim_` plus a shortened type name, e.g. + `nvim_buf_get_lines` represents the `get_lines` method of a Buffer instance. + - Global functions have `"method"` set to `false` and are prefixed with just + `nvim_`, e.g. `nvim_get_buffers`. So for an object-oriented language, an API client contains the classes representing Nvim special types, and the methods of each class could be -defined by inspecting the method name prefix. There could also be a singleton -Vim class with methods mapped to functions prefixed with `vim_`. +defined by stripping the prefix for the type as defined in the `types` metadata +(this will always be the first two "_"-separated parts of the function name). +There could also be a singleton Vim class with methods where the `nvim_` +prefix is stripped off. ============================================================================== 5. Types *rpc-types* @@ -219,18 +224,21 @@ an integer, but not a Window or Tabpage. The most reliable way of determining the type codes for the special Nvim types is to inspect the `types` key of metadata dictionary returned by the -`vim_get_api_info` method at runtime. Here's a sample JSON representation of +`nvim_get_api_info` method at runtime. Here's a sample JSON representation of the `types` object: > "types": { "Buffer": { - "id": 0 + "id": 0, + "prefix": "nvim_buf_" }, "Window": { - "id": 1 + "id": 1, + "prefix": "nvim_win_" }, "Tabpage": { - "id": 2 + "id": 2, + "prefix": "nvim_tabpage_" } } < diff --git a/scripts/dispatch_deprecated.lua b/scripts/dispatch_deprecated.lua new file mode 100644 index 0000000000..f3b299e3fc --- /dev/null +++ b/scripts/dispatch_deprecated.lua @@ -0,0 +1,77 @@ +local deprecated_aliases = { + nvim_buf_line_count="buffer_line_count", + nvim_buf_get_lines="buffer_get_lines", + nvim_buf_set_lines="buffer_set_lines", + nvim_buf_get_var="buffer_get_var", + nvim_buf_set_var="buffer_set_var", + nvim_buf_del_var="buffer_del_var", + nvim_buf_get_option="buffer_get_option", + nvim_buf_set_option="buffer_set_option", + nvim_buf_get_number="buffer_get_number", + nvim_buf_get_name="buffer_get_name", + nvim_buf_set_name="buffer_set_name", + nvim_buf_is_valid="buffer_is_valid", + nvim_buf_get_mark="buffer_get_mark", + nvim_buf_add_highlight="buffer_add_highlight", + nvim_buf_clear_highlight="buffer_clear_highlight", + nvim_tabpage_get_windows="tabpage_get_windows", + nvim_tabpage_get_var="tabpage_get_var", + nvim_tabpage_set_var="tabpage_set_var", + nvim_tabpage_del_var="tabpage_del_var", + nvim_tabpage_get_window="tabpage_get_window", + nvim_tabpage_is_valid="tabpage_is_valid", + nvim_ui_detach="ui_detach", + nvim_ui_try_resize="ui_try_resize", + nvim_command="vim_command", + nvim_feedkeys="vim_feedkeys", + nvim_input="vim_input", + nvim_replace_termcodes="vim_replace_termcodes", + nvim_command_output="vim_command_output", + nvim_eval="vim_eval", + nvim_call_function="vim_call_function", + nvim_strwidth="vim_strwidth", + nvim_list_runtime_paths="vim_list_runtime_paths", + nvim_change_directory="vim_change_directory", + nvim_get_var="vim_get_var", + nvim_set_var="vim_set_var", + nvim_del_var="vim_del_var", + nvim_get_vvar="vim_get_vvar", + nvim_get_option="vim_get_option", + nvim_set_option="vim_set_option", + nvim_out_write="vim_out_write", + nvim_err_write="vim_err_write", + nvim_report_error="vim_report_error", + nvim_get_buffers="vim_get_buffers", + nvim_get_current_buffer="vim_get_current_buffer", + nvim_set_current_buffer="vim_set_current_buffer", + nvim_get_windows="vim_get_windows", + nvim_get_current_window="vim_get_current_window", + nvim_set_current_window="vim_set_current_window", + nvim_get_tabpages="vim_get_tabpages", + nvim_get_current_tabpage="vim_get_current_tabpage", + nvim_set_current_tabpage="vim_set_current_tabpage", + nvim_set_current_line="vim_set_current_line", + nvim_get_current_line="vim_get_current_line", + nvim_del_current_line="vim_del_current_line", + nvim_subscribe="vim_subscribe", + nvim_unsubscribe="vim_unsubscribe", + nvim_name_to_color="vim_name_to_color", + nvim_get_color_map="vim_get_color_map", + nvim_get_api_info="vim_get_api_info", + nvim_win_get_buffer="window_get_buffer", + nvim_win_get_cursor="window_get_cursor", + nvim_win_set_cursor="window_set_cursor", + nvim_win_get_height="window_get_height", + nvim_win_set_height="window_set_height", + nvim_win_get_width="window_get_width", + nvim_win_set_width="window_set_width", + nvim_win_get_var="window_get_var", + nvim_win_set_var="window_set_var", + nvim_win_del_var="window_del_var", + nvim_win_get_option="window_get_option", + nvim_win_set_option="window_set_option", + nvim_win_get_position="window_get_position", + nvim_win_get_tabpage="window_get_tabpage", + nvim_win_is_valid="window_is_valid" +} +return deprecated_aliases diff --git a/scripts/gendispatch.lua b/scripts/gendispatch.lua index 68d4d44e2d..2846aece5d 100644 --- a/scripts/gendispatch.lua +++ b/scripts/gendispatch.lua @@ -42,10 +42,13 @@ c_proto = Ct( ) grammar = Ct((c_proto + c_comment + c_preproc + ws) ^ 1) --- we need at least 3 arguments since the last two are output files -assert(#arg >= 2) +-- we need at least 4 arguments since the last two are output files +assert(#arg >= 3) functions = {} +local scriptdir = arg[1] +package.path = scriptdir .. '/?.lua;' .. package.path + -- names of all headers relative to the source root (for inclusion in the -- generated file) headers = {} @@ -55,7 +58,7 @@ outputf = arg[#arg-1] mpack_outputf = arg[#arg] -- read each input file, parse and append to the api metadata -for i = 1, #arg - 2 do +for i = 2, #arg - 2 do local full_path = arg[i] local parts = {} for part in string.gmatch(full_path, '[^/]+') do @@ -87,6 +90,45 @@ for i = 1, #arg - 2 do input:close() end +local function shallowcopy(orig) + local copy = {} + for orig_key, orig_value in pairs(orig) do + copy[orig_key] = orig_value + end + return copy +end + +local function startswith(String,Start) + return string.sub(String,1,string.len(Start))==Start +end + +-- Export functions under older deprecated names. +-- These will be removed eventually. +local deprecated_aliases = require("dispatch_deprecated") +for i,f in ipairs(shallowcopy(functions)) do + local ismethod = false + if startswith(f.name, "nvim_buf_") then + ismethod = true + elseif startswith(f.name, "nvim_win_") then + ismethod = true + elseif startswith(f.name, "nvim_tabpage_") then + ismethod = true + elseif not startswith(f.name, "nvim_") then + f.noeval = true + f.deprecated_since = 1 + end + f.method = ismethod + local newname = deprecated_aliases[f.name] + if newname ~= nil then + local newf = shallowcopy(f) + newf.name = newname + newf.impl_name = f.name + newf.noeval = true + newf.deprecated_since = 1 + functions[#functions+1] = newf + end +end + -- start building the output output = io.open(outputf, 'wb') @@ -166,99 +208,101 @@ end -- the real API. for i = 1, #functions do local fn = functions[i] - local args = {} - - output:write('Object handle_'..fn.name..'(uint64_t channel_id, uint64_t request_id, Array args, Error *error)') - output:write('\n{') - output:write('\n Object ret = NIL;') - -- Declare/initialize variables that will hold converted arguments - for j = 1, #fn.parameters do - local param = fn.parameters[j] - local converted = 'arg_'..j - output:write('\n '..param[1]..' '..converted..' api_init_'..string.lower(real_type(param[1]))..';') - end - output:write('\n') - output:write('\n if (args.size != '..#fn.parameters..') {') - output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong number of arguments: expecting '..#fn.parameters..' but got %zu", args.size);') - output:write('\n error->set = true;') - output:write('\n goto cleanup;') - output:write('\n }\n') - - -- Validation/conversion for each argument - for j = 1, #fn.parameters do - local converted, convert_arg, param, arg - param = fn.parameters[j] - converted = 'arg_'..j - local rt = real_type(param[1]) - if rt ~= 'Object' then - output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..') {') - output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..rt:lower()..';') - if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') or rt:match('^Boolean$') then - -- accept nonnegative integers for Booleans, Buffers, Windows and Tabpages - output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer >= 0) {') - output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;') - end - output:write('\n } else {') - output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong type for argument '..j..', expecting '..param[1]..'");') - output:write('\n error->set = true;') - output:write('\n goto cleanup;') - output:write('\n }\n') - else - output:write('\n '..converted..' = args.items['..(j - 1)..'];\n') + if fn.impl_name == nil then + local args = {} + + output:write('Object handle_'..fn.name..'(uint64_t channel_id, uint64_t request_id, Array args, Error *error)') + output:write('\n{') + output:write('\n Object ret = NIL;') + -- Declare/initialize variables that will hold converted arguments + for j = 1, #fn.parameters do + local param = fn.parameters[j] + local converted = 'arg_'..j + output:write('\n '..param[1]..' '..converted..' api_init_'..string.lower(real_type(param[1]))..';') end + output:write('\n') + output:write('\n if (args.size != '..#fn.parameters..') {') + output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong number of arguments: expecting '..#fn.parameters..' but got %zu", args.size);') + output:write('\n error->set = true;') + output:write('\n goto cleanup;') + output:write('\n }\n') - args[#args + 1] = converted - end + -- Validation/conversion for each argument + for j = 1, #fn.parameters do + local converted, convert_arg, param, arg + param = fn.parameters[j] + converted = 'arg_'..j + local rt = real_type(param[1]) + if rt ~= 'Object' then + output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..') {') + output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..rt:lower()..';') + if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') or rt:match('^Boolean$') then + -- accept nonnegative integers for Booleans, Buffers, Windows and Tabpages + output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer >= 0) {') + output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;') + end + output:write('\n } else {') + output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong type for argument '..j..', expecting '..param[1]..'");') + output:write('\n error->set = true;') + output:write('\n goto cleanup;') + output:write('\n }\n') + else + output:write('\n '..converted..' = args.items['..(j - 1)..'];\n') + end - -- function call - local call_args = table.concat(args, ', ') - output:write('\n ') - if fn.return_type ~= 'void' then - -- has a return value, prefix the call with a declaration - output:write(fn.return_type..' rv = ') - end + args[#args + 1] = converted + end - -- write the function name and the opening parenthesis - output:write(fn.name..'(') + -- function call + local call_args = table.concat(args, ', ') + output:write('\n ') + if fn.return_type ~= 'void' then + -- has a return value, prefix the call with a declaration + output:write(fn.return_type..' rv = ') + end - if fn.receives_channel_id then - -- if the function receives the channel id, pass it as first argument - if #args > 0 or fn.can_fail then - output:write('channel_id, '..call_args) + -- write the function name and the opening parenthesis + output:write(fn.name..'(') + + if fn.receives_channel_id then + -- if the function receives the channel id, pass it as first argument + if #args > 0 or fn.can_fail then + output:write('channel_id, '..call_args) + else + output:write('channel_id') + end else - output:write('channel_id') + output:write(call_args) end - else - output:write(call_args) - end - if fn.can_fail then - -- if the function can fail, also pass a pointer to the local error object - if #args > 0 then - output:write(', error);\n') + if fn.can_fail then + -- if the function can fail, also pass a pointer to the local error object + if #args > 0 then + output:write(', error);\n') + else + output:write('error);\n') + end + -- and check for the error + output:write('\n if (error->set) {') + output:write('\n goto cleanup;') + output:write('\n }\n') else - output:write('error);\n') + output:write(');\n') end - -- and check for the error - output:write('\n if (error->set) {') - output:write('\n goto cleanup;') - output:write('\n }\n') - else - output:write(');\n') - end - if fn.return_type ~= 'void' then - output:write('\n ret = '..string.upper(real_type(fn.return_type))..'_OBJ(rv);') - end - -- Now generate the cleanup label for freeing memory allocated for the - -- arguments - output:write('\n\ncleanup:'); + if fn.return_type ~= 'void' then + output:write('\n ret = '..string.upper(real_type(fn.return_type))..'_OBJ(rv);') + end + -- Now generate the cleanup label for freeing memory allocated for the + -- arguments + output:write('\n\ncleanup:'); - for j = 1, #fn.parameters do - local param = fn.parameters[j] - output:write('\n api_free_'..string.lower(real_type(param[1]))..'(arg_'..j..');') + for j = 1, #fn.parameters do + local param = fn.parameters[j] + output:write('\n api_free_'..string.lower(real_type(param[1]))..'(arg_'..j..');') + end + output:write('\n return ret;\n}\n\n'); end - output:write('\n return ret;\n}\n\n'); end -- Generate a function that initializes method names with handler functions @@ -284,7 +328,7 @@ for i = 1, #functions do output:write(' msgpack_rpc_add_method_handler('.. '(String) {.data = "'..fn.name..'", '.. '.size = sizeof("'..fn.name..'") - 1}, '.. - '(MsgpackRpcRequestHandler) {.fn = handle_'.. fn.name.. + '(MsgpackRpcRequestHandler) {.fn = handle_'.. (fn.impl_name or fn.name).. ', .async = '..tostring(fn.async)..'});\n') if #fn.name > max_fname_len then diff --git a/scripts/geneval.lua b/scripts/geneval.lua index a6171f0993..b1ba76296c 100644 --- a/scripts/geneval.lua +++ b/scripts/geneval.lua @@ -26,7 +26,7 @@ local funcs = require('eval').funcs local metadata = mpack.unpack(io.open(arg[3], 'rb'):read("*all")) for i,fun in ipairs(metadata) do if not fun.noeval then - funcs['api_'..fun.name] = { + funcs[fun.name] = { args=#fun.parameters, func='api_wrapper', data='&handle_'..fun.name, diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index e36bf400cc..3ae75c01c3 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -199,7 +199,7 @@ add_custom_command(OUTPUT ${GENERATED_UNICODE_TABLES} ) add_custom_command(OUTPUT ${GENERATED_API_DISPATCH} ${API_METADATA} - COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_HEADERS} ${GENERATED_API_DISPATCH} ${API_METADATA} + COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${PROJECT_SOURCE_DIR}/scripts ${API_HEADERS} ${GENERATED_API_DISPATCH} ${API_METADATA} DEPENDS ${API_HEADERS} ${MSGPACK_RPC_HEADERS} diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 89fb7feaa9..cf8d538f86 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -32,7 +32,7 @@ /// @param buffer The buffer handle /// @param[out] err Details of an error that may have occurred /// @return The line count -Integer buffer_line_count(Buffer buffer, Error *err) +Integer nvim_buf_line_count(Buffer buffer, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -45,23 +45,22 @@ Integer buffer_line_count(Buffer buffer, Error *err) /// Gets a buffer line /// -/// @deprecated use buffer_get_lines instead. +/// @deprecated use nvim_buf_get_lines instead. /// for positive indices (including 0) use -/// "buffer_get_lines(buffer, index, index+1, true)" +/// "nvim_buf_get_lines(buffer, index, index+1, true)" /// for negative indices use -/// "buffer_get_lines(buffer, index-1, index, true)" +/// "nvim_buf_get_lines(buffer, index-1, index, true)" /// /// @param buffer The buffer handle /// @param index The line index /// @param[out] err Details of an error that may have occurred /// @return The line string String buffer_get_line(Buffer buffer, Integer index, Error *err) - FUNC_API_NOEVAL { String rv = { .size = 0 }; index = convert_index(index); - Array slice = buffer_get_lines(0, buffer, index, index+1, true, err); + Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err); if (!err->set && slice.size) { rv = slice.items[0].data.string; @@ -74,46 +73,44 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// Sets a buffer line /// -/// @deprecated use buffer_set_lines instead. +/// @deprecated use nvim_buf_set_lines instead. /// for positive indices use -/// "buffer_set_lines(buffer, index, index+1, true, [line])" +/// "nvim_buf_set_lines(buffer, index, index+1, true, [line])" /// for negative indices use -/// "buffer_set_lines(buffer, index-1, index, true, [line])" +/// "nvim_buf_set_lines(buffer, index-1, index, true, [line])" /// /// @param buffer The buffer handle /// @param index The line index /// @param line The new line. /// @param[out] err Details of an error that may have occurred void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) - FUNC_API_NOEVAL { Object l = STRING_OBJ(line); Array array = { .items = &l, .size = 1 }; index = convert_index(index); - buffer_set_lines(0, buffer, index, index+1, true, array, err); + nvim_buf_set_lines(0, buffer, index, index+1, true, array, err); } /// Deletes a buffer line /// -/// @deprecated use buffer_set_lines instead. +/// @deprecated use nvim_buf_set_lines instead. /// for positive indices use -/// "buffer_set_lines(buffer, index, index+1, true, [])" +/// "nvim_buf_set_lines(buffer, index, index+1, true, [])" /// for negative indices use -/// "buffer_set_lines(buffer, index-1, index, true, [])" +/// "nvim_buf_set_lines(buffer, index-1, index, true, [])" /// @param buffer The buffer handle /// @param index The line index /// @param[out] err Details of an error that may have occurred void buffer_del_line(Buffer buffer, Integer index, Error *err) - FUNC_API_NOEVAL { Array array = ARRAY_DICT_INIT; index = convert_index(index); - buffer_set_lines(0, buffer, index, index+1, true, array, err); + nvim_buf_set_lines(0, buffer, index, index+1, true, array, err); } /// Retrieves a line range from the buffer /// -/// @deprecated use buffer_get_lines(buffer, newstart, newend, false) +/// @deprecated use nvim_buf_get_lines(buffer, newstart, newend, false) /// where newstart = start + int(not include_start) - int(start < 0) /// newend = end + int(include_end) - int(end < 0) /// int(bool) = 1 if bool is true else 0 @@ -130,11 +127,10 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, Boolean include_start, Boolean include_end, Error *err) - FUNC_API_NOEVAL { start = convert_index(start) + !include_start; end = convert_index(end) + include_end; - return buffer_get_lines(0, buffer, start , end, false, err); + return nvim_buf_get_lines(0, buffer, start , end, false, err); } @@ -153,12 +149,12 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, /// @param strict_indexing whether out-of-bounds should be an error. /// @param[out] err Details of an error that may have occurred /// @return An array of lines -ArrayOf(String) buffer_get_lines(uint64_t channel_id, - Buffer buffer, - Integer start, - Integer end, - Boolean strict_indexing, - Error *err) +ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id, + Buffer buffer, + Integer start, + Integer end, + Boolean strict_indexing, + Error *err) { Array rv = ARRAY_DICT_INIT; buf_T *buf = find_buffer_by_handle(buffer, err); @@ -219,7 +215,7 @@ end: /// Replaces a line range on the buffer /// -/// @deprecated use buffer_set_lines(buffer, newstart, newend, false, lines) +/// @deprecated use nvim_buf_set_lines(buffer, newstart, newend, false, lines) /// where newstart = start + int(not include_start) + int(start < 0) /// newend = end + int(include_end) + int(end < 0) /// int(bool) = 1 if bool is true else 0 @@ -237,13 +233,12 @@ void buffer_set_line_slice(Buffer buffer, Integer end, Boolean include_start, Boolean include_end, - ArrayOf(String) replacement, + ArrayOf(String) replacement, // NOLINT Error *err) - FUNC_API_NOEVAL { start = convert_index(start) + !include_start; end = convert_index(end) + include_end; - buffer_set_lines(0, buffer, start, end, false, replacement, err); + nvim_buf_set_lines(0, buffer, start, end, false, replacement, err); } @@ -265,13 +260,13 @@ void buffer_set_line_slice(Buffer buffer, /// @param strict_indexing whether out-of-bounds should be an error. /// @param replacement An array of lines to use as replacement /// @param[out] err Details of an error that may have occurred -void buffer_set_lines(uint64_t channel_id, - Buffer buffer, - Integer start, - Integer end, - Boolean strict_indexing, - ArrayOf(String) replacement, - Error *err) +void nvim_buf_set_lines(uint64_t channel_id, + Buffer buffer, + Integer start, + Integer end, + Boolean strict_indexing, + ArrayOf(String) replacement, // NOLINT + Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -421,7 +416,7 @@ end: /// @param name The variable name /// @param[out] err Details of an error that may have occurred /// @return The variable value -Object buffer_get_var(Buffer buffer, String name, Error *err) +Object nvim_buf_get_var(Buffer buffer, String name, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -442,7 +437,7 @@ Object buffer_get_var(Buffer buffer, String name, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) +Object nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -462,7 +457,7 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object buffer_del_var(Buffer buffer, String name, Error *err) +Object nvim_buf_del_var(Buffer buffer, String name, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -479,7 +474,7 @@ Object buffer_del_var(Buffer buffer, String name, Error *err) /// @param name The option name /// @param[out] err Details of an error that may have occurred /// @return The option value -Object buffer_get_option(Buffer buffer, String name, Error *err) +Object nvim_buf_get_option(Buffer buffer, String name, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -497,7 +492,7 @@ Object buffer_get_option(Buffer buffer, String name, Error *err) /// @param name The option name /// @param value The option value /// @param[out] err Details of an error that may have occurred -void buffer_set_option(Buffer buffer, String name, Object value, Error *err) +void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -513,7 +508,7 @@ void buffer_set_option(Buffer buffer, String name, Object value, Error *err) /// @param buffer The buffer handle /// @param[out] err Details of an error that may have occurred /// @return The buffer number -Integer buffer_get_number(Buffer buffer, Error *err) +Integer nvim_buf_get_number(Buffer buffer, Error *err) { Integer rv = 0; buf_T *buf = find_buffer_by_handle(buffer, err); @@ -530,7 +525,7 @@ Integer buffer_get_number(Buffer buffer, Error *err) /// @param buffer The buffer handle /// @param[out] err Details of an error that may have occurred /// @return The buffer name -String buffer_get_name(Buffer buffer, Error *err) +String nvim_buf_get_name(Buffer buffer, Error *err) { String rv = STRING_INIT; buf_T *buf = find_buffer_by_handle(buffer, err); @@ -547,7 +542,7 @@ String buffer_get_name(Buffer buffer, Error *err) /// @param buffer The buffer handle /// @param name The buffer name /// @param[out] err Details of an error that may have occurred -void buffer_set_name(Buffer buffer, String name, Error *err) +void nvim_buf_set_name(Buffer buffer, String name, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -576,7 +571,7 @@ void buffer_set_name(Buffer buffer, String name, Error *err) /// /// @param buffer The buffer handle /// @return true if the buffer is valid, false otherwise -Boolean buffer_is_valid(Buffer buffer) +Boolean nvim_buf_is_valid(Buffer buffer) { Error stub = ERROR_INIT; return find_buffer_by_handle(buffer, &stub) != NULL; @@ -584,7 +579,7 @@ Boolean buffer_is_valid(Buffer buffer) /// Inserts a sequence of lines to a buffer at a certain index /// -/// @deprecated use buffer_set_lines(buffer, lnum, lnum, true, lines) +/// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines) /// /// @param buffer The buffer handle /// @param lnum Insert the lines after `lnum`. If negative, it will append @@ -595,11 +590,10 @@ void buffer_insert(Buffer buffer, Integer lnum, ArrayOf(String) lines, Error *err) - FUNC_API_NOEVAL { // "lnum" will be the index of the line after inserting, // no matter if it is negative or not - buffer_set_lines(0, buffer, lnum, lnum, true, lines, err); + nvim_buf_set_lines(0, buffer, lnum, lnum, true, lines, err); } /// Return a tuple (row,col) representing the position of the named mark @@ -608,7 +602,7 @@ void buffer_insert(Buffer buffer, /// @param name The mark's name /// @param[out] err Details of an error that may have occurred /// @return The (row, col) tuple -ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err) +ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err) { Array rv = ARRAY_DICT_INIT; buf_T *buf = find_buffer_by_handle(buffer, err); @@ -658,7 +652,7 @@ ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err) /// called with src_id = 0, an unique source id is generated and returned. /// Succesive calls can pass in it as "src_id" to add new highlights to the same /// source group. All highlights in the same group can then be cleared with -/// buffer_clear_highlight. If the highlight never will be manually deleted +/// nvim_buf_clear_highlight. If the highlight never will be manually deleted /// pass in -1 for "src_id". /// /// If "hl_group" is the empty string no highlight is added, but a new src_id @@ -676,13 +670,13 @@ ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err) /// or -1 to highlight to end of line /// @param[out] err Details of an error that may have occurred /// @return The src_id that was used -Integer buffer_add_highlight(Buffer buffer, - Integer src_id, - String hl_group, - Integer line, - Integer col_start, - Integer col_end, - Error *err) +Integer nvim_buf_add_highlight(Buffer buffer, + Integer src_id, + String hl_group, + Integer line, + Integer col_start, + Integer col_end, + Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { @@ -718,11 +712,11 @@ Integer buffer_add_highlight(Buffer buffer, /// @param line_end End of range of lines to clear (exclusive) /// or -1 to clear to end of file. /// @param[out] err Details of an error that may have occurred -void buffer_clear_highlight(Buffer buffer, - Integer src_id, - Integer line_start, - Integer line_end, - Error *err) +void nvim_buf_clear_highlight(Buffer buffer, + Integer src_id, + Integer line_start, + Integer line_end, + Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 32cdb03130..7df2079d93 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -776,12 +776,15 @@ static void init_type_metadata(Dictionary *metadata) Dictionary buffer_metadata = ARRAY_DICT_INIT; PUT(buffer_metadata, "id", INTEGER_OBJ(kObjectTypeBuffer)); + PUT(buffer_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_buf_"))); Dictionary window_metadata = ARRAY_DICT_INIT; PUT(window_metadata, "id", INTEGER_OBJ(kObjectTypeWindow)); + PUT(window_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_win_"))); Dictionary tabpage_metadata = ARRAY_DICT_INIT; PUT(tabpage_metadata, "id", INTEGER_OBJ(kObjectTypeTabpage)); + PUT(tabpage_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_tabpage_"))); PUT(types, "Buffer", DICTIONARY_OBJ(buffer_metadata)); PUT(types, "Window", DICTIONARY_OBJ(window_metadata)); diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index c8311b0aa0..5eb901bcb1 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -14,7 +14,7 @@ /// @param tabpage The tabpage /// @param[out] err Details of an error that may have occurred /// @return The windows in `tabpage` -ArrayOf(Window) tabpage_get_windows(Tabpage tabpage, Error *err) +ArrayOf(Window) nvim_tabpage_get_windows(Tabpage tabpage, Error *err) { Array rv = ARRAY_DICT_INIT; tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -43,7 +43,7 @@ ArrayOf(Window) tabpage_get_windows(Tabpage tabpage, Error *err) /// @param name The variable name /// @param[out] err Details of an error that may have occurred /// @return The variable value -Object tabpage_get_var(Tabpage tabpage, String name, Error *err) +Object nvim_tabpage_get_var(Tabpage tabpage, String name, Error *err) { tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -64,7 +64,10 @@ Object tabpage_get_var(Tabpage tabpage, String name, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) +Object nvim_tabpage_set_var(Tabpage tabpage, + String name, + Object value, + Error *err) { tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -84,7 +87,7 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object tabpage_del_var(Tabpage tabpage, String name, Error *err) +Object nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err) { tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -100,7 +103,7 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err) /// @param tabpage The tab page handle /// @param[out] err Details of an error that may have occurred /// @return The Window handle -Window tabpage_get_window(Tabpage tabpage, Error *err) +Window nvim_tabpage_get_window(Tabpage tabpage, Error *err) { Window rv = 0; tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -110,7 +113,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err) } if (tab == curtab) { - return vim_get_current_window(); + return nvim_get_current_window(); } else { FOR_ALL_WINDOWS_IN_TAB(wp, tab) { if (wp == tab->tp_curwin) { @@ -126,7 +129,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err) /// /// @param tabpage The tab page handle /// @return true if the tab page is valid, false otherwise -Boolean tabpage_is_valid(Tabpage tabpage) +Boolean nvim_tabpage_is_valid(Tabpage tabpage) { Error stub = ERROR_INIT; return find_tab_by_handle(tabpage, &stub) != NULL; diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 5426ccc8aa..56b41f1eea 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -127,11 +127,6 @@ void nvim_ui_detach(uint64_t channel_id, Error *err) remote_ui_disconnect(channel_id); } -/// @deprecated -void ui_detach(uint64_t channel_id, Error *err) -{ - nvim_ui_detach(channel_id, err); -} void nvim_ui_try_resize(uint64_t channel_id, Integer width, Integer height, Error *err) @@ -154,13 +149,6 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width, ui_refresh(); } -/// @deprecated -void ui_try_resize(uint64_t channel_id, Integer width, - Integer height, Error *err) -{ - nvim_ui_try_resize(channel_id, width, height, err); -} - void nvim_ui_set_option(uint64_t channel_id, String name, Object value, Error *error) FUNC_API_NOEVAL diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index aa86e61e29..bba7d7b9c2 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -36,7 +36,7 @@ /// /// @param str The command str /// @param[out] err Details of an error that may have occurred -void vim_command(String str, Error *err) +void nvim_command(String str, Error *err) { // Run the command try_start(); @@ -52,7 +52,7 @@ void vim_command(String str, Error *err) /// @param escape_csi the string needs escaping for K_SPECIAL/CSI bytes /// @see feedkeys() /// @see vim_strsave_escape_csi -void vim_feedkeys(String keys, String mode, Boolean escape_csi) +void nvim_feedkeys(String keys, String mode, Boolean escape_csi) { bool remap = true; bool insert = false; @@ -96,14 +96,14 @@ void vim_feedkeys(String keys, String mode, Boolean escape_csi) } } -/// Passes input keys to Neovim. Unlike `vim_feedkeys`, this will use a +/// Passes input keys to Neovim. Unlike `nvim_feedkeys`, this will use a /// lower-level input buffer and the call is not deferred. /// This is the most reliable way to emulate real user input. /// /// @param keys to be typed /// @return The number of bytes actually written, which can be lower than /// requested if the buffer becomes full. -Integer vim_input(String keys) +Integer nvim_input(String keys) FUNC_API_ASYNC { return (Integer)input_enqueue(keys); @@ -113,7 +113,7 @@ Integer vim_input(String keys) /// /// @see replace_termcodes /// @see cpoptions -String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, +String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Boolean special) { if (str.size == 0) { @@ -133,10 +133,10 @@ String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, return cstr_as_string(ptr); } -String vim_command_output(String str, Error *err) +String nvim_command_output(String str, Error *err) { do_cmdline_cmd("redir => v:command_output"); - vim_command(str, err); + nvim_command(str, err); do_cmdline_cmd("redir END"); if (err->set) { @@ -153,7 +153,7 @@ String vim_command_output(String str, Error *err) /// @param str The expression str /// @param[out] err Details of an error that may have occurred /// @return The expanded object -Object vim_eval(String str, Error *err) +Object nvim_eval(String str, Error *err) { Object rv = OBJECT_INIT; // Evaluate the expression @@ -180,7 +180,7 @@ Object vim_eval(String str, Error *err) /// @param args Functions arguments packed in an Array /// @param[out] err Details of an error that may have occurred /// @return Result of the function call -Object vim_call_function(String fname, Array args, Error *err) +Object nvim_call_function(String fname, Array args, Error *err) { Object rv = OBJECT_INIT; if (args.size > MAX_FUNC_ARGS) { @@ -229,7 +229,7 @@ free_vim_args: /// @param str Some text /// @param[out] err Details of an error that may have occurred /// @return The number of cells -Integer vim_strwidth(String str, Error *err) +Integer nvim_strwidth(String str, Error *err) { if (str.size > INT_MAX) { api_set_error(err, Validation, _("String length is too high")); @@ -242,7 +242,7 @@ Integer vim_strwidth(String str, Error *err) /// Gets a list of paths contained in 'runtimepath' /// /// @return The list of paths -ArrayOf(String) vim_list_runtime_paths(void) +ArrayOf(String) nvim_list_runtime_paths(void) { Array rv = ARRAY_DICT_INIT; uint8_t *rtp = p_rtp; @@ -283,7 +283,7 @@ ArrayOf(String) vim_list_runtime_paths(void) /// /// @param dir The new working directory /// @param[out] err Details of an error that may have occurred -void vim_change_directory(String dir, Error *err) +void nvim_change_directory(String dir, Error *err) { if (dir.size >= MAXPATHL) { api_set_error(err, Validation, _("Directory string is too long")); @@ -311,7 +311,7 @@ void vim_change_directory(String dir, Error *err) /// /// @param[out] err Details of an error that may have occurred /// @return The current line string -String vim_get_current_line(Error *err) +String nvim_get_current_line(Error *err) { return buffer_get_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); } @@ -320,7 +320,7 @@ String vim_get_current_line(Error *err) /// /// @param line The line contents /// @param[out] err Details of an error that may have occurred -void vim_set_current_line(String line, Error *err) +void nvim_set_current_line(String line, Error *err) { buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err); } @@ -328,7 +328,7 @@ void vim_set_current_line(String line, Error *err) /// Deletes the current line /// /// @param[out] err Details of an error that may have occurred -void vim_del_current_line(Error *err) +void nvim_del_current_line(Error *err) { buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err); } @@ -338,7 +338,7 @@ void vim_del_current_line(Error *err) /// @param name The variable name /// @param[out] err Details of an error that may have occurred /// @return The variable value -Object vim_get_var(String name, Error *err) +Object nvim_get_var(String name, Error *err) { return dict_get_value(&globvardict, name, err); } @@ -352,7 +352,7 @@ Object vim_get_var(String name, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object vim_set_var(String name, Object value, Error *err) +Object nvim_set_var(String name, Object value, Error *err) { return dict_set_value(&globvardict, name, value, false, err); } @@ -365,7 +365,7 @@ Object vim_set_var(String name, Object value, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object vim_del_var(String name, Error *err) +Object nvim_del_var(String name, Error *err) { return dict_set_value(&globvardict, name, NIL, true, err); } @@ -375,7 +375,7 @@ Object vim_del_var(String name, Error *err) /// @param name The variable name /// @param[out] err Details of an error that may have occurred /// @return The variable value -Object vim_get_vvar(String name, Error *err) +Object nvim_get_vvar(String name, Error *err) { return dict_get_value(&vimvardict, name, err); } @@ -385,7 +385,7 @@ Object vim_get_vvar(String name, Error *err) /// @param name The option name /// @param[out] err Details of an error that may have occurred /// @return The option value -Object vim_get_option(String name, Error *err) +Object nvim_get_option(String name, Error *err) { return get_option_from(NULL, SREQ_GLOBAL, name, err); } @@ -395,7 +395,7 @@ Object vim_get_option(String name, Error *err) /// @param name The option name /// @param value The new option value /// @param[out] err Details of an error that may have occurred -void vim_set_option(String name, Object value, Error *err) +void nvim_set_option(String name, Object value, Error *err) { set_option_to(NULL, SREQ_GLOBAL, name, value, err); } @@ -403,7 +403,7 @@ void vim_set_option(String name, Object value, Error *err) /// Writes a message to vim output buffer /// /// @param str The message -void vim_out_write(String str) +void nvim_out_write(String str) { write_msg(str, false); } @@ -411,25 +411,25 @@ void vim_out_write(String str) /// Writes a message to vim error buffer /// /// @param str The message -void vim_err_write(String str) +void nvim_err_write(String str) { write_msg(str, true); } /// Higher level error reporting function that ensures all str contents -/// are written by sending a trailing linefeed to `vim_err_write` +/// are written by sending a trailing linefeed to `nvim_err_write` /// /// @param str The message -void vim_report_error(String str) +void nvim_report_error(String str) { - vim_err_write(str); - vim_err_write((String) {.data = "\n", .size = 1}); + nvim_err_write(str); + nvim_err_write((String) { .data = "\n", .size = 1 }); } /// Gets the current list of buffer handles /// /// @return The number of buffers -ArrayOf(Buffer) vim_get_buffers(void) +ArrayOf(Buffer) nvim_get_buffers(void) { Array rv = ARRAY_DICT_INIT; @@ -450,7 +450,7 @@ ArrayOf(Buffer) vim_get_buffers(void) /// Gets the current buffer /// /// @reqturn The buffer handle -Buffer vim_get_current_buffer(void) +Buffer nvim_get_current_buffer(void) { return curbuf->handle; } @@ -459,7 +459,7 @@ Buffer vim_get_current_buffer(void) /// /// @param id The buffer handle /// @param[out] err Details of an error that may have occurred -void vim_set_current_buffer(Buffer buffer, Error *err) +void nvim_set_current_buffer(Buffer buffer, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -480,7 +480,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err) /// Gets the current list of window handles /// /// @return The number of windows -ArrayOf(Window) vim_get_windows(void) +ArrayOf(Window) nvim_get_windows(void) { Array rv = ARRAY_DICT_INIT; @@ -501,7 +501,7 @@ ArrayOf(Window) vim_get_windows(void) /// Gets the current window /// /// @return The window handle -Window vim_get_current_window(void) +Window nvim_get_current_window(void) { return curwin->handle; } @@ -509,7 +509,7 @@ Window vim_get_current_window(void) /// Sets the current window /// /// @param handle The window handle -void vim_set_current_window(Window window, Error *err) +void nvim_set_current_window(Window window, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -530,7 +530,7 @@ void vim_set_current_window(Window window, Error *err) /// Gets the current list of tabpage handles /// /// @return The number of tab pages -ArrayOf(Tabpage) vim_get_tabpages(void) +ArrayOf(Tabpage) nvim_get_tabpages(void) { Array rv = ARRAY_DICT_INIT; @@ -551,7 +551,7 @@ ArrayOf(Tabpage) vim_get_tabpages(void) /// Gets the current tab page /// /// @return The tab page handle -Tabpage vim_get_current_tabpage(void) +Tabpage nvim_get_current_tabpage(void) { return curtab->handle; } @@ -560,7 +560,7 @@ Tabpage vim_get_current_tabpage(void) /// /// @param handle The tab page handle /// @param[out] err Details of an error that may have occurred -void vim_set_current_tabpage(Tabpage tabpage, Error *err) +void nvim_set_current_tabpage(Tabpage tabpage, Error *err) { tabpage_T *tp = find_tab_by_handle(tabpage, err); @@ -582,7 +582,7 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err) /// /// @param channel_id The channel id (passed automatically by the dispatcher) /// @param event The event type string -void vim_subscribe(uint64_t channel_id, String event) +void nvim_subscribe(uint64_t channel_id, String event) FUNC_API_NOEVAL { size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN); @@ -596,7 +596,7 @@ void vim_subscribe(uint64_t channel_id, String event) /// /// @param channel_id The channel id (passed automatically by the dispatcher) /// @param event The event type string -void vim_unsubscribe(uint64_t channel_id, String event) +void nvim_unsubscribe(uint64_t channel_id, String event) FUNC_API_NOEVAL { size_t length = (event.size < METHOD_MAXLEN ? @@ -608,12 +608,12 @@ void vim_unsubscribe(uint64_t channel_id, String event) channel_unsubscribe(channel_id, e); } -Integer vim_name_to_color(String name) +Integer nvim_name_to_color(String name) { return name_to_color((uint8_t *)name.data); } -Dictionary vim_get_color_map(void) +Dictionary nvim_get_color_map(void) { Dictionary colors = ARRAY_DICT_INIT; @@ -625,7 +625,7 @@ Dictionary vim_get_color_map(void) } -Array vim_get_api_info(uint64_t channel_id) +Array nvim_get_api_info(uint64_t channel_id) FUNC_API_ASYNC FUNC_API_NOEVAL { Array rv = ARRAY_DICT_INIT; diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f644453358..9c7fdb0697 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -19,7 +19,7 @@ /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return The buffer handle -Buffer window_get_buffer(Window window, Error *err) +Buffer nvim_win_get_buffer(Window window, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -35,7 +35,7 @@ Buffer window_get_buffer(Window window, Error *err) /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return the (row, col) tuple -ArrayOf(Integer, 2) window_get_cursor(Window window, Error *err) +ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err) { Array rv = ARRAY_DICT_INIT; win_T *win = find_window_by_handle(window, err); @@ -53,7 +53,7 @@ ArrayOf(Integer, 2) window_get_cursor(Window window, Error *err) /// @param window The window handle /// @param pos the (row, col) tuple representing the new position /// @param[out] err Details of an error that may have occurred -void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err) +void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -99,7 +99,7 @@ void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err) /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return the height in rows -Integer window_get_height(Window window, Error *err) +Integer nvim_win_get_height(Window window, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -116,7 +116,7 @@ Integer window_get_height(Window window, Error *err) /// @param window The window handle /// @param height the new height in rows /// @param[out] err Details of an error that may have occurred -void window_set_height(Window window, Integer height, Error *err) +void nvim_win_set_height(Window window, Integer height, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -142,7 +142,7 @@ void window_set_height(Window window, Integer height, Error *err) /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return the width in columns -Integer window_get_width(Window window, Error *err) +Integer nvim_win_get_width(Window window, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -159,7 +159,7 @@ Integer window_get_width(Window window, Error *err) /// @param window The window handle /// @param width the new width in columns /// @param[out] err Details of an error that may have occurred -void window_set_width(Window window, Integer width, Error *err) +void nvim_win_set_width(Window window, Integer width, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -186,7 +186,7 @@ void window_set_width(Window window, Integer width, Error *err) /// @param name The variable name /// @param[out] err Details of an error that may have occurred /// @return The variable value -Object window_get_var(Window window, String name, Error *err) +Object nvim_win_get_var(Window window, String name, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -207,7 +207,7 @@ Object window_get_var(Window window, String name, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object window_set_var(Window window, String name, Object value, Error *err) +Object nvim_win_set_var(Window window, String name, Object value, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -227,7 +227,7 @@ Object window_set_var(Window window, String name, Object value, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object window_del_var(Window window, String name, Error *err) +Object nvim_win_del_var(Window window, String name, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -244,7 +244,7 @@ Object window_del_var(Window window, String name, Error *err) /// @param name The option name /// @param[out] err Details of an error that may have occurred /// @return The option value -Object window_get_option(Window window, String name, Error *err) +Object nvim_win_get_option(Window window, String name, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -262,7 +262,7 @@ Object window_get_option(Window window, String name, Error *err) /// @param name The option name /// @param value The option value /// @param[out] err Details of an error that may have occurred -void window_set_option(Window window, String name, Object value, Error *err) +void nvim_win_set_option(Window window, String name, Object value, Error *err) { win_T *win = find_window_by_handle(window, err); @@ -278,7 +278,7 @@ void window_set_option(Window window, String name, Object value, Error *err) /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return The (row, col) tuple with the window position -ArrayOf(Integer, 2) window_get_position(Window window, Error *err) +ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err) { Array rv = ARRAY_DICT_INIT; win_T *win = find_window_by_handle(window, err); @@ -296,7 +296,7 @@ ArrayOf(Integer, 2) window_get_position(Window window, Error *err) /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return The tab page that contains the window -Tabpage window_get_tabpage(Window window, Error *err) +Tabpage nvim_win_get_tabpage(Window window, Error *err) { Tabpage rv = 0; win_T *win = find_window_by_handle(window, err); @@ -312,7 +312,7 @@ Tabpage window_get_tabpage(Window window, Error *err) /// /// @param window The window handle /// @return true if the window is valid, false otherwise -Boolean window_is_valid(Window window) +Boolean nvim_win_is_valid(Window window) { Error stub = ERROR_INIT; return find_window_by_handle(window, &stub) != NULL; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8313d726e7..ac34ad4923 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7131,7 +7131,7 @@ static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr) Object result = fn(INVALID_CHANNEL, NO_RESPONSE, args, &err); if (err.set) { - vim_report_error(cstr_as_string(err.msg)); + nvim_report_error(cstr_as_string(err.msg)); goto end; } @@ -8837,8 +8837,8 @@ static void f_feedkeys(typval_T *argvars, typval_T *rettv, FunPtr fptr) flags = get_tv_string_buf(&argvars[1], nbuf); } - vim_feedkeys(cstr_as_string((char *)keys), - cstr_as_string((char *)flags), true); + nvim_feedkeys(cstr_as_string((char *)keys), + cstr_as_string((char *)flags), true); } } @@ -13751,7 +13751,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr) } if (err.set) { - vim_report_error(cstr_as_string(err.msg)); + nvim_report_error(cstr_as_string(err.msg)); goto end; } diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 3ef4d34c9a..44521c5ae6 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -216,8 +216,8 @@ static int get_key_code_timeout(void) // Check 'ttimeout' to determine if we should send ESC after 'ttimeoutlen'. // See :help 'ttimeout' for more information Error err = ERROR_INIT; - if (vim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) { - ms = vim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer; + if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) { + ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer; } return (int)ms; diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index cf8a83ad81..2cc803da52 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -3,105 +3,111 @@ local helpers = require('test.functional.helpers')(after_each) local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq local curbufmeths, ok = helpers.curbufmeths, helpers.ok -local funcs = helpers.funcs +local funcs, request = helpers.funcs, helpers.request describe('buffer_* functions', function() before_each(clear) + -- access deprecated functions + local function curbuf_depr(method, ...) + return request('buffer_'..method, 0, ...) + end + + describe('line_count, insert and del_line', function() it('works', function() - eq(1, curbuf('line_count')) - curbuf('insert', -1, {'line'}) - eq(2, curbuf('line_count')) - curbuf('insert', -1, {'line'}) - eq(3, curbuf('line_count')) - curbuf('del_line', -1) - eq(2, curbuf('line_count')) - curbuf('del_line', -1) - curbuf('del_line', -1) + eq(1, curbuf_depr('line_count')) + curbuf_depr('insert', -1, {'line'}) + eq(2, curbuf_depr('line_count')) + curbuf_depr('insert', -1, {'line'}) + eq(3, curbuf_depr('line_count')) + curbuf_depr('del_line', -1) + eq(2, curbuf_depr('line_count')) + curbuf_depr('del_line', -1) + curbuf_depr('del_line', -1) -- There's always at least one line - eq(1, curbuf('line_count')) + eq(1, curbuf_depr('line_count')) end) end) describe('{get,set,del}_line', function() it('works', function() - eq('', curbuf('get_line', 0)) - curbuf('set_line', 0, 'line1') - eq('line1', curbuf('get_line', 0)) - curbuf('set_line', 0, 'line2') - eq('line2', curbuf('get_line', 0)) - curbuf('del_line', 0) - eq('', curbuf('get_line', 0)) + eq('', curbuf_depr('get_line', 0)) + curbuf_depr('set_line', 0, 'line1') + eq('line1', curbuf_depr('get_line', 0)) + curbuf_depr('set_line', 0, 'line2') + eq('line2', curbuf_depr('get_line', 0)) + curbuf_depr('del_line', 0) + eq('', curbuf_depr('get_line', 0)) end) it('get_line: out-of-bounds is an error', function() - curbuf('set_line', 0, 'line1.a') - eq(1, curbuf('line_count')) -- sanity - eq(false, pcall(curbuf, 'get_line', 1)) - eq(false, pcall(curbuf, 'get_line', -2)) + curbuf_depr('set_line', 0, 'line1.a') + eq(1, curbuf_depr('line_count')) -- sanity + eq(false, pcall(curbuf_depr, 'get_line', 1)) + eq(false, pcall(curbuf_depr, 'get_line', -2)) end) it('set_line, del_line: out-of-bounds is an error', function() - curbuf('set_line', 0, 'line1.a') - eq(false, pcall(curbuf, 'set_line', 1, 'line1.b')) - eq(false, pcall(curbuf, 'set_line', -2, 'line1.b')) - eq(false, pcall(curbuf, 'del_line', 2)) - eq(false, pcall(curbuf, 'del_line', -3)) + curbuf_depr('set_line', 0, 'line1.a') + eq(false, pcall(curbuf_depr, 'set_line', 1, 'line1.b')) + eq(false, pcall(curbuf_depr, 'set_line', -2, 'line1.b')) + eq(false, pcall(curbuf_depr, 'del_line', 2)) + eq(false, pcall(curbuf_depr, 'del_line', -3)) end) it('can handle NULs', function() - curbuf('set_line', 0, 'ab\0cd') - eq('ab\0cd', curbuf('get_line', 0)) + curbuf_depr('set_line', 0, 'ab\0cd') + eq('ab\0cd', curbuf_depr('get_line', 0)) end) end) describe('{get,set}_line_slice', function() it('get_line_slice: out-of-bounds returns empty array', function() - curbuf('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'}) - eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 2, true, true)) --sanity - - eq({}, curbuf('get_line_slice', 2, 3, false, true)) - eq({}, curbuf('get_line_slice', 3, 9, true, true)) - eq({}, curbuf('get_line_slice', 3, -1, true, true)) - eq({}, curbuf('get_line_slice', -3, -4, false, true)) - eq({}, curbuf('get_line_slice', -4, -5, true, true)) + curbuf_depr('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, 2, true, true)) --sanity + + eq({}, curbuf_depr('get_line_slice', 2, 3, false, true)) + eq({}, curbuf_depr('get_line_slice', 3, 9, true, true)) + eq({}, curbuf_depr('get_line_slice', 3, -1, true, true)) + eq({}, curbuf_depr('get_line_slice', -3, -4, false, true)) + eq({}, curbuf_depr('get_line_slice', -4, -5, true, true)) end) it('set_line_slice: out-of-bounds extends past end', function() - curbuf('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'}) - eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 2, true, true)) --sanity - - eq({'c'}, curbuf('get_line_slice', -1, 4, true, true)) - eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 5, true, true)) - curbuf('set_line_slice', 4, 5, true, true, {'d'}) - eq({'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true)) - curbuf('set_line_slice', -4, -5, true, true, {'e'}) - eq({'e', 'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true)) + curbuf_depr('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, 2, true, true)) --sanity + + eq({'c'}, curbuf_depr('get_line_slice', -1, 4, true, true)) + eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, 5, true, true)) + curbuf_depr('set_line_slice', 4, 5, true, true, {'d'}) + eq({'a', 'b', 'c', 'd'}, curbuf_depr('get_line_slice', 0, 5, true, true)) + curbuf_depr('set_line_slice', -4, -5, true, true, {'e'}) + eq({'e', 'a', 'b', 'c', 'd'}, curbuf_depr('get_line_slice', 0, 5, true, true)) end) it('works', function() - eq({''}, curbuf('get_line_slice', 0, -1, true, true)) + eq({''}, curbuf_depr('get_line_slice', 0, -1, true, true)) -- Replace buffer - curbuf('set_line_slice', 0, -1, true, true, {'a', 'b', 'c'}) - eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, -1, true, true)) - eq({'b', 'c'}, curbuf('get_line_slice', 1, -1, true, true)) - eq({'b'}, curbuf('get_line_slice', 1, 2, true, false)) - eq({}, curbuf('get_line_slice', 1, 1, true, false)) - eq({'a', 'b'}, curbuf('get_line_slice', 0, -1, true, false)) - eq({'b'}, curbuf('get_line_slice', 1, -1, true, false)) - eq({'b', 'c'}, curbuf('get_line_slice', -2, -1, true, true)) - curbuf('set_line_slice', 1, 2, true, false, {'a', 'b', 'c'}) - eq({'a', 'a', 'b', 'c', 'c'}, curbuf('get_line_slice', 0, -1, true, true)) - curbuf('set_line_slice', -1, -1, true, true, {'a', 'b', 'c'}) + curbuf_depr('set_line_slice', 0, -1, true, true, {'a', 'b', 'c'}) + eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, -1, true, true)) + eq({'b', 'c'}, curbuf_depr('get_line_slice', 1, -1, true, true)) + eq({'b'}, curbuf_depr('get_line_slice', 1, 2, true, false)) + eq({}, curbuf_depr('get_line_slice', 1, 1, true, false)) + eq({'a', 'b'}, curbuf_depr('get_line_slice', 0, -1, true, false)) + eq({'b'}, curbuf_depr('get_line_slice', 1, -1, true, false)) + eq({'b', 'c'}, curbuf_depr('get_line_slice', -2, -1, true, true)) + curbuf_depr('set_line_slice', 1, 2, true, false, {'a', 'b', 'c'}) + eq({'a', 'a', 'b', 'c', 'c'}, curbuf_depr('get_line_slice', 0, -1, true, true)) + curbuf_depr('set_line_slice', -1, -1, true, true, {'a', 'b', 'c'}) eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'}, - curbuf('get_line_slice', 0, -1, true, true)) - curbuf('set_line_slice', 0, -3, true, false, {}) - eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, -1, true, true)) - curbuf('set_line_slice', 0, -1, true, true, {}) - eq({''}, curbuf('get_line_slice', 0, -1, true, true)) + curbuf_depr('get_line_slice', 0, -1, true, true)) + curbuf_depr('set_line_slice', 0, -3, true, false, {}) + eq({'a', 'b', 'c'}, curbuf_depr('get_line_slice', 0, -1, true, true)) + curbuf_depr('set_line_slice', 0, -1, true, true, {}) + eq({''}, curbuf_depr('get_line_slice', 0, -1, true, true)) end) end) @@ -286,7 +292,7 @@ describe('buffer_* functions', function() describe('get_mark', function() it('works', function() - curbuf('insert', -1, {'a', 'bit of', 'text'}) + curbuf('set_lines', -1, -1, true, {'a', 'bit of', 'text'}) curwin('set_cursor', {3, 4}) nvim('command', 'mark V') eq({3, 0}, curbuf('get_mark', 'V')) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 848935fc0f..4195a614c3 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -7,6 +7,7 @@ local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local os_name = helpers.os_name local meths = helpers.meths local funcs = helpers.funcs +local request = helpers.request describe('vim_* functions', function() before_each(clear) @@ -41,6 +42,10 @@ describe('vim_* functions', function() eq(1, nvim('eval',"matcharg(1) == ['', '']")) eq({'', ''}, nvim('eval','matcharg(1)')) end) + + it('works under deprecated name', function() + eq(2, request("vim_eval", "1+1")) + end) end) describe('call_function', function() diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 8dca4c5bbe..65da278f9e 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -133,11 +133,11 @@ local function stop() end local function nvim_command(cmd) - request('vim_command', cmd) + request('nvim_command', cmd) end local function nvim_eval(expr) - return request('vim_eval', expr) + return request('nvim_eval', expr) end local os_name = (function() @@ -157,12 +157,12 @@ local os_name = (function() end)() local function nvim_call(name, ...) - return request('vim_call_function', name, {...}) + return request('nvim_call_function', name, {...}) end local function nvim_feed(input) while #input > 0 do - local written = request('vim_input', input) + local written = request('nvim_input', input) input = input:sub(written + 1) end end @@ -339,7 +339,7 @@ local function source(code) end local function nvim(method, ...) - return request('vim_'..method, ...) + return request('nvim_'..method, ...) end local function ui(method, ...) @@ -347,27 +347,26 @@ local function ui(method, ...) end local function nvim_async(method, ...) - session:notify('vim_'..method, ...) + session:notify('nvim_'..method, ...) end local function buffer(method, ...) - return request('buffer_'..method, ...) + return request('nvim_buf_'..method, ...) end local function window(method, ...) - return request('window_'..method, ...) + return request('nvim_win_'..method, ...) end local function tabpage(method, ...) - return request('tabpage_'..method, ...) + return request('nvim_tabpage_'..method, ...) end local function curbuf(method, ...) - local buf = nvim('get_current_buffer') if not method then - return buf + return nvim('get_current_buffer') end - return buffer(method, buf, ...) + return buffer(method, 0, ...) end local function wait() @@ -387,19 +386,17 @@ local function curbuf_contents() end local function curwin(method, ...) - local win = nvim('get_current_window') if not method then - return win + return nvim('get_current_window') end - return window(method, win, ...) + return window(method, 0, ...) end local function curtab(method, ...) - local tab = nvim('get_current_tabpage') if not method then - return tab + return nvim('get_current_tabpage') end - return tabpage(method, tab, ...) + return tabpage(method, 0, ...) end local function expect(contents) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 2595f22929..b1209a22e9 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -2463,17 +2463,17 @@ describe('ftplugin/shada.vim', function() nvim_command('setlocal filetype=shada') funcs.setline(1, ' Replacement with timestamp ' .. epoch) nvim_feed('ggA:\027') - eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_line', 0)) + eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1]) nvim_feed('o-\027') - eq(' -', curbuf('get_line', 1)) + eq({' -'}, curbuf('get_lines', 1, 2, true)) nvim_feed('ggO+\027') - eq('+', curbuf('get_line', 0)) + eq({'+'}, curbuf('get_lines', 0, 1, true)) nvim_feed('GO*\027') - eq(' *', curbuf('get_line', 2)) + eq({' *'}, curbuf('get_lines', 2, 3, true)) nvim_feed('ggO /\027') - eq(' /', curbuf('get_line', 0)) + eq({' /'}, curbuf('get_lines', 0, 1, true)) nvim_feed('ggOx\027') - eq('x', curbuf('get_line', 0)) + eq({'x'}, curbuf('get_lines', 0, 1, true)) end) end) diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua index 6694e736dc..01952560d6 100644 --- a/test/functional/shada/buffers_spec.lua +++ b/test/functional/shada/buffers_spec.lua @@ -80,9 +80,9 @@ describe('ShaDa support code', function() it('does not dump unnamed buffers', function() set_additional_cmd('set shada+=% hidden') reset() - curbufmeths.set_line(0, 'foo') + curbufmeths.set_lines(0, 1, true, {'foo'}) nvim_command('enew') - curbufmeths.set_line(0, 'bar') + curbufmeths.set_lines(0, 1, true, {'bar'}) eq(2, funcs.bufnr('$')) nvim_command('qall!') reset() |