local M = { "neovim/nvim-lspconfig", dependencies = { { "folke/lazydev.nvim", ft = "lua", opts = { library = { { path = "${3rd}/luv/library", words = { "vim%.uv" } }, }, }, }, { "j-hui/fidget.nvim", opts = {}, }, { "ray-x/go.nvim", ft = "go", config = function(_, opts) require("go").setup(opts) vim.keymap.set("n", "gmt", ":GoModTidy", { desc = "[Go] Tidy", }) end, build = function() vim.cmd([[silent! GoModTidy]]) end, }, }, } function M.config() local lspconfig = require("lspconfig") vim.lsp.enable({ "tsgo" }) local servers = { "gopls", "jsonls", "clangd", "lua_ls", "yamlls", "graphql", "html", "cssls", "omnisharp", "svelte", "templ", "tinymist", "jdtls", "nixd", "qmlls", "zls", } for _, server in ipairs(servers) do lspconfig[server].setup({}) end vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("lsp", { clear = true }), callback = function(ev) local opts = { buffer = ev.buf, silent = true } local client = vim.lsp.get_client_by_id(ev.data.client_id) nmap("K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover Doc" })) nmap("", vim.lsp.buf.signature_help, vim.tbl_extend("force", opts, { desc = "Signature Help" })) nmap("r", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename" })) nmap("ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code Action" })) nmap("vd", vim.diagnostic.open_float, vim.tbl_extend("force", opts, { desc = "View Diagnostics" })) nmap("lr", "LspRestart", vim.tbl_extend("force", opts, { desc = "Restart LSP" })) if client and client.server_capabilities.documentHighlightProvider then local hl_group = vim.api.nvim_create_augroup("lsp_document_highlight_" .. ev.buf, { clear = true }) vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { group = hl_group, buffer = ev.buf, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { group = hl_group, buffer = ev.buf, callback = vim.lsp.buf.clear_references, }) end end, }) end return M --