File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -446,17 +446,20 @@ end
446446--- Flattens a nested table structure into a flat array of strings. Only
447447--- traverses numeric keys, recursively flattening tables and collecting
448448--- strings.
449- --- @param x table<any,any > The input table to flatten.
450- --- @return string[] A flat array of strings extracted from the nested table.
449+ --- @param x table<integer,string | string[] ? > The input table to flatten.
450+ --- @return string[] # A flat array of strings extracted from the nested table.
451451function M .flatten (x )
452452 local ret = {} --- @type string[]
453- for k , v in pairs (x ) do
454- if type (k ) == ' number' then
455- if type (v ) == ' table' then
456- vim .list_extend (ret , M .flatten (v ))
457- elseif type (v ) == ' string' then
458- ret [# ret + 1 ] = v
459- end
453+ for i = 1 , table.maxn (x ) do
454+ local v = x [i ]
455+ if type (v ) == ' table' then
456+ vim .list_extend (ret , M .flatten (v ))
457+ elseif type (v ) == ' string' then
458+ ret [# ret + 1 ] = v
459+ elseif v == nil then
460+ -- skip
461+ else
462+ error (' Expected string or table, got ' .. type (v ))
460463 end
461464 end
462465 return ret
You can’t perform that action at this time.
0 commit comments