summaryrefslogtreecommitdiff
path: root/test/test_go_to_definition.vader
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-26 22:27:08 +0000
committerw0rp <devw0rp@gmail.com>2017-11-26 22:27:08 +0000
commit21b460bb1dcb099786ebe57d8cd6ec4fd9618861 (patch)
tree6c65fa3b3408187e5cd9aa67baa5ca6fab75428b /test/test_go_to_definition.vader
parent01318b6930c536cb63f09541bde11a9d48d4a12e (diff)
downloadale-21b460bb1dcb099786ebe57d8cd6ec4fd9618861.zip
Implement go to defintion for LSP linters
Diffstat (limited to 'test/test_go_to_definition.vader')
-rw-r--r--test/test_go_to_definition.vader161
1 files changed, 154 insertions, 7 deletions
diff --git a/test/test_go_to_definition.vader b/test/test_go_to_definition.vader
index c6e87712..dd0e9903 100644
--- a/test/test_go_to_definition.vader
+++ b/test/test_go_to_definition.vader
@@ -4,7 +4,7 @@ Before:
let g:old_filename = expand('%:p')
let g:Callback = 0
- let g:message = []
+ let g:message_list = []
let g:expr_list = []
runtime autoload/ale/definition.vim
@@ -21,7 +21,7 @@ Before:
endfunction
function! ale#lsp#Send(conn_id, message, root) abort
- let g:message = a:message
+ call add(g:message_list, a:message)
return 42
endfunction
@@ -36,8 +36,9 @@ After:
unlet! g:old_filename
unlet! g:Callback
- unlet! g:message
+ unlet! g:message_list
unlet! g:expr_list
+ unlet! b:ale_linters
runtime autoload/ale/definition.vim
runtime autoload/ale/linter.vim
@@ -119,8 +120,8 @@ Execute(tsserver completion requests should be sent):
\ 'function(''ale#definition#HandleTSServerResponse'')',
\ string(g:Callback)
AssertEqual
- \ [0, 'ts@definition', {'file': expand('%:p'), 'line': 2, 'offset': 5}],
- \ g:message
+ \ [[0, 'ts@definition', {'file': expand('%:p'), 'line': 2, 'offset': 5}]],
+ \ g:message_list
AssertEqual {'42': {'open_in_tab': 0}}, ale#definition#GetMap()
Execute(tsserver tab completion requests should be sent):
@@ -133,6 +134,152 @@ Execute(tsserver tab completion requests should be sent):
\ 'function(''ale#definition#HandleTSServerResponse'')',
\ string(g:Callback)
AssertEqual
- \ [0, 'ts@definition', {'file': expand('%:p'), 'line': 2, 'offset': 5}],
- \ g:message
+ \ [[0, 'ts@definition', {'file': expand('%:p'), 'line': 2, 'offset': 5}]],
+ \ g:message_list
+ AssertEqual {'42': {'open_in_tab': 1}}, ale#definition#GetMap()
+
+Given python(Some Python file):
+ foo
+ somelongerline
+ bazxyzxyzxyz
+
+Execute(Other files should be jumped to for LSP definition responses):
+ call ale#definition#SetMap({3: {'open_in_tab': 0}})
+ call ale#definition#HandleLSPResponse(
+ \ 1,
+ \ {
+ \ 'id': 3,
+ \ 'result': {
+ \ 'uri': ale#path#ToURI(g:dir . '/completion_dummy_file'),
+ \ 'range': {
+ \ 'start': {'line': 2, 'character': 7},
+ \ },
+ \ },
+ \ }
+ \)
+
+ AssertEqual
+ \ [
+ \ 'edit ' . fnameescape(g:dir . '/completion_dummy_file'),
+ \ ],
+ \ g:expr_list
+ AssertEqual [3, 7], getpos('.')[1:2]
+ AssertEqual {}, ale#definition#GetMap()
+
+Execute(Other files should be jumped to in tabs for LSP definition responses):
+ call ale#definition#SetMap({3: {'open_in_tab': 1}})
+ call ale#definition#HandleLSPResponse(
+ \ 1,
+ \ {
+ \ 'id': 3,
+ \ 'result': {
+ \ 'uri': ale#path#ToURI(g:dir . '/completion_dummy_file'),
+ \ 'range': {
+ \ 'start': {'line': 2, 'character': 7},
+ \ },
+ \ },
+ \ }
+ \)
+
+ AssertEqual
+ \ [
+ \ 'tabedit ' . fnameescape(g:dir . '/completion_dummy_file'),
+ \ ],
+ \ g:expr_list
+ AssertEqual [3, 7], getpos('.')[1:2]
+ AssertEqual {}, ale#definition#GetMap()
+
+Execute(Definition responses with lists should be handled):
+ call ale#definition#SetMap({3: {'open_in_tab': 0}})
+ call ale#definition#HandleLSPResponse(
+ \ 1,
+ \ {
+ \ 'id': 3,
+ \ 'result': [
+ \ {
+ \ 'uri': ale#path#ToURI(g:dir . '/completion_dummy_file'),
+ \ 'range': {
+ \ 'start': {'line': 2, 'character': 7},
+ \ },
+ \ },
+ \ {
+ \ 'uri': ale#path#ToURI(g:dir . '/other_file'),
+ \ 'range': {
+ \ 'start': {'line': 20, 'character': 3},
+ \ },
+ \ },
+ \ ],
+ \ }
+ \)
+
+ AssertEqual
+ \ [
+ \ 'edit ' . fnameescape(g:dir . '/completion_dummy_file'),
+ \ ],
+ \ g:expr_list
+ AssertEqual [3, 7], getpos('.')[1:2]
+ AssertEqual {}, ale#definition#GetMap()
+
+Execute(Definition responses with null response should be handled):
+ call ale#definition#SetMap({3: {'open_in_tab': 0}})
+ call ale#definition#HandleLSPResponse(1, {'id': 3, 'result': v:null})
+
+ AssertEqual [], g:expr_list
+
+Execute(LSP completion requests should be sent):
+ runtime ale_linters/python/pyls.vim
+ let b:ale_linters = ['pyls']
+ call setpos('.', [bufnr(''), 1, 5, 0])
+
+ ALEGoToDefinition
+
+ AssertEqual
+ \ 'function(''ale#definition#HandleLSPResponse'')',
+ \ string(g:Callback)
+
+ AssertEqual
+ \ [
+ \ [1, 'textDocument/didChange', {
+ \ 'textDocument': {
+ \ 'uri': ale#path#ToURI(expand('%:p')),
+ \ 'version': g:ale_lsp_next_version_id - 1,
+ \ },
+ \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}]
+ \ }],
+ \ [0, 'textDocument/definition', {
+ \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))},
+ \ 'position': {'line': 0, 'character': 3},
+ \ }],
+ \ ],
+ \ g:message_list
+
+ AssertEqual {'42': {'open_in_tab': 0}}, ale#definition#GetMap()
+
+Execute(LSP tab completion requests should be sent):
+ runtime ale_linters/python/pyls.vim
+ let b:ale_linters = ['pyls']
+ call setpos('.', [bufnr(''), 1, 5, 0])
+
+ ALEGoToDefinitionInTab
+
+ AssertEqual
+ \ 'function(''ale#definition#HandleLSPResponse'')',
+ \ string(g:Callback)
+
+ AssertEqual
+ \ [
+ \ [1, 'textDocument/didChange', {
+ \ 'textDocument': {
+ \ 'uri': ale#path#ToURI(expand('%:p')),
+ \ 'version': g:ale_lsp_next_version_id - 1,
+ \ },
+ \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}]
+ \ }],
+ \ [0, 'textDocument/definition', {
+ \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))},
+ \ 'position': {'line': 0, 'character': 3},
+ \ }],
+ \ ],
+ \ g:message_list
+
AssertEqual {'42': {'open_in_tab': 1}}, ale#definition#GetMap()