Skip to content

Commit

Permalink
added pull limit seperate from max items
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Nov 15, 2024
1 parent a25baaf commit fa78ba2
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 32 deletions.
24 changes: 24 additions & 0 deletions config/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,38 @@ auto_start: False
clients:
buffers:
always_on_top: False
always_wait: false
enabled: True
match_syms: False
max_pulls: null
parent_scope: ""
same_filetype: False
short_name: "BF"
weight_adjust: 0

lsp:
always_on_top: null
always_wait: false
enabled: True
max_pulls: 88
resolve_timeout: 0.06
short_name: "LS"
weight_adjust: 0.5

lsp_inline:
always_on_top: []
always_wait: false
enabled: True
max_pulls: null
resolve_timeout: 0.06
short_name: "IS"
weight_adjust: 1

paths:
always_on_top: False
always_wait: false
enabled: True
max_pulls: null
path_seps: []
preview_lines: 6
resolution:
Expand All @@ -38,9 +46,11 @@ clients:

registers:
always_on_top: False
always_wait: false
enabled: True
lines: []
match_syms: False
max_pulls: null
max_yank_size: 8888
register_scope: ""
short_name: "RS"
Expand All @@ -49,7 +59,9 @@ clients:

snippets:
always_on_top: False
always_wait: false
enabled: True
max_pulls: null
short_name: "SP"
user_path: null
warn:
Expand All @@ -59,43 +71,55 @@ clients:

tabnine:
always_on_top: False
always_wait: false
enabled: False
max_pulls: null
short_name: "T9"
weight_adjust: -0.1

tags:
always_on_top: False
always_wait: false
enabled: True
max_pulls: null
parent_scope: ""
path_sep: ""
short_name: "TG"
weight_adjust: 0.1

third_party:
always_on_top: null
always_wait: false
enabled: True
max_pulls: null
short_name: "3P"
weight_adjust: 0

third_party_inline:
always_on_top: []
always_wait: false
enabled: True
max_pulls: null
short_name: "3L"
weight_adjust: 0

tmux:
all_sessions: True
always_on_top: False
always_wait: false
enabled: True
match_syms: False
max_pulls: null
parent_scope: ""
path_sep: ""
short_name: "TX"
weight_adjust: -0.1

