return { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, opts = { servers = { clangd = {}, gdscript = {}, gopls = {}, lua_ls = { settings = { Lua = { completion = { callSnippet = "Replace", }, runtime = { version = "LuaJIT", }, workspace = { checkThirdParty = false, library = { "${3rd}/luv/library", unpack(vim.api.nvim_get_runtime_file("", true)), }, }, }, }, }, rust_analyzer = { settings = { ["rust-analyzer"] = { imports = { granularity = { group = "module", }, prefix = "self", }, cargo = { buildScripts = { enable = true, }, }, procMacro = { enable = true }, }, }, }, }, }, config = function(_, opts) -- Servers local servers = opts.servers for server, server_opts in pairs(servers) do require("lspconfig")[server].setup(server_opts) end -- Icons local icons = { Error = " ", Warn = " ", Hint = " ", Info = " ", } for name, icon in pairs(icons) do name = "DiagnosticSign" .. name vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) end -- Runs when the LSP is attached vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), callback = function(event) local function map(mode, lhs, rhs, info) vim.keymap.set(mode, lhs, rhs, { buffer = event.buf, desc = "LSP: " .. info }) end map("n", "gr", require("telescope.builtin").lsp_references, "References") map("n", "gd", require("telescope.builtin").lsp_definitions, "Definition") map({ "n", "i" }, "", vim.lsp.buf.hover, "Hover") map({ "n", "i" }, "", vim.lsp.buf.rename, "Rename") map({ "n", "i" }, "", vim.lsp.buf.format, "Format") map("n", "ca", vim.lsp.buf.code_action, "Code action") -- Highlight the word your cursor is on -- local client = vim.lsp.get_client_by_id(event.data.client_id) -- -- if client and client.server_capabilities.documentHighlightProvider then -- vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { -- buffer = event.buf, -- callback = vim.lsp.buf.document_highlight, -- }) -- -- vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { -- buffer = event.buf, -- callback = vim.lsp.buf.clear_references, -- }) -- end end, }) end, }