From c7cfacd360553f9aa425031729398a5da1332989 Mon Sep 17 00:00:00 2001 From: siduck Date: Tue, 24 May 2022 23:01:35 +0530 Subject: [PATCH] register lsp mappings for buffer only --- lua/plugins/configs/lspconfig.lua | 12 +++++++++++- lua/plugins/configs/whichkey.lua | 11 ++++++----- lua/plugins/init.lua | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 5ef73a5..f660a81 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -18,9 +18,19 @@ win.default_opts = function(options) return opts end -function M.on_attach(client, _) +M.on_attach = function(client, bufnr) client.resolved_capabilities.document_formatting = false client.resolved_capabilities.document_range_formatting = false + + local lsp_mappings = nvchad.load_config().mappings.lspconfig + local wk_exists, wk = pcall(require, "which-key") + + if wk_exists then + wk.register(lsp_mappings.n, { buffer = bufnr }) + else + -- todo, make use of bufnr here + -- add no whichkey func logic here + end end local capabilities = vim.lsp.protocol.make_client_capabilities() diff --git a/lua/plugins/configs/whichkey.lua b/lua/plugins/configs/whichkey.lua index 57ab519..70b1a11 100644 --- a/lua/plugins/configs/whichkey.lua +++ b/lua/plugins/configs/whichkey.lua @@ -66,10 +66,12 @@ mappings.groups = nil -- register mappings local function register_mappings(maps, opts) for mode, opt in pairs(opts.mode_opts) do - for _, value in pairs(maps) do - 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) + 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 @@ -78,5 +80,4 @@ end register_mappings(mappings, options) register_mappings(mapping_groups, options) - wk.setup(options) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index f75a86c..0c3d16d 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -186,7 +186,7 @@ local plugins = { -- file managing , picker etc ["kyazdani42/nvim-tree.lua"] = { - ft = 'alpha', + ft = "alpha", cmd = { "NvimTreeToggle", "NvimTreeFocus" }, config = function() require "plugins.configs.nvimtree"