From c66c71e73d18fb080a3d969d8e73b74ee11e18ef Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 14 Jul 2018 20:52:21 +0200 Subject: [PATCH] Add RemoteApi.__dir__ with info from nvim_get_api_info --- neovim/api/common.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/neovim/api/common.py b/neovim/api/common.py index 5bb09df6..2d0bf995 100644 --- a/neovim/api/common.py +++ b/neovim/api/common.py @@ -60,10 +60,26 @@ def __init__(self, obj, api_prefix): self._obj = obj self._api_prefix = api_prefix + self._api_names = None + def __getattr__(self, name): """Return wrapper to named api method.""" return functools.partial(self._obj.request, self._api_prefix + name) + def __dir__(self): + """Return info via nvim_get_api_info. + + This can be used for introspection, and especially completion. + """ + if self._api_names is None: + api_info = self._obj.request('nvim_get_api_info') + start = len(self._api_prefix) + self._api_names = [ + x['name'][start:] for x in api_info[1]['functions'] + if x['name'].startswith(self._api_prefix) + ] + return super(RemoteApi, self).__dir__() + self._api_names + class RemoteMap(object):