Attach and show msg only once

pull/20/head
Marco Hinz 8 years ago
parent 06d49ed4a7
commit ae0fa3ae3c

@ -33,48 +33,28 @@ from neovim import attach
class Neovim():
def __init__(self, address):
self.address = address
self.server = None
self.address = address
self.server = None
self._msg_shown = False
def is_attached(self, silent=False):
if self.server is not None:
return True
def attach(self):
try:
addr = self.address.split(':')
if len(addr) == 1:
self.server = attach('socket', path=self.address)
if ':' in self.address:
ip, port = self.address.split(':')
self.server = attach('tcp', address=ip, port=int(port))
else:
ip, port = addr
self.server = attach("tcp", address=ip, port=int(port))
self.server = attach('socket', path=self.address)
except:
if not silent:
print(textwrap.dedent("""
[!] Can't connect to: {}
If your intention was to communicate with a remote nvim
instance, verify that \":echo v:servername\" in your
instance uses the same address.
SOLUTION 1 (from server side):
pass
Expose $NVIM_LISTEN_ADDRESS to the environment before
starting nvim, so that v:servername gets set accordingly.
$ NVIM_LISTEN_ADDRESS=/tmp/foo nvim
SOLUTION 2 (from client side):
Expose $NVIM_LISTEN_ADDRESS to the environment before
using nvr or use its --servername option. If neither
is given, nvr assumes \"/tmp/nvimsocket\".
$ NVIM_LISTEN_ADDRESS=/tmp/foo nvr --remote file1 file2
$ nvr --servername /tmp/foo --remote file1 file2
[*] Starting a new instance with this address: {}
""".format(self.address, self.address)))
def is_attached(self, silent=False):
if self.server:
return True
else:
if not silent and not self._msg_shown:
self._show_msg()
self._msg_shown = True
return False
return True
def execute(self, arguments, cmd='edit', silent=False, wait=False):
if self.is_attached(silent):
@ -112,6 +92,33 @@ class Neovim():
self.server.run_loop(None, notification_cb, setup_cb)
def _show_msg(self):
print(textwrap.dedent("""
[!] Can't connect to: {}
If your intention was to communicate with a remote nvim
instance, verify that \":echo v:servername\" in your
instance uses the same address.
SOLUTION 1 (from server side):
Expose $NVIM_LISTEN_ADDRESS to the environment before
starting nvim, so that v:servername gets set accordingly.
$ NVIM_LISTEN_ADDRESS=/tmp/foo nvim
SOLUTION 2 (from client side):
Expose $NVIM_LISTEN_ADDRESS to the environment before
using nvr or use its --servername option. If neither
is given, nvr assumes \"/tmp/nvimsocket\".
$ NVIM_LISTEN_ADDRESS=/tmp/foo nvr --remote file1 file2
$ nvr --servername /tmp/foo --remote file1 file2
[*] Starting a new instance with this address: {}
""".format(self.address, self.address)))
def parse_args():
form_class = argparse.RawDescriptionHelpFormatter
@ -227,6 +234,7 @@ def main():
print(address)
neovim = Neovim(address)
neovim.attach()
if flags.l and neovim.is_attached():
neovim.server.command('wincmd p')

Loading…
Cancel
Save