I broke up with neovim....vim is my best friend now
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
function! s:sort_item_by_text(lhs, rhs) abort
|
||||
if a:lhs['text'] <# a:rhs['text']
|
||||
return -1
|
||||
endif
|
||||
if a:lhs['text'] ># a:rhs['text']
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:add_end_pos(loc) abort
|
||||
let a:loc['end_lnum'] = 0
|
||||
let a:loc['end_col'] = 0
|
||||
return a:loc
|
||||
endfunction
|
||||
|
||||
Describe lsp#internal#diagnostics#document_diagnostics_command
|
||||
Before
|
||||
%bwipeout!
|
||||
let g:lsp_diagnostics_enabled = 1
|
||||
call lsp#internal#diagnostics#state#_disable()
|
||||
call lsp#internal#diagnostics#state#_enable()
|
||||
End
|
||||
|
||||
After all
|
||||
%bwipeout!
|
||||
let g:lsp_diagnostics_enabled = 0
|
||||
call lsp#internal#diagnostics#state#_disable()
|
||||
End
|
||||
|
||||
It should be able to show document diagnostics for a buffer
|
||||
normal! m'
|
||||
execute printf('keepalt keepjumps edit %s', lsp#test#projectdir('rust') . '/src/documentdiagnostics.rs')
|
||||
let l:uri = lsp#utils#get_buffer_uri()
|
||||
let l:uri2 = l:uri . '2'
|
||||
let l:bufnr = bufnr('%')
|
||||
|
||||
let l:server1_response1 = {'method': 'textDocument/publishDiagnostics', 'params': {'uri': l:uri, 'diagnostics': [
|
||||
\ {'severity': 1, 'message': 'm1', 'range': { 'start': { 'line': 1, 'character': 1, 'end': { 'line': 1, 'character': 1 } } }},
|
||||
\ {'severity': 1, 'message': 'm2', 'range': { 'start': { 'line': 1, 'character': 2, 'end': { 'line': 1, 'character': 3 } } }},
|
||||
\ ]}}
|
||||
|
||||
let l:server1_response2 = {'method': 'textDocument/publishDiagnostics', 'params': {'uri': l:uri2, 'diagnostics': [
|
||||
\ {'severity': 2, 'message': 'm3', 'range': { 'start': { 'line': 2, 'character': 1, 'end': { 'line': 1, 'character': 1 } } }},
|
||||
\ {'severity': 2, 'message': 'm4', 'range': { 'start': { 'line': 3, 'character': 2, 'end': { 'line': 1, 'character': 3 } } }},
|
||||
\ ]}}
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response1 })
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response2 })
|
||||
|
||||
execute ':LspDocumentDiagnostics'
|
||||
let l:result = getloclist(0)
|
||||
|
||||
" NOTE Older version of Vim does not sort results, and does not include module.
|
||||
call sort(l:result, function('s:sort_item_by_text'))
|
||||
call map(l:result, {_, v -> extend(v, {'module': ''})})
|
||||
|
||||
let l:expected = [
|
||||
\ {'bufnr': l:bufnr, 'lnum': 2, 'col': 2, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': 'E', 'module': '', 'text': 'Error:m1'},
|
||||
\ {'bufnr': l:bufnr, 'lnum': 2, 'col': 3, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': 'E', 'module': '', 'text': 'Error:m2'},
|
||||
\ ]
|
||||
if has_key(l:result[0], 'end_lnum') " feature detection
|
||||
call map(l:expected, { _, v -> s:add_end_pos(v) })
|
||||
endif
|
||||
Assert Equals(l:result, l:expected)
|
||||
execute ':lclose'
|
||||
|
||||
execute ':LspDocumentDiagnostics --buffers=*'
|
||||
let l:result = getloclist(0)
|
||||
|
||||
" NOTE Older version of Vim does not sort results, and does not include module.
|
||||
call sort(l:result, function('s:sort_item_by_text'))
|
||||
call map(l:result, {_, v -> extend(v, {'module': ''})})
|
||||
|
||||
" +2 for bufnr because original bufnr + loclist + new unopened file
|
||||
let l:expected = [
|
||||
\ {'bufnr': l:bufnr, 'lnum': 2, 'col': 2, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': 'E', 'module': '', 'text': 'Error:m1'},
|
||||
\ {'bufnr': l:bufnr, 'lnum': 2, 'col': 3, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': 'E', 'module': '', 'text': 'Error:m2'},
|
||||
\ {'bufnr': l:bufnr + 2, 'lnum': 3, 'col': 2, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': 'W', 'module': '', 'text': 'Warning:m3'},
|
||||
\ {'bufnr': l:bufnr + 2, 'lnum': 4, 'col': 3, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': 'W', 'module': '', 'text': 'Warning:m4'},
|
||||
\ ]
|
||||
if has_key(l:result[0], 'end_lnum') " feature detection
|
||||
call map(l:expected, { _, v -> s:add_end_pos(v) })
|
||||
endif
|
||||
Assert Equals(l:result, l:expected)
|
||||
execute ':lclose'
|
||||
End
|
||||
End
|
||||
@@ -0,0 +1,70 @@
|
||||
Describe lsp#internal#diagnostics#state
|
||||
Before
|
||||
%bwipeout!
|
||||
let g:lsp_diagnostics_enabled = 1
|
||||
call lsp#internal#diagnostics#state#_disable()
|
||||
call lsp#internal#diagnostics#state#_enable()
|
||||
End
|
||||
|
||||
After all
|
||||
%bwipeout!
|
||||
let g:lsp_diagnostics_enabled = 0
|
||||
call lsp#internal#diagnostics#state#_disable()
|
||||
End
|
||||
|
||||
It should be able to subscribe to textDocument/publishDiagnostics stream and update state correctly
|
||||
let l:uri = 'file://some/uri'
|
||||
|
||||
let l:server1_response1 = {'method': 'textDocument/publishDiagnostics', 'params': {'uri': l:uri, 'diagnostics': [
|
||||
\ {'severity': 1, 'message': 'm1', 'range': { 'start': { 'line': 1, 'character': 1, 'end': { 'line': 1, 'character': 1 } } }},
|
||||
\ {'severity': 1, 'message': 'm2', 'range': { 'start': { 'line': 1, 'character': 2, 'end': { 'line': 1, 'character': 3 } } }},
|
||||
\ ]}}
|
||||
let l:server2_response1 = {'method': 'textDocument/publishDiagnostics', 'params': {'uri': l:uri, 'diagnostics': [
|
||||
\ {'severity': 1, 'message': 's2', 'range': { 'start': { 'line': 2, 'character': 3, 'end': { 'line': 4, 'character': 5 } } }},
|
||||
\ ]}}
|
||||
let l:server1_response2 = {'method': 'textDocument/publishDiagnostics', 'params': {'uri': l:uri, 'diagnostics': [
|
||||
\ {'severity': 1, 'message': 'm2', 'range': { 'start': { 'line': 1, 'character': 2, 'end': { 'line': 1, 'character': 3 } } }},
|
||||
\ ]}}
|
||||
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(l:uri), {})
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response1 })
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(l:uri), { 'server1': l:server1_response1 })
|
||||
let l:want = {}
|
||||
let l:want[l:uri] = { 'server1': l:server1_response1 }
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_uri_and_server(), l:want)
|
||||
|
||||
call lsp#stream(1, { 'server': 'server2', 'response': l:server2_response1 })
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(l:uri), { 'server1': l:server1_response1, 'server2': l:server2_response1 })
|
||||
let l:want = {}
|
||||
let l:want[l:uri] = { 'server1': l:server1_response1, 'server2': l:server2_response1 }
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_uri_and_server(), l:want)
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response2 })
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_server_for_uri(l:uri), { 'server1': l:server1_response2, 'server2': l:server2_response1 })
|
||||
let l:want = {}
|
||||
let l:want[l:uri] = { 'server1': l:server1_response2, 'server2': l:server2_response1 }
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_uri_and_server(), l:want)
|
||||
|
||||
call lsp#stream(1, { 'server': '$vimlsp',
|
||||
\ 'response': { 'method': '$/vimlsp/lsp_server_exit', 'params': { 'server': 'server1' } } })
|
||||
let l:want = {}
|
||||
let l:want[l:uri] = { 'server2': l:server2_response1 }
|
||||
Assert Equals(lsp#internal#diagnostics#state#_get_all_diagnostics_grouped_by_uri_and_server(), l:want)
|
||||
End
|
||||
|
||||
|
||||
It should correctly return the state of buffer
|
||||
call lsp#internal#diagnostics#state#_disable()
|
||||
call lsp#internal#diagnostics#state#_enable()
|
||||
|
||||
let l:bufnr = bufnr('%')
|
||||
Assert True(lsp#internal#diagnostics#state#_is_enabled_for_buffer(l:bufnr))
|
||||
|
||||
call lsp#internal#diagnostics#state#_disable_for_buffer(l:bufnr)
|
||||
Assert False(lsp#internal#diagnostics#state#_is_enabled_for_buffer(l:bufnr))
|
||||
|
||||
call lsp#internal#diagnostics#state#_enable_for_buffer(l:bufnr)
|
||||
Assert True(lsp#internal#diagnostics#state#_is_enabled_for_buffer(l:bufnr))
|
||||
End
|
||||
End
|
||||
@@ -0,0 +1,92 @@
|
||||
let s:Error = 1
|
||||
let s:Warn = 2
|
||||
let s:Info = 3
|
||||
let s:Log = 4
|
||||
|
||||
function! s:response(type, message) abort
|
||||
return {
|
||||
\ 'server': 'server1',
|
||||
\ 'response': {
|
||||
\ 'method': 'window/showMessage',
|
||||
\ 'params': {
|
||||
\ 'type': a:type,
|
||||
\ 'message': a:message
|
||||
\ }
|
||||
\ }
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
Describe lsp#internal#show_message
|
||||
Before
|
||||
%bwipeout!
|
||||
let g:lsp_show_message_log_level = 'warning'
|
||||
call lsp#internal#show_message#_disable()
|
||||
call lsp#internal#show_message#_enable()
|
||||
End
|
||||
|
||||
After all
|
||||
%bwipeout!
|
||||
let g:lsp_show_message_log_level = 'none'
|
||||
call lsp#internal#show_message#_disable()
|
||||
End
|
||||
|
||||
It should show all messages when 'log' is set to g:lsp_show_message_log_level
|
||||
let g:lsp_show_message_log_level = 'log'
|
||||
|
||||
redir => message_area
|
||||
call lsp#stream(1, s:response(s:Error, 'error message'))
|
||||
call lsp#stream(1, s:response(s:Warn, 'warn message'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message'))
|
||||
call lsp#stream(1, s:response(s:Log, 'log message'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message2'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message3'))
|
||||
redir END
|
||||
|
||||
Assert Match(message_area, 'server1: error: error message')
|
||||
Assert Match(message_area, 'server1: warning: warn message')
|
||||
Assert Match(message_area, 'server1: info: info message')
|
||||
Assert Match(message_area, 'server1: log: log message')
|
||||
Assert Match(message_area, 'server1: info: info message2')
|
||||
Assert Match(message_area, 'server1: info: info message3')
|
||||
End
|
||||
|
||||
It should filter shown messages by log level set to g:lsp_show_message_log_level
|
||||
let g:lsp_show_message_log_level = 'warning'
|
||||
|
||||
redir => message_area
|
||||
call lsp#stream(1, s:response(s:Error, 'error message'))
|
||||
call lsp#stream(1, s:response(s:Warn, 'warn message'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message'))
|
||||
call lsp#stream(1, s:response(s:Log, 'log message'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message2'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message3'))
|
||||
redir END
|
||||
|
||||
Assert Match(message_area, 'server1: error: error message')
|
||||
Assert Match(message_area, 'server1: warning: warn message')
|
||||
Assert NotMatch(message_area, 'server1: info: info message')
|
||||
Assert NotMatch(message_area, 'server1: log: log message')
|
||||
Assert NotMatch(message_area, 'server1: info: info message2')
|
||||
Assert NotMatch(message_area, 'server1: info: info message3')
|
||||
End
|
||||
|
||||
It should show no message when 'none' is set to g:lsp_show_message_log_level
|
||||
let g:lsp_show_message_log_level = 'none'
|
||||
|
||||
redir => message_area
|
||||
call lsp#stream(1, s:response(s:Error, 'error message'))
|
||||
call lsp#stream(1, s:response(s:Warn, 'warn message'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message'))
|
||||
call lsp#stream(1, s:response(s:Log, 'log message'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message2'))
|
||||
call lsp#stream(1, s:response(s:Info, 'info message3'))
|
||||
redir END
|
||||
|
||||
Assert NotMatch(message_area, 'server1: error: error message')
|
||||
Assert NotMatch(message_area, 'server1: warning: warn message')
|
||||
Assert NotMatch(message_area, 'server1: info: info message')
|
||||
Assert NotMatch(message_area, 'server1: log: log message')
|
||||
Assert NotMatch(message_area, 'server1: info: info message2')
|
||||
Assert NotMatch(message_area, 'server1: info: info message3')
|
||||
End
|
||||
End
|
||||
499
dot_vim/plugged/vim-lsp/test/lsp/omni.vimspec
Normal file
499
dot_vim/plugged/vim-lsp/test/lsp/omni.vimspec
Normal file
@@ -0,0 +1,499 @@
|
||||
Describe lsp#omni
|
||||
|
||||
let g:lsp_get_vim_completion_item_set_kind = 1
|
||||
|
||||
Before each
|
||||
call lsp#omni#_clear_managed_user_data_map()
|
||||
End
|
||||
|
||||
Describe lsp#omni#get_vim_completion_items
|
||||
It should return item with proper kind
|
||||
let item = {
|
||||
\ 'label': 'my-label',
|
||||
\ 'documentation': 'my documentation.',
|
||||
\ 'detail': 'my-detail',
|
||||
\ 'kind': '3'
|
||||
\}
|
||||
|
||||
let options = {
|
||||
\ 'server': { 'name': 'dummy-server' },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': [item] },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label',
|
||||
\ 'abbr': 'my-label',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
|
||||
Assert Equals(lsp#omni#get_vim_completion_items(options), want)
|
||||
End
|
||||
|
||||
It should get user_data by the item
|
||||
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': {
|
||||
\ 'range': {
|
||||
\ 'start': {'line': 5, 'character': 0},
|
||||
\ 'end': {'line': 5, 'character': 5}
|
||||
\ },
|
||||
\ 'newText': 'yyy'
|
||||
\ }
|
||||
\}
|
||||
|
||||
let options = {
|
||||
\ 'server': { 'name': 'dummy-server' },
|
||||
\ 'position': { 'line': 1, 'character': 1 },
|
||||
\ 'response': { 'result': [item] },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'yyy',
|
||||
\ 'abbr': 'my-label',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', {'line': 1, 'character': 0}),
|
||||
\}
|
||||
|
||||
let got = lsp#omni#get_vim_completion_items(options)
|
||||
Assert Equals(got, want)
|
||||
Assert Equals(lsp#omni#get_managed_user_data_from_completed_item(got['items'][0]), {
|
||||
\ 'server_name': 'dummy-server',
|
||||
\ 'completion_item': item,
|
||||
\ 'complete_position': { 'line': 1, 'character': 1 },
|
||||
\ 'start_character': 0,
|
||||
\ })
|
||||
End
|
||||
|
||||
It should not raise errors
|
||||
let item = {
|
||||
\ 'label': 'my-label',
|
||||
\ 'textEdit': v:null,
|
||||
\}
|
||||
|
||||
let options = {
|
||||
\ 'server': { 'name': 'dummy-server' },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': [item] },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label',
|
||||
\ 'abbr': 'my-label',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': '',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
|
||||
let got = lsp#omni#get_vim_completion_items(options)
|
||||
Assert Equals(got, want)
|
||||
|
||||
let item = {
|
||||
\ 'label': 'my-label',
|
||||
\ 'textEdit': v:null,
|
||||
\ 'insertText': v:null,
|
||||
\}
|
||||
|
||||
let options = {
|
||||
\ 'server': { 'name': 'dummy-server' },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': [item] },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label',
|
||||
\ 'abbr': 'my-label',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': '',
|
||||
\ 'user_data': '{"vim-lsp/key":"1"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
|
||||
let got = lsp#omni#get_vim_completion_items(options)
|
||||
Assert Equals(got, want)
|
||||
End
|
||||
|
||||
It should return correct items for snippets
|
||||
if !has('patch-8.0.1493')
|
||||
Skip This test requires 'patch-8.0.1493'
|
||||
endif
|
||||
|
||||
let item = {
|
||||
\ "label": "sysout",
|
||||
\ "insertText": "System.out.println(${0});",
|
||||
\ "kind": 15,
|
||||
\ "insertTextFormat": 2,
|
||||
\ "documentation": "System.out.println();",
|
||||
\ "detail": "print to standard out"
|
||||
\ }
|
||||
|
||||
let options = {
|
||||
\ 'server': { 'name': 'dummy-server' },
|
||||
\ 'position': { 'line': 1, 'character': 1 },
|
||||
\ 'response': { 'result': [item] },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'System.out.println',
|
||||
\ 'abbr': 'sysout~',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'snippet',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', { 'line': 1, 'character': 1 }),
|
||||
\}
|
||||
|
||||
let got = lsp#omni#get_vim_completion_items(options)
|
||||
Assert Equals(got, want)
|
||||
Assert Equals(lsp#omni#get_managed_user_data_from_completed_item(got['items'][0]), {
|
||||
\ 'server_name': 'dummy-server',
|
||||
\ 'completion_item': item,
|
||||
\ 'complete_position': { 'line': 1, 'character': 1 },
|
||||
\ 'start_character': 0,
|
||||
\ })
|
||||
End
|
||||
|
||||
It should sort by sortText
|
||||
let items = [{
|
||||
\ 'label': 'my-label1',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': 'c'
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label2',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': 'a'
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label3',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': 'b'
|
||||
\}]
|
||||
|
||||
let options = {
|
||||
\ 'server': {
|
||||
\ 'name': 'dummy-server',
|
||||
\ 'config': {
|
||||
\ 'sort': { 'max': 100 },
|
||||
\ },
|
||||
\ },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': items },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label2',
|
||||
\ 'abbr': 'my-label2',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label3',
|
||||
\ 'abbr': 'my-label3',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"1"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label1',
|
||||
\ 'abbr': 'my-label1',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"2"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
|
||||
Assert Equals(lsp#omni#get_vim_completion_items(options), want)
|
||||
End
|
||||
|
||||
It should not sort over max
|
||||
let items = [{
|
||||
\ 'label': 'my-label3',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': '3'
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label1',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': '1'
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label2',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': '2'
|
||||
\}]
|
||||
|
||||
let options = {
|
||||
\ 'server': {
|
||||
\ 'name': 'dummy-server',
|
||||
\ 'config': {
|
||||
\ 'sort': { 'max': 2 },
|
||||
\ },
|
||||
\ },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': items },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label3',
|
||||
\ 'abbr': 'my-label3',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label1',
|
||||
\ 'abbr': 'my-label1',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"1"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label2',
|
||||
\ 'abbr': 'my-label2',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"2"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
Assert Equals(lsp#omni#get_vim_completion_items(options), want)
|
||||
End
|
||||
|
||||
It should sort by label(sortText not exists)
|
||||
let items = [{
|
||||
\ 'label': 'my-label3',
|
||||
\ 'kind': '3',
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label1',
|
||||
\ 'kind': '3',
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label2',
|
||||
\ 'kind': '3',
|
||||
\}]
|
||||
|
||||
let options = {
|
||||
\ 'server': {
|
||||
\ 'name': 'dummy-server',
|
||||
\ 'config': {
|
||||
\ 'sort': { 'max': 10 },
|
||||
\ },
|
||||
\ },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': items },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label1',
|
||||
\ 'abbr': 'my-label1',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label2',
|
||||
\ 'abbr': 'my-label2',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"1"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label3',
|
||||
\ 'abbr': 'my-label3',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"2"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
Assert Equals(lsp#omni#get_vim_completion_items(options), want)
|
||||
End
|
||||
|
||||
It should sort by label(empty sortText)
|
||||
let items = [{
|
||||
\ 'label': 'my-label3',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': ''
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label1',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': '',
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label2',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': '',
|
||||
\}]
|
||||
|
||||
let options = {
|
||||
\ 'server': {
|
||||
\ 'name': 'dummy-server',
|
||||
\ 'config': {
|
||||
\ 'sort': { 'max': 10 },
|
||||
\ },
|
||||
\ },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': items },
|
||||
\}
|
||||
|
||||
let want = {
|
||||
\ 'items': [{
|
||||
\ 'word': 'my-label1',
|
||||
\ 'abbr': 'my-label1',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label2',
|
||||
\ 'abbr': 'my-label2',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"1"}',
|
||||
\ },
|
||||
\ {
|
||||
\ 'word': 'my-label3',
|
||||
\ 'abbr': 'my-label3',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"2"}',
|
||||
\ }],
|
||||
\ 'incomplete': 0,
|
||||
\ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
|
||||
\}
|
||||
Assert Equals(lsp#omni#get_vim_completion_items(options), want)
|
||||
End
|
||||
|
||||
Describe g:lsp_ignorecase
|
||||
Before all
|
||||
let saved_ignorecase = get(g:, 'lsp_ignorecase', v:null)
|
||||
End
|
||||
|
||||
After all
|
||||
if saved_ignorecase isnot v:null
|
||||
let g:lsp_ignorecase = saved_ignorecase
|
||||
endif
|
||||
End
|
||||
|
||||
It should sort completion items case-insensitive when true is set
|
||||
let g:lsp_ignorecase = v:true
|
||||
|
||||
" 'B' < 'a' but 'a' < 'b'
|
||||
let result = [{
|
||||
\ 'label': 'my-label1',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': 'B'
|
||||
\},
|
||||
\{
|
||||
\ 'label': 'my-label2',
|
||||
\ 'kind': '3',
|
||||
\ 'sortText': 'a'
|
||||
\}]
|
||||
|
||||
let options = {
|
||||
\ 'server': {
|
||||
\ 'name': 'dummy-server',
|
||||
\ 'config': {
|
||||
\ 'sort': { 'max': 10 },
|
||||
\ },
|
||||
\ },
|
||||
\ 'position': lsp#get_position(),
|
||||
\ 'response': { 'result': result },
|
||||
\}
|
||||
|
||||
let want = [{
|
||||
\ 'word': 'my-label2',
|
||||
\ 'abbr': 'my-label2',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"0"}',
|
||||
\},
|
||||
\{
|
||||
\ 'word': 'my-label1',
|
||||
\ 'abbr': 'my-label1',
|
||||
\ 'icase': 1,
|
||||
\ 'dup': 1,
|
||||
\ 'empty': 1,
|
||||
\ 'kind': 'function',
|
||||
\ 'user_data': '{"vim-lsp/key":"1"}',
|
||||
\}]
|
||||
|
||||
Assert Equals(lsp#omni#get_vim_completion_items(options).items, want)
|
||||
End
|
||||
End
|
||||
End
|
||||
End
|
||||
134
dot_vim/plugged/vim-lsp/test/lsp/ui/vim/code_lens.vimspec
Normal file
134
dot_vim/plugged/vim-lsp/test/lsp/ui/vim/code_lens.vimspec
Normal file
@@ -0,0 +1,134 @@
|
||||
Describe lsp#uivim#code_lens
|
||||
Describe lsp#ui#vim#code_lens#_get_subtitle
|
||||
It should generate subtitle from response of rust-analyzer
|
||||
" Example response of Code Lens extracted from #1118
|
||||
let item = {
|
||||
\ 'codelens': {
|
||||
\ 'command': {
|
||||
\ 'arguments': [
|
||||
\ {
|
||||
\ 'args': {
|
||||
\ 'cargoArgs': ['test', '--package', 'tmp', '--lib'],
|
||||
\ 'cargoExtraArgs': [],
|
||||
\ 'executableArgs': ['tests::it_works', '--exact', '--nocapture'],
|
||||
\ 'overrideCargo': v:null,
|
||||
\ 'workspaceRoot': '/tmp'
|
||||
\ },
|
||||
\ 'kind': 'cargo',
|
||||
\ 'label': 'test tests::it_works',
|
||||
\ 'location': {
|
||||
\ 'targetRange': {'end': {'character': 5, 'line': 14}, 'start': {'character': 4, 'line': 11}},
|
||||
\ 'targetSelectionRange': {'end': {'character': 15, 'line': 12}, 'start': {'character': 7, 'line': 12}},
|
||||
\ 'targetUri': 'file:////tmp/src/lib.rs'
|
||||
\ }
|
||||
\ }
|
||||
\ ],
|
||||
\ 'command': 'rust-analyzer.runSingle',
|
||||
\ 'title': '▶︎ Run Test'
|
||||
\ },
|
||||
\ 'range': {'end': {'character': 5, 'line': 14}, 'start': {'character': 4, 'line': 11}}
|
||||
\ },
|
||||
\ 'server': 'rust-analyzer'
|
||||
\ }
|
||||
|
||||
let subtitle = lsp#ui#vim#code_lens#_get_subtitle(item)
|
||||
Assert Equals(subtitle, ': test tests::it_works')
|
||||
End
|
||||
|
||||
It should generate subtitle from multiple labels of command arguments
|
||||
let item = {
|
||||
\ 'codelens': {
|
||||
\ 'command': {
|
||||
\ 'arguments': [
|
||||
\ {
|
||||
\ 'args': {},
|
||||
\ 'kind': 'kind1',
|
||||
\ 'label': 'do command1',
|
||||
\ 'location': {}
|
||||
\ },
|
||||
\ {
|
||||
\ 'args': {},
|
||||
\ 'kind': 'kind2',
|
||||
\ 'label': 'do command2',
|
||||
\ 'location': {}
|
||||
\ }
|
||||
\ ],
|
||||
\ 'command': 'server.someCommand',
|
||||
\ 'title': 'lens title'
|
||||
\ },
|
||||
\ 'range': {'end': {'character': 5, 'line': 14}, 'start': {'character': 4, 'line': 11}}
|
||||
\ },
|
||||
\ 'server': 'rust-analyzer'
|
||||
\ }
|
||||
|
||||
let subtitle = lsp#ui#vim#code_lens#_get_subtitle(item)
|
||||
Assert Equals(subtitle, ': do command1 > do command2')
|
||||
End
|
||||
|
||||
It should return empty string when 'arguments' field is not found
|
||||
let item = {
|
||||
\ 'codelens': {
|
||||
\ 'command': {
|
||||
\ 'command': 'server.someCommand',
|
||||
\ 'title': 'lens title'
|
||||
\ },
|
||||
\ 'range': {'end': {'character': 5, 'line': 14}, 'start': {'character': 4, 'line': 11}}
|
||||
\ },
|
||||
\ 'server': 'rust-analyzer'
|
||||
\ }
|
||||
|
||||
let subtitle = lsp#ui#vim#code_lens#_get_subtitle(item)
|
||||
Assert Equals(subtitle, '')
|
||||
End
|
||||
|
||||
It should return empty string when 'arguments' field is not an object
|
||||
let item = {
|
||||
\ 'codelens': {
|
||||
\ 'command': {
|
||||
\ 'arguments': [
|
||||
\ 'command1',
|
||||
\ 'command2',
|
||||
\ 'command3'
|
||||
\ ],
|
||||
\ 'command': 'server.someCommand',
|
||||
\ 'title': 'lens title'
|
||||
\ },
|
||||
\ 'range': {'end': {'character': 5, 'line': 14}, 'start': {'character': 4, 'line': 11}}
|
||||
\ },
|
||||
\ 'server': 'rust-analyzer'
|
||||
\ }
|
||||
|
||||
let subtitle = lsp#ui#vim#code_lens#_get_subtitle(item)
|
||||
Assert Equals(subtitle, '')
|
||||
End
|
||||
|
||||
It should return empty string when at least one of elements in 'arguments' field does not have 'label' field
|
||||
let item = {
|
||||
\ 'codelens': {
|
||||
\ 'command': {
|
||||
\ 'arguments': [
|
||||
\ {
|
||||
\ 'args': {},
|
||||
\ 'kind': 'kind1',
|
||||
\ 'label': 'do command1',
|
||||
\ 'location': {}
|
||||
\ },
|
||||
\ {
|
||||
\ 'args': {},
|
||||
\ 'kind': 'kind2',
|
||||
\ 'location': {}
|
||||
\ }
|
||||
\ ],
|
||||
\ 'command': 'server.someCommand',
|
||||
\ 'title': 'lens title'
|
||||
\ },
|
||||
\ 'range': {'end': {'character': 5, 'line': 14}, 'start': {'character': 4, 'line': 11}}
|
||||
\ },
|
||||
\ 'server': 'rust-analyzer'
|
||||
\ }
|
||||
|
||||
let subtitle = lsp#ui#vim#code_lens#_get_subtitle(item)
|
||||
Assert Equals(subtitle, '')
|
||||
End
|
||||
End
|
||||
End
|
||||
37
dot_vim/plugged/vim-lsp/test/lsp/ui/vim/completion.vimspec
Normal file
37
dot_vim/plugged/vim-lsp/test/lsp/ui/vim/completion.vimspec
Normal file
@@ -0,0 +1,37 @@
|
||||
Describe lsp#uivim#completion
|
||||
|
||||
Before each
|
||||
%delete _
|
||||
setlocal filetype=html
|
||||
setlocal omnifunc=lsp#omni#complete
|
||||
End
|
||||
|
||||
It should expand simple snippet with multibyte chars
|
||||
Skip This test needs asynchronous process and snippetSupport=true
|
||||
|
||||
call setline(1, ['<div class="あいうえお">'])
|
||||
execute "normal! 'gg$ha id\<C-x>\<C-o>\<C-n>\<Tab>'"
|
||||
|
||||
" wait for feedkeys.
|
||||
|
||||
Assert Equals(getline(1), '<div class="あいうえお" id="">')
|
||||
Assert Equals(getpos('.')[1 : 2], [1, 30])
|
||||
End
|
||||
|
||||
It should expand when textEdit.start.character is less than completion start col
|
||||
Skip This test needs asynchronous process and snippetSupport=true
|
||||
|
||||
call setline(1, [
|
||||
\ '<html>',
|
||||
\ ' <div>',
|
||||
\ ' </>',
|
||||
\ '</html>'])
|
||||
execute "normal! ':gg2j$ha\<C-x>\<C-o>\<C-n>\<Tab>'"
|
||||
|
||||
" wait for feedkeys.
|
||||
|
||||
Assert Equals(getline(3), ' </div>')
|
||||
Assert Equals(getpos('.')[1 : 2], [1, 8])
|
||||
End
|
||||
|
||||
End
|
||||
316
dot_vim/plugged/vim-lsp/test/lsp/utils.vimspec
Normal file
316
dot_vim/plugged/vim-lsp/test/lsp/utils.vimspec
Normal file
@@ -0,0 +1,316 @@
|
||||
Describe lsp#utils
|
||||
|
||||
Describe lsp#utils#empty_complete
|
||||
It should return empty complete
|
||||
let items = lsp#utils#empty_complete()
|
||||
Assert type(items) == type([])
|
||||
Assert len(items) == 0
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#uri_to_path
|
||||
It should return path from uri (Windows)
|
||||
if !has('win32')
|
||||
Skip This tests is not for UNIX
|
||||
endif
|
||||
let tests = [
|
||||
\ {'uri': 'file:///C:/path/to/the/file.txt', 'path': 'C:\path\to\the\file.txt'},
|
||||
\ {'uri': 'file:///C:/path/to/the/file+name.txt', 'path': 'C:\path\to\the\file+name.txt'},
|
||||
\ {'uri': 'file:///C:/path/to/the/file%2Bname.txt', 'path': 'C:\path\to\the\file+name.txt'},
|
||||
\ {'uri': 'file:///C:/path/to/the/file%20name.txt', 'path': 'C:\path\to\the\file name.txt'},
|
||||
\ {'uri': 'file:///C:/path+name?query=your+value', 'path': 'C:\path+name'},
|
||||
\ {'uri': 'file:///C:/path+name#hash', 'path': 'C:\path+name'},
|
||||
\]
|
||||
for test in tests
|
||||
let path = lsp#utils#uri_to_path(test.uri)
|
||||
Assert Equals(path, test.path)
|
||||
endfor
|
||||
End
|
||||
|
||||
It should return path from uri (UNIX)
|
||||
if has('win32')
|
||||
Skip This tests is not for Windows
|
||||
endif
|
||||
let tests = [
|
||||
\ {'uri': 'file:///path/to/the/file.txt', 'path': '/path/to/the/file.txt'},
|
||||
\ {'uri': 'file:///path/to/the/file+name.txt', 'path': '/path/to/the/file+name.txt'},
|
||||
\ {'uri': 'file:///path/to/the/file%2Bname.txt', 'path': '/path/to/the/file+name.txt'},
|
||||
\ {'uri': 'file:///path/to/the/file%20name.txt', 'path': '/path/to/the/file name.txt'},
|
||||
\ {'uri': 'file:///path+name?query=your+value', 'path': '/path+name'},
|
||||
\ {'uri': 'file:///path+name#hash', 'path': '/path+name'},
|
||||
\]
|
||||
for test in tests
|
||||
let path = lsp#utils#uri_to_path(test.uri)
|
||||
Assert Equals(path, test.path)
|
||||
endfor
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#path_to_uri
|
||||
It should return uri from path (Windows)
|
||||
if !has('win32')
|
||||
Skip This tests is not for UNIX
|
||||
endif
|
||||
let tests = [
|
||||
\ {'path': 'C:\path\to\the\file.txt', 'uri': 'file:///C:/path/to/the/file.txt'},
|
||||
\ {'path': 'C:\path\to\the\file+name.txt', 'uri': 'file:///C:/path/to/the/file%2Bname.txt'},
|
||||
\ {'path': 'C:\path\to\the\file name.txt', 'uri': 'file:///C:/path/to/the/file%20name.txt'},
|
||||
\ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
|
||||
\]
|
||||
for test in tests
|
||||
let uri = lsp#utils#path_to_uri(test.path)
|
||||
Assert Equals(uri, test.uri)
|
||||
endfor
|
||||
End
|
||||
|
||||
It should return uri from path (UNIX)
|
||||
if has('win32')
|
||||
Skip This tests is not for Windows
|
||||
endif
|
||||
let tests = [
|
||||
\ {'path': '/path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
|
||||
\ {'path': '/path/to/the/file+name.txt', 'uri': 'file:///path/to/the/file%2Bname.txt'},
|
||||
\ {'path': '/path/to/the/file name.txt', 'uri': 'file:///path/to/the/file%20name.txt'},
|
||||
\ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
|
||||
\]
|
||||
for test in tests
|
||||
let uri = lsp#utils#path_to_uri(test.path)
|
||||
Assert Equals(uri, test.uri)
|
||||
endfor
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#normalize_uri
|
||||
It should return normalized uri (Windows)
|
||||
if !has('win32')
|
||||
Skip This tests is not for UNIX
|
||||
endif
|
||||
let tests = [
|
||||
\ {'path': 'file:///C:\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
|
||||
\ {'path': 'file:///c:\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
|
||||
\ {'path': 'file:///C%3A\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
|
||||
\ {'path': 'file:///c%3a\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
|
||||
\ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
|
||||
\]
|
||||
for test in tests
|
||||
let uri = lsp#utils#normalize_uri(test.path)
|
||||
Assert Equals(uri, test.uri)
|
||||
endfor
|
||||
End
|
||||
|
||||
It should return normalized uri (UNIX)
|
||||
if has('win32')
|
||||
Skip This tests is not for Windows
|
||||
endif
|
||||
let tests = [
|
||||
\ {'path': 'file:///path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
|
||||
\]
|
||||
for test in tests
|
||||
let uri = lsp#utils#normalize_uri(test.path)
|
||||
Assert Equals(uri, test.uri)
|
||||
endfor
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#find_nearest_parent_file_directory
|
||||
It should return the root directory if it is found
|
||||
let tests = [
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': ['.ccls', 'compile_commands.json', 'README.md', 'git/'], 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': ['.ccls', 'build/', 'CMakeLists.txt', 'git/'], 'root': './test/testproject/src'},
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': '.ccls', 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': 'git/', 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': 'CMakeLists.txt', 'root': './test/testproject/src'},
|
||||
\ {'from': './test/testproject/README.md', 'target': ['.ccls', 'compile_commands.json', 'README.md', 'git/'], 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/README.md', 'target': ['.ccls', 'build/', 'CMakeLists.txt', 'git/'], 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/README.md', 'target': '.ccls', 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/README.md', 'target': 'git/', 'root': './test/testproject'},
|
||||
\ {'from': './test/testproject/README.md', 'target': 'CMakeLists.txt', 'root': './test/testproject'},
|
||||
\]
|
||||
for test in tests
|
||||
let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
|
||||
Assert Equals(path, fnamemodify(test.root, ':p:h'))
|
||||
endfor
|
||||
End
|
||||
|
||||
It should return an empty string if not target has been found
|
||||
let tests = [
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': ['fdrvbws/', 'asbr/', 'bgdf/', 'abfrb.txt', 'ngo.c']},
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': 'asbr/'},
|
||||
\ {'from': './test/testproject/src/main.cpp', 'target': 'btr.c'},
|
||||
\ {'from': './test/testproject/.gitignore', 'target': ['fdrvbws/', 'asbr/', 'bgdf/', 'abfrb.txt', 'ngo.c']},
|
||||
\ {'from': './test/testproject/.gitignore', 'target': 'asbr/'},
|
||||
\ {'from': './test/testproject/.gitignore', 'target': 'btr.c'},
|
||||
\]
|
||||
for test in tests
|
||||
let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
|
||||
Assert Empty(path)
|
||||
endfor
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#to_char
|
||||
It should return the character-index from the given byte-index on a buffer
|
||||
call setline(1, ['a β c', 'δ', ''])
|
||||
Assert lsp#utils#to_char('%', 1, 1) == 0
|
||||
Assert lsp#utils#to_char('%', 1, 2) == 1
|
||||
Assert lsp#utils#to_char('%', 1, 3) == 2
|
||||
Assert lsp#utils#to_char('%', 1, 5) == 3
|
||||
Assert lsp#utils#to_char('%', 1, 6) == 4
|
||||
Assert lsp#utils#to_char('%', 1, 7) == 5
|
||||
Assert lsp#utils#to_char('%', 2, 1) == 0
|
||||
Assert lsp#utils#to_char('%', 2, 3) == 1
|
||||
Assert lsp#utils#to_char('%', 3, 1) == 0
|
||||
%delete
|
||||
End
|
||||
|
||||
It should return the character-index from the given byte-index in an unloaded file
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 1) == 0
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 2) == 1
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 3) == 2
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 5) == 3
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 6) == 4
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 7) == 5
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 2, 1) == 0
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 2, 3) == 1
|
||||
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 3, 1) == 0
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#_get_before_line
|
||||
It should return line before cursor on col=1
|
||||
enew!
|
||||
call setline(1, ['123456789'])
|
||||
call cursor(1, 1)
|
||||
Assert Equals(lsp#utils#_get_before_line(), '')
|
||||
End
|
||||
|
||||
It should return line before cursor on col=$
|
||||
let l:saved_virtualedit = &virtualedit
|
||||
let &virtualedit = 'all'
|
||||
enew!
|
||||
call setline(1, ['123456789'])
|
||||
call cursor(1, 10)
|
||||
Assert Equals(lsp#utils#_get_before_line(), '123456789')
|
||||
let &virtualedit = l:saved_virtualedit
|
||||
End
|
||||
|
||||
It should return line before cursor with multibyte
|
||||
enew!
|
||||
call setline(1, ['あいうえおabc'])
|
||||
call cursor(1, 18)
|
||||
Assert Equals(lsp#utils#_get_before_line(), 'あいうえおab')
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#_get_before_char_skip_white
|
||||
It should return before char in above of line
|
||||
enew!
|
||||
call setline(1, ['(', ''])
|
||||
call cursor(2, 1)
|
||||
Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
|
||||
End
|
||||
It should return before char with multibyte
|
||||
enew!
|
||||
call setline(1, ['あいうえお( '])
|
||||
call cursor(1, 21)
|
||||
Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#base64_decode
|
||||
It should decode basic string correctly
|
||||
Assert Equals(lsp#utils#base64_decode('TWFu'), [77, 97, 110])
|
||||
End
|
||||
|
||||
It should decode multiple groups correctly
|
||||
Assert Equals(lsp#utils#base64_decode('TWFuIHRlc3R4'), [77, 97, 110, 32, 116, 101, 115, 116, 120])
|
||||
End
|
||||
|
||||
It should handle padding (one octet)
|
||||
Assert Equals(lsp#utils#base64_decode('TQ=='), [77])
|
||||
End
|
||||
|
||||
It should handle padding (two octets)
|
||||
Assert Equals(lsp#utils#base64_decode('TWE='), [77, 97])
|
||||
End
|
||||
|
||||
It should handle more complex string
|
||||
Assert Equals(lsp#utils#base64_decode('AAAAEgAJABYAAAAIAAQAFw=='), [0, 0, 0, 18, 0, 9, 0, 22, 0, 0, 0, 8, 0, 4, 0, 23])
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#make_valid_word
|
||||
It should make valid word
|
||||
Assert Equals(lsp#utils#make_valid_word('my-word'), 'my-word')
|
||||
Assert Equals(lsp#utils#make_valid_word("my\nword"), 'my')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-word: description'), 'my-word')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-word : description'), 'my-word')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-word is word'), 'my-word')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-func()'), 'my-func')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-name::space'), 'my-name::space')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-name#space'), 'my-name#space')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-name.space'), 'my-name.space')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-name.space: foo'), 'my-name.space')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-name%space: foo'), 'my-name%space')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-name&space: foo'), 'my-name&space')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-array[0]'), 'my-array')
|
||||
Assert Equals(lsp#utils#make_valid_word('my-array<string>'), 'my-array')
|
||||
Assert Equals(lsp#utils#make_valid_word("my-name\tdescription"), 'my-name')
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#_split_by_eol
|
||||
|
||||
It should split text by \r\n
|
||||
Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\nかきくけこ"), ['あいうえお', 'かきくけこ'])
|
||||
End
|
||||
|
||||
It should split text by \r
|
||||
Assert Equals(lsp#utils#_split_by_eol("あいうえお\rかきくけこ"), ['あいうえお', 'かきくけこ'])
|
||||
End
|
||||
|
||||
It should split text by \r\n\r
|
||||
Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\rかきくけこ"), ['あいうえお', '', 'かきくけこ'])
|
||||
End
|
||||
|
||||
It should split text by \r\n\n\r\r\n
|
||||
Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\n\r\r\nかきくけこ"), ['あいうえお', '', '', '', 'かきくけこ'])
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
Describe lsp#utils#_compare_nearest_path
|
||||
It should return looong since it is longest
|
||||
Assert Equals(lsp#utils#_nearest_path(
|
||||
\ {'/path/to/looong': 1, '/path/to/short': 1,}
|
||||
\), '/path/to/looong')
|
||||
End
|
||||
|
||||
It should return loong since they are both longest but loong matches mostly
|
||||
Assert Equals(lsp#utils#_nearest_path(
|
||||
\ {'/path/to/loong': 2, '/path/to/short': 1,}
|
||||
\), '/path/to/loong')
|
||||
End
|
||||
|
||||
It should return not long since it is not longest
|
||||
Assert Equals(lsp#utils#_nearest_path(
|
||||
\ {'/path/to/long': 2, '/path/to/short': 1,}
|
||||
\), '/path/to/short')
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#iteratable
|
||||
It should return empty list if non-list is given
|
||||
Assert Equals(lsp#utils#iteratable(''), [])
|
||||
Assert Equals(lsp#utils#iteratable(1), [])
|
||||
Assert Equals(lsp#utils#iteratable(2.3), [])
|
||||
Assert Equals(lsp#utils#iteratable(v:false), [])
|
||||
Assert Equals(lsp#utils#iteratable(v:true), [])
|
||||
Assert Equals(lsp#utils#iteratable({}), [])
|
||||
End
|
||||
|
||||
It should return the list it self if list is given
|
||||
Assert Equals(lsp#utils#iteratable([1,2,3]), [1,2,3])
|
||||
End
|
||||
End
|
||||
End
|
||||
101
dot_vim/plugged/vim-lsp/test/lsp/utils/buffer.vimspec
Normal file
101
dot_vim/plugged/vim-lsp/test/lsp/utils/buffer.vimspec
Normal file
@@ -0,0 +1,101 @@
|
||||
Describe lsp#utils#buffer
|
||||
|
||||
Before each
|
||||
% delete _
|
||||
0put ='foo'
|
||||
1put ='bar'
|
||||
3delete _
|
||||
End
|
||||
|
||||
After all
|
||||
% delete _
|
||||
End
|
||||
|
||||
Describe lsp#utils#buffer#_get_lines
|
||||
It adds a blank line when nobinary and fixendofline are set
|
||||
if !exists('+fixendofline')
|
||||
Skip This test requires 'fixendofline'
|
||||
endif
|
||||
setl nobinary
|
||||
setl fixendofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar', ''])
|
||||
End
|
||||
|
||||
It adds a blank line when nobinary, nofixendofline, and endofline are set
|
||||
if !exists('+fixendofline')
|
||||
Skip This test requires 'fixendofline'
|
||||
endif
|
||||
setl nobinary
|
||||
setl nofixendofline
|
||||
setl endofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar', ''])
|
||||
End
|
||||
|
||||
It adds a blank line when binary and endofline are set
|
||||
if !exists('+fixendofline')
|
||||
Skip This test requires 'fixendofline'
|
||||
endif
|
||||
setl binary
|
||||
setl endofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar', ''])
|
||||
End
|
||||
|
||||
It does not add a blank line when nobinary, nofixendofline, and noendofline are set
|
||||
if !exists('+fixendofline')
|
||||
Skip This test requires 'fixendofline'
|
||||
endif
|
||||
setl nobinary
|
||||
setl nofixendofline
|
||||
setl noendofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar'])
|
||||
End
|
||||
|
||||
It does not add a blank line when binary and noendofline are set
|
||||
if !exists('+fixendofline')
|
||||
Skip This test requires 'fixendofline'
|
||||
endif
|
||||
setl binary
|
||||
setl noendofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar'])
|
||||
End
|
||||
|
||||
It adds a blank line when nobinary is set
|
||||
if exists('+fixendofline')
|
||||
Skip This test is not for 'fixendofline'
|
||||
endif
|
||||
setl nobinary
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar', ''])
|
||||
End
|
||||
|
||||
It adds a blank line when binary and endofline are set
|
||||
if exists('+fixendofline')
|
||||
Skip This test is not for 'fixendofline'
|
||||
endif
|
||||
setl binary
|
||||
setl endofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar', ''])
|
||||
End
|
||||
|
||||
It does not add a blank line when binary and noendofline are set
|
||||
if exists('+fixendofline')
|
||||
Skip This test is not for 'fixendofline'
|
||||
endif
|
||||
setl binary
|
||||
setl noendofline
|
||||
Assert Equals(lsp#utils#buffer#_get_lines(bufnr('$')), ['foo', 'bar'])
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#buffer#get_indent_size
|
||||
It gets shiftwidth if set
|
||||
setl shiftwidth=4
|
||||
setl tabstop=8
|
||||
Assert Equals(lsp#utils#buffer#get_indent_size(bufnr('$')), 4)
|
||||
End
|
||||
It gets tabstop if shiftwidth not set
|
||||
setl shiftwidth=0
|
||||
setl tabstop=12
|
||||
Assert Equals(lsp#utils#buffer#get_indent_size(bufnr('$')), 12)
|
||||
End
|
||||
End
|
||||
End
|
||||
86
dot_vim/plugged/vim-lsp/test/lsp/utils/diff.vimspec
Normal file
86
dot_vim/plugged/vim-lsp/test/lsp/utils/diff.vimspec
Normal file
@@ -0,0 +1,86 @@
|
||||
Describe lsp#utils#diff
|
||||
|
||||
Describe lsp#utils#diff#compute
|
||||
It should return diff of one letter
|
||||
let lines1 = [
|
||||
\ 'foo',
|
||||
\ 'bar',
|
||||
\ 'baz',
|
||||
\]
|
||||
let lines2 = [
|
||||
\ 'foo',
|
||||
\ 'baR',
|
||||
\ 'baz',
|
||||
\]
|
||||
let want = {
|
||||
\ 'range': {
|
||||
\ 'start': { 'line': 1, 'character': 2 },
|
||||
\ 'end': { 'line': 1, 'character': 3 },
|
||||
\ },
|
||||
\ 'text': 'R',
|
||||
\ 'rangeLength': 1
|
||||
\}
|
||||
let got = lsp#utils#diff#compute(lines1, lines2)
|
||||
Assert Equals(got, want)
|
||||
End
|
||||
|
||||
It should return diff of multi-lines
|
||||
let lines1 = [
|
||||
\ 'foo',
|
||||
\ 'bar',
|
||||
\ 'baz',
|
||||
\]
|
||||
let lines2 = [
|
||||
\ 'Foo',
|
||||
\ 'baR',
|
||||
\ 'baz',
|
||||
\]
|
||||
let want = {
|
||||
\ 'range': {
|
||||
\ 'start': { 'line': 0, 'character': 0 },
|
||||
\ 'end': { 'line': 1, 'character': 3, }
|
||||
\ },
|
||||
\ 'text': "Foo\nbaR",
|
||||
\ "rangeLength": 7
|
||||
\}
|
||||
let got = lsp#utils#diff#compute(lines1, lines2)
|
||||
Assert Equals(got, want)
|
||||
End
|
||||
|
||||
It should return diff for empty list
|
||||
let lines1 = []
|
||||
let lines2 = [
|
||||
\ 'foo',
|
||||
\ 'bar',
|
||||
\ 'baz',
|
||||
\]
|
||||
let want = {
|
||||
\ 'range': {
|
||||
\ 'start': { 'line': 0, 'character': 0 },
|
||||
\ 'end': { 'line': 0, 'character': 0, }
|
||||
\ },
|
||||
\ 'text': "foo\nbar\nbaz\n",
|
||||
\ "rangeLength": 0
|
||||
\}
|
||||
let got = lsp#utils#diff#compute(lines1, lines2)
|
||||
Assert Equals(got, want)
|
||||
|
||||
let lines1 = [
|
||||
\ 'foo',
|
||||
\ 'bar',
|
||||
\ 'baz',
|
||||
\]
|
||||
let lines2 = []
|
||||
let want = {
|
||||
\ 'range': {
|
||||
\ 'start': { 'line': 0, 'character': 0 },
|
||||
\ 'end': { 'line': 3, 'character': 0, }
|
||||
\ },
|
||||
\ 'text': '',
|
||||
\ "rangeLength": 12
|
||||
\}
|
||||
let got = lsp#utils#diff#compute(lines1, lines2)
|
||||
Assert Equals(got, want)
|
||||
End
|
||||
End
|
||||
End
|
||||
65
dot_vim/plugged/vim-lsp/test/lsp/utils/position.vimspec
Normal file
65
dot_vim/plugged/vim-lsp/test/lsp/utils/position.vimspec
Normal file
@@ -0,0 +1,65 @@
|
||||
Describe lsp#utils#position
|
||||
|
||||
Before each
|
||||
% delete _
|
||||
End
|
||||
|
||||
After all
|
||||
% delete _
|
||||
End
|
||||
|
||||
Describe lsp#utils#position#lsp_to_vim
|
||||
|
||||
It should return the byte-index from the given character-index on a buffer
|
||||
call setline(1, ['a β c', 'δ', ''])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 0, 'character': 0 }), [1, 1])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 0, 'character': 1 }), [1, 2])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 0, 'character': 2 }), [1, 3])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 0, 'character': 3 }), [1, 5])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 0, 'character': 4 }), [1, 6])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 1, 'character': 0 }), [2, 1])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 1, 'character': 1 }), [2, 3])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('%', { 'line': 2, 'character': 0 }), [3, 1])
|
||||
End
|
||||
|
||||
It should return the byte-index from the given character-index in an unloaded file
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 0, 'character': 0 }), [1, 1])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 0, 'character': 1 }), [1, 2])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 0, 'character': 2 }), [1, 3])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 0, 'character': 3 }), [1, 5])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 0, 'character': 4 }), [1, 6])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 1, 'character': 0 }), [2, 1])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 1, 'character': 1 }), [2, 3])
|
||||
Assert Equals(lsp#utils#position#lsp_to_vim('./test/testfiles/multibyte.txt', { 'line': 2, 'character': 0 }), [3, 1])
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
Describe lsp#utils#position#vim_to_lsp
|
||||
|
||||
It should return the character-index from the given byte-index on a buffer
|
||||
call setline(1, ['a β c', 'δ', ''])
|
||||
Assert Equals({ 'line': 0, 'character': 0 }, lsp#utils#position#vim_to_lsp('%', [1, 1]))
|
||||
Assert Equals({ 'line': 0, 'character': 1 }, lsp#utils#position#vim_to_lsp('%', [1, 2]))
|
||||
Assert Equals({ 'line': 0, 'character': 2 }, lsp#utils#position#vim_to_lsp('%', [1, 3]))
|
||||
Assert Equals({ 'line': 0, 'character': 3 }, lsp#utils#position#vim_to_lsp('%', [1, 5]))
|
||||
Assert Equals({ 'line': 0, 'character': 4 }, lsp#utils#position#vim_to_lsp('%', [1, 6]))
|
||||
Assert Equals({ 'line': 1, 'character': 0 }, lsp#utils#position#vim_to_lsp('%', [2, 1]))
|
||||
Assert Equals({ 'line': 1, 'character': 1 }, lsp#utils#position#vim_to_lsp('%', [2, 3]))
|
||||
Assert Equals({ 'line': 2, 'character': 0 }, lsp#utils#position#vim_to_lsp('%', [3, 1]))
|
||||
End
|
||||
|
||||
It should return the character-index from the given byte-index in an unloaded file
|
||||
Assert Equals({ 'line': 0, 'character': 0 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [1, 1]))
|
||||
Assert Equals({ 'line': 0, 'character': 1 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [1, 2]))
|
||||
Assert Equals({ 'line': 0, 'character': 2 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [1, 3]))
|
||||
Assert Equals({ 'line': 0, 'character': 3 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [1, 5]))
|
||||
Assert Equals({ 'line': 0, 'character': 4 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [1, 6]))
|
||||
Assert Equals({ 'line': 1, 'character': 0 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [2, 1]))
|
||||
Assert Equals({ 'line': 1, 'character': 1 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [2, 3]))
|
||||
Assert Equals({ 'line': 2, 'character': 0 }, lsp#utils#position#vim_to_lsp('./test/testfiles/multibyte.txt', [3, 1]))
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
End
|
||||
61
dot_vim/plugged/vim-lsp/test/lsp/utils/range.vimspec
Normal file
61
dot_vim/plugged/vim-lsp/test/lsp/utils/range.vimspec
Normal file
@@ -0,0 +1,61 @@
|
||||
Describe lsp#utils#range
|
||||
|
||||
Before each
|
||||
% delete _
|
||||
End
|
||||
|
||||
Describe lsp#utils#range#_get_recent_visual_range
|
||||
|
||||
It should return single line visual selection
|
||||
call setline(1, ['あいうえお'])
|
||||
normal! gg0llvly
|
||||
Assert Equals(lsp#utils#range#_get_recent_visual_range(), {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 2
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 4
|
||||
\ }
|
||||
\ })
|
||||
End
|
||||
|
||||
It should return multi line visual selection
|
||||
call setline(1, ['あいうえお', 'かきくけこ'])
|
||||
normal! gg0llvjly
|
||||
Assert Equals(lsp#utils#range#_get_recent_visual_range(), {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 2
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 4
|
||||
\ }
|
||||
\ })
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
Describe lsp#utils#range#_get_current_line_range
|
||||
|
||||
It should return current line range
|
||||
call setline(1, ['あいうえお', 'かきくけこ', 'さしすせそ'])
|
||||
call cursor(2, 1)
|
||||
Assert Equals(lsp#utils#range#_get_current_line_range(), {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 5
|
||||
\ }
|
||||
\ })
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
End
|
||||
|
||||
75
dot_vim/plugged/vim-lsp/test/lsp/utils/tagstack.vimspec
Normal file
75
dot_vim/plugged/vim-lsp/test/lsp/utils/tagstack.vimspec
Normal file
@@ -0,0 +1,75 @@
|
||||
Describe lsp#utils#tagstack
|
||||
|
||||
Before each
|
||||
% delete _
|
||||
if exists('*settagstack')
|
||||
call settagstack(1, {'items' : []})
|
||||
endif
|
||||
End
|
||||
|
||||
After all
|
||||
% delete _
|
||||
End
|
||||
|
||||
Describe lsp#utils#tagstack#_update()
|
||||
It should correctly preserve the tag stack
|
||||
let l:bufnr = bufnr('%')
|
||||
|
||||
0put = 'foo'
|
||||
1put = 'bar'
|
||||
2put = 'baz'
|
||||
|
||||
call cursor(1, 1)
|
||||
call lsp#utils#tagstack#_update()
|
||||
|
||||
call cursor(1, 2)
|
||||
call lsp#utils#tagstack#_update()
|
||||
|
||||
call cursor(3, 3)
|
||||
call lsp#utils#tagstack#_update()
|
||||
|
||||
call cursor(2, 1)
|
||||
call lsp#utils#tagstack#_update()
|
||||
|
||||
if !exists('*gettagstack') || !exists('*settagstack')
|
||||
" calling lsp#utils#tagstack#_update() should be safe if
|
||||
" gettagstack and settagstack doesn't exist
|
||||
return
|
||||
endif
|
||||
|
||||
let l:tagstack = gettagstack()
|
||||
|
||||
Assert Equals(l:tagstack['length'], 4)
|
||||
Assert Equals(l:tagstack['curidx'], 5)
|
||||
|
||||
Assert Equals(l:tagstack['items'][0], {
|
||||
\ 'bufnr': l:bufnr,
|
||||
\ 'tagname': 'foo',
|
||||
\ 'from': [l:bufnr, 1, 1, 0],
|
||||
\ 'matchnr': 1,
|
||||
\ })
|
||||
|
||||
Assert Equals(l:tagstack['items'][1], {
|
||||
\ 'bufnr': l:bufnr,
|
||||
\ 'tagname': 'foo',
|
||||
\ 'from': [l:bufnr, 1, 2, 0],
|
||||
\ 'matchnr': 1,
|
||||
\ })
|
||||
|
||||
Assert Equals(l:tagstack['items'][2], {
|
||||
\ 'bufnr': l:bufnr,
|
||||
\ 'tagname': 'baz',
|
||||
\ 'from': [l:bufnr, 3, 3, 0],
|
||||
\ 'matchnr': 1,
|
||||
\ })
|
||||
|
||||
Assert Equals(l:tagstack['items'][3], {
|
||||
\ 'bufnr': l:bufnr,
|
||||
\ 'tagname': 'bar',
|
||||
\ 'from': [l:bufnr, 2, 1, 0],
|
||||
\ 'matchnr': 1,
|
||||
\ })
|
||||
End
|
||||
End
|
||||
|
||||
End
|
||||
647
dot_vim/plugged/vim-lsp/test/lsp/utils/text_edit.vimspec
Normal file
647
dot_vim/plugged/vim-lsp/test/lsp/utils/text_edit.vimspec
Normal file
@@ -0,0 +1,647 @@
|
||||
function! s:set_text(lines)
|
||||
% delete _
|
||||
put =a:lines
|
||||
execute 'normal ggdd'
|
||||
endfunction
|
||||
|
||||
function! s:get_text()
|
||||
return lsp#utils#buffer#_get_lines(bufnr('$'))
|
||||
endfunction
|
||||
|
||||
Describe lsp#utils#text_edit
|
||||
|
||||
Before all
|
||||
let s:endofline_backup = &endofline
|
||||
set endofline
|
||||
End
|
||||
|
||||
After all
|
||||
let &endofline = s:endofline_backup
|
||||
End
|
||||
|
||||
Before each
|
||||
enew!
|
||||
End
|
||||
|
||||
Describe lsp#utils#text_edit#apply_text_edits
|
||||
It insert newText
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': 'baz'
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', 'bbazar', ''])
|
||||
End
|
||||
|
||||
It insert empty newText
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', 'bar', ''])
|
||||
End
|
||||
|
||||
It replace range string to newText
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': 'replaced'
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', 'replacedar', ''])
|
||||
End
|
||||
|
||||
It replace range string to empty newText
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', 'ar', ''])
|
||||
End
|
||||
|
||||
It single line start character is -1
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': -1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 3
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', '', ''])
|
||||
End
|
||||
|
||||
It single line start character is 0
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 3
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', '', ''])
|
||||
End
|
||||
|
||||
It single line start character is 1
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 3
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', 'b', ''])
|
||||
End
|
||||
|
||||
It single line end character is `len(getline('.')) - 1`
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 2
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', 'r', ''])
|
||||
End
|
||||
|
||||
It single line end character is `len(getline('.'))`
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 3
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', '', ''])
|
||||
End
|
||||
|
||||
It single line end character is `len(getline('.')) + 1`
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 4
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
" if newline character deleting, need end position is next line zero character.
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['foo', '', ''])
|
||||
End
|
||||
|
||||
It replace range string to empty newText, multiline top to top
|
||||
call s:set_text(['foo', 'bar', 'baz'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['bar', 'baz', ''])
|
||||
End
|
||||
|
||||
It replace range string to empty newText, multiline top to tail
|
||||
call s:set_text(['foo', 'bar', 'baz'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 2
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['r', 'baz', ''])
|
||||
|
||||
call s:set_text(['foo', 'bar', 'baz'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 3
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['', 'baz', ''])
|
||||
|
||||
call s:set_text(['foo', 'bar', 'baz'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 4
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
" if newline character deleting, need end position is next line zero character.
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['', 'baz', ''])
|
||||
End
|
||||
|
||||
It replace range string to empty newText, multiline middle to middle
|
||||
call s:set_text(['foo', 'bar', 'baz'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 2
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['fr', 'baz', ''])
|
||||
End
|
||||
|
||||
It replaces entire buffer correctly
|
||||
call s:set_text(['foo', 'bar', 'baz'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 3,
|
||||
\ 'character': 0
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': "x\ny\nz\n"
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['x', 'y', 'z', ''])
|
||||
End
|
||||
|
||||
It multiple textEdit with inserting \r.
|
||||
" Add some text to buffer
|
||||
call s:set_text(['class ABC {', ' private:', ' ', 'int a;};', ])
|
||||
|
||||
" Format
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "end": {
|
||||
\ "character": 2,
|
||||
\ "line": 1
|
||||
\ },
|
||||
\ "start": {
|
||||
\ "character": 11,
|
||||
\ "line": 0
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "\n"
|
||||
\ },
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "end": {
|
||||
\ "character": 0,
|
||||
\ "line": 3
|
||||
\ },
|
||||
\ "start": {
|
||||
\ "character": 10,
|
||||
\ "line": 1
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "\n "
|
||||
\ },
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "end": {
|
||||
\ "character": 6,
|
||||
\ "line": 3
|
||||
\ },
|
||||
\ "start": {
|
||||
\ "character": 6,
|
||||
\ "line": 3
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "\n"
|
||||
\ }
|
||||
\ ])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['class ABC {', 'private:', ' int a;', '};', ''])
|
||||
End
|
||||
|
||||
It preserves v:completed_item
|
||||
" Add some text to buffer
|
||||
call s:set_text(['foo', 'bar'])
|
||||
|
||||
" Go to end of file and invoke completion
|
||||
execute "normal Gof\<C-p>\<Esc>"
|
||||
|
||||
" Make sure that v:completed_item is set
|
||||
Assert Equals(v:completed_item["word"], "foo")
|
||||
let l:old_completed_item = v:completed_item
|
||||
|
||||
" Perform some text edits
|
||||
|
||||
" Insert
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': 'baz'
|
||||
\ }])
|
||||
|
||||
" Insert empty
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
" Replace
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': 'replaced'
|
||||
\ }])
|
||||
|
||||
" Delete
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': ''
|
||||
\ }])
|
||||
|
||||
" Make sure v:completed_item is not changed
|
||||
Assert Equals(v:completed_item, l:old_completed_item)
|
||||
End
|
||||
|
||||
It replaces entire buffer correctly when end column is 1
|
||||
call s:set_text(['foo', 'b'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': "x\ny\nz\n"
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['x', 'y', 'z', '', ''])
|
||||
End
|
||||
|
||||
It should apply edit that contains \r\n
|
||||
call s:set_text(['foo', 'b'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 1,
|
||||
\ 'character': 1
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': "x\r\ny\r\nz\r\n"
|
||||
\ }])
|
||||
|
||||
let l:buffer_text = s:get_text()
|
||||
Assert Equals(l:buffer_text, ['x', 'y', 'z', '', ''])
|
||||
End
|
||||
|
||||
It adds imports correctly
|
||||
call s:set_text(['package main', '', 'import java.util.ArrayList;', '', 'public class Main {}'])
|
||||
|
||||
call lsp#utils#text_edit#apply_text_edits(
|
||||
\ expand('%'),
|
||||
\ [{
|
||||
\ "range": {
|
||||
\ "start": {
|
||||
\ "character": 0,
|
||||
\ "line": 2
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "character": 0,
|
||||
\ "line": 3
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": ""
|
||||
\ },
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "start": {
|
||||
\ "character": 0,
|
||||
\ "line": 2
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "character": 0,
|
||||
\ "line": 2
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "import java.util.ArrayList;\n"
|
||||
\ }
|
||||
\ ])
|
||||
|
||||
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
|
||||
|
||||
It should apply edits to unloaded file
|
||||
let l:target = globpath(&runtimepath, 'test/lsp/utils/text_edit.vimspec')
|
||||
call themis#log(l:target)
|
||||
call lsp#utils#text_edit#apply_text_edits(lsp#utils#path_to_uri(l:target), [{
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0,
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 0,
|
||||
\ 'character': 0,
|
||||
\ }
|
||||
\ },
|
||||
\ 'newText': "aiueo\n"
|
||||
\ }])
|
||||
|
||||
Assert Equals(getbufline(l:target, 1), ['aiueo'])
|
||||
End
|
||||
End
|
||||
End
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
Describe lsp#internal#work_done_progress
|
||||
Before each
|
||||
let g:lsp_work_done_progress_enabled = 1
|
||||
call lsp#internal#work_done_progress#_enable()
|
||||
End
|
||||
|
||||
After each
|
||||
let g:lsp_work_done_progress_enabled = 0
|
||||
call lsp#internal#work_done_progress#_disable()
|
||||
End
|
||||
|
||||
It should be able to subscribe to $progress stream
|
||||
let l:server1_response1 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'begin', 'title':'title'}}}
|
||||
let l:server1_response2 = {'method': '$/progress', 'params':{'token':'token text','value':{'percentage':50,'message':'test message','kind':'report'}}}
|
||||
let l:server1_response3 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'end'}}}
|
||||
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(), [])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response1 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': '', 'token': 'token text', 'title': 'title', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response2 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': 'test message', 'token': 'token text', 'percentage': 50, 'title': 'title', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response3 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(), [])
|
||||
End
|
||||
|
||||
It should be able to subscribe to multi $progress stream
|
||||
let l:server1_response1 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'begin', 'title':'title1'}}}
|
||||
let l:server1_response2 = {'method': '$/progress', 'params':{'token':'token text','value':{'percentage':50,'message':'msg1','kind':'report'}}}
|
||||
let l:server1_response3 = {'method': '$/progress', 'params':{'token':'token text','value':{'percentage':90,'message':'msg1','kind':'report'}}}
|
||||
let l:server1_response4 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'end'}}}
|
||||
let l:server2_response1 = {'method': '$/progress', 'params':{'token':'server2_token','value':{'kind':'begin', 'title':'title2'}}}
|
||||
let l:server2_response2 = {'method': '$/progress', 'params':{'token':'server2_token','value':{'percentage':0,'message':'msg2','kind':'report'}}}
|
||||
let l:server2_response3 = {'method': '$/progress', 'params':{'token':'server2_token','value':{'kind':'end'}}}
|
||||
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(), [])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response1 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': '', 'token': 'token text', 'title': 'title1', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server2', 'response': l:server2_response1 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': '', 'token': 'server2_token', 'title': 'title2', 'server': 'server2'},
|
||||
\ {'message': '', 'token': 'token text', 'title': 'title1', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server2', 'response': l:server2_response2 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': 'msg2', 'token': 'server2_token', 'percentage':0, 'title': 'title2', 'server': 'server2'},
|
||||
\ {'message': '', 'token': 'token text', 'title': 'title1', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response2 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': 'msg1', 'token': 'token text', 'percentage':50, 'title': 'title1', 'server': 'server1'},
|
||||
\ {'message': 'msg2', 'token': 'server2_token', 'percentage':0, 'title': 'title2', 'server': 'server2'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response3 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': 'msg1', 'token': 'token text', 'percentage':90, 'title': 'title1', 'server': 'server1'},
|
||||
\ {'message': 'msg2', 'token': 'server2_token', 'percentage':0, 'title': 'title2', 'server': 'server2'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response4 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': 'msg2', 'token': 'server2_token', 'percentage':0, 'title': 'title2', 'server': 'server2'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server2', 'response': l:server2_response3 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(), [])
|
||||
End
|
||||
|
||||
It should be returned correctly even if percentage and message do not exist.
|
||||
let l:server1_response1 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'begin', 'title':'title'}}}
|
||||
let l:server1_response2 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'report'}}}
|
||||
let l:server1_response3 = {'method': '$/progress', 'params':{'token':'token text','value':{'kind':'end'}}}
|
||||
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(), [])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response1 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': '', 'token': 'token text', 'title': 'title', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response2 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(),
|
||||
\ [{'message': '', 'token': 'token text', 'title': 'title', 'server': 'server1'}])
|
||||
|
||||
call lsp#stream(1, { 'server': 'server1', 'response': l:server1_response3 })
|
||||
Assert Equals(lsp#internal#work_done_progress#get_progress(), [])
|
||||
End
|
||||
End
|
||||
@@ -0,0 +1,81 @@
|
||||
Describe lsp#utils#workspace_edit
|
||||
|
||||
Describe lsp#utils#text_edit#apply_workspace_edit
|
||||
It populates location list with changes
|
||||
let g:lsp_show_workspace_edits = 1
|
||||
|
||||
call lsp#utils#workspace_edit#apply_workspace_edit({
|
||||
\ 'documentChanges': [{
|
||||
\ 'textDocument': { 'uri': 'file:///path/to/file' },
|
||||
\ 'edits': [
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "start": {
|
||||
\ "character": 0,
|
||||
\ "line": 1
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "character": 0,
|
||||
\ "line": 1
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "import java.util.LinkedList;"
|
||||
\ },
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "start": {
|
||||
\ "character": 0,
|
||||
\ "line": 0
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "character": 0,
|
||||
\ "line": 0
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "import java.util.ArrayList;"
|
||||
\ }
|
||||
\ ]
|
||||
\ }]})
|
||||
|
||||
let l:loclist = getloclist(0)
|
||||
|
||||
Assert Equals(len(l:loclist), 2)
|
||||
|
||||
Assert Equals(l:loclist[0]['lnum'], 2)
|
||||
Assert Equals(l:loclist[0]['col'], 1)
|
||||
Assert Equals(l:loclist[0]['text'], 'import java.util.LinkedList;')
|
||||
|
||||
Assert Equals(l:loclist[1]['lnum'], 1)
|
||||
Assert Equals(l:loclist[1]['col'], 1)
|
||||
Assert Equals(l:loclist[1]['text'], 'import java.util.ArrayList;')
|
||||
|
||||
end
|
||||
|
||||
It should not set location list if not enabled
|
||||
let g:lsp_show_workspace_edits = 0
|
||||
|
||||
call lsp#utils#workspace_edit#apply_workspace_edit({
|
||||
\ 'documentChanges': [{
|
||||
\ 'textDocument': { 'uri': 'file:///path/to/file' },
|
||||
\ 'edits': [
|
||||
\ {
|
||||
\ "range": {
|
||||
\ "start": {
|
||||
\ "character": 0,
|
||||
\ "line": 3
|
||||
\ },
|
||||
\ "end": {
|
||||
\ "character": 0,
|
||||
\ "line": 3
|
||||
\ }
|
||||
\ },
|
||||
\ "newText": "import java.util.LinkedList;"
|
||||
\ }
|
||||
\ ]
|
||||
\ }]})
|
||||
|
||||
Assert Equals(len(getloclist(0)), 0)
|
||||
End
|
||||
End
|
||||
End
|
||||
|
||||
Reference in New Issue
Block a user