Skip to content

Commit c8f93a9

Browse files
committed
refactor: follow config structure for ACCEPTED_TYPES
1 parent 94c7c81 commit c8f93a9

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

lua/nvim-tree.lua

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,27 @@ local FIELD_SKIP_VALIDATE = {
620620
open_win_config = true,
621621
}
622622

623-
local FIELD_OVERRIDE_TYPECHECK = {
624-
width = { string = true, ["function"] = true, number = true, ["table"] = true },
625-
max = { string = true, ["function"] = true, number = true },
626-
min = { string = true, ["function"] = true, number = true },
627-
on_attach = { ["function"] = true, string = true },
628-
sorter = { ["function"] = true, string = true },
629-
root_folder_label = { ["function"] = true, string = true, boolean = true },
630-
picker = { ["function"] = true, string = true },
623+
local ACCEPTED_TYPES = {
624+
on_attach = { "function", "string" },
625+
sort = {
626+
sorter = { "function", "string" },
627+
},
628+
view = {
629+
width = { "string", "function", "number", "table",
630+
min = { "string", "function", "number" },
631+
max = { "string", "function", "number" },
632+
},
633+
},
634+
renderer = {
635+
root_folder_label = { "function", "string", "boolean" },
636+
},
637+
actions = {
638+
open_file = {
639+
window_picker = {
640+
picker = { "function", "string" },
641+
},
642+
},
643+
},
631644
}
632645

633646
local ACCEPTED_STRINGS = {
@@ -652,7 +665,7 @@ local ACCEPTED_STRINGS = {
652665
local function validate_options(conf)
653666
local msg
654667

655-
local function validate(user, def, strs, prefix)
668+
local function validate(user, def, strs, types, prefix)
656669
-- only compare tables with contents that are not integer indexed
657670
if type(user) ~= "table" or type(def) ~= "table" or not next(def) or type(next(def)) == "number" then
658671
return
@@ -661,11 +674,11 @@ local function validate_options(conf)
661674
for k, v in pairs(user) do
662675
if not FIELD_SKIP_VALIDATE[k] then
663676
local invalid
664-
local override_typecheck = FIELD_OVERRIDE_TYPECHECK[k] or {}
677+
665678
if def[k] == nil then
666679
-- option does not exist
667680
invalid = string.format("[NvimTree] unknown option: %s%s", prefix, k)
668-
elseif type(v) ~= type(def[k]) and not override_typecheck[type(v)] then
681+
elseif type(v) ~= type(def[k]) and types[k] and not vim.tbl_contains(types[k], type(v)) then
669682
-- option is of the wrong type and is not a function
670683
invalid =
671684
string.format("[NvimTree] invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
@@ -682,13 +695,13 @@ local function validate_options(conf)
682695
end
683696
user[k] = nil
684697
else
685-
validate(v, def[k], strs[k] or {}, prefix .. k .. ".")
698+
validate(v, def[k], strs[k] or {}, types[k] or {}, prefix .. k .. ".")
686699
end
687700
end
688701
end
689702
end
690703

691-
validate(conf, DEFAULT_OPTS, ACCEPTED_STRINGS, "")
704+
validate(conf, DEFAULT_OPTS, ACCEPTED_STRINGS, ACCEPTED_TYPES, "")
692705

693706
if msg then
694707
vim.notify_once(msg .. " | see :help nvim-tree-opts for available configuration options", vim.log.levels.WARN)

0 commit comments

Comments
 (0)