예제 #1
0
파일: omnifunc.py 프로젝트: ms-jpq/coq-nvim
        async def c0(s: State, manual: bool) -> None:
            with with_suppress(), timeit("**OVERALL**"):
                if lock.locked():
                    log.warn("%s", "SHOULD NOT BE LOCKED <><> OODA")
                async with lock:
                    ctx = await async_call(
                        nvim,
                        lambda: context(
                            nvim,
                            db=stack.bdb,
                            options=stack.settings.match,
                            state=s,
                            manual=manual,
                        ),
                    )
                    should = _should_cont(s, prev=s.context,
                                          cur=ctx) if ctx else False
                    _, col = ctx.position

                    if should:
                        state(context=ctx)
                        await stack.supervisor.interrupt()
                        metrics, _ = await gather(
                            stack.supervisor.collect(ctx),
                            async_call(
                                nvim,
                                lambda: complete(
                                    nvim, stack=stack, col=col, comps=()),
                            ) if stack.settings.display.pum.fast_close else
                            sleep(0),
                        )
                        s = state()
                        if s.change_id == ctx.change_id:
                            vim_comps = tuple(
                                trans(
                                    stack,
                                    pum_width=s.pum_width,
                                    context=ctx,
                                    metrics=metrics,
                                ))
                            await async_call(
                                nvim,
                                lambda: complete(nvim,
                                                 stack=stack,
                                                 col=col,
                                                 comps=vim_comps),
                            )
                    else:
                        await async_call(
                            nvim, lambda: complete(
                                nvim, stack=stack, col=col, comps=()))
                        state(inserted_pos=(-1, -1))
예제 #2
0
파일: omnifunc.py 프로젝트: ms-jpq/coq-nvim
        async def c2() -> None:
            nonlocal task
            while True:
                with with_suppress():
                    await event.wait()
                    event.clear()

                    if task:
                        await cancel(task)

                    if incoming:
                        assert isinstance(nvim.loop, AbstractEventLoop)
                        s, manual = incoming
                        task = nvim.loop.create_task(c0(s, manual=manual))
예제 #3
0
    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)
예제 #4
0
        async def supervise(worker: Worker, assoc: BaseClient) -> None:
            instance, items = uuid4(), 0

            with with_suppress(), timeit(f"WORKER -- {assoc.short_name}"):
                await self._reviewer.s_begin(assoc, instance=instance)
                try:
                    async for completion in worker.work(context):
                        if not done and completion:
                            metric = self._reviewer.trans(
                                instance, completion=completion)
                            acc.append(metric)
                            items += 1
                        else:
                            await sleep(0)
                finally:
                    elapsed = monotonic() - t1
                    await self._reviewer.s_end(
                        instance,
                        interrupted=done,
                        elapsed=elapsed,
                        items=items,
                    )
예제 #5
0
    async def cont() -> None:
        while True:
            with with_suppress():
                qmsg: _Qmsg = await to_thread(q.get)
                lo, hi = qmsg.range
                await stack.supervisor.interrupt()

                size = sum(map(len, qmsg.lines))
                heavy_bufs = ({
                    qmsg.buf.number
                } if size > stack.settings.limits.index_cutoff else set())
                os = state()
                s = state(change_id=uuid4(), nono_bufs=heavy_bufs)

                if qmsg.buf.number not in s.nono_bufs:
                    await stack.bdb.set_lines(
                        qmsg.buf.number,
                        filetype=qmsg.filetype,
                        lo=lo,
                        hi=hi,
                        lines=qmsg.lines,
                        unifying_chars=stack.settings.match.unifying_chars,
                    )

                if (qmsg.buf.number in s.nono_bufs
                        and qmsg.buf.number not in os.nono_bufs):
                    msg = LANG(
                        "buf 2 fat",
                        size=size,
                        limit=stack.settings.limits.index_cutoff,
                    )
                    await awrite(nvim, msg)

                if (stack.settings.completion.always and not qmsg.pending
                        and qmsg.mode.startswith("i") and qmsg.comp_mode
                        in {"", "eval", "function", "ctrl_x"}):
                    comp_func(nvim, s=s, manual=False)
예제 #6
0
        async def cont() -> Sequence[Metric]:
            nonlocal done

            with with_suppress(), timeit("COLLECTED -- ALL"):
                if self._lock.locked():
                    log.warn("%s", "SHOULD NOT BE LOCKED <><> supervisor")
                async with self._lock:
                    await self._reviewer.begin(context)
                    self._tasks = tasks = tuple(
                        loop.create_task(supervise(worker, assoc=assoc))
                        for worker, assoc in self._workers.items())
                    try:
                        if not tasks:
                            return ()
                        else:
                            _, pending = await wait(tasks, timeout=timeout)
                            if not acc:
                                for fut in as_completed(pending):
                                    await fut
                                    if acc:
                                        break
                            return acc
                    finally:
                        done = True
예제 #7
0
파일: client.py 프로젝트: ms-jpq/chadtree
    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)
예제 #8
0
파일: omnifunc.py 프로젝트: ms-jpq/coq-nvim
 async def c1() -> None:
     nonlocal incoming
     while True:
         with with_suppress():
             incoming = await to_thread(_Q.get)
             event.set()