Fix cursor pos on appling additionalTextEdit (#726)

This commit is contained in:
hrsh7th
2020-02-21 23:35:35 +09:00
committed by GitHub
parent 77f3536c8b
commit 651bccfab8
2 changed files with 2 additions and 9 deletions

View File

@@ -90,19 +90,12 @@ function! s:on_complete_done_after() abort
" apply additionalTextEdits.
if has_key(l:completion_item, 'additionalTextEdits') && !empty(l:completion_item['additionalTextEdits'])
let l:saved_mark = getpos("'a")
let l:pos = getpos('.')
call setpos("'a", l:pos)
call lsp#utils#text_edit#apply_text_edits(
\ lsp#utils#get_buffer_uri(bufnr('%')),
\ l:completion_item['additionalTextEdits']
\ )
let l:pos = getpos("'a")
call setpos("'a", l:saved_mark)
call setpos('.', l:pos)
endif
" expand textEdit or insertText.
if strlen(l:expand_text) > 0
if exists('g:lsp_snippet_expand') && len(g:lsp_snippet_expand) > 0

View File

@@ -12,7 +12,7 @@ function! lsp#utils#text_edit#apply_text_edits(uri, text_edits) abort
call s:_switch(l:current_bufname)
if bufnr(l:current_bufname) == bufnr(l:target_bufname)
let l:length = strlen(getline(l:cursor_pos[0]))
let l:length = strlen(getline(l:cursor_pos[0])) + 1
let l:cursor_pos[2] = max([0, l:cursor_pos[1] + l:cursor_pos[2] - l:length])
let l:cursor_pos[1] = min([l:length, l:cursor_pos[1] + l:cursor_pos[2]])
call cursor(l:cursor_pos)
@@ -49,7 +49,7 @@ function! s:_apply(bufnr, text_edit, cursor_pos) abort
" fix cursor pos
let l:cursor_offset = 0
if a:text_edit.range.end.line <= a:cursor_pos[0]
if a:text_edit.range.end.line + 1 < a:cursor_pos[0]
let l:cursor_offset = l:new_lines_len - (a:text_edit.range.end.line - a:text_edit.range.start.line) - 1
let a:cursor_pos[0] += l:cursor_offset
endif