diff --git a/lua/config/maps.lua b/lua/config/maps.lua index 7967789..b41c81f 100644 --- a/lua/config/maps.lua +++ b/lua/config/maps.lua @@ -28,3 +28,33 @@ map("n", "", "BufferLineCyclePrev", { desc = "Previous buffer" } map("n", "ba", "BufferLineCloseOthers", { desc = "Close other buffers" }) map("n", "x", "BufferLinePickClose", { desc = "Close buffer" }) map("n", "bc", "BufferLinePick", { desc = "Close buffer" }) + +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(ev) + local bufnr = ev.buf + + local opts = function(desc) + return { buffer = bufnr, silent = true, desc = desc } + end + + map("n", "gd", vim.lsp.buf.definition, opts "LSP: Go to definition") + map("n", "gD", vim.lsp.buf.declaration, opts "LSP: Go to declaration") + map("n", "gi", vim.lsp.buf.implementation, opts "LSP: Go to implementation") + map("n", "gr", vim.lsp.buf.references, opts "LSP: References") + map("n", "K", vim.lsp.buf.hover, opts "LSP: Hover") + map("n", "rn", vim.lsp.buf.rename, opts "LSP: Rename") + map("n", "ca", vim.lsp.buf.code_action, opts "LSP: Code action") + + map("n", "[d", function() + vim.diagnostic.jump { count = -1, float = true } + end, opts "Diag: Prev") + map("n", "]d", function() + vim.diagnostic.jump { count = 1, float = true } + end, opts "Diag: Next") + map("n", "dd", vim.diagnostic.open_float, opts "Diag: Line diagnostics") + + map("n", "lf", function() + vim.lsp.buf.format { async = true } + end, opts "LSP: Format (server)") + end, +}) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..4061dfd --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,58 @@ +return { + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "L3MON4D3/LuaSnip", + }, + config = function() + local cmp = require "cmp" + cmp.setup { + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [""] = cmp.mapping.confirm { select = true }, + [""] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, + } + end, + }, + { + "neovim/nvim-lspconfig", + dependencies = { + { "hrsh7th/nvim-cmp" }, + { "j-hui/fidget.nvim", opts = {} }, + }, + config = function() + local caps = vim.lsp.protocol.make_client_capabilities() + caps = require("cmp_nvim_lsp").default_capabilities(caps) + + vim.lsp.config("*", { capabilities = caps }) + + vim.lsp.config("lua_ls", { + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + workspace = { + checkThirdParty = false, + }, + telemetry = { enable = false }, + }, + }, + }) + + vim.lsp.enable { + "lua_ls", + } + end, + }, +}