Skip to content

Commit 605897b

Browse files
committed
support async command and eval
1 parent b467cef commit 605897b

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

neovim/api/nvim.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ def unsubscribe(self, event):
112112
"""Unsubscribe to a Nvim event."""
113113
return self._session.request('vim_unsubscribe', event)
114114

115-
def command(self, string):
115+
def command(self, string, async=False):
116116
"""Execute a single ex command."""
117-
return self._session.request('vim_command', string)
117+
return self._session.request('vim_command', string, async=async)
118118

119119
def command_output(self, string):
120120
"""Execute a single ex command and return the output."""
121121
return self._session.request('vim_command_output', string)
122122

123-
def eval(self, string):
123+
def eval(self, string, async=False):
124124
"""Evaluate a vimscript expression."""
125-
return self._session.request('vim_eval', string)
125+
return self._session.request('vim_eval', string, async=async)
126126

127127
def strwidth(self, string):
128128
"""Return the number of display cells `string` occupies.

test/test_client_rpc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ def request_cb(name, args):
4242
vim.vars['result'] = 17
4343
vim.session.stop()
4444

45-
cmd = 'call rpcrequest(%d, "test-event")' % vim.channel_id
4645
# this would have dead-locked if not async
47-
vim.session.request('vim_command', cmd, async=True)
46+
vim.eval('rpcrequest(%d, "test-event")' % vim.channel_id, async=True)
4847
vim.session.run(request_cb, None, None)
4948
eq(vim.vars['result'], 17)
5049

test/test_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def test_receiving_events():
1919
@with_setup(setup=cleanup)
2020
def test_sending_notify():
2121
# notify after notify
22-
vim.session.request('vim_command', "let g:test = 3", async=True)
22+
vim.command("let g:test = 3", async=True)
2323
cmd = 'call rpcnotify(%d, "test-event", g:test)' % vim.channel_id
24-
vim.session.request('vim_command', cmd, async=True)
24+
vim.command(cmd, async=True)
2525
event = vim.session.next_message()
2626
eq(event[1], 'test-event')
2727
eq(event[2], [3])
2828

2929
# request after notify
30-
vim.session.request('vim_command', "let g:data = 'xyz'", async=True)
30+
vim.command("let g:data = 'xyz'", async=True)
3131
eq(vim.eval('g:data'), 'xyz')
3232

3333

0 commit comments

Comments
 (0)