Skip to content

Commit 6a141f4

Browse files
committed
refactor!: drop support for AstroNvim v3 internals
1 parent 4175bd9 commit 6a141f4

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

lua/astrolsp/init.lua

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,9 @@ local function event(name)
2020
vim.schedule(function() vim.api.nvim_exec_autocmds("User", { pattern = "AstroLsp" .. name, modeline = false }) end)
2121
end
2222

23-
function M.setup(opts)
24-
M.config = vim.tbl_deep_extend("force", M.config, opts)
25-
26-
M.setup_diagnostics()
27-
28-
M.format_opts = vim.deepcopy(M.config.formatting)
29-
M.format_opts.disabled = nil
30-
M.format_opts.format_on_save = nil
31-
M.format_opts.filter = function(client)
32-
local filter = M.config.formatting.filter
33-
local disabled = M.config.formatting.disabled or {}
34-
-- check if client is fully disabled or filtered by function
35-
return not (vim.tbl_contains(disabled, client.name) or (type(filter) == "function" and not filter(client)))
36-
end
37-
38-
local orig_handler = vim.lsp.handlers["$/progress"]
39-
vim.lsp.handlers["$/progress"] = function(_, msg, info)
40-
local progress, id = M.lsp_progress, ("%s.%s"):format(info.client_id, msg.token)
41-
progress[id] = progress[id] and vim.tbl_deep_extend("force", progress[id], msg.value) or msg.value
42-
if progress[id].kind == "end" then
43-
vim.defer_fn(function()
44-
progress[id] = nil
45-
event "Progress"
46-
end, 100)
47-
end
48-
event "Progress"
49-
orig_handler(_, msg, info)
50-
end
51-
52-
if M.config.features.lsp_handlers then
53-
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded", silent = true })
54-
vim.lsp.handlers["textDocument/signatureHelp"] =
55-
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded", silent = true })
56-
end
57-
end
58-
5923
M.diagnostics = { [0] = {}, {}, {}, {} }
6024

61-
function M.setup_diagnostics()
25+
local function setup_diagnostics()
6226
for _, sign in ipairs(M.config.diagnostics.signs.active) do
6327
vim.fn.sign_define(sign.name, sign)
6428
end
@@ -83,10 +47,6 @@ end
8347
--- Helper function to set up a given server with the Neovim LSP client
8448
---@param server string The name of the server to be setup
8549
function M.lsp_setup(server)
86-
-- HACK: add astronvim interoperability, remove after AstroNvim v4
87-
if type(astronvim) == "table" and type(astronvim.lsp) == "table" and type(astronvim.lsp.skip_setup) == "table" then
88-
if vim.tbl_contains(astronvim.lsp.skip_setup, server) then return end
89-
end
9050
-- if server doesn't exist, set it up from user server definition
9151
local config_avail, config = pcall(require, "lspconfig.server_configurations." .. server)
9252
if not config_avail or not config.default_config then
@@ -126,6 +86,7 @@ local function del_buffer_autocmd(augroup, bufnr)
12686
end
12787

12888
local function has_capability(capability, filter)
89+
-- TODO: remove check after dropping support for Neovim v0.9
12990
for _, client in ipairs((vim.lsp.get_clients or vim.lsp.get_active_clients)(filter)) do
13091
if client.supports_method(capability) then return true end
13192
end
@@ -248,6 +209,7 @@ M.on_attach = function(client, bufnr)
248209
end
249210

250211
for id, _ in pairs(M.lsp_progress) do -- clear lingering progress messages
212+
-- TODO: remove check after dropping support for Neovim v0.9
251213
if not next((vim.lsp.get_clients or vim.lsp.get_active_clients) { id = tonumber(id:match "^%d+") }) then
252214
M.lsp_progress[id] = nil
253215
end
@@ -267,10 +229,6 @@ function M.lsp_opts(server_name)
267229
vim.tbl_deep_extend("force", server.document_config.default_config, server),
268230
{ capabilities = M.config.capabilities, flags = M.config.flags }
269231
)
270-
-- HACK: add astronvim interoperability, remove after AstroNvim v4
271-
if type(astronvim) == "table" and type(astronvim.user_opts) == "function" then
272-
opts = astronvim.user_opts("lsp.config." .. server_name, opts)
273-
end
274232
if M.config.config[server_name] then opts = vim.tbl_deep_extend("force", opts, M.config.config[server_name]) end
275233
assert(opts)
276234

@@ -284,4 +242,43 @@ function M.lsp_opts(server_name)
284242
return opts
285243
end
286244

245+
--- Setup and configure AstroLSP
246+
---@param opts table options passed by the user to configure AstroLSP
247+
-- @see astrolsp.config
248+
function M.setup(opts)
249+
M.config = vim.tbl_deep_extend("force", M.config, opts)
250+
251+
setup_diagnostics()
252+
253+
M.format_opts = vim.deepcopy(M.config.formatting)
254+
M.format_opts.disabled = nil
255+
M.format_opts.format_on_save = nil
256+
M.format_opts.filter = function(client)
257+
local filter = M.config.formatting.filter
258+
local disabled = M.config.formatting.disabled or {}
259+
-- check if client is fully disabled or filtered by function
260+
return not (vim.tbl_contains(disabled, client.name) or (type(filter) == "function" and not filter(client)))
261+
end
262+
263+
local orig_handler = vim.lsp.handlers["$/progress"]
264+
vim.lsp.handlers["$/progress"] = function(_, msg, info)
265+
local progress, id = M.lsp_progress, ("%s.%s"):format(info.client_id, msg.token)
266+
progress[id] = progress[id] and vim.tbl_deep_extend("force", progress[id], msg.value) or msg.value
267+
if progress[id].kind == "end" then
268+
vim.defer_fn(function()
269+
progress[id] = nil
270+
event "Progress"
271+
end, 100)
272+
end
273+
event "Progress"
274+
orig_handler(_, msg, info)
275+
end
276+
277+
if M.config.features.lsp_handlers then
278+
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded", silent = true })
279+
vim.lsp.handlers["textDocument/signatureHelp"] =
280+
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded", silent = true })
281+
end
282+
end
283+
287284
return M

0 commit comments

Comments
 (0)