Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: use get_clients() instead of get_active_clients() #47

Closed
wants to merge 10 commits into from
7 changes: 3 additions & 4 deletions lua/yaml-companion/context/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ M.schema = function(bufnr, new_schema)

local bufuri = vim.uri_from_bufnr(bufnr)
local client = M.ctxs[bufnr].client
local settings = client.config.settings
local settings = client.settings

-- we don't want more than 1 schema per file
for key, _ in pairs(settings.yaml.schemas) do
Expand All @@ -165,9 +165,8 @@ M.schema = function(bufnr, new_schema)
log.fmt_debug("file=%s schema=%s set new override", bufuri, new_schema.uri)

settings = vim.tbl_deep_extend("force", settings, { yaml = { schemas = override } })
client.config.settings =
vim.tbl_deep_extend("force", settings, { yaml = { schemas = override } })
client.workspace_did_change_configuration(client.config.settings)
client.settings = vim.tbl_deep_extend("force", settings, { yaml = { schemas = override } })
client.workspace_did_change_configuration(client.settings)
end

return M.ctxs[bufnr].schema
Expand Down
4 changes: 3 additions & 1 deletion lua/yaml-companion/lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ local sync_timeout = 5000
---@param bufnr number
---@return vim.lsp.client | nil
M.get_client = function(bufnr)
return vim.lsp.get_active_clients({ name = "yamlls", bufnr = bufnr })[1]
---@diagnostic disable-next-line: deprecated
local get_clients = vim.lsp.get_clients and vim.lsp.get_clients or vim.lsp.get_active_clients
return get_clients({ name = "yamlls", bufnr = bufnr })[1]
end

---@param bufnr number
Expand Down
10 changes: 7 additions & 3 deletions tests/schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ local function buf(input, ft, name)
vim.api.nvim_command("buffer " .. b)
vim.api.nvim_buf_set_lines(b, 0, -1, true, vim.split(input, "\n"))
return wait_until(function()
local clients = vim.lsp.get_active_clients()
---@diagnostic disable-next-line: deprecated
local get_clients = vim.lsp.get_clients and vim.lsp.get_clients or vim.lsp.get_active_clients
local clients = get_clients()
if #clients > 0 then
return true
end
Expand All @@ -40,11 +42,13 @@ describe("user defined schemas:", function()
vim.api.nvim_buf_delete(0, { force = true })
vim.fn.delete("foo.yaml", "rf")
assert(wait_until(function()
local clients = vim.lsp.get_active_clients()
---@diagnostic disable-next-line: deprecated
local get_clients = vim.lsp.get_clients and vim.lsp.get_clients or vim.lsp.get_active_clients
local clients = get_clients()
if #clients == 0 then
return true
end
vim.lsp.stop_client(vim.lsp.get_active_clients(), true)
vim.lsp.stop_client(get_clients(), true)
end))
end)

Expand Down
4 changes: 3 additions & 1 deletion tests/yaml-companion_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ local function buf(input, ft, name)
vim.api.nvim_command("buffer " .. b)
vim.api.nvim_buf_set_lines(b, 0, -1, true, vim.split(input, "\n"))
return wait_until(function()
local clients = vim.lsp.get_active_clients()
---@diagnostic disable-next-line: deprecated
local get_clients = vim.lsp.get_clients and vim.lsp.get_clients or vim.lsp.get_active_clients
local clients = get_clients()
if #clients > 0 then
return true
end
Expand Down
Loading