return { { -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins "folke/lazydev.nvim", ft = "lua", opts = { library = { { path = "luvit-meta/library", words = { "vim%.uv" } }, }, }, }, { -- Mason for installing LSP servers and tools "williamboman/mason.nvim", config = function() require("mason").setup() end, }, { "WhoIsSethDaniel/mason-tool-installer.nvim", dependencies = { "williamboman/mason.nvim" }, opts = { ensure_installed = { "gopls", "vtsls", "zls", "astro-language-server", "lua-language-server", "stylua", }, }, }, { -- LSP keymaps and native configuration (Neovim 0.11+) "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { "williamboman/mason.nvim", "WhoIsSethDaniel/mason-tool-installer.nvim", "saghen/blink.cmp", }, config = function() -- Apply blink.cmp capabilities to all LSP servers vim.lsp.config("*", { capabilities = require("blink.cmp").get_lsp_capabilities(), }) -- Enable all configured servers (configs live in lsp/ directory) vim.lsp.enable({ "gopls", "vtsls", "zls", "astro", "lua_ls", }) vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), callback = function(event) local map = function(keys, func, desc, mode) mode = mode or "n" vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) end map("gd", vim.lsp.buf.definition, "Goto Definition") map("gr", vim.lsp.buf.references, "Goto References") map("gI", vim.lsp.buf.implementation, "Goto Implementation") map("gD", vim.lsp.buf.declaration, "Goto Declaration") map("D", vim.lsp.buf.type_definition, "Type Definition") map("ds", require("telescope.builtin").lsp_document_symbols, "Document Symbols") map("ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "Workspace Symbols") map("rn", vim.lsp.buf.rename, "Rename") map("ca", vim.lsp.buf.code_action, "Code Action", { "n", "x" }) local client = vim.lsp.get_client_by_id(event.data.client_id) -- Highlight references on cursor hold if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then local highlight_augroup = vim.api.nvim_create_augroup("lsp-highlight", { clear = false }) vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) vim.api.nvim_create_autocmd("LspDetach", { group = vim.api.nvim_create_augroup("lsp-detach", { clear = true }), callback = function(event2) vim.lsp.buf.clear_references() vim.api.nvim_clear_autocmds({ group = "lsp-highlight", buffer = event2.buf }) end, }) end -- Toggle inlay hints if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then map("th", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) end, "Toggle Inlay Hints") end end, }) -- Enable inlay hints by default vim.lsp.inlay_hint.enable(true) end, }, }