mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2026-06-09 15:37:30 +02:00
Rename lsp#utils#byteindex to lsp#utils#to_col
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
+19
-19
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user