76 lines
1.9 KiB
Lua
76 lines
1.9 KiB
Lua
-- Get all LSP servers to configure
|
|
local function get_all_servers()
|
|
local servers = {}
|
|
|
|
-- Auto-detect LSP servers installed by Mason using mason-lspconfig
|
|
local ok, mason_lspconfig = pcall(require, "mason-lspconfig")
|
|
if ok then
|
|
local installed_servers = mason_lspconfig.get_installed_servers()
|
|
for _, server in ipairs(installed_servers) do
|
|
servers[server] = true
|
|
end
|
|
end
|
|
|
|
-- If no servers detected, fall back to common servers that might be system-installed
|
|
if vim.tbl_isempty(servers) then
|
|
local fallback_servers = {
|
|
"lua_ls",
|
|
}
|
|
for _, server in pairs(fallback_servers) do
|
|
servers[server] = true
|
|
end
|
|
end
|
|
|
|
return servers
|
|
end
|
|
|
|
-- Configure a single LSP server
|
|
local function configure_server(server, lspconfig, capabilities)
|
|
local ok, settings = pcall(require, "lsp." .. server)
|
|
if ok then
|
|
if lspconfig then
|
|
settings.capabilities = capabilities
|
|
lspconfig[server].setup(settings)
|
|
else
|
|
vim.lsp.config(server, settings)
|
|
vim.lsp.enable(server)
|
|
end
|
|
else
|
|
if lspconfig then
|
|
lspconfig[server].setup({ capabilities = capabilities })
|
|
else
|
|
vim.lsp.config(server, {})
|
|
vim.lsp.enable(server)
|
|
end
|
|
end
|
|
end
|
|
|
|
if require("commons").tools.is_version_gte_0_11() then
|
|
-- Neovim 0.11+ native LSP configuration
|
|
vim.lsp.config("*", {
|
|
capabilities = require("blink.cmp").get_lsp_capabilities(),
|
|
root_markers = { ".git" },
|
|
})
|
|
|
|
-- Configure all servers
|
|
for server in pairs(get_all_servers()) do
|
|
configure_server(server)
|
|
end
|
|
|
|
vim.diagnostic.config({
|
|
update_in_insert = true,
|
|
severity_sort = true,
|
|
float = { source = true },
|
|
virtual_text = true,
|
|
})
|
|
else
|
|
-- Legacy nvim-lspconfig setup for Neovim < 0.11
|
|
local lspconfig = require("lspconfig")
|
|
local capabilities = require("blink.cmp").get_lsp_capabilities()
|
|
|
|
-- Configure all servers
|
|
for server in pairs(get_all_servers()) do
|
|
configure_server(server, lspconfig, capabilities)
|
|
end
|
|
end
|