-- 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", "Telescope lsp_references", 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", "Telescope lsp_definitions", opts ) opts.desc = "Show LSP implementations" vim.keymap.set( "n", "gi", "Telescope lsp_implementations", opts ) opts.desc = "Show LSP type definitions" vim.keymap.set( "n", "gt", "Telescope lsp_type_definitions", 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" }, "ca", vim.lsp.buf.code_action, opts ) opts.desc = "Smart rename" vim.keymap.set( "n", "rn", vim.lsp.buf.rename, opts ) opts.desc = "Show buffer diagnostics" vim.keymap.set( "n", "D", "Telescope diagnostics bufnr=0", opts ) opts.desc = "Show line diagnostics" vim.keymap.set( "n", "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", "lua vim.lsp.buf.format({async = true})", opts ) opts.desc = "Restart LSP" vim.keymap.set( "n", "rs", ":LspRestart", 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, }