Skip to content

Commit d2bcbb8

Browse files
committed
can decide to reject
1 parent 2e8e4b8 commit d2bcbb8

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

coq/clients/cache/worker.py

Lines changed: 6 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-
inline_shift: bool, cursor: Cursors, comp: Completion, sort_by: Optional[str]
63+
cursor: Cursors, comp: Completion, sort_by: Optional[str]
6464
) -> Optional[Completion]:
65-
if edit := sanitize(inline_shift, cursor, edit=comp.primary_edit):
65+
if edit := sanitize(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, inline_shift: bool
129+
self, context: Context, always: bool
130130
) -> Tuple[bool, AbstractSet[str], Iterator[Completion]]:
131131
cache_ctx = self._cache_ctx
132132
row, col = context.position
@@ -165,7 +165,9 @@ def get() -> Iterator[Completion]:
165165
for key, sort_by in selected:
166166
if (comp := self._cached.get(key)) and (
167167
cached := sanitize_cached(
168-
inline_shift, cursor=context.cursor, comp=comp, sort_by=sort_by
168+
cursor=context.cursor,
169+
comp=comp,
170+
sort_by=sort_by,
169171
)
170172
):
171173
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, inline_shift=True)
74+
_, _, cached = self._cache.apply_cache(context, always=True)
7575
lsp_stream = (
7676
self._request(context)
7777
if self._options.live_pulling

coq/clients/lsp/worker.py

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

145145
async def _work(self, context: Context) -> AsyncIterator[Completion]:
146-
inline_shift = False
147146
limit = (
148147
BIGGEST_INT
149148
if context.manual
@@ -153,7 +152,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:
153152
async with self._work_lock, self._working:
154153
try:
155154
use_cache, cached_clients, cached = self._cache.apply_cache(
156-
context, always=False, inline_shift=inline_shift
155+
context, always=False
157156
)
158157
if not use_cache:
159158
self._local_cached.pre.clear()
@@ -182,7 +181,6 @@ async def stream() -> AsyncIterator[Tuple[_Src, LSPcomp]]:
182181
for item in cached_items
183182
if (
184183
cached := sanitize_cached(
185-
inline_shift=inline_shift,
186184
cursor=context.cursor,
187185
comp=item,
188186
sort_by=None,

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(True, cursor=(-1, -1, -1, -1), edit=prev)
14+
sanitized = sanitize(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: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
)
1919

2020

21-
def _shift(cursor: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
21+
def _shift_or_reject(
22+
cursor: Cursors, edit: BaseRangeEdit
23+
) -> Optional[Tuple[WTF8Pos, WTF8Pos]]:
2224
row, u8, u16, u32 = cursor
2325
if edit.encoding == UTF16:
2426
col = u16
@@ -30,6 +32,9 @@ def _shift(cursor: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
3032
never(edit.encoding)
3133

3234
(b_row, b_col), (e_row, e_col) = edit.begin, edit.end
35+
if e_col < col:
36+
return None
37+
3338
edit_col = edit.cursor_pos
3439
diff = col - edit_col
3540

@@ -53,7 +58,7 @@ def _shift(cursor: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
5358
return new_begin, new_end
5459

5560

56-
def sanitize(inline_shift: bool, cursor: Cursors, edit: Edit) -> Optional[Edit]:
61+
def sanitize(cursor: Cursors, edit: Edit) -> Optional[Edit]:
5762
row, *_ = cursor
5863
if isinstance(edit, SnippetRangeEdit):
5964
if row == -1:
@@ -67,17 +72,17 @@ def sanitize(inline_shift: bool, cursor: Cursors, edit: Edit) -> Optional[Edit]:
6772
return SnippetEdit(grammar=edit.grammar, new_text=fallback)
6873
elif not requires_snip(edit.new_text):
6974
return Edit(new_text=edit.new_text)
70-
else:
71-
begin, end = _shift(cursor, edit=edit)
75+
elif shift := _shift_or_reject(cursor, edit=edit):
76+
begin, end = shift
7277
return replace(edit, begin=begin, end=end)
78+
else:
79+
return None
7380
elif isinstance(edit, RangeEdit):
74-
if inline_shift:
75-
begin, end = _shift(cursor, edit=edit)
76-
return replace(edit, begin=begin, end=end)
77-
elif fallback := edit.fallback:
81+
if fallback := edit.fallback:
7882
return Edit(new_text=fallback)
79-
elif not requires_snip(edit.new_text):
80-
return Edit(new_text=edit.new_text)
83+
elif shift := _shift_or_reject(cursor, edit=edit):
84+
begin, end = shift
85+
return replace(edit, begin=begin, end=end)
8186
else:
8287
return None
8388
elif isinstance(edit, SnippetEdit):

0 commit comments

Comments
 (0)