From fd612b740133462162327289d27a7aa0aac3569c Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 18 Apr 2022 14:01:11 +1000 Subject: [PATCH 01/13] #1166 validate user's options --- lua/nvim-tree.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index fd34be0f412..b847782c246 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -416,6 +416,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, } -- END_DEFAULT_OPTS +-- nil or no defaults +local NO_VALIDATE_OPTS = { + "system_open.cmd", + "view.mappings.list", +} + local function merge_options(conf) if conf and conf.update_to_buf_dir then conf.hijack_directories = conf.update_to_buf_dir @@ -424,7 +430,41 @@ local function merge_options(conf) return vim.tbl_deep_extend("force", DEFAULT_OPTS, conf or {}) end +local function validate_options(conf) + local msg = "" + + local function walk_options(user, def, prefix) + for k, v in pairs(user) do + for _, no in ipairs(NO_VALIDATE_OPTS) do + if no == prefix .. k then + return + end + end + + if def[k] == nil then + msg = string.format("%s\nunknown option: %s%s", msg, prefix, k) + return + elseif type(v) ~= type(def[k]) then + msg = string.format("%s\ninvalid option: %s%s expected: %s actual: %s", msg, prefix, k, type(def[k]), type(v)) + return + end + + if type(v) == "table" then + walk_options(v, def[k], prefix .. k .. ".") + end + end + end + + walk_options(conf, DEFAULT_OPTS, "") + + if #msg > 0 then + utils.warn(msg) + end +end + function M.setup(conf) + validate_options(conf) + legacy.migrate_legacy_options(conf or {}) local opts = merge_options(conf) From ccd3d89fef2027ad6f98a7d7ba7f380885ff990a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Thu, 21 Apr 2022 09:47:27 +1000 Subject: [PATCH 02/13] #1166 validate user's options --- lua/nvim-tree.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index b847782c246..5a6428073aa 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -434,6 +434,9 @@ local function validate_options(conf) local msg = "" local function walk_options(user, def, prefix) + if type(user) ~= "table" then + return + end for k, v in pairs(user) do for _, no in ipairs(NO_VALIDATE_OPTS) do if no == prefix .. k then From 5a0430b340ba0ddc94fe48e7a7837edb0fd5e040 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 23 Apr 2022 15:08:15 +1000 Subject: [PATCH 03/13] #1166 validate user's options --- lua/nvim-tree.lua | 51 +++++++++++---------------- lua/nvim-tree/actions/system-open.lua | 4 +-- lua/nvim-tree/legacy.lua | 46 +++++++++++++++--------- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 9f6699259bb..5ff12e822af 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -360,7 +360,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, ignore_ft_on_setup = {}, system_open = { - cmd = nil, + cmd = "", args = {}, }, diagnostics = { @@ -420,12 +420,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, } -- END_DEFAULT_OPTS --- nil or no defaults -local NO_VALIDATE_OPTS = { - "system_open.cmd", - "view.mappings.list", -} - local function merge_options(conf) if conf and conf.update_to_buf_dir then conf.hijack_directories = conf.update_to_buf_dir @@ -435,52 +429,49 @@ local function merge_options(conf) end local function validate_options(conf) - local msg = "" + local msg - local function walk_options(user, def, prefix) - if type(user) ~= "table" then + local function validate(user, def, prefix) + if type(user) ~= "table" or type(def) ~= "table" or not next(def) then return end - for k, v in pairs(user) do - for _, no in ipairs(NO_VALIDATE_OPTS) do - if no == prefix .. k then - return - end - end + for k, v in pairs(user) do + local invalid if def[k] == nil then - msg = string.format("%s\nunknown option: %s%s", msg, prefix, k) - return + invalid = string.format("unknown option: %s%s", prefix, k) elseif type(v) ~= type(def[k]) then - msg = string.format("%s\ninvalid option: %s%s expected: %s actual: %s", msg, prefix, k, type(def[k]), type(v)) - return + invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v)) end - if type(v) == "table" then - walk_options(v, def[k], prefix .. k .. ".") + if invalid then + if msg then + msg = string.format("%s | %s", msg, invalid) + else + msg = string.format("%s", invalid) + end + user[k] = nil + else + validate(v, def[k], prefix .. k .. ".") end end end - walk_options(conf, DEFAULT_OPTS, "") + validate(conf, DEFAULT_OPTS, "") - if #msg > 0 then + if msg then utils.warn(msg) end end function M.setup(conf) - validate_options(conf) - legacy.migrate_legacy_options(conf or {}) + validate_options(conf) + local opts = merge_options(conf) local netrw_disabled = opts.disable_netrw or opts.hijack_netrw - if opts.auto_close then - utils.warn "auto close feature has been removed, see note in the README (tips & reminder section)" - end - _config.update_focused_file = opts.update_focused_file _config.open_on_setup = opts.open_on_setup _config.open_on_setup_file = opts.open_on_setup_file diff --git a/lua/nvim-tree/actions/system-open.lua b/lua/nvim-tree/actions/system-open.lua index b0f63596429..e44e357a72c 100644 --- a/lua/nvim-tree/actions/system-open.lua +++ b/lua/nvim-tree/actions/system-open.lua @@ -9,7 +9,7 @@ local M = { } function M.fn(node) - if not M.config.system_open.cmd then + if #M.config.system_open.cmd == 0 then require("nvim-tree.utils").warn "Cannot open file with system application. Unrecognized platform." return end @@ -53,7 +53,7 @@ end function M.setup(opts) M.config.system_open = opts or {} - if not M.config.system_open.cmd then + if #M.config.system_open.cmd == 0 then if M.config.is_windows then M.config.system_open = { cmd = "cmd", diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index f4023c628d7..3030630a933 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -5,7 +5,7 @@ local M = {} -- TODO update git.io/JPhyt when adding a migration -- migrate the g: to o if the user has not specified that when calling setup -local migrations = { +local g_migrations = { nvim_tree_disable_netrw = function(o) if o.disable_netrw == nil then o.disable_netrw = vim.g.nvim_tree_disable_netrw ~= 0 @@ -178,22 +178,7 @@ local migrations = { end, } -function M.migrate_legacy_options(opts) - local msg = nil - - -- g: options - for g, m in pairs(migrations) do - if vim.fn.exists("g:" .. g) ~= 0 then - m(opts) - msg = (msg and msg .. ", " or "Following options were moved to setup, see git.io/JPhyt: ") .. g - end - end - - if msg then - require("nvim-tree.utils").warn(msg) - end - - -- regular opts +local function refactored(opts) if opts.view then if opts.view.mappings then if opts.view.mappings.list then @@ -207,4 +192,31 @@ function M.migrate_legacy_options(opts) end end +local function removed(opts) + if opts.auto_close then + utils.warn "auto close feature has been removed, see note in the README (tips & reminder section)" + opts.auto_close = nil + end +end + +function M.migrate_legacy_options(opts) + -- g: options + local msg + for g, m in pairs(g_migrations) do + if vim.fn.exists("g:" .. g) ~= 0 then + m(opts) + msg = (msg and msg .. ", " or "Following options were moved to setup, see git.io/JPhyt: ") .. g + end + end + if msg then + utils.warn(msg) + end + + -- silently move + refactored(opts) + + -- warn and delete + removed(opts) +end + return M From 8a43ae2a3f268655775eb3d3c82c3abb9a6393e7 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 23 Apr 2022 16:11:09 +1000 Subject: [PATCH 04/13] #1166 validate user's options --- doc/nvim-tree-lua.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 243fcf0ec94..32c7b74ff24 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -310,10 +310,10 @@ Here is a list of the options available in the setup call: *nvim-tree.system_open* - |system_open|: configuration options for the system open command - - |system_open.cmd|: the command to run, leaving nil should work but + - |system_open.cmd|: the command to run, leaving empty should work but useful if you want to override the default command with another one. type: `string` - default: `nil` + default: `""` - |system_open.args|: the command arguments as a list type: `{string}` From 2e228667b026d12d4522ab1584ceb5865703379f Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 23 Apr 2022 10:55:52 +0200 Subject: [PATCH 05/13] fix: add missing hide_root_folder from view config --- lua/nvim-tree.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 5ff12e822af..1f27b55b8d6 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -324,6 +324,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS view = { width = 30, height = 30, + hide_root_folder = false, side = "left", preserve_window_proportions = false, number = false, From 039fdfa4bcfed107d218f29e1b9301d02d909c87 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 24 Apr 2022 11:03:00 +1000 Subject: [PATCH 06/13] #1666 remove unused hide_root_folder and update defaults --- README.md | 4 ++-- doc/nvim-tree-lua.txt | 4 ++-- lua/nvim-tree.lua | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 699eec16f54..a8d00737698 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,6 @@ require'nvim-tree'.setup { require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, disable_netrw = false, - hide_root_folder = false, hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, @@ -130,6 +129,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS view = { width = 30, height = 30, + hide_root_folder = false, side = "left", preserve_window_proportions = false, number = false, @@ -166,7 +166,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS }, ignore_ft_on_setup = {}, system_open = { - cmd = nil, + cmd = "", args = {}, }, diagnostics = { diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 32c7b74ff24..9e8f53c8a84 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -86,7 +86,6 @@ function. require("nvim-tree").setup { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, disable_netrw = false, - hide_root_folder = false, hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, @@ -99,6 +98,7 @@ function. view = { width = 30, height = 30, + hide_root_folder = false, side = "left", preserve_window_proportions = false, number = false, @@ -135,7 +135,7 @@ function. }, ignore_ft_on_setup = {}, system_open = { - cmd = nil, + cmd = "", args = {}, }, diagnostics = { diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 1f27b55b8d6..130f22a12c8 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -311,7 +311,6 @@ end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, disable_netrw = false, - hide_root_folder = false, hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, From 3a0999e744a8b8688542e589110a3e98787e136a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 18 Apr 2022 14:01:11 +1000 Subject: [PATCH 07/13] #1166 validate user's options --- lua/nvim-tree.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 651bbf620be..b5a3b9049ff 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -421,6 +421,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, } -- END_DEFAULT_OPTS +-- nil or no defaults +local NO_VALIDATE_OPTS = { + "system_open.cmd", + "view.mappings.list", +} + local function merge_options(conf) if conf and conf.update_to_buf_dir then conf.hijack_directories = conf.update_to_buf_dir @@ -429,7 +435,41 @@ local function merge_options(conf) return vim.tbl_deep_extend("force", DEFAULT_OPTS, conf or {}) end +local function validate_options(conf) + local msg = "" + + local function walk_options(user, def, prefix) + for k, v in pairs(user) do + for _, no in ipairs(NO_VALIDATE_OPTS) do + if no == prefix .. k then + return + end + end + + if def[k] == nil then + msg = string.format("%s\nunknown option: %s%s", msg, prefix, k) + return + elseif type(v) ~= type(def[k]) then + msg = string.format("%s\ninvalid option: %s%s expected: %s actual: %s", msg, prefix, k, type(def[k]), type(v)) + return + end + + if type(v) == "table" then + walk_options(v, def[k], prefix .. k .. ".") + end + end + end + + walk_options(conf, DEFAULT_OPTS, "") + + if #msg > 0 then + utils.warn(msg) + end +end + function M.setup(conf) + validate_options(conf) + legacy.migrate_legacy_options(conf or {}) local opts = merge_options(conf) From eda1c562cfd8fab8ac6157093b98d43f1193df02 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Thu, 21 Apr 2022 09:47:27 +1000 Subject: [PATCH 08/13] #1166 validate user's options --- lua/nvim-tree.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index b5a3b9049ff..44191f1fbdf 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -439,6 +439,9 @@ local function validate_options(conf) local msg = "" local function walk_options(user, def, prefix) + if type(user) ~= "table" then + return + end for k, v in pairs(user) do for _, no in ipairs(NO_VALIDATE_OPTS) do if no == prefix .. k then From 934402317409dd319406ab0c3bc9e7447421dfde Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 23 Apr 2022 15:08:15 +1000 Subject: [PATCH 09/13] #1166 validate user's options --- lua/nvim-tree.lua | 51 +++++++++++---------------- lua/nvim-tree/actions/system-open.lua | 4 +-- lua/nvim-tree/legacy.lua | 46 +++++++++++++++--------- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 44191f1fbdf..4d99968909f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -360,7 +360,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, ignore_ft_on_setup = {}, system_open = { - cmd = nil, + cmd = "", args = {}, }, diagnostics = { @@ -421,12 +421,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, } -- END_DEFAULT_OPTS --- nil or no defaults -local NO_VALIDATE_OPTS = { - "system_open.cmd", - "view.mappings.list", -} - local function merge_options(conf) if conf and conf.update_to_buf_dir then conf.hijack_directories = conf.update_to_buf_dir @@ -436,52 +430,49 @@ local function merge_options(conf) end local function validate_options(conf) - local msg = "" + local msg - local function walk_options(user, def, prefix) - if type(user) ~= "table" then + local function validate(user, def, prefix) + if type(user) ~= "table" or type(def) ~= "table" or not next(def) then return end - for k, v in pairs(user) do - for _, no in ipairs(NO_VALIDATE_OPTS) do - if no == prefix .. k then - return - end - end + for k, v in pairs(user) do + local invalid if def[k] == nil then - msg = string.format("%s\nunknown option: %s%s", msg, prefix, k) - return + invalid = string.format("unknown option: %s%s", prefix, k) elseif type(v) ~= type(def[k]) then - msg = string.format("%s\ninvalid option: %s%s expected: %s actual: %s", msg, prefix, k, type(def[k]), type(v)) - return + invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v)) end - if type(v) == "table" then - walk_options(v, def[k], prefix .. k .. ".") + if invalid then + if msg then + msg = string.format("%s | %s", msg, invalid) + else + msg = string.format("%s", invalid) + end + user[k] = nil + else + validate(v, def[k], prefix .. k .. ".") end end end - walk_options(conf, DEFAULT_OPTS, "") + validate(conf, DEFAULT_OPTS, "") - if #msg > 0 then + if msg then utils.warn(msg) end end function M.setup(conf) - validate_options(conf) - legacy.migrate_legacy_options(conf or {}) + validate_options(conf) + local opts = merge_options(conf) local netrw_disabled = opts.disable_netrw or opts.hijack_netrw - if opts.auto_close then - utils.warn "auto close feature has been removed, see note in the README (tips & reminder section)" - end - _config.update_focused_file = opts.update_focused_file _config.open_on_setup = opts.open_on_setup _config.open_on_setup_file = opts.open_on_setup_file diff --git a/lua/nvim-tree/actions/system-open.lua b/lua/nvim-tree/actions/system-open.lua index b0f63596429..e44e357a72c 100644 --- a/lua/nvim-tree/actions/system-open.lua +++ b/lua/nvim-tree/actions/system-open.lua @@ -9,7 +9,7 @@ local M = { } function M.fn(node) - if not M.config.system_open.cmd then + if #M.config.system_open.cmd == 0 then require("nvim-tree.utils").warn "Cannot open file with system application. Unrecognized platform." return end @@ -53,7 +53,7 @@ end function M.setup(opts) M.config.system_open = opts or {} - if not M.config.system_open.cmd then + if #M.config.system_open.cmd == 0 then if M.config.is_windows then M.config.system_open = { cmd = "cmd", diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index f4023c628d7..3030630a933 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -5,7 +5,7 @@ local M = {} -- TODO update git.io/JPhyt when adding a migration -- migrate the g: to o if the user has not specified that when calling setup -local migrations = { +local g_migrations = { nvim_tree_disable_netrw = function(o) if o.disable_netrw == nil then o.disable_netrw = vim.g.nvim_tree_disable_netrw ~= 0 @@ -178,22 +178,7 @@ local migrations = { end, } -function M.migrate_legacy_options(opts) - local msg = nil - - -- g: options - for g, m in pairs(migrations) do - if vim.fn.exists("g:" .. g) ~= 0 then - m(opts) - msg = (msg and msg .. ", " or "Following options were moved to setup, see git.io/JPhyt: ") .. g - end - end - - if msg then - require("nvim-tree.utils").warn(msg) - end - - -- regular opts +local function refactored(opts) if opts.view then if opts.view.mappings then if opts.view.mappings.list then @@ -207,4 +192,31 @@ function M.migrate_legacy_options(opts) end end +local function removed(opts) + if opts.auto_close then + utils.warn "auto close feature has been removed, see note in the README (tips & reminder section)" + opts.auto_close = nil + end +end + +function M.migrate_legacy_options(opts) + -- g: options + local msg + for g, m in pairs(g_migrations) do + if vim.fn.exists("g:" .. g) ~= 0 then + m(opts) + msg = (msg and msg .. ", " or "Following options were moved to setup, see git.io/JPhyt: ") .. g + end + end + if msg then + utils.warn(msg) + end + + -- silently move + refactored(opts) + + -- warn and delete + removed(opts) +end + return M From 27defe3aae92d23f61e0738bd44ecb98cc09c86c Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 23 Apr 2022 16:11:09 +1000 Subject: [PATCH 10/13] #1166 validate user's options --- doc/nvim-tree-lua.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index b2019508f86..aa7dbc49a0a 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -311,10 +311,10 @@ Here is a list of the options available in the setup call: *nvim-tree.system_open* - |system_open|: configuration options for the system open command - - |system_open.cmd|: the command to run, leaving nil should work but + - |system_open.cmd|: the command to run, leaving empty should work but useful if you want to override the default command with another one. type: `string` - default: `nil` + default: `""` - |system_open.args|: the command arguments as a list type: `{string}` From 3e642bad0423342f1afca86a30554df9943e430f Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 23 Apr 2022 10:55:52 +0200 Subject: [PATCH 11/13] fix: add missing hide_root_folder from view config --- lua/nvim-tree.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 4d99968909f..89af06c6c02 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -324,6 +324,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS view = { width = 30, height = 30, + hide_root_folder = false, side = "left", preserve_window_proportions = false, number = false, From e6d1938e936212afb2f3250b9aebc8ef77e8f0e0 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 24 Apr 2022 11:03:00 +1000 Subject: [PATCH 12/13] #1666 remove unused hide_root_folder and update defaults --- README.md | 4 ++-- doc/nvim-tree-lua.txt | 4 ++-- lua/nvim-tree.lua | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c59e0778812..074f0fc4901 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,6 @@ require'nvim-tree'.setup { require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, disable_netrw = false, - hide_root_folder = false, hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, @@ -130,6 +129,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS view = { width = 30, height = 30, + hide_root_folder = false, side = "left", preserve_window_proportions = false, number = false, @@ -166,7 +166,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS }, ignore_ft_on_setup = {}, system_open = { - cmd = nil, + cmd = "", args = {}, }, diagnostics = { diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index aa7dbc49a0a..cc4433a4007 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -86,7 +86,6 @@ function. require("nvim-tree").setup { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, disable_netrw = false, - hide_root_folder = false, hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, @@ -99,6 +98,7 @@ function. view = { width = 30, height = 30, + hide_root_folder = false, side = "left", preserve_window_proportions = false, number = false, @@ -135,7 +135,7 @@ function. }, ignore_ft_on_setup = {}, system_open = { - cmd = nil, + cmd = "", args = {}, }, diagnostics = { diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 89af06c6c02..4f5caed2d3c 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -311,7 +311,6 @@ end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, disable_netrw = false, - hide_root_folder = false, hijack_cursor = false, hijack_netrw = true, hijack_unnamed_buffer_when_opening = false, From 10b22065efb4dbf9b294caf59a9b2e671a49ac8f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 25 Apr 2022 13:01:06 +1000 Subject: [PATCH 13/13] #1166 validate user's options --- doc/nvim-tree-lua.txt | 1 + lua/nvim-tree.lua | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index cc4433a4007..face92e68a0 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -82,6 +82,7 @@ SETUP *nvim-tree.setup* To configure the tree (and make it runnable), you should call the setup function. +Values may be functions. Warning: this may result in unexpected behaviour. > require("nvim-tree").setup { -- BEGIN_DEFAULT_OPTS auto_reload_on_write = true, diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 4f5caed2d3c..0a56efc7e1d 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -433,15 +433,18 @@ local function validate_options(conf) local msg local function validate(user, def, prefix) - if type(user) ~= "table" or type(def) ~= "table" or not next(def) then + -- only compare tables with contents that are not integer indexed + if type(user) ~= "table" or type(def) ~= "table" or not next(def) or type(next(def)) == "number" then return end for k, v in pairs(user) do local invalid if def[k] == nil then + -- option does not exist invalid = string.format("unknown option: %s%s", prefix, k) - elseif type(v) ~= type(def[k]) then + elseif type(v) ~= type(def[k]) and type(v) ~= "function" then + -- option is of the wrong type and is not a function invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v)) end