Skip to content

Commit

Permalink
ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Jul 5, 2023
1 parent 9ad77a1 commit 0293fd2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.ccls-cache/
/.vars/
/.venv/
/temp/
__pycache__/
/.vscode/
/temp/
/test/
__pycache__/
10 changes: 10 additions & 0 deletions coq/server/context.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from os import environ
from os.path import normcase
from typing import Optional, Tuple, cast

from pynvim_pp.atomic import Atomic
from pynvim_pp.buffer import Buffer, linefeed
from pynvim_pp.lib import decode, encode
from pynvim_pp.nvim import Nvim
from pynvim_pp.text_object import gen_split
from pynvim_pp.types import NoneType

from ..consts import DEBUG
from ..shared.parse import lower
from ..shared.settings import MatchOptions
from ..shared.types import UTF16, UTF32, ChangeEvent, Context
Expand Down Expand Up @@ -65,6 +68,13 @@ async def context(
l_syms_before, l_syms_after = lower(split.syms_lhs), lower(split.syms_rhs)
is_lower = l_words_before + l_words_after == split.word_lhs + split.word_rhs

if DEBUG:
u32, u16 = await Nvim.api.exec_lua(
Tuple[int, int], "return {vim.str_utfindex(...)}", (line, col)
)
assert utf16_col == u16
assert utf32_col == u32

ctx = Context(
manual=manual,
change_id=state.change_id,
Expand Down
17 changes: 9 additions & 8 deletions coq/shared/repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def _whitespaced(text: str) -> bool:
return any(c.isspace() for c in text)


def _shift(cursors: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
row, u8, u16, u32 = cursors
def _shift(cursor: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
row, u8, u16, u32 = cursor
if edit.encoding == UTF16:
col = u16
elif edit.encoding == UTF8:
Expand All @@ -33,7 +33,7 @@ def _shift(cursors: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
never(edit.encoding)

prev_col = edit.cursor_pos
(b_row, b_col), (e_row, e_col) = edit.begin, edit.end
(b_row, b_col), (e_row, e_col) = sorted((edit.begin, edit.end))
diff = col - prev_col

if b_row == row:
Expand All @@ -52,11 +52,12 @@ def _shift(cursors: Cursors, edit: BaseRangeEdit) -> Tuple[WTF8Pos, WTF8Pos]:
else:
new_e_col = e_col

return (b_row, max(0, new_b_col)), (e_row, max(0, new_e_col))
new_begin, new_end = (b_row, max(0, new_b_col)), (e_row, max(0, new_e_col))
return new_begin, new_end


def sanitize(cursors: Cursors, edit: Edit) -> Optional[Edit]:
row, *_ = cursors
def sanitize(cursor: Cursors, edit: Edit) -> Optional[Edit]:
row, *_ = cursor
if isinstance(edit, SnippetRangeEdit):
if row == -1:
if edit.fallback == edit.new_text:
Expand All @@ -69,7 +70,7 @@ def sanitize(cursors: Cursors, edit: Edit) -> Optional[Edit]:
else:
return None
else:
begin, end = _shift(cursors, edit=edit)
begin, end = _shift(cursor, edit=edit)
return replace(edit, begin=begin, end=end)
elif isinstance(edit, RangeEdit):
if row == -1:
Expand All @@ -80,7 +81,7 @@ def sanitize(cursors: Cursors, edit: Edit) -> Optional[Edit]:
elif not _whitespaced(edit.new_text):
return Edit(new_text=edit.fallback)
else:
begin, end = _shift(cursors, edit=edit)
begin, end = _shift(cursor, edit=edit)
return replace(edit, begin=begin, end=end)
elif isinstance(edit, SnippetEdit):
return edit
Expand Down
4 changes: 4 additions & 0 deletions tests/lsp/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main() {
/*𐐀*/
return 0;
}

0 comments on commit 0293fd2

Please sign in to comment.