Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit 87e110e

Browse files
committed
fix highligh position with unicode characters for neovim
1 parent 0925448 commit 87e110e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

autoload/lsp_cxx_hl/textprop_nvim.vim

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,19 @@ function! s:buf_add_hl(buf, ns_id, hl_group,
1919
" single line symbol
2020
if a:s_line == a:e_line
2121
if a:e_char - a:s_char > 0
22-
call nvim_buf_add_highlight(a:buf, a:ns_id, a:hl_group,
23-
\ a:s_line, a:s_char, a:e_char)
22+
try
23+
" Convert byte positions to column position in the file.
24+
let line = getbufline(a:buf, a:s_line + 1)[0]
25+
call nvim_buf_add_highlight(a:buf, a:ns_id, a:hl_group,
26+
\ a:s_line,
27+
\ byteidx(line, a:s_char),
28+
\ byteidx(line, a:e_char))
29+
" If the user fastly edits the file, this can be slower then the
30+
" edits, and `getbufline` can return zero lines or these columns
31+
" may just not exists anymore.
32+
catch /Column value outside range/
33+
catch /^Vim\%((\a\+)\)\=:E684/
34+
endtry
2435
return
2536
else
2637
return

0 commit comments

Comments
 (0)