" Remove keys we're not interested in function! PreprocessItem(item) abort let l:item = a:item if has_key(l:item, 'user_data') let l:user_data = json_decode(l:item['user_data']) unlet l:user_data['vim-lsp/insertStart'] let l:item['user_data'] = json_encode(l:user_data) endif if l:item['user_data'] == '{}' unlet l:item['user_data'] endif return l:item endfunction Describe lsp#omni Describe lsp#omni#get_vim_completion_item It should return item with proper kind let item = { \ 'label': 'my-label', \ 'documentation': 'my documentation.', \ 'detail': 'my-detail', \ 'kind': '3' \} let want = { \ 'word': 'my-label', \ 'abbr': 'my-label', \ 'info': 'my documentation.', \ 'icase': 1, \ 'dup': 1, \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail' \} let got = lsp#omni#get_vim_completion_item(item) Assert Equals(PreprocessItem(got), want) End It should return result contained user_data['vim-lsp/textEdit'], if exist textEdit in item if !has('patch-8.0.1493') Skip This test requires 'patch-8.0.1493' endif let l:text_edit = { \ 'range': { \ 'start': {'line': 5, 'character': 0}, \ 'end': {'line': 5, 'character': 5} \ }, \ 'newText': 'yyy' \ } let item = { \ 'label': 'my-label', \ 'documentation': 'my documentation.', \ 'detail': 'my-detail', \ 'kind': '3', \ 'textEdit': l:text_edit \} let l:want_user_data = { \ 'vim-lsp/textEdit': l:text_edit \} let l:want_user_data_string = json_encode(l:want_user_data) let want = { \ 'word': 'my-label', \ 'abbr': 'my-label', \ 'info': 'my documentation.', \ 'icase': 1, \ 'dup': 1, \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail', \ 'user_data': l:want_user_data_string \} let got = lsp#omni#get_vim_completion_item(item) Assert Equals(PreprocessItem(got), want) End It should not add user_data, if provide textEdit property and textEdit value is null if !has('patch-8.0.1493') Skip This test requires 'patch-8.0.1493' endif let item = { \ 'label': 'my-label', \ 'documentation': 'my documentation.', \ 'detail': 'my-detail', \ 'kind': '3', \ 'textEdit': v:null \} let want = { \ 'word': 'my-label', \ 'abbr': 'my-label', \ 'info': 'my documentation.', \ 'icase': 1, \ 'dup': 1, \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail', \} let got = lsp#omni#get_vim_completion_item(item) Assert Equals(PreprocessItem(got), want) End It should return item with newlines in 'menu' replaced let item = { \ 'label': 'my-label', \ 'documentation': 'my documentation.', \ 'detail': "my-detail\nmore-detail", \ 'kind': '3' \} let want = { \ 'word': 'my-label', \ 'abbr': 'my-label', \ 'info': 'my documentation.', \ 'icase': 1, \ 'dup': 1, \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail more-detail' \} let got = lsp#omni#get_vim_completion_item(item) Assert Equals(PreprocessItem(got), want) End End End