fix: fixed lspconfig issues and cleaned up

This commit is contained in:
Leon Heidelbach 2022-05-26 17:49:13 +02:00 committed by siduck
parent cdf18fd334
commit f8b5571466
4 changed files with 25 additions and 28 deletions

View File

@ -102,7 +102,8 @@ M.comment = {
M.lspconfig = { M.lspconfig = {
-- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions -- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions
ignore = { "/lua/plugins/configs/whichkey.lua" }, -- define all paths from which these maps should not be applied through the mapping function
ignore = { "/lua/custom/init.lua", "/lua/plugins/configs/whichkey.lua" },
n = { n = {
["gD"] = { ["gD"] = {

View File

@ -129,7 +129,7 @@ end
-- register mappings through which-key -- register mappings through which-key
nvchad.whichKey_map = function(maps, opts) nvchad.whichKey_map = function(maps, opts)
local present, wk = pcall(require, "which-key") local present, wk = pcall(require, "which-key")
local caller_path = nvchad.get_caller_file_path() local caller_path = nvchad.get_caller_file_path(4)
if not present then if not present then
return false return false
@ -140,8 +140,7 @@ nvchad.whichKey_map = function(maps, opts)
if value[mode] then if value[mode] then
-- check if caller_path is in the ignore list -- check if caller_path is in the ignore list
if not value["ignore"] or not vim.tbl_contains(value["ignore"], caller_path) then if not value["ignore"] or not vim.tbl_contains(value["ignore"], caller_path) then
local mode_opts = value["mode_opts"] and local mode_opts = value["mode_opts"] and vim.tbl_deep_extend("force", opt, value["mode_opts"]) or opt
vim.tbl_deep_extend("force", opt, value["mode_opts"]) or opt
wk.register(value[mode], mode_opts) wk.register(value[mode], mode_opts)
end end
end end
@ -152,28 +151,25 @@ nvchad.whichKey_map = function(maps, opts)
end end
-- for those who disabled whichkey and want to add specific mapping tables -- for those who disabled whichkey and want to add specific mapping tables
nvchad.no_WhichKey_table_map = function(mappings) nvchad.no_WhichKey_map = function(mappings)
local caller_path = nvchad.get_caller_file_path(4)
local ignore_modes = { "mode_opts" } local ignore_modes = { "mode_opts" }
mappings = mappings or nvchad.load_config().mappings
for _, value in pairs(mappings) do for _, value in pairs(mappings) do
if not value["ignore"] or not vim.tbl_contains(value["ignore"], caller_path) then
for mode, keymap in pairs(value) do for mode, keymap in pairs(value) do
if not vim.tbl_contains(ignore_modes, mode) then if not vim.tbl_contains(ignore_modes, mode) then
for keybind, cmd in pairs(keymap) do for keybind, cmd in pairs(keymap) do
-- disabled keys will not have cmd set -- disabled keys will not have cmd set
if cmd ~= "" and cmd[1] then if cmd ~= "" and cmd[1] then
nvchad.map(mode, keybind, cmd[1]) nvchad.map(mode, keybind, cmd[1], value["mode_opts"] or nil)
end
end end
end end
end end
end end
end end
end
-- for those who disabled whichkey
nvchad.no_WhichKey_map = function()
local mappings = nvchad.load_config().mappings
nvchad.no_WhichKey_table_map(mappings)
end end
-- load plugin after entering vim ui -- load plugin after entering vim ui
@ -229,11 +225,11 @@ nvchad.load_override = function(default_table, plugin_name)
return default_table return default_table
end end
nvchad.get_caller_file_path = function() nvchad.get_caller_file_path = function(call_stack_depth)
local success, result = pcall(debug.getinfo, 4, "S") local success, result = pcall(debug.getinfo, call_stack_depth, "S")
if success then if success then
return result.source:match("@(.*)"):gsub(vim.fn.stdpath("config"), "") return result.source:match("@(.*)"):gsub(vim.fn.stdpath "config", "")
else else
return "" return ""
end end

View File

@ -28,7 +28,7 @@ M.on_attach = function(client, bufnr)
lsp_mappings[1]["mode_opts"] = { buffer = bufnr } lsp_mappings[1]["mode_opts"] = { buffer = bufnr }
if not nvchad.whichKey_map(lsp_mappings, options) then if not nvchad.whichKey_map(lsp_mappings, options) then
nvchad.no_WhichKey_table_map(lsp_mappings) nvchad.no_WhichKey_map(lsp_mappings)
end end
end end

View File

@ -1,9 +1,3 @@
local present, wk = pcall(require, "which-key")
if not present then
return
end
local M = {} local M = {}
M.options = { M.options = {
@ -60,6 +54,12 @@ M.options = {
M.options = nvchad.load_override(M.options, "folke/which-key.nvim") M.options = nvchad.load_override(M.options, "folke/which-key.nvim")
M.setup = function() M.setup = function()
local present, wk = pcall(require, "which-key")
if not present then
return
end
local mappings = nvchad.load_config().mappings local mappings = nvchad.load_config().mappings
local mapping_groups = { groups = vim.deepcopy(mappings.groups) } local mapping_groups = { groups = vim.deepcopy(mappings.groups) }