From 2f239a5216b184ce9a9fb6c73cae18bbf3c578ef Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 9 Jun 2024 13:58:39 +0200 Subject: [PATCH] fix(lsp): make sure `client.handlers` is unique for each client. Fixes #29 --- lua/lazydev/lsp.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lua/lazydev/lsp.lua b/lua/lazydev/lsp.lua index 46166e9..6fbbfe1 100644 --- a/lua/lazydev/lsp.lua +++ b/lua/lazydev/lsp.lua @@ -3,14 +3,29 @@ local Workspace = require("lazydev.workspace") local M = {} M.attached = {} ---@type table +function M.assert(client) + assert(client and client.name == "lua_ls", "lazydev: Not a lua_ls client??") +end + ---@param client vim.lsp.Client function M.attach(client) if M.attached[client.id] then return end + + M.assert(client) + M.attached[client.id] = client.id + + -- lspconfig uses the same empty table for all clients. + -- We need to make sure that each client has its own handlers table. + client.handlers = vim.tbl_extend("force", {}, client.handlers or {}) + ---@param params lsp.ConfigurationParams client.handlers["workspace/configuration"] = function(err, params, ctx, cfg) + local c = vim.lsp.get_client_by_id(ctx.client_id) + assert(c == client, "lazydev: Invalid client " .. (c and c.name or "unknown")) + M.assert(c) if not params.items or #params.items == 0 then return {} end @@ -50,6 +65,7 @@ end ---@param client vim.lsp.Client function M.update(client) + M.assert(client) client.notify("workspace/didChangeConfiguration", { settings = { Lua = {} }, })