local lspconfig = require("lspconfig") local mappings = { ["k"] = vim.diagnostic.open_float, ["[d"] = vim.diagnostic.goto_prev, ["]d"] = vim.diagnostic.goto_next, ["q"] = vim.diagnostic.setloclist, ["gD"] = vim.lsp.buf.declaration, ["gd"] = vim.lsp.buf.definition, ["K"] = vim.lsp.buf.hover, ["gi"] = vim.lsp.buf.implementation, ["wa"] = vim.lsp.buf.add_workspace_folder, ["wr"] = vim.lsp.buf.remove_workspace_folder, ["wl"] = function() print(vim.inspect(vim.lsp.buf.list_workleader_folders())) end, ["D"] = vim.lsp.buf.type_definition, ["rn"] = vim.lsp.buf.rename, ["ca"] = vim.lsp.buf.code_action, ["gr"] = vim.lsp.buf.references, ["fm"] = function() vim.lsp.buf.format({ async = true }) end, } local on_attach = function(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") local bufopts = { noremap = true, silent = true, buffer = bufnr } for key, mapping in pairs(mappings) do vim.keymap.set("n", key, mapping, bufopts) end end local servers = { "tsserver", "intelephense", "tailwindcss", "lua_ls", } local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem = { documentationFormat = { "markdown", "plaintext" }, snippetSupport = true, preselectSupport = true, insertReplaceSupport = true, labelDetailsSupport = true, deprecatedSupport = true, commitCharactersSupport = true, tagSupport = { valueSet = { 1 } }, resolveSupport = { properties = { "documentation", "detail", "additionalTextEdits", }, }, } for _, lsp in ipairs(servers) do lspconfig[lsp].setup({ on_attach = on_attach, capabilities = capabilities, }) end