All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 Save g:ale_completion_delay
3 Save g:ale_completion_enabled
4 Save g:ale_completion_max_suggestions
5 Save g:ale_completion_info
6 Save g:ale_completion_autoimport
10 let g:ale_completion_enabled = v:true
11 let g:ale_completion_autoimport = v:true
13 call ale#test#SetDirectory('/testplugin/test/completion')
14 call ale#test#SetFilename('dummy.txt')
16 runtime autoload/ale/lsp.vim
18 let g:message_list = []
19 let g:capability_checked = ''
20 let g:conn_id = v:null
22 let g:init_callback_list = []
24 function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
25 let g:conn_id = ale#lsp#Register('executable', '/foo/bar', '', {})
26 call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
29 \ 'command': 'foobar',
31 \ 'connection_id': g:conn_id,
32 \ 'project_root': '/foo/bar',
35 call add(g:init_callback_list, {-> a:Callback(a:linter, l:details)})
38 " Pretend we're in insert mode for most tests.
39 function! ale#util#Mode(...) abort
43 function! ale#lsp#HasCapability(conn_id, capability) abort
44 let g:capability_checked = a:capability
49 function! ale#lsp#RegisterCallback(conn_id, callback) abort
50 let g:Callback = a:callback
53 " Replace the Send function for LSP, so we can monitor calls to it.
54 function! ale#lsp#Send(conn_id, message) abort
55 call add(g:message_list, a:message)
63 if g:conn_id isnot v:null
64 call ale#lsp#RemoveConnectionWithID(g:conn_id)
68 unlet! g:capability_checked
69 unlet! g:init_callback_list
72 unlet! b:ale_old_omnifunc
73 unlet! b:ale_old_completeopt
74 unlet! b:ale_completion_info
75 unlet! b:ale_complete_done_time
77 unlet! b:ale_tsserver_completion_names
80 function! ale#util#Mode(...) abort
81 return call('mode', a:000)
84 call ale#test#RestoreDirectory()
85 call ale#linter#Reset()
87 " Stop any timers we left behind.
88 " This stops the tests from failing randomly.
89 call ale#completion#StopTimer()
91 runtime autoload/ale/completion.vim
92 runtime autoload/ale/lsp.vim
93 runtime autoload/ale/lsp_linter.vim
95 Given typescript(Some typescript file):
100 Execute(The right message should be sent for the initial tsserver request):
101 runtime ale_linters/typescript/tsserver.vim
102 let b:ale_linters = ['tsserver']
103 " The cursor position needs to match what was saved before.
104 call setpos('.', [bufnr(''), 1, 3, 0])
106 call ale#completion#GetCompletions('ale-automatic')
108 " We shouldn't register the callback yet.
109 AssertEqual '''''', string(g:Callback)
111 AssertEqual 1, len(g:init_callback_list)
112 call map(g:init_callback_list, 'v:val()')
114 AssertEqual 'completion', g:capability_checked
116 " We should send the right callback.
118 \ 'function(''ale#completion#HandleTSServerResponse'')',
120 " We should send the right message.
122 \ [[0, 'ts@completions', {
123 \ 'file': expand('%:p'),
127 \ 'includeExternalModuleExports': g:ale_completion_autoimport,
130 " We should set up the completion info correctly.
134 \ 'conn_id': g:conn_id,
139 \ 'source': 'ale-automatic',
141 \ get(b:, 'ale_completion_info', {})
143 Execute(The right message sent to the tsserver LSP when the first completion message is received):
144 " The cursor position needs to match what was saved before.
145 call setpos('.', [bufnr(''), 1, 1, 0])
146 let b:ale_completion_info = {
153 " We should only show up to this many suggestions.
154 let g:ale_completion_max_suggestions = 3
156 " Handle the response for completions.
157 call ale#completion#HandleTSServerResponse(123, {
159 \ 'command': 'completions',
162 \ {'name': 'dingDong'},
163 \ {'name': 'Foo', 'source': '/path/to/foo.ts'},
164 \ {'name': 'FooBar'},
165 \ {'name': 'frazzle'},
170 " We should save the names we got in the buffer, as TSServer doesn't return
171 " details for every name.
174 \ 'source': '/path/to/foo.ts',
182 \ get(b:, 'ale_tsserver_completion_names', [])
184 " The entry details messages should have been sent.
188 \ 'ts@completionEntryDetails',
190 \ 'file': expand('%:p'),
193 \ 'source': '/path/to/foo.ts',
205 Given python(Some Python file):
210 Execute(The right message should be sent for the initial LSP request):
211 runtime ale_linters/python/pylsp.vim
212 let b:ale_linters = ['pylsp']
213 " The cursor position needs to match what was saved before.
214 call setpos('.', [bufnr(''), 1, 5, 0])
216 call ale#completion#GetCompletions('ale-automatic')
218 " We shouldn't register the callback yet.
219 AssertEqual '''''', string(g:Callback)
221 AssertEqual 1, len(g:init_callback_list)
222 call map(g:init_callback_list, 'v:val()')
224 AssertEqual 'completion', g:capability_checked
226 " We should send the right callback.
228 \ 'function(''ale#completion#HandleLSPResponse'')',
230 " We should send the right message.
231 " The character index needs to be at most the index of the last character on
232 " the line, or integration with pylsp will be broken.
234 " We need to send the message for changing the document first.
237 \ [1, 'textDocument/didChange', {
239 \ 'uri': ale#path#ToFileURI(expand('%:p')),
240 \ 'version': g:ale_lsp_next_version_id - 1,
242 \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}]
244 \ [0, 'textDocument/completion', {
245 \ 'textDocument': {'uri': ale#path#ToFileURI(expand('%:p'))},
246 \ 'position': {'line': 0, 'character': 2},
250 " We should set up the completion info correctly.
254 \ 'conn_id': g:conn_id,
259 \ 'source': 'ale-automatic',
260 \ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
262 \ get(b:, 'ale_completion_info', {})
264 Execute(Two completion requests shouldn't be sent in a row):
265 call ale#linter#PreventLoading('python')
266 call ale#linter#Define('python', {
269 \ 'executable': 'foo',
271 \ 'project_root': {-> '/foo/bar'},
273 call ale#linter#Define('python', {
276 \ 'executable': 'foo',
278 \ 'project_root': {-> '/foo/bar'},
280 let b:ale_linters = ['foo', 'bar']
282 " The cursor position needs to match what was saved before.
283 call setpos('.', [bufnr(''), 1, 5, 0])
285 call ale#completion#GetCompletions('ale-automatic')
287 " We shouldn't register the callback yet.
288 AssertEqual '''''', string(g:Callback)
290 AssertEqual 2, len(g:init_callback_list)
291 call map(g:init_callback_list, 'v:val()')
293 AssertEqual 'completion', g:capability_checked
295 " We should only send one completion message for two LSP servers.
298 \ [1, 'textDocument/didChange', {
300 \ 'uri': ale#path#ToFileURI(expand('%:p')),
301 \ 'version': g:ale_lsp_next_version_id - 1,
303 \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}]
305 \ [0, 'textDocument/completion', {
306 \ 'textDocument': {'uri': ale#path#ToFileURI(expand('%:p'))},
307 \ 'position': {'line': 0, 'character': 2},