diff options
Diffstat (limited to 'test/test_find_references.vader')
-rw-r--r-- | test/test_find_references.vader | 97 |
1 files changed, 67 insertions, 30 deletions
diff --git a/test/test_find_references.vader b/test/test_find_references.vader index 88b2d762..1a147849 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -8,30 +8,38 @@ Before: let g:message_list = [] let g:preview_called = 0 let g:item_list = [] + let g:options = {} let g:capability_checked = '' let g:conn_id = v:null - let g:WaitCallback = v:null + let g:InitCallback = v:null - runtime autoload/ale/linter.vim + runtime autoload/ale/lsp_linter.vim runtime autoload/ale/lsp.vim runtime autoload/ale/util.vim runtime autoload/ale/preview.vim - function! ale#lsp_linter#StartLSP(buffer, linter) abort + function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort let g:conn_id = ale#lsp#Register('executable', '/foo/bar', {}) call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer) - return { + if a:linter.lsp is# 'tsserver' + call ale#lsp#MarkConnectionAsTsserver(g:conn_id) + endif + + let l:details = { + \ 'command': 'foobar', \ 'buffer': a:buffer, \ 'connection_id': g:conn_id, \ 'project_root': '/foo/bar', - \ 'language_id': 'python', \} + + let g:InitCallback = {-> ale#lsp_linter#OnInit(a:linter, l:details, a:Callback)} endfunction - function! ale#lsp#WaitForCapability(conn_id, capability, callback) abort + function! ale#lsp#HasCapability(conn_id, capability) abort let g:capability_checked = a:capability - let g:WaitCallback = a:callback + + return 1 endfunction function! ale#lsp#RegisterCallback(conn_id, callback) abort @@ -48,9 +56,10 @@ Before: call add(g:expr_list, a:expr) endfunction - function! ale#preview#ShowSelection(item_list) abort + function! ale#preview#ShowSelection(item_list, options) abort let g:preview_called = 1 let g:item_list = a:item_list + let g:options = a:options endfunction After: @@ -63,13 +72,14 @@ After: call ale#linter#Reset() unlet! g:capability_checked - unlet! g:WaitCallback + unlet! g:InitCallback unlet! g:old_filename unlet! g:conn_id unlet! g:Callback unlet! g:message_list unlet! g:expr_list unlet! b:ale_linters + unlet! g:options unlet! g:item_list unlet! g:preview_called @@ -135,9 +145,9 @@ Execute(Results should be shown for tsserver responses): AssertEqual \ [ - \ {'filename': '/foo/bar/app.ts', 'column': 9, 'line': 9}, - \ {'filename': '/foo/bar/app.ts', 'column': 3, 'line': 804}, - \ {'filename': '/foo/bar/other/app.ts', 'column': 3, 'line': 51}, + \ {'filename': '/foo/bar/app.ts', 'column': 9, 'line': 9, 'match': 'import {doSomething} from ''./whatever'''}, + \ {'filename': '/foo/bar/app.ts', 'column': 3, 'line': 804, 'match': 'doSomething()'}, + \ {'filename': '/foo/bar/other/app.ts', 'column': 3, 'line': 51, 'match': 'doSomething()'}, \ ], \ g:item_list AssertEqual {}, ale#references#GetMap() @@ -162,6 +172,8 @@ Execute(The preview window should not be opened for empty tsserver responses): AssertEqual ['echom ''No references found.'''], g:expr_list Execute(tsserver reference requests should be sent): + call ale#linter#Reset() + runtime ale_linters/typescript/tsserver.vim call setpos('.', [bufnr(''), 2, 5, 0]) @@ -170,17 +182,30 @@ Execute(tsserver reference requests should be sent): " We shouldn't register the callback yet. AssertEqual '''''', string(g:Callback) - AssertEqual type(function('type')), type(g:WaitCallback) - AssertEqual 'references', g:capability_checked - call call(g:WaitCallback, [g:conn_id, '/foo/bar']) + AssertEqual type(function('type')), type(g:InitCallback) + call g:InitCallback() + AssertEqual 'references', g:capability_checked AssertEqual \ 'function(''ale#references#HandleTSServerResponse'')', \ string(g:Callback) AssertEqual - \ [[0, 'ts@references', {'file': expand('%:p'), 'line': 2, 'offset': 5}]], + \ [ + \ ale#lsp#tsserver_message#Change(bufnr('')), + \ [0, 'ts@references', {'file': expand('%:p'), 'line': 2, 'offset': 5}] + \ ], \ g:message_list - AssertEqual {'42': {}}, ale#references#GetMap() + AssertEqual {'42': {'use_relative_paths': 0}}, ale#references#GetMap() + +Execute('-relative' argument should enable 'use_relative_paths' in HandleTSServerResponse): + runtime ale_linters/typescript/tsserver.vim + call setpos('.', [bufnr(''), 2, 5, 0]) + + ALEFindReferences -relative + + call g:InitCallback() + + AssertEqual {'42': {'use_relative_paths': 1}}, ale#references#GetMap() Given python(Some Python file): foo @@ -228,14 +253,15 @@ Execute(LSP reference responses should be handled): Execute(Preview windows should not be opened for empty LSP reference responses): call ale#references#SetMap({3: {}}) - call ale#references#HandleLSPResponse( - \ 1, - \ { - \ 'id': 3, - \ 'result': [ - \ ], - \ } - \) + call ale#references#HandleLSPResponse(1, {'id': 3, 'result': []}) + + Assert !g:preview_called + AssertEqual {}, ale#references#GetMap() + AssertEqual ['echom ''No references found.'''], g:expr_list + +Execute(LSP reference responses with a null result should be handled): + call ale#references#SetMap({3: {}}) + call ale#references#HandleLSPResponse(1, {'id': 3, 'result': v:null}) Assert !g:preview_called AssertEqual {}, ale#references#GetMap() @@ -251,10 +277,10 @@ Execute(LSP reference requests should be sent): " We shouldn't register the callback yet. AssertEqual '''''', string(g:Callback) - AssertEqual type(function('type')), type(g:WaitCallback) - AssertEqual 'references', g:capability_checked - call call(g:WaitCallback, [g:conn_id, '/foo/bar']) + AssertEqual type(function('type')), type(g:InitCallback) + call g:InitCallback() + AssertEqual 'references', g:capability_checked AssertEqual \ 'function(''ale#references#HandleLSPResponse'')', \ string(g:Callback) @@ -270,10 +296,21 @@ Execute(LSP reference requests should be sent): \ }], \ [0, 'textDocument/references', { \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, - \ 'position': {'line': 0, 'character': 3}, + \ 'position': {'line': 0, 'character': 2}, \ 'context': {'includeDeclaration': v:false}, \ }], \ ], \ g:message_list - AssertEqual {'42': {}}, ale#references#GetMap() + AssertEqual {'42': {'use_relative_paths': 0}}, ale#references#GetMap() + +Execute('-relative' argument should enable 'use_relative_paths' in HandleLSPResponse): + runtime ale_linters/python/pyls.vim + let b:ale_linters = ['pyls'] + call setpos('.', [bufnr(''), 1, 5, 0]) + + ALEFindReferences -relative + + call g:InitCallback() + + AssertEqual {'42': {'use_relative_paths': 1}}, ale#references#GetMap() |