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

Draft: Fix highlight with unicode #77

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions autoload/lsp_cxx_hl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ function! s:common_notify_checks(server, buffer, data) abort
return l:bufnr
endfunction

" Convert range of bytes starting from s_line character s_char
" to line e_line character e_char in buffer a:buf into a range of columns.
" These are equal when each displayed character takes exactly one column,
" but there's also UTF-8.
function! lsp_cxx_hl#bytes_to_columns(buf, s_line, s_char, e_line, e_char)
if get(g:, 'lsp_cxx_hl_use_byteidx', 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this outside the function and each place we need to call it we wrap that. It's a bit more repeated code but we avoid the call which might have less of an impact on the runtime.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to have it's default in plugin/vim-lsp-cxx-highlight.vim. You can then access it directly via g:lsp_cxx_hl_use_byteidx instead of via get(g:. I think most of the code currently uses get(g: but it's probably unnecessary as it's always defined anyways.

Also a doc entry would be good as well.

try
return [byteidx(getbufline(a:buf, a:s_line)[0], a:s_char),
\ byteidx(getbufline(a:buf, a:e_line)[0], a:e_char)]
" If the user fastly edits the file, this can be slower then the
" edits, and `getbufline` can return zero lines or these columns
" may just not exists anymore.
catch /^Vim\%((\a\+)\)\=:E684/
endtry
endif
return [ a:s_char, a:e_char ]
endfunction

" Section: Misc Helpers
function! s:uri2bufnr(uri) abort
" Absolute paths on windows has 3 leading /
Expand Down
3 changes: 3 additions & 0 deletions autoload/lsp_cxx_hl/textprop/symbols.vim
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ function! s:hl_symbols(bufnr, timer) abort

for l:prop in l:props
call extend(l:prop[2], l:prop_extra)
let [ l:prop[1], l:prop[2]['end_col'] ] = lsp_cxx_hl#bytes_to_columns(
\ a:bufnr, l:prop[0], l:prop[1],
\ get(l:prop[2], 'end_lnum', l:prop[0]), l:prop[2]['end_col'])

try
call prop_add(l:prop[0], l:prop[1], l:prop[2])
Expand Down
17 changes: 10 additions & 7 deletions autoload/lsp_cxx_hl/textprop_nvim.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
" Textprops neovim
"
"
" It should be noted that neovim uses zero based indexing like LSP
" this is unlike regular vim APIs which are 1 based.

Expand All @@ -18,13 +18,16 @@ function! s:buf_add_hl(buf, ns_id, hl_group,

" single line symbol
if a:s_line == a:e_line
if a:e_char - a:s_char > 0
call nvim_buf_add_highlight(a:buf, a:ns_id, a:hl_group,
\ a:s_line, a:s_char, a:e_char)
return
else
return
let [ s_char, e_char ] = lsp_cxx_hl#bytes_to_columns(a:buf,
\ a:s_line + 1, a:s_char, a:s_line + 1, a:e_char)
if s_char < e_char
try
call nvim_buf_add_highlight(a:buf, a:ns_id, a:hl_group,
\ a:s_line, s_char, e_char)
catch /Column value outside range/
endtry
endif
return
endif

call lsp_cxx_hl#log('Error (textprop_nvim): symbol (', a:hl_group,
Expand Down
1 change: 1 addition & 0 deletions syntax/lsp_cxx_highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ hi default link LspCxxHlSymNamespace LspCxxHlGroupNamespace
hi default link LspCxxHlSymVariable Normal
hi default link LspCxxHlSymParameter Normal
hi default link LspCxxHlSymField LspCxxHlGroupMemberVariable
" LspCxxHlSymLocalVariable

" clangd-only groups
" A static member variable
Expand Down