From af5914b92241b87ffe422a4def3bfb95fd182039 Mon Sep 17 00:00:00 2001 From: Geoffrey Yu Date: Fri, 23 Feb 2018 23:36:55 -0500 Subject: [PATCH] Update vim/neovim plugins for hole punching (4/5) (#97) * Update vim/neovim plugins for hole punching * Remove unneeded assignment --- plugins/vim/tandem_lib/tandem_plugin.py | 21 ++++++++------------- plugins/vim/tandem_neovim.py | 10 +++++++--- plugins/vim/tandem_vim.vim | 6 ++++-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/plugins/vim/tandem_lib/tandem_plugin.py b/plugins/vim/tandem_lib/tandem_plugin.py index ca04420..92eea52 100644 --- a/plugins/vim/tandem_lib/tandem_plugin.py +++ b/plugins/vim/tandem_lib/tandem_plugin.py @@ -73,16 +73,15 @@ def _start_agent(self): self._agent_stdout_iter = iter(self._agent.stdout.readline, b"") if self._connect_to is not None: - host_ip, host_port = self._connect_to - message = m.ConnectTo(host_ip, int(host_port)) - self._agent.stdin.write(m.serialize(message)) - self._agent.stdin.write("\n") - self._agent.stdin.flush() + message = m.JoinSession(self._connect_to) + else: + message = m.HostSession() + self._agent.stdin.write(m.serialize(message)) + self._agent.stdin.write("\n") + self._agent.stdin.flush() self._output_checker.start() - self._vim.command('echom "Bound agent to port: {}"'.format(self._agent_port)) - def _check_document_sync(self): global is_active while is_active: @@ -280,17 +279,13 @@ def _handle_apply_patches(self, message): def _handle_message(self, message): self._message_handler(message) - def start(self, host_ip=None, host_port=None): + def start(self, session_id=None): global is_active if is_active: print "Cannot start. An instance is already running on :{}".format(self._agent_port) return - if host_ip is not None and host_port is None: - print "Cannot start. IP specified. You must also provide a port" - return - - self._connect_to = (host_ip, host_port) if host_ip is not None else None + self._connect_to = session_id self._target_buffer = self._vim.current.buffer diff --git a/plugins/vim/tandem_neovim.py b/plugins/vim/tandem_neovim.py index 89713fc..f1c1760 100644 --- a/plugins/vim/tandem_neovim.py +++ b/plugins/vim/tandem_neovim.py @@ -24,9 +24,8 @@ def __init__(self, vim): @neovim.command("Tandem", nargs="*", sync=True) def start(self, args): - host_ip = args[0] if len(args) >= 1 else None - port = args[1] if len(args) >= 2 else None - self._tandem.start(host_ip, port) + session_id = args[0] if len(args) >= 1 else None + self._tandem.start(session_id) @neovim.command("TandemStop", nargs="*", sync=True) def stop(self, args): @@ -63,3 +62,8 @@ def _handle_message(self, message): lambda: self._vim.funcs.TandemHandleWriteRequest(async=True), ) self._text_applied.wait() + elif isinstance(message, m.SessionInfo): + self._vim.async_call( + lambda: self._vim.command('echom "Session ID: {}"' + .format(message.session_id)), + ) diff --git a/plugins/vim/tandem_vim.vim b/plugins/vim/tandem_vim.vim index cc64562..0fa52a7 100644 --- a/plugins/vim/tandem_vim.vim +++ b/plugins/vim/tandem_vim.vim @@ -47,6 +47,8 @@ class TandemVimPlugin: vim.command(":doautocmd User TandemApplyText") elif isinstance(message, m.WriteRequest): vim.command(":doautocmd User TandemWriteRequest") + elif isinstance(message, m.SessionInfo): + vim.command('echom "Session ID: {}"'.format(message.session_id)) def _handle_apply_text(self): self._tandem.handle_apply_text(self._message) @@ -67,8 +69,8 @@ class TandemVimPlugin: vim.command("autocmd User TandemApplyText py tandem_plugin._handle_apply_text()") vim.command("autocmd User TandemWriteRequest py tandem_plugin._handle_write_request()") - def start(self, host_ip=None, host_port=None): - self._tandem.start(host_ip, host_port) + def start(self, session_id=None): + self._tandem.start(session_id) def stop(self, invoked_from_autocmd=True): self._tandem.stop(invoked_from_autocmd)