MCPcopy
hub / github.com/SirVer/ultisnips / consume_edits

Method consume_edits

pythonx/UltiSnips/change_provider.py:611–639  ·  view source on GitHub ↗
(self, buf, snippet, vstate)

Source from the content-addressed store, hash-verified

609 vim.command("let g:_ultisnips_listener_changes = []")
610
611 def consume_edits(self, buf, snippet, vstate):
612 vim.command("call UltiSnips#listener#Flush()")
613 raw = vim.eval("g:_ultisnips_listener_changes")
614 vim.command("let g:_ultisnips_listener_changes = []")
615 if not raw:
616 return None
617
618 old_lines = vstate.remembered_buffer
619 snippet_start = snippet.start.line
620 pos = buf.cursor
621
622 if len(raw) == 1:
623 # Single event: use listener metadata to scope comparison
624 es = _listener_to_edits(
625 raw[0], old_lines, buf, snippet_start, pos.line, pos.col
626 )
627 if es is not None:
628 return es
629
630 # Multiple events or scoped detection failed: full snippet comparison
631 new_end = snippet.end.line + (len(buf) - vstate.remembered_buffer_length)
632 new_lines = buf[snippet_start : new_end + 1]
633
634 es = detect_edits(old_lines, new_lines, snippet_start, pos.line, pos.col)
635 if es is not None:
636 return es
637 if _is_pathological_diff_input(old_lines, new_lines):
638 return DROP_SNIPPET
639 return diff("\n".join(old_lines), "\n".join(new_lines), snippet_start)
640
641
642class NvimChangeProvider(_ChangeProvider):

Callers 1

_cursor_movedMethod · 0.45

Calls 4

_listener_to_editsFunction · 0.85
detect_editsFunction · 0.85
diffFunction · 0.85

Tested by

no test coverage detected