Skip to content

Commit 135362d

Browse files
committed
Add --notify cli option
This is a synchronization helper for debugging functional tests in nvim. When --notify is passed, the string "attached" will be printed to stdout as soon as nvim is attached.
1 parent c628be9 commit 135362d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

neovim/ui/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@click.command(context_settings=dict(allow_extra_args=True))
1111
@click.option('--prog')
12+
@click.option('--notify', '-n', default=False, is_flag=True)
1213
@click.option('--gui', '-g', default=False, is_flag=True)
1314
@click.option('--listen', '-l')
1415
@click.option('--connect', '-c')
@@ -17,7 +18,7 @@
1718
type=click.Choice(['ncalls', 'tottime', 'percall', 'cumtime',
1819
'name', 'disable']))
1920
@click.pass_context
20-
def main(ctx, prog, gui, listen, connect, profile):
21+
def main(ctx, prog, notify, gui, listen, connect, profile):
2122
"""Entry point."""
2223
address = connect or listen
2324

@@ -65,7 +66,7 @@ def main(ctx, prog, gui, listen, connect, profile):
6566
from .tickit_ui import TickitUI
6667
ui = TickitUI()
6768
bridge = UIBridge()
68-
bridge.connect(nvim, ui, profile if profile != 'disable' else None)
69+
bridge.connect(nvim, ui, profile if profile != 'disable' else None, notify)
6970

7071

7172
if __name__ == '__main__':

neovim/ui/ui_bridge.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Bridge for connecting a UI instance to nvim."""
2+
import sys
23
from threading import Semaphore, Thread
34
from traceback import format_exc
45

@@ -7,12 +8,13 @@ class UIBridge(object):
78

89
"""UIBridge class. Connects a Nvim instance to a UI class."""
910

10-
def connect(self, nvim, ui, profile=None):
11+
def connect(self, nvim, ui, profile=None, notify=False):
1112
"""Connect nvim and the ui.
1213
1314
This will start loops for handling the UI and nvim events while
1415
also synchronizing both.
1516
"""
17+
self._notify = notify
1618
self._error = None
1719
self._nvim = nvim
1820
self._ui = ui
@@ -76,6 +78,10 @@ def on_request(method, args):
7678

7779
def on_notification(method, updates):
7880
def apply_updates():
81+
if self._notify:
82+
sys.stdout.write('attached\n')
83+
sys.stdout.flush()
84+
self._notify = False
7985
try:
8086
for update in updates:
8187
# import sys

0 commit comments

Comments
 (0)