aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt6
-rw-r--r--runtime/doc/msgpack_rpc.txt6
-rw-r--r--src/nvim/eval.c10
-rw-r--r--test/functional/viml/function_spec.lua9
4 files changed, 29 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index b89b68837e..16f9713d2a 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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.
diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt
index 2c4b1b35bc..7fff0959d0 100644
--- a/runtime/doc/msgpack_rpc.txt
+++ b/runtime/doc/msgpack_rpc.txt
@@ -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): >
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 915484ebfb..e2cebf0751 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -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
*/
diff --git a/test/functional/viml/function_spec.lua b/test/functional/viml/function_spec.lua
index 776e760aaf..f0a4406593 100644
--- a/test/functional/viml/function_spec.lua
+++ b/test/functional/viml/function_spec.lua
@@ -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)