feat: include tables for all map modes in mappings and lsp.mappings

This commit is contained in:
Micah Halter
2023-07-06 15:29:37 -04:00
parent a918f876a9
commit 31fbc64551
3 changed files with 22 additions and 22 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ local get_icon = utils.get_icon
local is_available = utils.is_available
local ui = require "astronvim.utils.ui"
local maps = { i = {}, n = {}, v = {}, t = {} }
local maps = require("astronvim.utils").empty_map_table()
local sections = {
f = { desc = get_icon("Search", 1, true) .. "Find" },
+15
View File
@@ -273,6 +273,21 @@ function M.which_key_register()
end
end
--- Get an empty table of mappings with a key for each map mode
---@return table<string,table> # a table with entries for each map mode
function M.empty_map_table()
local maps = {}
for _, mode in ipairs { "", "n", "v", "x", "s", "o", "!", "i", "l", "c", "t" } do
maps[mode] = {}
end
if vim.fn.has "nvim-0.10.0" == 1 then
for _, abbr_mode in ipairs { "ia", "ca", "!a" } do
maps[abbr_mode] = {}
end
end
return maps
end
--- Table based API for setting keybindings
---@param map_table table A nested table where the first key is the vim mode, the second key is the key to map, and the value is the function to set the mapping to
---@param base? table A base set of options to set on every keybinding
+6 -21
View File
@@ -128,27 +128,12 @@ end
---@param client table The LSP client details when attaching
---@param bufnr number The buffer that the LSP client is attaching to
M.on_attach = function(client, bufnr)
local lsp_mappings = {
n = {
["<leader>ld"] = {
function() vim.diagnostic.open_float() end,
desc = "Hover diagnostics",
},
["[d"] = {
function() vim.diagnostic.goto_prev() end,
desc = "Previous diagnostic",
},
["]d"] = {
function() vim.diagnostic.goto_next() end,
desc = "Next diagnostic",
},
["gl"] = {
function() vim.diagnostic.open_float() end,
desc = "Hover diagnostics",
},
},
v = {},
}
local lsp_mappings = require("astronvim.utils").empty_map_table()
lsp_mappings.n["<leader>ld"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" }
lsp_mappings.n["[d"] = { function() vim.diagnostic.goto_prev() end, desc = "Previous diagnostic" }
lsp_mappings.n["]d"] = { function() vim.diagnostic.goto_next() end, desc = "Next diagnostic" }
lsp_mappings.n["gl"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" }
if is_available "telescope.nvim" then
lsp_mappings.n["<leader>lD"] =