Skip to content

Commit 99543ea

Browse files
dbarnettsnu5mumr1k
authored andcommitted
Fix neovim >=0.8 compatibility (pass --listen arg)
1 parent 86826cf commit 99543ea

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

vroom/neovim_mod.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from vroom.vim import CONFIGFILE
22
from vroom.vim import Communicator as VimCommunicator
33
import subprocess
4+
import tempfile
45
import time
56
import neovim
67
import os
78

89
class Communicator(VimCommunicator):
910
"""Object to communicate with a Neovim server."""
1011

12+
_listen_addr = None
13+
1114
def __init__(self, args, env, writer):
1215
self.writer = writer.commands
1316
self.args = args
@@ -16,7 +19,6 @@ def __init__(self, args, env, writer):
1619
'-u', args.vimrc,
1720
'-c', 'set shell=' + args.shell,
1821
'-c', 'source %s' % CONFIGFILE]
19-
env['NVIM_LISTEN_ADDRESS'] = args.servername
2022
self.env = env
2123
self._cache = {}
2224

@@ -29,13 +31,21 @@ def Quit(self):
2931

3032
def Start(self):
3133
"""Starts Neovim"""
34+
if self._listen_addr is not None:
35+
raise InvocationError('Called Start on already-running neovim instance')
36+
tmpdir = tempfile.mkdtemp()
37+
self._listen_addr = os.path.join(tmpdir, 'nvim.pipe')
38+
# Legacy env var, used by nvim <0.8
39+
self.env['NVIM_LISTEN_ADDRESS'] = self._listen_addr
40+
self.start_command += ['--listen', self._listen_addr]
41+
3242
self.process = subprocess.Popen(self.start_command, env=self.env)
3343
start_time = time.time()
3444
# Wait at most 5s for the Neovim socket
35-
while not os.path.exists(self.args.servername) \
45+
while not os.path.exists(self._listen_addr) \
3646
and time.time() - start_time < 5:
3747
time.sleep(0.01)
38-
self.nvim = neovim.attach('socket', path=self.args.servername)
48+
self.nvim = neovim.attach('socket', path=self._listen_addr)
3949

4050
def Communicate(self, command, extra_delay=0):
4151
"""Sends a command to Neovim.
@@ -101,5 +111,12 @@ def Kill(self):
101111
"""Kills the Neovim process and removes the socket"""
102112
VimCommunicator.Kill(self)
103113

104-
if os.path.exists(self.args.servername):
105-
os.remove(self.args.servername)
114+
if os.path.exists(self._listen_addr):
115+
os.remove(self._listen_addr)
116+
117+
118+
class InvocationError(Exception):
119+
"""Raised when there's a problem starting or interacting with neovim instance.
120+
"""
121+
is_fatal = True
122+

0 commit comments

Comments
 (0)