local uv = vim.uv
local api = vim.api
local lsp = vim.lsp
local log = lsp.log
local changetracking = lsp._changetracking
local validate = vim.validate
--- Tracks all clients initialized.
---@type table<integer,vim.lsp.Client>
local all_clients = {}
---@param provider string
---@param capability string[]?
local function is_nested_server_capability_provider(provider, capability)
return capability ~= nil and #capability > 1 and provider == table.concat(capability, '.')
end
--- @alias vim.lsp.client.on_init_cb fun(client: vim.lsp.Client, init_result: lsp.InitializeResult)
--- @alias vim.lsp.client.on_attach_cb fun(client: vim.lsp.Client, bufnr: integer)
--- @alias vim.lsp.client.on_exit_cb fun(code: integer, signal: integer, client_id: integer)
--- @alias vim.lsp.client.before_init_cb fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)
--- @class vim.lsp.Client.Flags
--- @inlinedoc
---
--- Allow using incremental sync for buffer edits
--- (default: `true`)
--- @field allow_incremental_sync? boolean
---
--- Debounce `didChange` notifications to the server by the given number in milliseconds.
--- (default: `150`)
--- @field debounce_text_changes? integer
--- @class vim.lsp.ClientConfig
---
--- Callback which can modify parameters before they are sent to the server. Invoked before LSP
--- "initialize" phase (after `cmd` is invoked), where `params` is the parameters being sent to the
--- server and `config` is the config passed to |vim.lsp.start()|.
---
--- Hint: use |vim.tbl_deep_extend()| to set nested fields easily.
--- ```lua
--- before_init = function(_, config)
--- config.settings = vim.tbl_deep_extend('force',
--- config.settings,
--- { tailwindCSS = { experimental = { configFile = find_tailwind_global_css() } } }
--- )
--- end
--- ```
--- @field before_init? fun(params: lsp.InitializeParams, config: vim.lsp.ClientConfig)
---
--- Map overriding the default capabilities defined by |vim.lsp.protocol.make_client_capabilities()|,
--- passed to the language server on initialization. Hint: use make_client_capabilities() and modify
--- its result.
--- - Note: To send an empty dictionary use |vim.empty_dict()|, else it will be encoded as an
--- array.
--- @field capabilities? lsp.ClientCapabilities
---
--- Command `string[]` that launches the language server (treated as in |jobstart()|, must be
--- absolute or on `$PATH`, shell constructs like "~" are not expanded), or function that creates an
--- RPC client (or an in-process |lsp-server|). Function receives a `dispatchers` table and the
--- resolved `config`, and must return an object in the form of |vim.lsp.rpc.Client|.
---
--- Example (list):
--- ```lua
--- cmd = { 'flow', 'lsp' }
--- ```
--- Example (function):
--- ```lua
--- cmd = function(dispatchers, config)
--- local cmd = vim.fn.executable('flow') == 1 and { 'flow', 'lsp' } or { 'npx', '--no-install', 'flow', 'lsp' }
|