Skip to content

Commit 8851e05

Browse files
committed
Fix cursor position following multibyte characters
Closes #427 Use `charcol` over `col` where it exists. Gate the function definition behind the feature check to avoid repeating it for every call.
1 parent 4b0fc48 commit 8851e05

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- Avoid a state where no document highlights reference calls are made following
99
a server restart.
1010
- Avoid creating public functions for callbacks which should be temporary.
11+
- Fix character positions when the cursor is on a line following multibyte
12+
characters for recent versions of vim. Older versions and neovim continue to
13+
have incorrect positions.
1114

1215
**Minor breaking changes**
1316
- Remove `noselect` from the default `completeopts` used during autocompletion.

autoload/lsc/params.vim

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@ function! lsc#params#textDocument() abort
22
return {'textDocument': {'uri': lsc#uri#documentUri()}}
33
endfunction
44

5-
function! lsc#params#documentPosition() abort
6-
return { 'textDocument': {'uri': lsc#uri#documentUri()},
7-
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
8-
\ }
9-
endfunction
10-
11-
function! lsc#params#documentRange() abort
12-
return { 'textDocument': {'uri': lsc#uri#documentUri()},
13-
\ 'range': {
14-
\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},
15-
\ 'end': {'line': line('.') - 1, 'character': col('.')}},
16-
\ }
17-
endfunction
5+
if exists('*charcol')
6+
function! lsc#params#documentPosition() abort
7+
return { 'textDocument': {'uri': lsc#uri#documentUri()},
8+
\ 'position': {'line': line('.') - 1, 'character': charcol('.') - 1}
9+
\ }
10+
endfunction
11+
function! lsc#params#documentRange() abort
12+
return { 'textDocument': {'uri': lsc#uri#documentUri()},
13+
\ 'range': {
14+
\ 'start': {'line': line('.') - 1, 'character': charcol('.') - 1},
15+
\ 'end': {'line': line('.') - 1, 'character': charcol('.')}},
16+
\ }
17+
endfunction
18+
else
19+
" TODO - this is broken following multibyte characters.
20+
function! lsc#params#documentPosition() abort
21+
return { 'textDocument': {'uri': lsc#uri#documentUri()},
22+
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
23+
\ }
24+
endfunction
25+
function! lsc#params#documentRange() abort
26+
return { 'textDocument': {'uri': lsc#uri#documentUri()},
27+
\ 'range': {
28+
\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},
29+
\ 'end': {'line': line('.') - 1, 'character': col('.')}},
30+
\ }
31+
endfunction
32+
endif

0 commit comments

Comments
 (0)