From a0856863c1686f7b2d8ec3bd7c2f0c056dc7b615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Mizio?= Date: Tue, 9 Jan 2024 13:38:02 +0100 Subject: [PATCH] fix: `on_attach` called multiple times with `separate_diagnostic_server` --- lua/typescript-tools/init.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/typescript-tools/init.lua b/lua/typescript-tools/init.lua index 0b7108af..6558aa47 100644 --- a/lua/typescript-tools/init.lua +++ b/lua/typescript-tools/init.lua @@ -44,6 +44,26 @@ function M.setup(config) } end + -- INFO: some nasty ifology but it need to be placed somewhere + -- I prefer it here than in huge file tsserver.lua + -- Rationale: `on_attach` is called based on response from `configure` request and because we + -- have two servers nvim get also two responses + local on_attach_called = false + local config_on_attach = config.on_attach + + local function on_attach(...) + if on_attach_called then + return + end + + on_attach_called = true + config_on_attach(...) + end + + if config.on_attach then + config.on_attach = on_attach + end + lspconfig[plugin_config.plugin_name].setup(config) end