---@type fun(name: string, cfg: vim.lsp.Config) vim.lsp.config = vim.lsp.config local log = require("log") local M = {} M.diagnostic_signs = { text = { [vim.diagnostic.severity.ERROR] = "E", [vim.diagnostic.severity.WARN] = "W", [vim.diagnostic.severity.INFO] = "I", [vim.diagnostic.severity.HINT] = "H", }, } --- Load a JSON file and return a parsed table merged with settings ---@param path string ---@param settings? table ---@return table? local function with_file(path, settings) local file = io.open(path, "r") if not file then return end local json = file:read("*all") file:close() local ok, resp = pcall( vim.json.decode, json, { luanil = { object = true, array = true } } ) if not ok then log.warning("Failed to parse json file %s: %s", path, resp) return end return vim.tbl_deep_extend("force", settings or {}, resp) end function M.on_attach(client, _) client.settings = with_file( string.format(".%s.json", client.name), client.settings ) or client.settings end function M.setup() vim.diagnostic.config({ underline = true, signs = M.diagnostic_signs, virtual_text = false, float = { show_header = false, source = true, border = "rounded", focusable = true, format = function(diagnostic) return string.format("%s", diagnostic.message) end, width = 80, }, update_in_insert = false, severity_sort = true, jump = { float = true, wrap = false, }, }) vim.lsp.enable({ "bashls", "clangd", "cmake", "gopls", -- "hyprls", "intelephense", -- "jedi_language_server", "lemminx", -- "xml_ls", "lua_ls", "mesonlsp", "oxfmt", "oxlint", -- "phpactor", -- "pyrefly", "pyright", "ruff", "rust_analyzer", "svelte", "tailwindcss", "tsgo", "zls", }) local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = vim.tbl_deep_extend( "force", capabilities, require("blink.cmp").get_lsp_capabilities({ textDocument = { completion = { completionItem = { snippetSupport = false, }, }, }, }, false) ) vim.lsp.config("*", { capabilities = capabilities, on_attach = M.on_attach, }) vim.lsp.log.set_level(vim.log.levels.WARN) end return M