@@ -6,6 +6,7 @@ describe("ale.lsp.start", function()
66 local rpc_connect_calls
77 local vim_fn_calls
88 local defer_calls
9+ local nvim_default_capabilities
910
1011 setup (function ()
1112 _G .vim = {
@@ -21,7 +22,7 @@ describe("ale.lsp.start", function()
2122 return " python"
2223 end
2324
24- if key ~= " ale#lsp_linter#HandleLSPResponse "
25+ if key ~= " ale#lsp_linter#HandleLSPDiagnostics "
2526 and key ~= " ale#lsp#UpdateCapabilities"
2627 and key ~= " ale#lsp#CallInitCallbacks"
2728 then
@@ -49,6 +50,11 @@ describe("ale.lsp.start", function()
4950
5051 return 42
5152 end ,
53+ protocol = {
54+ make_client_capabilities = function ()
55+ return nvim_default_capabilities
56+ end ,
57+ },
5258 },
5359 }
5460 end )
@@ -62,6 +68,9 @@ describe("ale.lsp.start", function()
6268 rpc_connect_calls = {}
6369 vim_fn_calls = {}
6470 defer_calls = {}
71+ nvim_default_capabilities = {
72+ textDocument = {},
73+ }
6574 end )
6675
6776 it (" should start lsp programs with the correct arguments" , function ()
@@ -148,6 +157,24 @@ describe("ale.lsp.start", function()
148157 eq ({{" ale#lsp#GetLanguage" , " server:/code" , 347 }}, vim_fn_calls )
149158 end )
150159
160+ it (" should enable dynamicRegistration for the pull model" , function ()
161+ nvim_default_capabilities = {textDocument = {diagnostic = {}}}
162+
163+ lsp .start ({name = " server:/code" })
164+ eq (1 , # start_calls )
165+
166+ eq (
167+ {
168+ textDocument = {
169+ diagnostic = {
170+ dynamicRegistration = true ,
171+ },
172+ },
173+ },
174+ start_calls [1 ][1 ].capabilities
175+ )
176+ end )
177+
151178 it (" should initialize clients with ALE correctly" , function ()
152179 lsp .start ({name = " server:/code" })
153180
@@ -185,39 +212,150 @@ describe("ale.lsp.start", function()
185212 handler_names [key ] = true
186213 end
187214
188- eq ({[" textDocument/publishDiagnostics" ] = true }, handler_names )
215+ eq ({
216+ [" textDocument/publishDiagnostics" ] = true ,
217+ [" textDocument/diagnostic" ] = true ,
218+ [" workspace/diagnostic/refresh" ] = true ,
219+ }, handler_names )
220+ end )
221+
222+ it (" should handle push model published diagnostics" , function ()
223+ lsp .start ({name = " server:/code" })
224+
225+ eq (1 , # start_calls )
226+
227+ local handlers = start_calls [1 ][1 ].handlers
228+
229+ eq (" function" , type (handlers [" textDocument/publishDiagnostics" ]))
189230
190231 handlers [" textDocument/publishDiagnostics" ](nil , {
191- {
192- lnum = 1 ,
193- end_lnum = 2 ,
194- col = 3 ,
195- end_col = 5 ,
196- severity = 1 ,
197- code = " 123" ,
198- message = " Warning message" ,
232+ uri = " file://code/foo.py" ,
233+ diagnostics = {
234+ {
235+ lnum = 1 ,
236+ end_lnum = 2 ,
237+ col = 3 ,
238+ end_col = 5 ,
239+ severity = 1 ,
240+ code = " 123" ,
241+ message = " Warning message" ,
242+ }
199243 },
200244 })
201245
202246 eq ({
203247 {
204- " ale#lsp_linter#HandleLSPResponse " ,
248+ " ale#lsp_linter#HandleLSPDiagnostics " ,
205249 " server:/code" ,
250+ " file://code/foo.py" ,
206251 {
207- jsonrpc = " 2.0" ,
208- method = " textDocument/publishDiagnostics" ,
209- params = {
210- {
211- lnum = 1 ,
212- end_lnum = 2 ,
213- col = 3 ,
214- end_col = 5 ,
215- severity = 1 ,
216- code = " 123" ,
217- message = " Warning message" ,
218- },
252+ {
253+ lnum = 1 ,
254+ end_lnum = 2 ,
255+ col = 3 ,
256+ end_col = 5 ,
257+ severity = 1 ,
258+ code = " 123" ,
259+ message = " Warning message" ,
260+ },
261+ },
262+ },
263+ }, vim_fn_calls )
264+ end )
265+
266+ it (" should respond to workspace diagnostic refresh requests" , function ()
267+ lsp .start ({name = " server:/code" })
268+
269+ eq (1 , # start_calls )
270+
271+ local handlers = start_calls [1 ][1 ].handlers
272+
273+ eq (" function" , type (handlers [" workspace/diagnostic/refresh" ]))
274+
275+ eq ({}, handlers [" workspace/diagnostic/refresh" ]())
276+ end )
277+
278+ it (" should handle pull model diagnostics" , function ()
279+ lsp .start ({name = " server:/code" })
280+
281+ eq (1 , # start_calls )
282+
283+ local handlers = start_calls [1 ][1 ].handlers
284+
285+ eq (" function" , type (handlers [" textDocument/diagnostic" ]))
286+
287+ handlers [" textDocument/diagnostic" ](
288+ nil ,
289+ {
290+ kind = " full" ,
291+ items = {
292+ {
293+ lnum = 1 ,
294+ end_lnum = 2 ,
295+ col = 3 ,
296+ end_col = 5 ,
297+ severity = 1 ,
298+ code = " 123" ,
299+ message = " Warning message" ,
219300 }
220- }
301+ },
302+ },
303+ {
304+ params = {
305+ textDocument = {
306+ uri = " file://code/foo.py" ,
307+ },
308+ },
309+ }
310+ )
311+
312+ eq ({
313+ {
314+ " ale#lsp_linter#HandleLSPDiagnostics" ,
315+ " server:/code" ,
316+ " file://code/foo.py" ,
317+ {
318+ {
319+ lnum = 1 ,
320+ end_lnum = 2 ,
321+ col = 3 ,
322+ end_col = 5 ,
323+ severity = 1 ,
324+ code = " 123" ,
325+ message = " Warning message" ,
326+ },
327+ },
328+ },
329+ }, vim_fn_calls )
330+ end )
331+
332+ it (" should handle unchanged pull model diagnostics" , function ()
333+ lsp .start ({name = " server:/code" })
334+
335+ eq (1 , # start_calls )
336+
337+ local handlers = start_calls [1 ][1 ].handlers
338+
339+ eq (" function" , type (handlers [" textDocument/diagnostic" ]))
340+
341+ handlers [" textDocument/diagnostic" ](
342+ nil ,
343+ {kind = " unchanged" },
344+ {
345+ params = {
346+ textDocument = {
347+ uri = " file://code/foo.py" ,
348+ },
349+ },
350+ }
351+ )
352+
353+ eq ({
354+ {
355+ " ale#lsp_linter#HandleLSPDiagnostics" ,
356+ " server:/code" ,
357+ " file://code/foo.py" ,
358+ " unchanged" ,
221359 },
222360 }, vim_fn_calls )
223361 end )
0 commit comments