diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index ee6da1b..bd736c3 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -96,73 +96,79 @@ M.comment = function() map("v", "/", " :lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())") end -M.lspconfig = function() +M.lspconfig = function(bufnr) -- See ` :help vim.lsp.*` for documentation on any of the below functions - map("n", "gD", function() + + local buf_map = function(...) + local key, lhs, rhs = ... + map(key, lhs, rhs, { buffer = bufnr }) + end + + buf_map("n", "gD", function() vim.lsp.buf.declaration() end) - map("n", "gd", function() + buf_map("n", "gd", function() vim.lsp.buf.definition() end) - map("n", "K", function() + buf_map("n", "K", function() vim.lsp.buf.hover() end) - map("n", "gi", function() + buf_map("n", "gi", function() vim.lsp.buf.implementation() end) - map("n", "", function() + buf_map("n", "", function() vim.lsp.buf.signature_help() end) - map("n", "D", function() + buf_map("n", "D", function() vim.lsp.buf.type_definition() end) - map("n", "ra", function() + buf_map("n", "ra", function() vim.lsp.buf.rename() end) - map("n", "ca", function() + buf_map("n", "ca", function() vim.lsp.buf.code_action() end) - map("n", "gr", function() + buf_map("n", "gr", function() vim.lsp.buf.references() end) - map("n", "f", function() + buf_map("n", "f", function() vim.diagnostic.open_float() end) - map("n", "[d", function() + buf_map("n", "[d", function() vim.diagnostic.goto_prev() end) - map("n", "d]", function() + buf_map("n", "d]", function() vim.diagnostic.goto_next() end) - map("n", "q", function() + buf_map("n", "q", function() vim.diagnostic.setloclist() end) - map("n", "fm", function() + buf_map("n", "fm", function() vim.lsp.buf.formatting() end) - map("n", "wa", function() + buf_map("n", "wa", function() vim.lsp.buf.add_workspace_folder() end) - map("n", "wr", function() + buf_map("n", "wr", function() vim.lsp.buf.remove_workspace_folder() end) - map("n", "wl", function() + buf_map("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end) end diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 4c375ed..ce4553a 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -10,7 +10,7 @@ function M.on_attach(client, bufnr) client.resolved_capabilities.document_formatting = false client.resolved_capabilities.document_range_formatting = false - require("core.mappings").lspconfig() + require("core.mappings").lspconfig(bufnr) end local capabilities = vim.lsp.protocol.make_client_capabilities()