dots/config/nvim/lua/aleidk/plugins-ide/lsp.lua
2024-12-17 12:07:00 -03:00

223 lines
5.7 KiB
Lua

return {
-- LSP Plugins
{
-- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = 'luvit-meta/library', words = { 'vim%.uv' } },
},
},
},
{ "Bilal2453/luvit-meta", lazy = true }, -- optional `vim.uv` typings
{
-- LSP Configuration & Plugins
"neovim/nvim-lspconfig",
event = { "BufReadPost", "BufNewFile", "BufWritePre" },
dependencies = {
-- Automatically install LSPs to stdpath for neovim
{ "williamboman/mason.nvim", config = true },
"williamboman/mason-lspconfig.nvim",
{ 'saghen/blink.cmp' } -- autocompletion
},
config = function()
-- LSP settings.
local on_attach = function(_, bufnr)
local nmap = function(keys, func, desc)
if desc then
desc = "LSP: " .. desc
end
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc })
end
nmap("<leader>lr", vim.lsp.buf.rename, "Rename")
-- stylua: ignore
vim.keymap.set({ "n", "x", "v" }, "<leader>la", vim.lsp.buf.code_action, { buffer = bufnr, desc = "Code Action" })
nmap("<leader>ld", vim.lsp.buf.type_definition, "Go to type definition")
nmap("<leader>lf", function()
vim.lsp.buf.format()
end, "Format")
nmap("gd", vim.lsp.buf.definition, "Go to definition")
nmap("gr", require("telescope.builtin").lsp_references, "Goto References")
nmap("gI", vim.lsp.buf.implementation, "Go to Implementation")
-- See `:help K` for why this keymap
nmap("K", vim.lsp.buf.hover, "Hover Documentation")
-- nmap("<C-k>", vim.lsp.buf.signature_help, "Signature Documentation")
-- Lesser used LSP functionality
nmap("gD", vim.lsp.buf.declaration, "Goto Declaration")
nmap("<leader>lj", vim.diagnostic.goto_next, "Go to next diagnostic")
nmap("<leader>lk", vim.diagnostic.goto_prev, "Go to prev diagnostic")
nmap("<leader>lK", function()
-- execute twice to enter the float inmediatly
vim.diagnostic.open_float()
vim.diagnostic.open_float()
end, "Hover current diagnostic")
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
vim.lsp.buf.format()
end, { desc = "Format current buffer with LSP" })
end
-- Enable the following language servers
-- To see options and cofigurations `:help lspconfig-all`
local servers = {
astro = {},
bashls = {},
cssls = {},
dockerls = {},
emmet_ls = {
filetypes = {
"astro",
"css",
"eruby",
"html",
"htmldjango",
"javascriptreact",
"less",
"pug",
"sass",
"scss",
"svelte",
"typescriptreact",
"vue",
"htmlangular",
"php",
"blade"
},
},
html = {},
marksman = {},
phpactor = {},
gopls = {
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
},
ruff = {},
rust_analyzer = {
settings = {
["rust-analyzer"] = {
imports = {
granularity = {
group = "module",
},
prefix = "self",
},
cargo = {
buildScripts = {
enable = true,
},
},
procMacro = {
enable = true,
},
},
},
},
sqlls = {},
yamlls = {
settings = {
yaml = {
schemas = {},
customTags = {
"!vault" -- ansible encrypted vars support
}
}
},
},
lua_ls = {
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
diagnostics = { disable = { 'missing-fields' } },
},
},
},
}
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("blink.cmp").get_lsp_capabilities(capabilities)
-- Ensure the servers above are installed
local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup({
ensure_installed = vim.tbl_keys(servers),
automatic_installation = false,
})
mason_lspconfig.setup_handlers({
function(server_name)
local _border = "single"
local default_config = {
capabilities = capabilities,
on_attach = on_attach,
handlers = {
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = _border,
}),
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = _border,
max_width = 200,
max_height = 200,
focus = true,
}),
},
}
require("lspconfig")[server_name].setup(
vim.tbl_deep_extend("force", default_config, servers[server_name] or {})
)
end,
})
vim.diagnostic.config({
update_in_insert = false,
underline = true,
float = {
source = true
},
virtual_text = {
severity = vim.diagnostic.severity.ERROR,
source = true,
spacing = -1,
prefix = nil,
format = function(diagnostic)
-- show small error code instead of whole error that probably won't fit in the screen
-- to see the whole error use other keybindings
return tostring(diagnostic.code)
end,
virt_text_hide = true
},
severity_sort = true,
})
-- Customize gutter icons
local signs = require("aleidk.constants").icons.diagnostics
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
end,
},
}