mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
improve diff by using lua if available (#821)
* use lua if available for diff * add docs * sync with latest vim-lsc changes * lazily init lua * update vim to 8.2.0817 * update vim to 8.2.0817 for windows * use vim 8.2.0814 * check for path 8.2.0775 before enabling lua * use vim 8.2.0813 since it exists for both linux and windows * update lua patch check * optimize vimscript diff by using range * fix lint issues
This commit is contained in:
2
.github/workflows/linux_vim.yml
vendored
2
.github/workflows/linux_vim.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
include:
|
||||
- name: vim-v82-x64
|
||||
os: ubuntu-latest
|
||||
vim_version: 8.2.0037
|
||||
vim_version: 8.2.0813
|
||||
glibc_version: 2.15
|
||||
- name: vim-v81-x64
|
||||
os: ubuntu-latest
|
||||
|
||||
2
.github/workflows/windows_vim.yml
vendored
2
.github/workflows/windows_vim.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
include:
|
||||
- name: vim-v82-x64
|
||||
os: windows-latest
|
||||
vim_version: 8.2.0037
|
||||
vim_version: 8.2.0813
|
||||
vim_arch: x64
|
||||
vim_ver_path: vim82
|
||||
- name: vim-v81-x64
|
||||
|
||||
@@ -11,6 +11,11 @@ Plug 'prabirshrestha/vim-lsp'
|
||||
|
||||
_Note: [async.vim](https://github.com/prabirshrestha/async.vim) is required and is used to normalize jobs between vim8 and neovim._
|
||||
|
||||
__Performance__
|
||||
|
||||
Certain bottlenecks in VimScript have been implemented in lua. If you would like to take advantage of these performance gains
|
||||
use vim compiled with lua or neovim v0.4.0+
|
||||
|
||||
## Registering servers
|
||||
|
||||
```viml
|
||||
|
||||
@@ -6,6 +6,40 @@
|
||||
" definition of `TextDocumentContentChangeEvent`.
|
||||
"
|
||||
" Finds a single change between the common prefix, and common postfix.
|
||||
let s:has_lua = has('nvim-0.4.0') || (has('lua') && has('patch-8.2.0775'))
|
||||
|
||||
function! s:init_lua() abort
|
||||
lua <<EOF
|
||||
-- Returns a zero-based index of the last line that is different between
|
||||
-- old and new. If old and new are not zero indexed, pass offset to indicate
|
||||
-- the index base.
|
||||
function vimlsp_last_difference(old, new, offset, line_count)
|
||||
for i = 0, line_count - 1 do
|
||||
if old[#old - i + offset] ~= new[#new - i + offset] then
|
||||
return -1 * i
|
||||
end
|
||||
end
|
||||
return -1 * line_count
|
||||
end
|
||||
-- Returns a zero-based index of the first line that is different between
|
||||
-- old and new. If old and new are not zero indexed, pass offset to indicate
|
||||
-- the index base.
|
||||
function vimlsp_first_difference(old, new, offset, line_count)
|
||||
for i = 0, line_count - 1 do
|
||||
if old[i + offset] ~= new[i + offset] then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return line_count - 1
|
||||
end
|
||||
EOF
|
||||
let s:lua = 1
|
||||
endfunction
|
||||
|
||||
if s:has_lua && !exists('s:lua')
|
||||
call s:init_lua()
|
||||
endif
|
||||
|
||||
function! lsp#utils#diff#compute(old, new) abort
|
||||
let [l:start_line, l:start_char] = s:FirstDifference(a:old, a:new)
|
||||
let [l:end_line, l:end_char] =
|
||||
@@ -31,11 +65,15 @@ endfunction
|
||||
function! s:FirstDifference(old, new) abort
|
||||
let l:line_count = min([len(a:old), len(a:new)])
|
||||
if l:line_count == 0 | return [0, 0] | endif
|
||||
let l:i = 0
|
||||
while l:i < l:line_count
|
||||
if a:old[l:i] !=# a:new[l:i] | break | endif
|
||||
let l:i += 1
|
||||
endwhile
|
||||
if g:lsp_use_lua && s:has_lua
|
||||
let l:eval = has('nvim') ? 'vim.api.nvim_eval' : 'vim.eval'
|
||||
let l:i = luaeval('vimlsp_first_difference('
|
||||
\.l:eval.'("a:old"),'.l:eval.'("a:new"),'.l:eval.'("has(\"nvim\")"),'.l:line_count.')')
|
||||
else
|
||||
for l:i in range(l:line_count)
|
||||
if a:old[l:i] !=# a:new[l:i] | break | endif
|
||||
endfor
|
||||
endif
|
||||
if l:i >= l:line_count
|
||||
return [l:line_count - 1, strchars(a:old[l:line_count - 1])]
|
||||
endif
|
||||
@@ -53,11 +91,15 @@ endfunction
|
||||
function! s:LastDifference(old, new, start_char) abort
|
||||
let l:line_count = min([len(a:old), len(a:new)])
|
||||
if l:line_count == 0 | return [0, 0] | endif
|
||||
let l:i = -1
|
||||
while l:i >= -1 * l:line_count
|
||||
if a:old[l:i] !=# a:new[l:i] | break | endif
|
||||
let l:i -= 1
|
||||
endwhile
|
||||
if g:lsp_use_lua && s:has_lua
|
||||
let l:eval = has('nvim') ? 'vim.api.nvim_eval' : 'vim.eval'
|
||||
let l:i = luaeval('vimlsp_last_difference('
|
||||
\.l:eval.'("a:old"),'.l:eval.'("a:new"),'.l:eval.'("has(\"nvim\")"),'.l:line_count.')')
|
||||
else
|
||||
for l:i in range(-1, -1 * l:line_count, -1)
|
||||
if a:old[l:i] !=# a:new[l:i] | break | endif
|
||||
endfor
|
||||
endif
|
||||
if l:i <= -1 * l:line_count
|
||||
let l:i = -1 * l:line_count
|
||||
let l:old_line = strcharpart(a:old[l:i], a:start_char)
|
||||
|
||||
@@ -6,6 +6,7 @@ CONTENTS *vim-lsp-contents*
|
||||
|
||||
Introduction |vim-lsp-introduction|
|
||||
Install |vim-lsp-install|
|
||||
Performance |vim-lsp-performance|
|
||||
Language Servers |vim-lsp-language-servers|
|
||||
Configure |vim-lsp-configure|
|
||||
vim-lsp-settings |vim-lsp-settings_plugin|
|
||||
@@ -132,6 +133,25 @@ Install the async.vim and vim-lsp plugins. Below is a sample using plug.vim
|
||||
Note: async.vim (https://github.com/prabirshrestha/async.vim) is required to
|
||||
use vim-lsp. It is used to normalize the jobs api between Vim 8 and Neovim.
|
||||
|
||||
==============================================================================
|
||||
PERFORMANCE *vim-lsp-performance*
|
||||
|
||||
While VimScript is very portable it has performance implications. If you would
|
||||
like to improve performance make sure you have vim/neovim with lua support.
|
||||
Currently only diff algorithm uses lua internally if available.
|
||||
Following is th default value used to detect lua.
|
||||
>
|
||||
let g:lsp_enable_lua = has('nvim-0.4.0') || (has('lua') && has('patch-8.2.0775'))
|
||||
|
||||
Windows users can download the binaries from the following url and place
|
||||
lua53.dll in the `PATH` or besides `vim.exe` or `gvim.exe` executables.
|
||||
|
||||
32 bit:
|
||||
http://downloads.sourceforge.net/luabinaries/lua-5.3.2_Win32_dllw4_lib.zip
|
||||
|
||||
64bit:
|
||||
http://downloads.sourceforge.net/luabinaries/lua-5.3.2_Win64_dllw4_lib.zip
|
||||
|
||||
==============================================================================
|
||||
LANGUAGE SERVERS *vim-lsp-language-servers*
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ if exists('g:lsp_loaded') || !exists('*json_encode') || !has('timers') || !has('
|
||||
endif
|
||||
let g:lsp_loaded = 1
|
||||
|
||||
let g:lsp_use_lua = get(g:, 'lsp_use_lua', has('nvim-0.4.0') || (has('lua') && has('patch-8.2.0775')))
|
||||
let g:lsp_auto_enable = get(g:, 'lsp_auto_enable', 1)
|
||||
let g:lsp_async_completion = get(g:, 'lsp_async_completion', 0)
|
||||
let g:lsp_log_file = get(g:, 'lsp_log_file', '')
|
||||
|
||||
Reference in New Issue
Block a user