Skip to content

Commit 651bccf

Browse files
authored
Fix cursor pos on appling additionalTextEdit (#726)
1 parent 77f3536 commit 651bccf

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

autoload/lsp/ui/vim/completion.vim

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,12 @@ function! s:on_complete_done_after() abort
9090

9191
" apply additionalTextEdits.
9292
if has_key(l:completion_item, 'additionalTextEdits') && !empty(l:completion_item['additionalTextEdits'])
93-
let l:saved_mark = getpos("'a")
94-
let l:pos = getpos('.')
95-
call setpos("'a", l:pos)
9693
call lsp#utils#text_edit#apply_text_edits(
9794
\ lsp#utils#get_buffer_uri(bufnr('%')),
9895
\ l:completion_item['additionalTextEdits']
9996
\ )
100-
let l:pos = getpos("'a")
101-
call setpos("'a", l:saved_mark)
102-
call setpos('.', l:pos)
10397
endif
10498

105-
10699
" expand textEdit or insertText.
107100
if strlen(l:expand_text) > 0
108101
if exists('g:lsp_snippet_expand') && len(g:lsp_snippet_expand) > 0

autoload/lsp/utils/text_edit.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function! lsp#utils#text_edit#apply_text_edits(uri, text_edits) abort
1212
call s:_switch(l:current_bufname)
1313

1414
if bufnr(l:current_bufname) == bufnr(l:target_bufname)
15-
let l:length = strlen(getline(l:cursor_pos[0]))
15+
let l:length = strlen(getline(l:cursor_pos[0])) + 1
1616
let l:cursor_pos[2] = max([0, l:cursor_pos[1] + l:cursor_pos[2] - l:length])
1717
let l:cursor_pos[1] = min([l:length, l:cursor_pos[1] + l:cursor_pos[2]])
1818
call cursor(l:cursor_pos)
@@ -49,7 +49,7 @@ function! s:_apply(bufnr, text_edit, cursor_pos) abort
4949

5050
" fix cursor pos
5151
let l:cursor_offset = 0
52-
if a:text_edit.range.end.line <= a:cursor_pos[0]
52+
if a:text_edit.range.end.line + 1 < a:cursor_pos[0]
5353
let l:cursor_offset = l:new_lines_len - (a:text_edit.range.end.line - a:text_edit.range.start.line) - 1
5454
let a:cursor_pos[0] += l:cursor_offset
5555
endif

0 commit comments

Comments
 (0)