From 589c36e26f99486e7ab5e2e6920636ffd5f3ae2a Mon Sep 17 00:00:00 2001 From: kiyan Date: Fri, 2 Jul 2021 15:12:12 +0200 Subject: [PATCH] fix(keymap setup): do not crash on vim.fn.extend to explain the user keymap config has changed --- lua/nvim-tree/view.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 810ebe4c..1e5fb3d2 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -112,6 +112,11 @@ function M._wipe_rogue_buffer() end end +local function warn_wrong_mapping() + local warn_str = "Wrong configuration for keymaps, refer to the new documentation. Keymaps setup aborted" + require'nvim-tree.utils'.echo_warning(warn_str) +end + -- set user options and create tree buffer (should never be wiped) function M.setup() M.View.side = vim.g.nvim_tree_side or M.View.side @@ -137,14 +142,20 @@ function M.setup() if vim.g.nvim_tree_disable_default_keybindings == 1 then M.View.bindings = user_mappings else - M.View.bindings = vim.fn.extend(M.View.bindings, user_mappings) + ok, result = pcall(vim.fn.extend, M.View.bindings, user_mappings) + if not ok then + -- TODO: remove this in a few weeks + warn_wrong_mapping() + return + else + M.View.bindings = result + end end for _, b in pairs(M.View.bindings) do -- TODO: remove this in a few weeks if type(b) == "string" then - local warn_str = "Wrong configuration for keymaps, refer to the new documentation. User keymaps setup aborted" - require'nvim-tree.utils'.echo_warning(warn_str) + warn_wrong_mapping() break end if type(b.key) == "table" then