From 50fc25b88fb28829ec7f5e5a4d4b458fca21a550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Modzelewski?= Date: Wed, 22 Mar 2023 08:28:19 +0100 Subject: [PATCH] Look for externally started LCP server (#105) --- lua/zk/lsp.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lua/zk/lsp.lua b/lua/zk/lsp.lua index 9da89c7..1004226 100644 --- a/lua/zk/lsp.lua +++ b/lua/zk/lsp.lua @@ -4,8 +4,34 @@ local client_id = nil local M = {} +---Tries to find a client by name +function M.external_client() + local client_name = config.options.lsp.config.name + if not client_name then + client_name = "zk" + end + + local active_clients = vim.lsp.get_active_clients({name=client_name}) + + if active_clients == {} then + return nil + end + + -- return first lsp server that is actually in use + for _,v in ipairs(active_clients) do + if v.attached_buffers ~= {} then + return v.id + end + end +end + + ---Starts an LSP client if necessary function M.start() + if not client_id then + client_id = M.external_client() + end + if not client_id then client_id = vim.lsp.start_client(config.options.lsp.config) end