neovim/lua/plugins/lsp/lspconfig.lua

160 lines
3.6 KiB
Lua
Raw 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 },
},
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 = "Show LSP references"
vim.keymap.set(
"n",
"gR",
"<cmd>Telescope lsp_references<CR>",
opts
)
opts.desc = "Go to declaration"
vim.keymap.set(
"n",
"gD",
vim.lsp.buf.declaration,
opts
)
opts.desc = "Show LSP definitions"
vim.keymap.set(
"n",
"gd",
"<cmd>Telescope lsp_definitions<CR>",
opts
)
opts.desc = "Show LSP implementations"
vim.keymap.set(
"n",
"gi",
"<cmd>Telescope lsp_implementations<CR>",
opts
)
opts.desc = "Show LSP type definitions"
vim.keymap.set(
"n",
"gt",
"<cmd>Telescope lsp_type_definitions<CR>",
opts
)
opts.desc = "Show LSP signature help"
vim.keymap.set(
"n",
"gs",
vim.lsp.buf.signature_help,
opts
)
opts.desc = "See available code actions"
vim.keymap.set(
{ "n", "v" },
"<leader>ca",
vim.lsp.buf.code_action,
opts
)
opts.desc = "Smart rename"
vim.keymap.set(
"n",
"<leader>rn",
vim.lsp.buf.rename,
opts
)
opts.desc = "Show buffer diagnostics"
vim.keymap.set(
"n",
"<leader>D",
"<cmd>Telescope diagnostics bufnr=0<CR>",
opts
)
opts.desc = "Show line diagnostics"
vim.keymap.set(
"n",
"<leader>d",
vim.diagnostic.open_float,
opts
)
opts.desc = "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 = "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 = "Show documentation for what is under cursor"
vim.keymap.set(
"n",
"K",
vim.lsp.buf.hover,
opts
)
opts.desc = "Format buffer"
vim.keymap.set(
{ "n", "x" },
"F",
"<cmd>lua vim.lsp.buf.format({async = true})<cr>",
opts
)
opts.desc = "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,
}