Skip to content

Commit 0e4f246

Browse files
committed
script_host: avoid race in initialization. fixes #337
1 parent d2cdf55 commit 0e4f246

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

neovim/plugin/script_host.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ def __init__(self, nvim):
4747

4848
# Handle DirChanged. #296
4949
nvim.command(
50-
'autocmd DirChanged * call rpcrequest({}, "python_chdir", v:event)'
50+
'au DirChanged * call rpcnotify({}, "python_chdir", v:event.cwd)'
5151
.format(nvim.channel_id), async_=True)
5252
# XXX: Avoid race condition.
5353
# https://github.com/neovim/python-client/pull/296#issuecomment-358970531
54-
os.chdir(nvim.eval('getcwd()', async_=False))
54+
# TODO(bfredl): when host initialization has been refactored,
55+
# to make __init__ safe again, the following should work:
56+
# os.chdir(nvim.eval('getcwd()', async_=False))
57+
nvim.command('call rpcnotify({}, "python_chdir", getcwd())'
58+
.format(nvim.channel_id), async_=True)
5559

5660
def setup(self, nvim):
5761
"""Setup import hooks and global streams.
@@ -161,10 +165,10 @@ def python_eval(self, expr):
161165
"""Handle the `pyeval` vim function."""
162166
return eval(expr, self.module.__dict__)
163167

164-
@rpc_export('python_chdir', sync=True)
165-
def python_chdir(self, args):
168+
@rpc_export('python_chdir', sync=False)
169+
def python_chdir(self, cwd):
166170
"""Handle working directory changes."""
167-
os.chdir(args['cwd'])
171+
os.chdir(cwd)
168172

169173
def _set_current_range(self, start, stop):
170174
current = self.legacy_vim.current

0 commit comments

Comments
 (0)