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.
1 local eq = assert.are.same
2 local lsp = require("ale.lsp")
4 describe("ale.lsp.start", function()
6 local rpc_connect_calls
9 local nvim_default_capabilities
13 defer_fn = function(func, delay)
14 table.insert(defer_calls, {func, delay})
16 fn = setmetatable({}, {
17 __index = function(_, key)
19 table.insert(vim_fn_calls, {key, ...})
21 if key == "ale#lsp#GetLanguage" then
25 if key ~= "ale#lsp_linter#HandleLSPDiagnostics"
26 and key ~= "ale#lsp#UpdateCapabilities"
27 and key ~= "ale#lsp#CallInitCallbacks"
29 assert(false, "Invalid ALE function: " .. key)
38 connect = function(host, port)
39 return function(dispatch)
40 table.insert(rpc_connect_calls, {
49 table.insert(start_calls, {...})
54 make_client_capabilities = function()
55 return nvim_default_capabilities
66 before_each(function()
68 rpc_connect_calls = {}
71 nvim_default_capabilities = {
76 it("should start lsp programs with the correct arguments", function()
78 name = "server:/code",
81 -- This Boolean value somehow ends up in Dictionaries from
82 -- Vim for init_options, and we need to remove it.
83 init_options = {[true] = 123},
86 -- Remove arguments with functions we can't apply equality checks
88 for _, args in pairs(start_calls) do
89 args[1].handlers = nil
91 args[1].get_language_id = nil
98 name = "server:/code",
102 {attach = false, silent = true}
108 it("should start lsp socket connections with the correct arguments", function()
110 name = "localhost:1234:/code",
114 init_options = {foo = "bar"},
119 -- Remove arguments with functions we can't apply equality checks
121 for _, args in pairs(start_calls) do
124 args[1].handlers = nil
125 args[1].on_init = nil
126 args[1].get_language_id = nil
132 name = "localhost:1234:/code",
134 init_options = {foo = "bar"},
136 {attach = false, silent = true}
140 cmd("dispatch_value")
143 {dispatch = "dispatch_value", host = "localhost", port = 1234},
144 }, rpc_connect_calls)
148 it("should return the client_id value from vim.lsp.start", function()
149 eq(42, lsp.start({}))
152 it("should implement get_language_id correctly", function()
153 lsp.start({name = "server:/code"})
156 eq("python", start_calls[1][1].get_language_id(347, "ftype"))
157 eq({{"ale#lsp#GetLanguage", "server:/code", 347}}, vim_fn_calls)
160 it("should enable dynamicRegistration for the pull model", function()
161 nvim_default_capabilities = {textDocument = {diagnostic = {}}}
163 lsp.start({name = "server:/code"})
170 dynamicRegistration = true,
174 start_calls[1][1].capabilities
178 it("should initialize clients with ALE correctly", function()
179 lsp.start({name = "server:/code"})
183 start_calls[1][1].on_init({server_capabilities = {cap = 1}})
186 {"ale#lsp#UpdateCapabilities", "server:/code", {cap = 1}},
189 eq(2, #defer_calls[1])
190 eq("function", type(defer_calls[1][1]))
191 eq(0, defer_calls[1][2])
196 {"ale#lsp#UpdateCapabilities", "server:/code", {cap = 1}},
197 {"ale#lsp#CallInitCallbacks", "server:/code"},
201 it("should configure handlers correctly", function()
202 lsp.start({name = "server:/code"})
206 local handlers = start_calls[1][1].handlers
207 local handler_names = {}
209 -- get keys from handlers
210 for key, _ in pairs(handlers) do
211 -- add key to handler_names mapping
212 handler_names[key] = true
216 ["textDocument/publishDiagnostics"] = true,
217 ["textDocument/diagnostic"] = true,
218 ["workspace/diagnostic/refresh"] = true,
222 it("should handle push model published diagnostics", function()
223 lsp.start({name = "server:/code"})
227 local handlers = start_calls[1][1].handlers
229 eq("function", type(handlers["textDocument/publishDiagnostics"]))
231 handlers["textDocument/publishDiagnostics"](nil, {
232 uri = "file://code/foo.py",
241 message = "Warning message",
248 "ale#lsp_linter#HandleLSPDiagnostics",
250 "file://code/foo.py",
259 message = "Warning message",
266 it("should respond to workspace diagnostic refresh requests", function()
267 lsp.start({name = "server:/code"})
271 local handlers = start_calls[1][1].handlers
273 eq("function", type(handlers["workspace/diagnostic/refresh"]))
275 eq({}, handlers["workspace/diagnostic/refresh"]())
278 it("should handle pull model diagnostics", function()
279 lsp.start({name = "server:/code"})
283 local handlers = start_calls[1][1].handlers
285 eq("function", type(handlers["textDocument/diagnostic"]))
287 handlers["textDocument/diagnostic"](
299 message = "Warning message",
306 uri = "file://code/foo.py",
314 "ale#lsp_linter#HandleLSPDiagnostics",
316 "file://code/foo.py",
325 message = "Warning message",
332 it("should handle unchanged pull model diagnostics", function()
333 lsp.start({name = "server:/code"})
337 local handlers = start_calls[1][1].handlers
339 eq("function", type(handlers["textDocument/diagnostic"]))
341 handlers["textDocument/diagnostic"](
343 {kind = "unchanged"},
347 uri = "file://code/foo.py",
355 "ale#lsp_linter#HandleLSPDiagnostics",
357 "file://code/foo.py",