Skip to content

Commit 2e8e4b8

Browse files
committed
shift inline comp
This reverts commit 0958f39.
1 parent 0958f39 commit 2e8e4b8

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

coq/clients/cache/worker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def _overlap(row: int, edit: BaseRangeEdit) -> bool:
6060

6161

6262
def sanitize_cached(
63-
cursor: Cursors, comp: Completion, sort_by: Optional[str]
63+
inline_shift: bool, cursor: Cursors, comp: Completion, sort_by: Optional[str]
6464
) -> Optional[Completion]:
65-
if edit := sanitize(cursor, edit=comp.primary_edit):
65+
if edit := sanitize(inline_shift, cursor, edit=comp.primary_edit):
6666
row, *_ = cursor
6767
cached = replace(
6868
comp,
@@ -126,7 +126,7 @@ def cont() -> Iterator[Tuple[bytes, str]]:
126126
self._cached.update(new_comps)
127127

128128
def apply_cache(
129-
self, context: Context, always: bool
129+
self, context: Context, always: bool, inline_shift: bool
130130
) -> Tuple[bool, AbstractSet[str], Iterator[Completion]]:
131131
cache_ctx = self._cache_ctx
132132
row, col = context.position
@@ -165,7 +165,7 @@ def get() -> Iterator[Completion]:
165165
for key, sort_by in selected:
166166
if (comp := self._cached.get(key)) and (
167167
cached := sanitize_cached(
168-
context.cursor, comp=comp, sort_by=sort_by
168+
inline_shift, cursor=context.cursor, comp=comp, sort_by=sort_by
169169
)
170170
):
171171
if (

coq/clients/inline/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def cont() -> None:
7171
async def _work(self, context: Context) -> AsyncIterator[Completion]:
7272
async with self._work_lock, self._working:
7373
try:
74-
_, _, cached = self._cache.apply_cache(context, always=True)
74+
_, _, cached = self._cache.apply_cache(context, always=True, inline_shift=True)
7575
lsp_stream = (
7676
self._request(context)
7777
if self._options.live_pulling

coq/clients/lsp/worker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ async def cont() -> None:
143143
await self._with_interrupt(cont())
144144

145145
async def _work(self, context: Context) -> AsyncIterator[Completion]:
146+
inline_shift = False
146147
limit = (
147148
BIGGEST_INT
148149
if context.manual
@@ -152,7 +153,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:
152153
async with self._work_lock, self._working:
153154
try:
154155
use_cache, cached_clients, cached = self._cache.apply_cache(
155-
context, always=False
156+
context, always=False, inline_shift=inline_shift
156157
)
157158
if not use_cache:
158159
self._local_cached.pre.clear()
@@ -181,7 +182,10 @@ async def stream() -> AsyncIterator[Tuple[_Src, LSPcomp]]:
181182
for item in cached_items
182183
if (
183184
cached := sanitize_cached(
184-
context.cursor, comp=item, sort_by=None
185+
inline_shift=inline_shift,
186+
cursor=context.cursor,
187+
comp=item,
188+
sort_by=None,
185189
)
186190
)
187191
)

coq/server/registrants/repeat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def _edit(prev: Edit) -> Optional[Edit]:
14-
sanitized = sanitize((-1, -1, -1, -1), edit=prev)
14+
sanitized = sanitize(True, cursor=(-1, -1, -1, -1), edit=prev)
1515
new_edit = (
1616
ContextualEdit(
1717
new_text=sanitized.new_text, old_prefix="", new_prefix=sanitized.new_text

coq/shared/repeat.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _shift(cursor: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
5353
return new_begin, new_end
5454

5555

56-
def sanitize(cursor: Cursors, edit: Edit) -> Optional[Edit]:
56+
def sanitize(inline_shift: bool, cursor: Cursors, edit: Edit) -> Optional[Edit]:
5757
row, *_ = cursor
5858
if isinstance(edit, SnippetRangeEdit):
5959
if row == -1:
@@ -71,7 +71,10 @@ def sanitize(cursor: Cursors, edit: Edit) -> Optional[Edit]:
7171
begin, end = _shift(cursor, edit=edit)
7272
return replace(edit, begin=begin, end=end)
7373
elif isinstance(edit, RangeEdit):
74-
if fallback := edit.fallback:
74+
if inline_shift:
75+
begin, end = _shift(cursor, edit=edit)
76+
return replace(edit, begin=begin, end=end)
77+
elif fallback := edit.fallback:
7578
return Edit(new_text=fallback)
7679
elif not requires_snip(edit.new_text):
7780
return Edit(new_text=edit.new_text)

0 commit comments

Comments
 (0)