From 73d98fc32875582dd97212eccb1d4bee2bb51cc6 Mon Sep 17 00:00:00 2001 From: machakann Date: Tue, 20 Aug 2019 19:42:21 +0800 Subject: [PATCH] Rename `lsp#utils#byteindex` to `lsp#utils#to_col` --- autoload/lsp/omni.vim | 2 +- autoload/lsp/ui/vim/diagnostics.vim | 10 +++--- autoload/lsp/ui/vim/diagnostics/textprop.vim | 4 +-- autoload/lsp/ui/vim/utils.vim | 6 ++-- autoload/lsp/utils.vim | 2 +- test/lsp/utils.vimspec | 38 ++++++++++---------- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/autoload/lsp/omni.vim b/autoload/lsp/omni.vim index a3bd6666..9fde9e55 100644 --- a/autoload/lsp/omni.vim +++ b/autoload/lsp/omni.vim @@ -358,7 +358,7 @@ function! s:get_cursor_pos_and_edit_length(text_edit) abort let l:start = a:text_edit['range']['start'] let l:line = l:start['line'] + 1 let l:char = l:start['character'] - let l:col = lsp#utils#byteindex('%', l:line, l:char) + let l:col = lsp#utils#to_col('%', l:line, l:char) let l:length = len(a:text_edit['newText']) let l:pos = [0, l:line, l:col, 0] else diff --git a/autoload/lsp/ui/vim/diagnostics.vim b/autoload/lsp/ui/vim/diagnostics.vim index e96dc78a..89b38143 100644 --- a/autoload/lsp/ui/vim/diagnostics.vim +++ b/autoload/lsp/ui/vim/diagnostics.vim @@ -67,7 +67,7 @@ function! lsp#ui#vim#diagnostics#get_diagnostics_under_cursor() abort let l:range = l:diagnostic['range'] let l:start_line = l:range['start']['line'] + 1 let l:start_char = l:range['start']['character'] - let l:start_col = lsp#utils#byteindex('%', l:start_line, l:start_char) + let l:start_col = lsp#utils#to_col('%', l:start_line, l:start_char) if l:line == l:start_line let l:distance = abs(l:start_col - l:col) @@ -95,7 +95,7 @@ function! lsp#ui#vim#diagnostics#next_error() abort for l:diagnostic in l:diagnostics let l:line = l:diagnostic['range']['start']['line'] + 1 let l:char = l:diagnostic['range']['start']['character'] - let l:col = lsp#utils#byteindex('%', l:line, l:char) + let l:col = lsp#utils#to_col('%', l:line, l:char) if l:line > l:view['lnum'] \ || (l:line == l:view['lnum'] && l:col > l:view['col'] + 1) let l:next_line = l:line @@ -108,7 +108,7 @@ function! lsp#ui#vim#diagnostics#next_error() abort " Wrap to start let l:next_line = l:diagnostics[0]['range']['start']['line'] + 1 let l:next_char = l:diagnostics[0]['range']['start']['character'] - let l:next_col = lsp#utils#byteindex('%', l:next_line, l:next_char) - 1 + let l:next_col = lsp#utils#to_col('%', l:next_line, l:next_char) - 1 endif let l:view['lnum'] = l:next_line @@ -142,7 +142,7 @@ function! lsp#ui#vim#diagnostics#previous_error() abort while l:index >= 0 let l:line = l:diagnostics[l:index]['range']['start']['line'] + 1 let l:char = l:diagnostics[l:index]['range']['start']['character'] - let l:col = lsp#utils#byteindex('%', l:line, l:char) + let l:col = lsp#utils#to_col('%', l:line, l:char) if l:line < l:view['lnum'] \ || (l:line == l:view['lnum'] && l:col < l:view['col']) let l:next_line = l:line @@ -156,7 +156,7 @@ function! lsp#ui#vim#diagnostics#previous_error() abort " Wrap to end let l:next_line = l:diagnostics[-1]['range']['start']['line'] + 1 let l:next_char = l:diagnostics[-1]['range']['start']['character'] - let l:next_col = lsp#utils#byteindex('%', l:next_line, l:next_char) - 1 + let l:next_col = lsp#utils#to_col('%', l:next_line, l:next_char) - 1 endif let l:view['lnum'] = l:next_line diff --git a/autoload/lsp/ui/vim/diagnostics/textprop.vim b/autoload/lsp/ui/vim/diagnostics/textprop.vim index 60ac22a6..4c3bc57c 100644 --- a/autoload/lsp/ui/vim/diagnostics/textprop.vim +++ b/autoload/lsp/ui/vim/diagnostics/textprop.vim @@ -119,10 +119,10 @@ function! s:place_highlights(server_name, path, diagnostics) abort for l:item in a:diagnostics let l:start_line = l:item['range']['start']['line'] + 1 let l:start_char = l:item['range']['start']['character'] - let l:start_col = lsp#utils#byteindex(l:bufnr, l:start_line, l:start_char) + let l:start_col = lsp#utils#to_col(l:bufnr, l:start_line, l:start_char) let l:end_line = l:item['range']['end']['line'] + 1 let l:end_char = l:item['range']['end']['character'] - let l:end_col = lsp#utils#byteindex(l:bufnr, l:end_line, l:end_char) + let l:end_col = lsp#utils#to_col(l:bufnr, l:end_line, l:end_char) let l:prop_type = s:get_prop_type(a:server_name, l:item['severity']) call prop_add(l:start_line, l:start_col, { diff --git a/autoload/lsp/ui/vim/utils.vim b/autoload/lsp/ui/vim/utils.vim index 5dbbc515..93225c23 100644 --- a/autoload/lsp/ui/vim/utils.vim +++ b/autoload/lsp/ui/vim/utils.vim @@ -14,7 +14,7 @@ function! lsp#ui#vim#utils#locations_to_loc_list(result) abort let l:path = lsp#utils#uri_to_path(l:location['uri']) let l:line = l:location['range']['start']['line'] + 1 let l:char = l:location['range']['start']['character'] - let l:col = lsp#utils#byteindex(l:path, l:line, l:char) + let l:col = lsp#utils#to_col(l:path, l:line, l:char) let l:index = l:line - 1 if has_key(l:cache, l:path) let l:text = l:cache[l:path][l:index] @@ -81,7 +81,7 @@ function! lsp#ui#vim#utils#symbols_to_loc_list(result) abort let l:bufnr = bufnr(l:path) let l:line = l:location['range']['start']['line'] + 1 let l:char = l:location['range']['start']['character'] - let l:col = lsp#utils#byteindex(l:path, l:line, l:char) + let l:col = lsp#utils#to_col(l:path, l:line, l:char) call add(l:list, { \ 'filename': l:path, \ 'lnum': l:line, @@ -122,7 +122,7 @@ function! lsp#ui#vim#utils#diagnostics_to_loc_list(result) abort let l:text .= l:item['message'] let l:line = l:item['range']['start']['line'] + 1 let l:char = l:item['range']['start']['character'] - let l:col = lsp#utils#byteindex(l:path, l:line, l:char) + let l:col = lsp#utils#to_col(l:path, l:line, l:char) call add(l:list, { \ 'filename': l:path, \ 'lnum': l:line, diff --git a/autoload/lsp/utils.vim b/autoload/lsp/utils.vim index 95acb6b2..546cc2f0 100644 --- a/autoload/lsp/utils.vim +++ b/autoload/lsp/utils.vim @@ -189,7 +189,7 @@ endfunction " Convert a character-index (0-based) to byte-index (1-based) " This function requires a buffer specifier (expr, see :help bufname()), " a line number (lnum, 1-based), and a character-index (char, 0-based). -function! lsp#utils#byteindex(expr, lnum, char) abort +function! lsp#utils#to_col(expr, lnum, char) abort let l:lines = getbufline(a:expr, a:lnum) if l:lines == [] if type(a:expr) != v:t_string || !filereadable(a:expr) diff --git a/test/lsp/utils.vimspec b/test/lsp/utils.vimspec index 6ac5dc3c..db14627f 100644 --- a/test/lsp/utils.vimspec +++ b/test/lsp/utils.vimspec @@ -82,31 +82,31 @@ Describe lsp#utils End End - Describe lsp#utils#byteindex + Describe lsp#utils#to_col It should return the byte-index from the given character-index on a buffer call setline(1, ['a β c', 'δ', '']) - Assert lsp#utils#byteindex('%', 1, 0) == 1 - Assert lsp#utils#byteindex('%', 1, 1) == 2 - Assert lsp#utils#byteindex('%', 1, 2) == 3 - Assert lsp#utils#byteindex('%', 1, 3) == 5 - Assert lsp#utils#byteindex('%', 1, 4) == 6 - Assert lsp#utils#byteindex('%', 1, 5) == 7 - Assert lsp#utils#byteindex('%', 2, 0) == 1 - Assert lsp#utils#byteindex('%', 2, 1) == 3 - Assert lsp#utils#byteindex('%', 3, 0) == 1 + Assert lsp#utils#to_col('%', 1, 0) == 1 + Assert lsp#utils#to_col('%', 1, 1) == 2 + Assert lsp#utils#to_col('%', 1, 2) == 3 + Assert lsp#utils#to_col('%', 1, 3) == 5 + Assert lsp#utils#to_col('%', 1, 4) == 6 + Assert lsp#utils#to_col('%', 1, 5) == 7 + Assert lsp#utils#to_col('%', 2, 0) == 1 + Assert lsp#utils#to_col('%', 2, 1) == 3 + Assert lsp#utils#to_col('%', 3, 0) == 1 %delete End It should return the byte-index from the given character-index in an unloaded file - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 0) == 1 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 1) == 2 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 2) == 3 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 3) == 5 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 4) == 6 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 1, 5) == 7 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 2, 0) == 1 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 2, 1) == 3 - Assert lsp#utils#byteindex('./test/testfiles/multibyte.txt', 3, 0) == 1 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 0) == 1 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 1) == 2 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 2) == 3 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 3) == 5 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 4) == 6 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 5) == 7 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 2, 0) == 1 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 2, 1) == 3 + Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 3, 0) == 1 End End End