local mylsp = require("lsp") local servers = { clangd = {}, cssls = {}, html = {}, jsonls = {}, ts_ls = {}, taplo = {}, yamlls = {}, bashls = {}, fish_lsp = {}, pyright = {}, lua_ls = {}, gopls = {}, -- -- fix this, it shows spamming message on top -- golangci_lint_ls = {}, tinymist = {}, nil_ls = { settings = { ["nil"] = { formatting = { command = { "alejandra" } } }, }, }, } vim.diagnostic.config { signs = { text = { [vim.diagnostic.severity.ERROR] = "E", [vim.diagnostic.severity.WARN] = "W", [vim.diagnostic.severity.INFO] = "I", [vim.diagnostic.severity.HINT] = "H", }, }, severity_sort = true, underline = { severity = { vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN, }, }, } do local index = 1 ---@type vim.diagnostic.Opts[] local modes = { { virtual_lines = false, }, { virtual_lines = { severity = { vim.diagnostic.severity.ERROR }, current_line = true }, }, { virtual_lines = { severity = { vim.diagnostic.severity.ERROR }, current_line = false }, }, } vim.diagnostic.config(modes[index]) ---@param direction 'forward' | 'backward' local function cycle_diagnostic_modes(direction) if direction == "forward" then index = (index % #modes) + 1 else index = (index - 2 + #modes) % #modes + 1 end vim.diagnostic.config(modes[index]) end vim.keymap.set("n", "]d", function() cycle_diagnostic_modes("forward") end) vim.keymap.set("n", "[d", function() cycle_diagnostic_modes("backward") end) end -- Helix style border local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview ---@diagnostic disable-next-line: duplicate-set-field function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) opts = opts or {} opts.border = mylsp.border return orig_util_open_floating_preview(contents, syntax, opts, ...) end -- Set log level vim.lsp.set_log_level("off") -- It is not recommended to break lspconfig into different settings -- related: https://github.com/neovim/nvim-lspconfig/issues/970#issuecomment-860080502 for name, user_config in pairs(servers) do if next(user_config) ~= nil then local default_config = { capabilities = mylsp.capabilities, settings = user_config, on_attach = function(client, bufno) mylsp.on_attach(client, bufno) end, } local merged_config = vim.tbl_deep_extend("force", default_config, user_config) vim.lsp.config(name, merged_config) end vim.lsp.enable(name) end