Skip to content

Commit

Permalink
Check text_edits is null (#697)
Browse files Browse the repository at this point in the history
* Check text_edits is null

Some Language Server return null

* Add test for textEdit is null

* Check additionalTextEdits is null
  • Loading branch information
mattn authored Feb 1, 2020
1 parent bf8d206 commit 701c734
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoload/lsp/ui/vim/completion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function! s:on_complete_done_after() abort
endif

" apply additionalTextEdits.
if has_key(l:completion_item, '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)
Expand Down
4 changes: 4 additions & 0 deletions autoload/lsp/utils/text_edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function! lsp#utils#text_edit#apply_text_edits(uri, text_edits) abort
" ((0, 0), (0, 1), "") - remove first character 'a'
" ((0, 4), (0, 5), "") - remove fifth character 'e'
" ((0, 2), (0, 3), "") - remove third character 'c'
if empty(a:text_edits)
return
endif

let l:text_edits = sort(deepcopy(a:text_edits), '<SID>sort_text_edit_desc')
let l:i = 0

Expand Down
12 changes: 12 additions & 0 deletions test/lsp/utils/text_edit.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@ Describe lsp#utils#text_edit
let l:buffer_text = s:get_text()
Assert Equals(l:buffer_text, ['package main', '', 'import java.util.ArrayList;', '', 'public class Main {}', ''])
End

It adds null
let l:text = ['package main', '', 'import java.util.ArrayList;', '', 'public class Main {}']
call s:set_text(l:text)

call lsp#utils#text_edit#apply_text_edits(
\ expand('%'),
\ v:null)

let l:buffer_text = s:get_text()
Assert Equals(l:buffer_text, l:text + [''])
End
End
End

0 comments on commit 701c734

Please sign in to comment.