local Plugin = { "neovim/nvim-lspconfig" } Plugin.dependencies = { "hrsh7th/cmp-nvim-lsp", "williamboman/mason-lspconfig.nvim", } local user = {} Plugin.event = { "BufReadPre", "BufNewFile" } Plugin.cmd = { "LspInfo", "LspInstall", "LspUnInstall" } function Plugin.init() -- See :help vim.diagnostic.config() vim.diagnostic.config({ virtual_text = true, severity_sort = true, float = { border = "rounded", source = "always", }, }) vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) end function Plugin.config() local lspconfig = require("lspconfig") local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities() local group = vim.api.nvim_create_augroup("lsp_cmds", { clear = true }) vim.api.nvim_create_autocmd("LspAttach", { group = group, desc = "LSP actions", callback = user.on_attach, }) -- See :help mason-lspconfig-settings require("mason-lspconfig").setup({ handlers = { -- See :help mason-lspconfig-dynamic-server-setup function(server) -- See :help lspconfig-setup lspconfig[server].setup({ capabilities = lsp_capabilities, }) end, ["lua_ls"] = function() -- if you install the language server for lua it will -- load the config from lua/plugins/lsp/lua_ls.lua require("plugins.lsp.lua_ls") end, }, }) end function user.on_attach(event) local bufmap = function(mode, lhs, rhs) local opts = { buffer = event.buf } vim.keymap.set(mode, lhs, rhs, opts) end -- You can search each function in the help page. -- For example :help vim.lsp.buf.hover() bufmap("n", "K", "lua vim.lsp.buf.hover()") bufmap("n", "gd", "lua vim.lsp.buf.definition()") bufmap("n", "gD", "lua vim.lsp.buf.declaration()") bufmap("n", "gi", "lua vim.lsp.buf.implementation()") bufmap("n", "go", "lua vim.lsp.buf.type_definition()") bufmap("n", "gr", "lua vim.lsp.buf.references()") bufmap("n", "gs", "lua vim.lsp.buf.signature_help()") bufmap("n", "", "lua vim.lsp.buf.rename()") bufmap({ "n", "x" }, "", "lua vim.lsp.buf.format({async = true})") bufmap("n", "", "lua vim.lsp.buf.code_action()") bufmap("n", "gl", "lua vim.diagnostic.open_float()") bufmap("n", "[d", "lua vim.diagnostic.goto_prev()") bufmap("n", "]d", "lua vim.diagnostic.goto_next()") end return Plugin