local mason_lsps = { -- LSPs "json-lsp", "lua_ls", "ruby_lsp", "rubocop", "rust_analyzer", "terraformls", -- Formatters "fixjson", "goimports", "hclfmt", "prettierd", "shellharden", "stylua", "yamlfix", } local non_mason_lsps = { "sourcekit", } return { { "WhoIsSethDaniel/mason-tool-installer.nvim", dependencies = { "mason-org/mason-lspconfig.nvim", }, opts = { ensure_installed = mason_lsps, }, }, { "mason-org/mason-lspconfig.nvim", opts = { ensure_installed = {}, automatic_enable = true, automatic_installation = false, }, dependencies = { { "mason-org/mason.nvim", opts = {} }, "neovim/nvim-lspconfig", }, }, { "neovim/nvim-lspconfig", dependencies = { "mason-org/mason.nvim", "mason-org/mason-lspconfig.nvim", "WhoIsSethDaniel/mason-tool-installer.nvim", { "j-hui/fidget.nvim", opts = {} }, "saghen/blink.cmp", }, config = function() for _, server in ipairs(non_mason_lsps) do vim.lsp.enable(server) end vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }), callback = function(event) local map = function(keys, func, desc, mode) vim.keymap.set( mode or "n", "" .. keys, func, { buffer = event.buf, desc = "[l]sp: " .. desc } ) end map("la", vim.lsp.buf.code_action, "[a]ctions", { "n", "x" }) map("lgr", require("telescope.builtin").lsp_references, "[g]oto [r]eferences") map("lgi", require("telescope.builtin").lsp_implementations, "[g]oto [i]mplementation") map("lgf", require("telescope.builtin").lsp_definitions, "[g]oto de[f]inition") map("lgd", vim.lsp.buf.declaration, "[g]oto [d]eclaration") map("lgt", require("telescope.builtin").lsp_type_definitions, "[g]oto [t]ype definition") map("lr", vim.lsp.buf.rename, "[r]ename") map("lsb", require("telescope.builtin").lsp_document_symbols, "[s]ymbols in [b]uffer") map("lsw", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[s]ymbols in [w]orkspace") local client = vim.lsp.get_client_by_id(event.data.client_id) local augroup = vim.api.nvim_create_augroup local autocmd = vim.api.nvim_create_autocmd if not client then return end if client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then local highlight_augroup = augroup("kickstart-lsp-highlight", { clear = false }) autocmd({ "CursorHold", "CursorHoldI" }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) autocmd({ "CursorMoved", "CursorMovedI" }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) autocmd("LspDetach", { group = augroup("kickstart-lsp-detach", { clear = true }), callback = function(event2) vim.lsp.buf.clear_references() vim.api.nvim_clear_autocmds({ group = "kickstart-lsp-highlight", buffer = event2.buf, }) end, }) end if client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then map("th", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) end, "[T]oggle Inlay [H]ints") end end, }) vim.diagnostic.config({ severity_sort = true, float = { border = "rounded", source = "if_many" }, underline = { severity = vim.diagnostic.severity.ERROR }, signs = vim.g.have_nerd_font and { text = { [vim.diagnostic.severity.ERROR] = "󰅚 ", [vim.diagnostic.severity.WARN] = "󰀪 ", [vim.diagnostic.severity.INFO] = "󰋽 ", [vim.diagnostic.severity.HINT] = "󰌶 ", }, } or {}, virtual_text = { source = "if_many", spacing = 2, format = function(diagnostic) local diagnostic_message = { [vim.diagnostic.severity.ERROR] = diagnostic.message, [vim.diagnostic.severity.WARN] = diagnostic.message, [vim.diagnostic.severity.INFO] = diagnostic.message, [vim.diagnostic.severity.HINT] = diagnostic.message, } return diagnostic_message[diagnostic.severity] end, }, }) end, }, }