Skip to content

Commit

Permalink
clear cache on words change over
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Dec 6, 2024
1 parent a68f920 commit 3c9362e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion coq/clients/cache/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _CacheCtx:
row: int
col: int
syms_before: str
words_before: str


def _use_cache(match: MatchOptions, cache: _CacheCtx, ctx: Context) -> bool:
Expand All @@ -46,6 +47,7 @@ def _use_cache(match: MatchOptions, cache: _CacheCtx, ctx: Context) -> bool:
and cache.commit_id == ctx.commit_id
and ctx.buf_id == cache.buf_id
and row == cache.row
and bool(cache.words_before) == bool(ctx.words_before)
and multi_set_ratio(
ctx.syms_before, cache.syms_before, look_ahead=match.look_ahead
)
Expand Down Expand Up @@ -88,6 +90,7 @@ def __init__(self, supervisor: Supervisor) -> None:
row=-1,
col=-1,
syms_before="",
words_before="",
)
self._clients: MutableSet[str] = set()
self._cached: MutableMapping[bytes, Completion] = {}
Expand Down Expand Up @@ -137,6 +140,7 @@ def apply_cache(
row=row,
col=col,
syms_before=context.syms_before,
words_before=context.words_before,
)

use_cache = _use_cache(
Expand Down Expand Up @@ -165,7 +169,10 @@ def get() -> Iterator[Completion]:
for key, sort_by in selected:
if (comp := self._cached.get(key)) and (
cached := sanitize_cached(
inline_shift, cursor=context.cursor, comp=comp, sort_by=sort_by
inline_shift,
cursor=context.cursor,
comp=comp,
sort_by=sort_by,
)
):
if (
Expand Down

0 comments on commit 3c9362e

Please sign in to comment.