mappings: Only set mappings if the plugin is enabled

format files

fix some lsp warnings
This commit is contained in:
Akianonymus 2022-08-04 20:02:16 +05:30 committed by Sidhanth Rathod
parent d7b97dfe63
commit f4655e13ec
5 changed files with 65 additions and 45 deletions

View file

@ -64,7 +64,7 @@ M.remove_default_keys = function(disabled_mappings, default_mappings)
return default_mappings
end
M.load_mappings = function(mappings, mapping_opt)
M.load_mappings = function(section, mapping_opt)
-- set mapping function with/without whichkey
local set_maps
local whichkey_exists, wk = pcall(require, "which-key")
@ -81,11 +81,9 @@ M.load_mappings = function(mappings, mapping_opt)
end
end
mappings = mappings or vim.deepcopy(M.load_config().mappings)
mappings.lspconfig = nil
for _, section in pairs(mappings) do
for mode, mode_values in pairs(section) do
local set_section_map = function(section_values)
section_values.plugin = nil
for mode, mode_values in pairs(section_values) do
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
@ -99,6 +97,18 @@ M.load_mappings = function(mappings, mapping_opt)
end
end
end
local mappings = require("core.utils").load_config().mappings
if type(section) == "string" then
set_section_map(mappings[section])
else
for _, sect in pairs(mappings) do
if sect.plugin == nil or sect.plugin == false then
set_section_map(sect)
end
end
end
end
-- remove plugins defined in chadrc
@ -119,7 +129,7 @@ M.merge_plugins = function(default_plugins)
local user_plugins = M.load_config().plugins.user
-- merge default + user plugin table
default_plugins = merge_tb("force", default_plugins, user_plugins)
default_plugins = merge_tb("force", default_plugins, user_plugins) or {}
local final_table = {}
@ -133,8 +143,8 @@ end
M.load_override = function(default_table, plugin_name)
local user_table = M.load_config().plugins.override[plugin_name] or {}
user_table = type(user_table) == "table" and user_table or user_table()
return merge_tb("force", default_table, user_table)
user_table = type(user_table) == "function" and user_table() or user_table
return merge_tb("force", default_table, user_table or {}) or {}
end
M.packer_sync = function(...)