@@ -620,14 +620,27 @@ local FIELD_SKIP_VALIDATE = {
620
620
open_win_config = true ,
621
621
}
622
622
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
+ },
631
644
}
632
645
633
646
local ACCEPTED_STRINGS = {
@@ -652,7 +665,7 @@ local ACCEPTED_STRINGS = {
652
665
local function validate_options (conf )
653
666
local msg
654
667
655
- local function validate (user , def , strs , prefix )
668
+ local function validate (user , def , strs , types , prefix )
656
669
-- only compare tables with contents that are not integer indexed
657
670
if type (user ) ~= " table" or type (def ) ~= " table" or not next (def ) or type (next (def )) == " number" then
658
671
return
@@ -661,11 +674,11 @@ local function validate_options(conf)
661
674
for k , v in pairs (user ) do
662
675
if not FIELD_SKIP_VALIDATE [k ] then
663
676
local invalid
664
- local override_typecheck = FIELD_OVERRIDE_TYPECHECK [ k ] or {}
677
+
665
678
if def [k ] == nil then
666
679
-- option does not exist
667
680
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
669
682
-- option is of the wrong type and is not a function
670
683
invalid =
671
684
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)
682
695
end
683
696
user [k ] = nil
684
697
else
685
- validate (v , def [k ], strs [k ] or {}, prefix .. k .. " ." )
698
+ validate (v , def [k ], strs [k ] or {}, types [ k ] or {}, prefix .. k .. " ." )
686
699
end
687
700
end
688
701
end
689
702
end
690
703
691
- validate (conf , DEFAULT_OPTS , ACCEPTED_STRINGS , " " )
704
+ validate (conf , DEFAULT_OPTS , ACCEPTED_STRINGS , ACCEPTED_TYPES , " " )
692
705
693
706
if msg then
694
707
vim .notify_once (msg .. " | see :help nvim-tree-opts for available configuration options" , vim .log .levels .WARN )
0 commit comments