jones-nvim-config/lua/lsp.lua

68 lines
1.8 KiB
Lua
Raw Normal View History

2024-04-08 14:46:05 +00:00
local lspconfig = require("lspconfig")
2024-04-07 03:14:14 +00:00
2024-04-08 14:46:05 +00:00
local mappings = {
["<leader>k"] = vim.diagnostic.open_float,
["[d"] = vim.diagnostic.goto_prev,
["]d"] = vim.diagnostic.goto_next,
["<leader>q"] = vim.diagnostic.setloclist,
["gD"] = vim.lsp.buf.declaration,
["gd"] = vim.lsp.buf.definition,
["K"] = vim.lsp.buf.hover,
["gi"] = vim.lsp.buf.implementation,
["<leader>wa"] = vim.lsp.buf.add_workspace_folder,
["<leader>wr"] = vim.lsp.buf.remove_workspace_folder,
["<leader>wl"] = function()
print(vim.inspect(vim.lsp.buf.list_workleader_folders()))
end,
["<leader>D"] = vim.lsp.buf.type_definition,
["<leader>rn"] = vim.lsp.buf.rename,
["<leader>ca"] = vim.lsp.buf.code_action,
["gr"] = vim.lsp.buf.references,
["<leader>fm"] = function()
vim.lsp.buf.format({ async = true })
end,
2024-04-07 03:14:14 +00:00
}
local on_attach = function(client, bufnr)
2024-04-08 14:46:05 +00:00
-- Enable completion triggered by <c-x><c-o>
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
2024-04-07 03:14:14 +00:00
end
local servers = {
2024-04-08 14:46:05 +00:00
"tsserver",
"intelephense",
"tailwindcss",
"lua_ls",
2024-04-07 03:14:14 +00:00
}
2024-04-08 14:46:05 +00:00
2024-04-07 03:14:14 +00:00
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem = {
2024-04-08 14:46:05 +00:00
documentationFormat = { "markdown", "plaintext" },
snippetSupport = true,
preselectSupport = true,
insertReplaceSupport = true,
labelDetailsSupport = true,
deprecatedSupport = true,
commitCharactersSupport = true,
tagSupport = { valueSet = { 1 } },
resolveSupport = {
properties = {
"documentation",
"detail",
"additionalTextEdits",
},
},
2024-04-07 03:14:14 +00:00
}
for _, lsp in ipairs(servers) do
2024-04-08 14:46:05 +00:00
lspconfig[lsp].setup({
on_attach = on_attach,
capabilities = capabilities,
})
2024-04-07 03:14:14 +00:00
end