Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cursor position following multibyte characters #428

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- Avoid creating public functions for callbacks which should be temporary.
- Fix file edits in buffers that aren't current when the current buffer is
shorter than the buffer being edited.
- Fix character positions when the cursor is on a line following multibyte
characters for recent versions of vim. Older versions and neovim continue to
have incorrect positions.

**Minor breaking changes**
- Remove `noselect` from the default `completeopts` used during autocompletion.
Expand Down
8 changes: 4 additions & 4 deletions autoload/lsc/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function! s:isCompletable() abort
return v:false
endif
if s:next_char !~# '\w' | return v:false | endif
let l:cur_col = col('.')
let l:cur_col = lsc#util#currentChar()
let l:min_length = exists('g:lsc_autocomplete_length') ?
\ g:lsc_autocomplete_length : 3
if l:min_length == v:false | return v:false | endif
Expand Down Expand Up @@ -108,8 +108,8 @@ function! s:SuggestCompletions(items) abort
return
endif
let l:start = s:FindStart(a:items)
let l:base = l:start != col('.')
\ ? getline('.')[l:start - 1:col('.') - 2]
let l:base = l:start != lsc#util#currentChar()
\ ? getline('.')[l:start - 1:lsc#util#currentChar() - 2]
\ : ''
let l:completion_items = s:CompletionItems(l:base, a:items)
call s:SetCompleteOpt()
Expand Down Expand Up @@ -169,7 +169,7 @@ endfunction
" Finds the 1-based index of the character after the last non word character
" behind the cursor.
function! s:GuessCompletionStart() abort
let l:search = col('.') - 2
let l:search = lsc#util#currentChar() - 2
let l:line = getline('.')
while l:search > 0
let l:char = l:line[l:search]
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/cursor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ endfunction
" not in any reference.
function! lsc#cursor#isInReference(references) abort
let l:line = line('.')
let l:col = col('.')
let l:col = lsc#util#currentChar()
let l:idx = 0
for l:reference in a:references
for l:range in l:reference.ranges
Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/diagnostics.vim
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function! lsc#diagnostics#underCursor() abort
return {}
endif
let l:diagnostics = l:file_diagnostics[l:line]
let l:col = col('.')
let l:col = lsc#util#currentChar()
let l:closest_diagnostic = {}
let l:closest_distance = -1
let l:closest_is_within = v:false
Expand Down
15 changes: 10 additions & 5 deletions autoload/lsc/params.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ endfunction

function! lsc#params#documentPosition() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'position': {'line': line('.') - 1, 'character': col('.') - 1}
\ 'position': {
\ 'line': line('.') - 1,
\ 'character': lsc#util#currentChar() - 1
\ }
\}
endfunction

function! lsc#params#documentRange() abort
return { 'textDocument': {'uri': lsc#uri#documentUri()},
\ 'range': {
\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},
\ 'end': {'line': line('.') - 1, 'character': col('.')}},
\ }
\ 'start': {
\ 'line': line('.') - 1,
\ 'character': lsc#util#currentChar() - 1,
\ },
\ 'end': {'line': line('.') - 1, 'character': lsc#util#currentChar()}},
\}
endfunction
12 changes: 12 additions & 0 deletions autoload/lsc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,15 @@ function! s:IgnoreArgs(name, Callback, args, ...) abort
let g:lsc_last_error_callback = [a:Callback, a:args]
endtry
endfunction

if exists('*charcol')
function! lsc#util#currentChar()
return charcol('.')
endfunction
else
function! lsc#util#currentChar()
" TODO - Can charcol be implemented manually?
" For now, vim without charcol does not handle multibyte characters
return col('.')
endfunction
endif