Skip to content

Commit

Permalink
Update vim/neovim plugins for hole punching (4/5) (#97)
Browse files Browse the repository at this point in the history
* Update vim/neovim plugins for hole punching

* Remove unneeded assignment
  • Loading branch information
geoffxy authored Feb 24, 2018
1 parent 4597bc0 commit af5914b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
21 changes: 8 additions & 13 deletions plugins/vim/tandem_lib/tandem_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions plugins/vim/tandem_neovim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)),
)
6 changes: 4 additions & 2 deletions plugins/vim/tandem_vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit af5914b

Please sign in to comment.