mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
Fix cursor pos on appling additionalTextEdit (#726)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user