Skip to content
This repository was archived by the owner on Aug 24, 2020. It is now read-only.

Commit 701c734

Browse files
authored
Check text_edits is null (prabirshrestha#697)
* Check text_edits is null Some Language Server return null * Add test for textEdit is null * Check additionalTextEdits is null
1 parent bf8d206 commit 701c734

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

autoload/lsp/ui/vim/completion.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function! s:on_complete_done_after() abort
102102
endif
103103

104104
" apply additionalTextEdits.
105-
if has_key(l:completion_item, 'additionalTextEdits')
105+
if has_key(l:completion_item, 'additionalTextEdits') && !empty(l:completion_item['additionalTextEdits'])
106106
let l:saved_mark = getpos("'a")
107107
let l:pos = getpos('.')
108108
call setpos("'a", l:pos)

autoload/lsp/utils/text_edit.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function! lsp#utils#text_edit#apply_text_edits(uri, text_edits) abort
4343
" ((0, 0), (0, 1), "") - remove first character 'a'
4444
" ((0, 4), (0, 5), "") - remove fifth character 'e'
4545
" ((0, 2), (0, 3), "") - remove third character 'c'
46+
if empty(a:text_edits)
47+
return
48+
endif
49+
4650
let l:text_edits = sort(deepcopy(a:text_edits), '<SID>sort_text_edit_desc')
4751
let l:i = 0
4852

test/lsp/utils/text_edit.vimspec

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,18 @@ Describe lsp#utils#text_edit
587587
let l:buffer_text = s:get_text()
588588
Assert Equals(l:buffer_text, ['package main', '', 'import java.util.ArrayList;', '', 'public class Main {}', ''])
589589
End
590+
591+
It adds null
592+
let l:text = ['package main', '', 'import java.util.ArrayList;', '', 'public class Main {}']
593+
call s:set_text(l:text)
594+
595+
call lsp#utils#text_edit#apply_text_edits(
596+
\ expand('%'),
597+
\ v:null)
598+
599+
let l:buffer_text = s:get_text()
600+
Assert Equals(l:buffer_text, l:text + [''])
601+
End
590602
End
591603
End
592604

0 commit comments

Comments
 (0)