neovim/lua/plugins/lsp/lspconfig.lua

161 lines
3.8 KiB
Lua
Raw Permalink Normal View History

-- Install and configure nvim-lspconfig
return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
-- Send LSP results to autocompletion nvim-cmp
"hrsh7th/cmp-nvim-lsp",
-- Adds code actions, such as smart file renaming, etc
{ "antosha417/nvim-lsp-file-operations", config = true },
-- 💫 Extensible UI for Neovim notifications and LSP progress messages
{ 'j-hui/fidget.nvim', tag = "legacy", opts = {} },
},
config = function()
-- Import lsp-zero
local lsp_zero = require("lsp-zero")
-- Activate some functionalities when a LSP is activated to the current
-- file
local lsp_attach = function(_, bufnr)
local opts = { buffer = bufnr, silent = true }
-- Keymaps
opts.desc = "[LSP] Show LSP references"
vim.keymap.set(
"n",
"gR",
"<cmd>Telescope lsp_references<CR>",
opts
)
opts.desc = "[LSP] Go to declaration"
vim.keymap.set(
"n",
"gD",
vim.lsp.buf.declaration,
opts
)
opts.desc = "[LSP] Show LSP definitions"
vim.keymap.set(
"n",
"gd",
"<cmd>Telescope lsp_definitions<CR>",
opts
)
opts.desc = "[LSP] Show LSP implementations"
vim.keymap.set(
"n",
"gi",
"<cmd>Telescope lsp_implementations<CR>",
opts
)
opts.desc = "[LSP] Show LSP type definitions"
vim.keymap.set(
"n",
"gt",
"<cmd>Telescope lsp_type_definitions<CR>",
opts
)
opts.desc = "[LSP] Show LSP signature help"
vim.keymap.set(
"n",
"gs",
vim.lsp.buf.signature_help,
opts
)
opts.desc = "[LSP] See available code actions"
vim.keymap.set(
{ "n", "v" },
"<leader>ca",
vim.lsp.buf.code_action,
opts
)
opts.desc = "[LSP] Smart rename"
vim.keymap.set(
"n",
"<leader>rn",
vim.lsp.buf.rename,
opts
)
opts.desc = "[LSP] Show buffer diagnostics"
vim.keymap.set(
"n",
"<leader>D",
"<cmd>Telescope diagnostics bufnr=0<CR>",
opts
)
opts.desc = "[LSP] Show line diagnostics"
vim.keymap.set(
"n",
"<leader>d",
vim.diagnostic.open_float,
opts
)
opts.desc = "[LSP] Go to previous diagnostic"
vim.keymap.set("n", "[d", function()
vim.diagnostic.jump({ count = -1, float = true })
end, opts) -- jump to previous diagnostic in buffer
opts.desc = "[LSP] Go to next diagnostic"
vim.keymap.set("n", "]d", function()
vim.diagnostic.jump({ count = 1, float = true })
end, opts) -- jump to next diagnostic in buffer
opts.desc = "[LSP] Show documentation for what is under cursor"
vim.keymap.set(
"n",
"K",
vim.lsp.buf.hover,
opts
)
opts.desc = "[LSP] Format buffer"
vim.keymap.set(
{ "n", "x" },
"F",
"<cmd>lua vim.lsp.buf.format({async = true})<cr>",
opts
)
opts.desc = "[LSP] Restart LSP"
vim.keymap.set(
"n",
"<leader>rs",
":LspRestart<CR>",
opts
)
end
lsp_zero.extend_lspconfig({
-- Display diagnostic signs in the sign column
sign_text = true,
-- Attach the keymap function
lsp_attach = lsp_attach,
-- Extend the default completion capabilities by LSP suggestions
capabilities = require("cmp_nvim_lsp").default_capabilities(),
})
-- Use lsp_zero to configure interface
lsp_zero.ui({
float_border = "rounded",
sign_text = {
error = "",
warn = "",
hint = "󰠠 ",
info = "",
},
})
end,
}