fix: moved lsp mappings to lspconfig to only be set on lsp attach
This commit is contained in:
parent
c7cfacd360
commit
5ba309a0df
@ -102,6 +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" },
|
||||||
|
|
||||||
n = {
|
n = {
|
||||||
["gD"] = {
|
["gD"] = {
|
||||||
function()
|
function()
|
||||||
|
@ -126,9 +126,33 @@ nvchad.map = function(mode, keys, command, opt)
|
|||||||
vim.keymap.set(mode, keys, command, opt)
|
vim.keymap.set(mode, keys, command, opt)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- For those who disabled whichkey
|
-- register mappings through which-key
|
||||||
nvchad.no_WhichKey_map = function()
|
nvchad.whichKey_map = function(maps, opts)
|
||||||
local mappings = nvchad.load_config().mappings
|
local present, wk = pcall(require, "which-key")
|
||||||
|
local caller_path = nvchad.get_caller_file_path()
|
||||||
|
|
||||||
|
if not present then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
for mode, opt in pairs(opts.mode_opts) do
|
||||||
|
for _, value in pairs(maps) do
|
||||||
|
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
|
||||||
|
wk.register(value[mode], mode_opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- for those who disabled whichkey and want to add specific mapping tables
|
||||||
|
nvchad.no_WhichKey_table_map = function(mappings)
|
||||||
local ignore_modes = { "mode_opts" }
|
local ignore_modes = { "mode_opts" }
|
||||||
|
|
||||||
for _, value in pairs(mappings) do
|
for _, value in pairs(mappings) do
|
||||||
@ -145,6 +169,13 @@ nvchad.no_WhichKey_map = function()
|
|||||||
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
|
||||||
|
|
||||||
-- load plugin after entering vim ui
|
-- load plugin after entering vim ui
|
||||||
nvchad.packer_lazy_load = function(plugin, timer)
|
nvchad.packer_lazy_load = function(plugin, timer)
|
||||||
if plugin then
|
if plugin then
|
||||||
@ -197,3 +228,13 @@ nvchad.load_override = function(default_table, plugin_name)
|
|||||||
|
|
||||||
return default_table
|
return default_table
|
||||||
end
|
end
|
||||||
|
|
||||||
|
nvchad.get_caller_file_path = function()
|
||||||
|
local success, result = pcall(debug.getinfo, 4, "S")
|
||||||
|
|
||||||
|
if success then
|
||||||
|
return result.source:match("@(.*)"):gsub(vim.fn.stdpath("config"), "")
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -22,14 +22,64 @@ M.on_attach = function(client, bufnr)
|
|||||||
client.resolved_capabilities.document_formatting = false
|
client.resolved_capabilities.document_formatting = false
|
||||||
client.resolved_capabilities.document_range_formatting = false
|
client.resolved_capabilities.document_range_formatting = false
|
||||||
|
|
||||||
local lsp_mappings = nvchad.load_config().mappings.lspconfig
|
local options = {
|
||||||
local wk_exists, wk = pcall(require, "which-key")
|
|
||||||
|
|
||||||
if wk_exists then
|
-- NOTE : this mode_opts table isnt in the default whichkey config
|
||||||
wk.register(lsp_mappings.n, { buffer = bufnr })
|
-- Its added here so you could configure it in chadrc
|
||||||
else
|
|
||||||
-- todo, make use of bufnr here
|
mode_opts = {
|
||||||
-- add no whichkey func logic here
|
n = {
|
||||||
|
mode = "n",
|
||||||
|
},
|
||||||
|
|
||||||
|
v = {
|
||||||
|
mode = "v",
|
||||||
|
},
|
||||||
|
|
||||||
|
i = {
|
||||||
|
mode = "i",
|
||||||
|
},
|
||||||
|
|
||||||
|
t = {
|
||||||
|
mode = "t",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
icons = {
|
||||||
|
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
|
||||||
|
separator = " ", -- symbol used between a key and it's label
|
||||||
|
group = "+", -- symbol prepended to a group
|
||||||
|
},
|
||||||
|
|
||||||
|
popup_mappings = {
|
||||||
|
scroll_down = "<c-d>", -- binding to scroll down inside the popup
|
||||||
|
scroll_up = "<c-u>", -- binding to scroll up inside the popup
|
||||||
|
},
|
||||||
|
|
||||||
|
window = {
|
||||||
|
border = "none", -- none/single/double/shadow
|
||||||
|
},
|
||||||
|
|
||||||
|
layout = {
|
||||||
|
spacing = 6, -- spacing between columns
|
||||||
|
},
|
||||||
|
|
||||||
|
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " },
|
||||||
|
|
||||||
|
triggers_blacklist = {
|
||||||
|
-- list of mode / prefixes that should never be hooked by WhichKey
|
||||||
|
i = { "j", "k" },
|
||||||
|
v = { "j", "k" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
options = nvchad.load_override(options, "folke/which-key.nvim")
|
||||||
|
|
||||||
|
local lsp_mappings = { nvchad.load_config().mappings.lspconfig }
|
||||||
|
lsp_mappings[1]["mode_opts"] = { buffer = bufnr }
|
||||||
|
|
||||||
|
if not nvchad.whichKey_map(lsp_mappings, options) then
|
||||||
|
nvchad.no_WhichKey_table_map(lsp_mappings)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,21 +63,7 @@ local mapping_groups = { groups = vim.deepcopy(mappings.groups) }
|
|||||||
mappings.disabled = nil
|
mappings.disabled = nil
|
||||||
mappings.groups = nil
|
mappings.groups = nil
|
||||||
|
|
||||||
-- register mappings
|
nvchad.whichKey_map(mappings, options)
|
||||||
local function register_mappings(maps, opts)
|
nvchad.whichKey_map(mapping_groups, options)
|
||||||
for mode, opt in pairs(opts.mode_opts) do
|
|
||||||
for key, value in pairs(maps) do
|
|
||||||
if key ~= "lspconfig" then
|
|
||||||
if value[mode] then
|
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
register_mappings(mappings, options)
|
|
||||||
register_mappings(mapping_groups, options)
|
|
||||||
|
|
||||||
wk.setup(options)
|
wk.setup(options)
|
||||||
|
Loading…
Reference in New Issue
Block a user