-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathlsp-utils.lua
More file actions
25 lines (19 loc) · 656 Bytes
/
lsp-utils.lua
File metadata and controls
25 lines (19 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
local M = {}
---Wait for LSP client to attach
---@param name string LSP client name
---@param timeout? number Timeout in milliseconds (defaults to 30000)
---@return vim.lsp.Client client The attached LSP client
function M.wait_for_lsp_attach(name, timeout)
timeout = timeout or 30000
local is_attached = function()
local clients = vim.lsp.get_clients({ name = name })
return #clients > 0
end
local success = vim.wait(timeout, is_attached, 100)
if not success then
error(string.format('LSP client "%s" failed to attach within %dms', name, timeout))
end
local clients = vim.lsp.get_clients({ name = name })
return clients[1]
end
return M