From a46c925858d1f19716b26816ef984a3942c7d902 Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 20 Aug 2022 21:10:55 -0400 Subject: [PATCH] Enforce kinds ordering in lua docs --- luacs-docs/lua/templates/sidebar.ltp | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/luacs-docs/lua/templates/sidebar.ltp b/luacs-docs/lua/templates/sidebar.ltp index aec7570c7..62135f97e 100644 --- a/luacs-docs/lua/templates/sidebar.ltp +++ b/luacs-docs/lua/templates/sidebar.ltp @@ -23,6 +23,36 @@ local function isSectionEmpty(mod, sections) end return true end + +local function kinds() + local kinds = {"Manual", "Code", "Enum"} + + local kindIndices = {} + for i, v in pairs(kinds) do + kindIndices[v] = i + end + + local t = {} + for kind, mods, type in ldoc.kinds() do + local entry = {kind, mods, type} + local idx = kindIndices[kind] + + if idx then + t[idx] = entry + else + t[#t + 1] = entry + end + end + + local idx + return function(t, i) + i = i + 1 + local v = t[i] + if v then + return i, table.unpack(v) + end + end, t, 0 +end %}