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 = {
-- 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 = {
["gD"] = {

View File

@ -129,7 +129,7 @@ end
-- register mappings through which-key
nvchad.whichKey_map = function(maps, opts)
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
return false
@ -140,8 +140,7 @@ nvchad.whichKey_map = function(maps, opts)
if value[mode] then
-- check if caller_path is in the ignore list
if not value["ignore"] or not vim.tbl_contains(value["ignore"], caller_path) then
local mode_opts = value["mode_opts"] and
vim.tbl_deep_extend("force", opt, value["mode_opts"]) or opt
local mode_opts = value["mode_opts"] and vim.tbl_deep_extend("force", opt, value["mode_opts"]) or opt
wk.register(value[mode], mode_opts)
end
end
@ -152,16 +151,20 @@ nvchad.whichKey_map = function(maps, opts)
end
-- 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" }
mappings = mappings or nvchad.load_config().mappings
for _, value in pairs(mappings) do
for mode, keymap in pairs(value) do
if not vim.tbl_contains(ignore_modes, mode) then
for keybind, cmd in pairs(keymap) do
-- disabled keys will not have cmd set
if cmd ~= "" and cmd[1] then
nvchad.map(mode, keybind, cmd[1])
if not value["ignore"] or not vim.tbl_contains(value["ignore"], caller_path) then
for mode, keymap in pairs(value) do
if not vim.tbl_contains(ignore_modes, mode) then
for keybind, cmd in pairs(keymap) do
-- disabled keys will not have cmd set
if cmd ~= "" and cmd[1] then
nvchad.map(mode, keybind, cmd[1], value["mode_opts"] or nil)
end
end
end
end
@ -169,13 +172,6 @@ nvchad.no_WhichKey_table_map = function(mappings)
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
-- load plugin after entering vim ui
nvchad.packer_lazy_load = function(plugin, timer)
if plugin then
@ -229,11 +225,11 @@ nvchad.load_override = function(default_table, plugin_name)
return default_table
end
nvchad.get_caller_file_path = function()
local success, result = pcall(debug.getinfo, 4, "S")
nvchad.get_caller_file_path = function(call_stack_depth)
local success, result = pcall(debug.getinfo, call_stack_depth, "S")
if success then
return result.source:match("@(.*)"):gsub(vim.fn.stdpath("config"), "")
return result.source:match("@(.*)"):gsub(vim.fn.stdpath "config", "")
else
return ""
end

View File

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

View File

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