Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add RemoteApi.__dir__ with info from nvim_get_api_info #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions neovim/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a shared metadata object as nvim.metadata though it is a bit tricky to access it as _obj could be either a Nvim or a Remote. Guess you could do something like nvim = _obj._session if isinstance(obj,Remote) else _obj

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):

Expand Down