Skip to content

Commit

Permalink
sameids: fix trailing identifier highlighting
Browse files Browse the repository at this point in the history
Fix same id highlighting of identifiers that are at the very end of a
line.

Fixes #3605
  • Loading branch information
bhcleek committed Dec 5, 2023
1 parent 8b7a4d2 commit 4e0f092
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 6 additions & 6 deletions autoload/go/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ function! s:character(line, col) abort
endfunction

" go#lsp#PositionOf returns len(content[0:units]) where units is utf-16 code
" units. This is mostly useful for converting LSP text position to vim
" position.
" units. This is mostly useful for converting zero-based LSP text position to
" vim one-based position.
function! go#lsp#lsp#PositionOf(content, units, ...) abort
if a:units == 0
return 1
if len(a:content) is 0
return 0
endif

let l:remaining = a:units
let l:str = ''
for l:rune in split(a:content, '\zs')
if l:remaining < 0
if l:remaining <= 0
break
endif
let l:remaining -= 1
Expand All @@ -48,7 +48,7 @@ function! go#lsp#lsp#PositionOf(content, units, ...) abort
let l:str = l:str . l:rune
endfor

return len(l:str)
return len(l:str) + 1
endfunction

function! go#lsp#lsp#SeverityToErrorType(severity) abort
Expand Down
17 changes: 17 additions & 0 deletions autoload/go/lsp/lsp_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ function! Test_PositionOf_Simple()
call assert_equal(4, l:actual)
endfunc

function! Test_PositionOf_Start()
let l:str = 'abcd'
let l:actual = go#lsp#lsp#PositionOf(l:str, 0)
call assert_equal(l:actual, 1)
" subtract one, because PositionOf returns a one-based cursor position and
" while string indices are zero based.
call assert_equal(l:str[l:actual-1], 'a')
endfunc

function! Test_PositionOf_End()
let l:str = 'abcd'
let l:actual = go#lsp#lsp#PositionOf(l:str, 3)
call assert_equal(l:actual, 4)
" subtract one, because PositionOf returns a one-based cursor position and
" while string indices are zero based.
call assert_equal(l:str[l:actual-1], 'd')
endfunc

function! Test_PositionOf_MultiByte()
" ⌘ is U+2318, which encodes to three bytes in utf-8 and 1 code unit in
Expand Down

0 comments on commit 4e0f092

Please sign in to comment.