tree_sitter:
always_on_top: False
always_wait: false
enabled: True
max_pulls: null
path_sep: ""
short_name: "TS"
slow_threshold: 0.168
Expand Down
4 changes: 2 additions & 2 deletions coq/clients/buffers/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def words(
filetype: Optional[str],
word: str,
sym: str,
limitless: int,
limit: int,
update: Optional[Update],
) -> Iterator[BufferWord]:
with suppress(OperationalError):
Expand All @@ -218,7 +218,7 @@ def words(
{
"cut_off": opts.fuzzy_cutoff,
"look_ahead": opts.look_ahead,
"limit": BIGGEST_INT if limitless else opts.max_results,
"limit": limit,
"filetype": filetype,
"word": word,
"sym": sym,
Expand Down
9 changes: 8 additions & 1 deletion coq/clients/buffers/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ...shared.runtime import Supervisor
from ...shared.runtime import Worker as BaseWorker
from ...shared.settings import BuffersClient
from ...shared.sql import BIGGEST_INT
from ...shared.types import Completion, Context, Doc, Edit
from .db.database import BDB, BufferWord, Update

Expand Down Expand Up @@ -144,6 +145,12 @@ async def cont() -> None:
await self._ex.submit(cont())

async def _work(self, context: Context) -> AsyncIterator[Completion]:
limit = (
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)

async with self._work_lock:
filetype = context.filetype if self._options.same_filetype else None
update = (
Expand All @@ -163,7 +170,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:
filetype=filetype,
word=context.words,
sym=context.syms if self._options.match_syms else "",
limitless=context.manual,
limit=limit,
update=update,
)
for word in words:
Expand Down
11 changes: 7 additions & 4 deletions coq/clients/lsp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _request(
always_on_top=self._options.always_on_top,
weight_adjust=self._options.weight_adjust,
context=context,
chunk=self._max_results * 2,
chunk=self._max_results,
clients=set() if context.manual else cached_clients,
)

Expand All @@ -126,11 +126,14 @@ async def cont() -> None:
await self._with_interrupt(cont())

async def _work(self, context: Context) -> AsyncIterator[Completion]:
limit = (
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)

async with self._work_lock, self._working:
try:
# TODO: extract this into an option
limit = BIGGEST_INT if context.manual else self._max_results * 6

use_cache, cached_clients, cached = self._cache.apply_cache(
context, always=False
)
Expand Down
4 changes: 3 additions & 1 deletion coq/clients/paths/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def cont() -> Iterator[Path]:
base_paths = {*cont()}

limit = (
BIGGEST_INT if context.manual else self._supervisor.match.max_results
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)
aw = tuple(
_parse(
Expand Down
6 changes: 3 additions & 3 deletions coq/clients/registers/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ....databases.types import DB
from ....shared.parse import coalesce, tokenize
from ....shared.settings import MatchOptions
from ....shared.sql import BIGGEST_INT, init_db, like_esc
from ....shared.sql import init_db, like_esc
from .sql import sql


Expand Down Expand Up @@ -86,7 +86,7 @@ def select(
opts: MatchOptions,
word: str,
sym: str,
limitless: int,
limit,
) -> Iterator[RegWord]:
def fetch(
cursor: Cursor, match_syms: bool, stmt: str, linewise: bool
Expand All @@ -96,7 +96,7 @@ def fetch(
{
"cut_off": opts.fuzzy_cutoff,
"look_ahead": opts.look_ahead,
"limit": BIGGEST_INT if limitless else opts.max_results,
"limit": limit,
"word": word,
"sym": (sym if match_syms else ""),
"like_word": like_esc(word[: opts.exact_matches]),
Expand Down
8 changes: 7 additions & 1 deletion coq/clients/registers/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ...shared.runtime import Supervisor
from ...shared.runtime import Worker as BaseWorker
from ...shared.settings import RegistersClient
from ...shared.sql import BIGGEST_INT
from ...shared.types import Completion, Context, Doc, Edit, SnippetEdit, SnippetGrammar
from .db.database import RDB

Expand Down Expand Up @@ -79,6 +80,11 @@ async def cont() -> None:
await self._ex.submit(cont())

async def _work(self, context: Context) -> AsyncIterator[Completion]:
limit = (
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)
async with self._work_lock:
before = removesuffix(context.line_before, suffix=context.syms_before)
linewise = not before or before.isspace()
Expand All @@ -88,7 +94,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:
opts=self._supervisor.match,
word=context.words,
sym=context.syms,
limitless=context.manual,
limit=limit,
)
for word in words:
edit = (
Expand Down
4 changes: 2 additions & 2 deletions coq/clients/snippet/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def populate(self, path: PurePath, mtime: float, loaded: LoadedSnips) -> None:
cursor.execute("PRAGMA optimize", ())

def select(
self, opts: MatchOptions, filetype: str, word: str, sym: str, limitless: int
self, opts: MatchOptions, filetype: str, word: str, sym: str, limit: int
) -> Iterator[_Snip]:
with suppress(OperationalError):
with self._conn, closing(self._conn.cursor()) as cursor:
Expand All @@ -105,7 +105,7 @@ def select(
{
"cut_off": opts.fuzzy_cutoff,
"look_ahead": opts.look_ahead,
"limit": BIGGEST_INT if limitless else opts.max_results,
"limit": limit,
"filetype": filetype,
"word": word,
"sym": sym,
Expand Down
9 changes: 8 additions & 1 deletion coq/clients/snippet/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ...shared.runtime import Supervisor
from ...shared.runtime import Worker as BaseWorker
from ...shared.settings import SnippetClient
from ...shared.sql import BIGGEST_INT
from ...shared.types import Completion, Context, Doc, SnippetEdit, SnippetGrammar
from ...snippets.types import LoadedSnips
from .db.database import SDB
Expand Down Expand Up @@ -47,13 +48,19 @@ async def cont() -> None:
await self._ex.submit(cont())

async def _work(self, context: Context) -> AsyncIterator[Completion]:
limit = (
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)

async with self._work_lock:
snippets = self._db.select(
self._supervisor.match,
filetype=context.filetype,
word=context.words,
sym=context.syms,
limitless=context.manual,
limit=limit,
)

for snip in snippets:
Expand Down
13 changes: 8 additions & 5 deletions coq/clients/t9/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ...shared.runtime import Supervisor
from ...shared.runtime import Worker as BaseWorker
from ...shared.settings import T9Client
from ...shared.sql import BIGGEST_INT
from ...shared.types import Completion, Context, ContextualEdit, Doc
from .install import ensure_updated, t9_bin, x_ok
from .types import ReqL1, ReqL2, Request, RespL1, Response
Expand Down Expand Up @@ -266,6 +267,12 @@ async def cont() -> Optional[str]:
return await shield(cont())

async def _work(self, context: Context) -> AsyncIterator[Completion]:
limit = (
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)

if self._t9_locked:
self._t9_locked = False
return
Expand All @@ -276,11 +283,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:

if self._bin:
id = next(self._count)
req = _encode(
context,
id=id,
limit=self._supervisor.match.max_results,
)
req = _encode(context, id=id, limit=limit)
json = dumps(req, check_circular=False, ensure_ascii=False)
if reply := await self._comm(context.cwd, json=json):
try:
Expand Down
6 changes: 3 additions & 3 deletions coq/clients/tags/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ....databases.types import DB
from ....shared.settings import MatchOptions
from ....shared.sql import BIGGEST_INT, init_db, like_esc
from ....shared.sql import init_db, like_esc
from ....tags.types import Tag, Tags
from .sql import sql

Expand Down Expand Up @@ -90,7 +90,7 @@ def select(
line_num: int,
word: str,
sym: str,
limitless: int,
limit: int,
) -> Iterator[Tag]:
with suppress(OperationalError):
with self._conn, closing(self._conn.cursor()) as cursor:
Expand All @@ -99,7 +99,7 @@ def select(
{
"cut_off": opts.fuzzy_cutoff,
"look_ahead": opts.look_ahead,
"limit": BIGGEST_INT if limitless else opts.max_results,
"limit": limit,
"filename": filename,
"line_num": line_num,
"word": word,
Expand Down
8 changes: 7 additions & 1 deletion coq/clients/tags/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ...shared.runtime import Supervisor
from ...shared.runtime import Worker as BaseWorker
from ...shared.settings import TagsClient
from ...shared.sql import BIGGEST_INT
from ...shared.timeit import timeit
from ...shared.types import Completion, Context, Doc, Edit
from ...tags.parse import parse, run
Expand Down Expand Up @@ -178,6 +179,11 @@ async def cont() -> None:
await self._ex.submit(cont())

async def _work(self, context: Context) -> AsyncIterator[Completion]:
limit = (
BIGGEST_INT
if context.manual
else self._options.max_pulls or self._supervisor.match.max_results
)
async with self._work_lock:
row, _ = context.position
tags = self._db.select(
Expand All @@ -186,7 +192,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:
line_num=row,
word=context.words,
sym=context.syms,
limitless=context.manual,
limit=limit,
)

seen: MutableSet[str] = set()
Expand Down
Loading

0 comments on commit fa78ba2

Please sign in to comment.