diff --git a/autoload/lsp/utils/diff.vim b/autoload/lsp/utils/diff.vim index 4f99a001..137d4131 100644 --- a/autoload/lsp/utils/diff.vim +++ b/autoload/lsp/utils/diff.vim @@ -6,7 +6,69 @@ " definition of `TextDocumentContentChangeEvent`. " " Finds a single change between the common prefix, and common postfix. +let s:lua_initialized = 0 + +function! s:init_lua() abort + let s:lua_initialized = 1 + + lua <= line_count then + return line_count - 1, vim.fn.strchars(old[line_count - 1]) + end + local old_line = old[i] + local new_line = new[i] + local length = math.min(vim.fn.strchars(old_line), vim.fn.strchars(new_line)) + local j = 0 + while j < length do + if vim.fn.strgetchar(old_line, j) ~= vim.fn.strgetchar(new_line, j) then + break + end + j = j + 1 + end + return i, j + end + + function M.compute(old, new) + local start_line, start_char = first_difference(old, new) + end +EOF +endfunction + function! lsp#utils#diff#compute(old, new) abort + if g:lsp_use_lua + if !s:lua_initialized + call s:init_lua() + endif + if has('nvim') + lua vimlsp.utils.diff.compute(vim.api.nvim_eval('a:old'), vim.api.nvim_eval('a:new')) + else + lua vimlsp.utils.diff.compute(vim.eval('a:old'), vim.eval('a:new')) + endif + return s:vim_compute(a:old, a:new) " once lua is ported remove this + else + return s:vim_compute(a:old, a:new) + endif +endfunction + +function! s:vim_compute(old, new) abort let [l:start_line, l:start_char] = s:FirstDifference(a:old, a:new) let [l:end_line, l:end_char] = \ s:LastDifference(a:old[l:start_line :], a:new[l:start_line :], l:start_char)