Merge pull request #4925 from bfredl/apiinfo

eval: add api_info()
This commit is contained in:
Björn Linse 2016-06-17 21:49:56 +02:00 committed by GitHub
commit a59330d6fc
4 changed files with 29 additions and 2 deletions

View File

@ -1783,6 +1783,7 @@ abs({expr}) Float or Number absolute value of {expr}
acos({expr}) Float arc cosine of {expr}
add({list}, {item}) List append {item} to |List| {list}
and({expr}, {expr}) Number bitwise AND
api_info() Dict api metadata
append({lnum}, {string}) Number append {string} below line {lnum}
append({lnum}, {list}) Number append lines {list} below line {lnum}
argc() Number number of files in the argument list
@ -2196,6 +2197,11 @@ and({expr}, {expr}) *and()*
:let flag = and(bits, 0x80)
api_info() *api_info()*
Return Dictionary containing api metadata.
See |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.

View File

@ -45,7 +45,7 @@ msgpack-rpc details from application developers. The wrappers can be
automatically generated by reading bundled API metadata from a compiled Nvim
instance.
There are two ways to obtain API metadata:
There are three ways to obtain API metadata:
1. Connect to a running Nvim instance and call `vim_get_api_info` via
msgpack-rpc. This is best for clients written in dynamic languages which
@ -55,8 +55,10 @@ There are two ways to obtain API metadata:
of msgpack metadata to standard output. This is useful for clients
written in statically-compiled languages.
3. In vimscript the metadata is available as |api_info()|.
To get a human-readable list of API functions: >
:new|put =map(msgpackparse(systemlist('nvim --api-info'))[0].functions, 'v:val.name._VAL[0]')
:new|put =map(api_info().functions, 'v:val.name')
<
To get a formatted dump of the API using python (requires the `pyyaml` and
`msgpack-python` packages): >

View File

@ -6684,6 +6684,7 @@ static struct fst {
{ "acos", 1, 1, f_acos }, // WJMc
{ "add", 2, 2, f_add },
{ "and", 2, 2, f_and },
{ "api_info", 0, 0, f_api_info },
{ "append", 2, 2, f_append },
{ "argc", 0, 0, f_argc },
{ "argidx", 0, 0, f_argidx },
@ -7466,6 +7467,15 @@ static void f_and(typval_T *argvars, typval_T *rettv)
& get_tv_number_chk(&argvars[1], NULL);
}
/// "api_info()" function
static void f_api_info(typval_T *argvars, typval_T *rettv)
{
Dictionary metadata = api_metadata();
object_to_vim(DICTIONARY_OBJ(metadata), rettv, NULL);
api_free_dictionary(metadata);
}
/*
* "append(lnum, string/list)" function
*/

View File

@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local exc_exec = helpers.exc_exec
describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
@ -27,3 +28,11 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function()
eq('Vim(call):E740: Too many arguments for function rpcnotify', ret)
end)
end)
describe('api_info()', function()
before_each(clear)
it('has the right keys', function()
local api_keys = eval("sort(keys(api_info()))")
eq({'error_types', 'functions', 'types'}, api_keys)
end)
end)