def cont() -> None: try: _open_gui(cast(Node, node).path, cwd=cwd) except (CalledProcessError, LookupError) as e: threadsafe_call(nvim, write, nvim, e, error=True) except Exception as e: log.exception("%s", e)
def enqueue_event(event: RpcCallable, *args: Any) -> None: try: msg: RpcMsg = (event.name, args) event_queue.put(msg) except Exception as e: log.exception("%s", e) raise
def c2() -> None: try: c1() except (CalledProcessError, LookupError) as e: threadsafe_call(nvim, write, nvim, e, error=True) except Exception as e: log.exception("%s", e) else: enqueue_event(_refresh, True)
def cont() -> None: if _lock.locked(): pass else: with _lock: try: vc = status(state.pool, cwd=cwd) except Exception as e: log.exception("%s", e) else: enqueue_event(_set_vc, vc)
def wait(self, nvim: Nvim) -> int: def cont() -> None: if isinstance(nvim.loop, AbstractEventLoop): nvim.loop.set_default_executor(pool) atomic, specs = rpc.drain(nvim.channel_id) self._handlers.update(specs) self._settings = initial_settings(nvim, specs) hl = highlight(*self._settings.view.hl_context.groups) (atomic + autocmd.drain() + hl).commit(nvim) self._state = initial_state(nvim, settings=self._settings) init_locale(self._settings.lang) try: threadsafe_call(nvim, cont) except DecodeError as e: msg1 = "Some options may hanve changed." msg2 = "See help doc on Github under [docs/CONFIGURATION.md]" print(e, msg1, msg2, sep=linesep, file=stderr) return 1 except Exception as e: log.exception("%s", e) return 1 def sched() -> None: period = cast(Settings, self._settings).polling_rate enqueue_event(vc_refresh) for _ in ticker(period, immediately=False): enqueue_event(schedule_update) enqueue_event(vc_refresh) enqueue_event(save_session) pool.submit(sched) while True: msg: RpcMsg = event_queue.get() name, args = msg handler = self._handlers.get(name, nil_handler(name)) def cont() -> None: stage = cast(AnyFun[Optional[Stage]], handler)(nvim, self._state, self._settings, *args) if stage: self._state = stage.state mgr = suppress( NvimError) if stage.silent else nullcontext() with mgr: redraw(nvim, state=self._state, focus=stage.focus) try: threadsafe_call(nvim, cont) except Exception as e: log.exception("%s", e)
def wait(self, nvim: Nvim) -> int: assert isinstance(nvim.loop, AbstractEventLoop) nvim.loop.set_debug(DEBUG) nvim.loop.set_default_executor(self._pool) def cont() -> bool: rpc_atomic, specs = rpc.drain(nvim.channel_id) self._handlers.update(specs) try: self._stack = stack(self._pool, nvim=nvim) except (DecodeError, ValidationError) as e: tpl = """ Some options may have changed. See help doc on Github under [docs/CONFIGURATION.md] ⚠️ ${e} """ msg = Template(dedent(tpl)).substitute(e=e) write(nvim, msg, error=True) return False else: (rpc_atomic + autocmd.drain() + atomic).commit(nvim) set_options( nvim, mapping=self._stack.settings.keymap, fast_close=self._stack.settings.display.pum.fast_close, ) return True try: succ = threadsafe_call(nvim, cont) except Exception as e: log.exception("%s", e) return 1 else: if not succ: return 1 while True: msg: RpcMsg = self._event_queue.get() with with_suppress(): threadsafe_call(nvim, self._handle, nvim, msg)
def wait(self, nvim: Nvim) -> int: def cont() -> bool: assert isinstance(nvim.loop, AbstractEventLoop) nvim.loop.set_default_executor(self._pool) atomic, specs = rpc.drain(nvim.channel_id) self._handlers.update(specs) try: self._settings = initial_settings(nvim, specs) except DecodeError as e: tpl = """ Some options may hanve changed. See help doc on Github under [docs/CONFIGURATION.md] ${e} """ ms = Template(dedent(tpl)).substitute(e=e) write(nvim, ms, error=True) return False else: hl = highlight(*self._settings.view.hl_context.groups) (atomic + autocmd.drain() + hl).commit(nvim) self._state = initial_state( nvim, pool=self._pool, settings=self._settings ) init_locale(self._settings.lang) return True try: go = threadsafe_call(nvim, cont) except Exception as e: log.exception("%s", e) return 1 else: if not go: return 1 else: settings = cast(Settings, self._settings) t1, has_drawn = monotonic(), False def sched() -> None: enqueue_event(vc_refresh) for _ in ticker(settings.polling_rate, immediately=False): enqueue_event(schedule_update) enqueue_event(vc_refresh) enqueue_event(save_session) self._pool.submit(sched) while True: msg: RpcMsg = event_queue.get() name, args = msg handler = cast( AnyFun[Optional[Stage]], self._handlers.get(name, nil_handler(name)) ) def cdraw() -> None: nonlocal has_drawn if stage := handler(nvim, self._state, settings, *args): self._state = stage.state for _ in range(RENDER_RETRIES - 1): try: redraw(nvim, state=self._state, focus=stage.focus) except NvimError: pass else: break else: try: redraw(nvim, state=self._state, focus=stage.focus) except NvimError as e: log.warn("%s", e) if settings.profiling and not has_drawn: has_drawn = True _profile(nvim, t1=t1) with with_suppress(): threadsafe_call(nvim, cdraw)
def wait(self, nvim: Nvim) -> int: def cont() -> None: if isinstance(nvim.loop, AbstractEventLoop): nvim.loop.set_default_executor(pool) atomic, specs = rpc.drain(nvim.channel_id) self._handlers.update(specs) self._settings = initial_settings(nvim, specs) hl = highlight(*self._settings.view.hl_context.groups) (atomic + autocmd.drain() + hl).commit(nvim) self._state = initial_state(nvim, settings=self._settings) init_locale(self._settings.lang) try: threadsafe_call(nvim, cont) except DecodeError as e: msg1 = "Some options may hanve changed." msg2 = "See help doc on Github under [docs/CONFIGURATION.md]" print(e, msg1, msg2, sep=linesep, file=stderr) return 1 except Exception as e: log.exception("%s", e) return 1 else: settings = cast(Settings, self._settings) t1, has_drawn = monotonic(), False def sched() -> None: enqueue_event(vc_refresh) for _ in ticker(settings.polling_rate, immediately=False): enqueue_event(schedule_update) enqueue_event(vc_refresh) enqueue_event(save_session) pool.submit(sched) while True: msg: RpcMsg = event_queue.get() name, args = msg handler = self._handlers.get(name, nil_handler(name)) def cont() -> None: nonlocal has_drawn stage = cast(AnyFun[Optional[Stage]], handler)(nvim, self._state, settings, *args) if stage: self._state = stage.state mgr = suppress( NvimError) if stage.silent else nullcontext() with mgr: redraw(nvim, state=self._state, focus=stage.focus) if settings.profiling and not has_drawn: has_drawn = True t2 = monotonic() info = uname() msg = f""" First msg {int((t2 - t1) * 1000)}ms Arch {info.machine} Processor {info.processor} Cores {cpu_count()} System {info.system} Version {info.version} Python {Path(executable).resolve()} """ write(nvim, dedent(msg)) try: threadsafe_call(nvim, cont) except Exception as e: log.exception("%s", e)