aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen_vimdoc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gen_vimdoc.lua')
-rwxr-xr-xscripts/gen_vimdoc.lua110
1 files changed, 81 insertions, 29 deletions
diff --git a/scripts/gen_vimdoc.lua b/scripts/gen_vimdoc.lua
index 22df411a35..9c6225efc3 100755
--- a/scripts/gen_vimdoc.lua
+++ b/scripts/gen_vimdoc.lua
@@ -94,12 +94,12 @@ end
local function fn_helptag_fmt_common(fun)
local fn_sfx = fun.table and '' or '()'
if fun.classvar then
- return fmt('*%s:%s%s*', fun.classvar, fun.name, fn_sfx)
+ return fmt('%s:%s%s', fun.classvar, fun.name, fn_sfx)
end
if fun.module then
- return fmt('*%s.%s%s*', fun.module, fun.name, fn_sfx)
+ return fmt('%s.%s%s', fun.module, fun.name, fn_sfx)
end
- return fmt('*%s%s*', fun.name, fn_sfx)
+ return fun.name .. fn_sfx
end
--- @type table<string,nvim.gen_vimdoc.Config>
@@ -129,7 +129,7 @@ local config = {
return name .. ' Functions'
end,
helptag_fmt = function(name)
- return fmt('*api-%s*', name:lower())
+ return fmt('api-%s', name:lower())
end,
},
lua = {
@@ -241,22 +241,22 @@ local config = {
end,
helptag_fmt = function(name)
if name == '_editor' then
- return '*lua-vim*'
+ return 'lua-vim'
elseif name == '_options' then
- return '*lua-vimscript*'
+ return 'lua-vimscript'
elseif name == 'tohtml' then
- return '*tohtml*'
+ return 'tohtml'
end
- return '*vim.' .. name:lower() .. '*'
+ return 'vim.' .. name:lower()
end,
fn_helptag_fmt = function(fun)
local name = fun.name
if vim.startswith(name, 'vim.') then
local fn_sfx = fun.table and '' or '()'
- return fmt('*%s%s*', name, fn_sfx)
+ return name .. fn_sfx
elseif fun.classvar == 'Option' then
- return fmt('*vim.opt:%s()*', name)
+ return fmt('vim.opt:%s()', name)
end
return fn_helptag_fmt_common(fun)
@@ -297,9 +297,9 @@ local config = {
end,
helptag_fmt = function(name)
if name:lower() == 'lsp' then
- return '*lsp-core*'
+ return 'lsp-core'
end
- return fmt('*lsp-%s*', name:lower())
+ return fmt('lsp-%s', name:lower())
end,
},
diagnostic = {
@@ -312,7 +312,7 @@ local config = {
return 'Lua module: vim.diagnostic'
end,
helptag_fmt = function()
- return '*diagnostic-api*'
+ return 'diagnostic-api'
end,
},
treesitter = {
@@ -337,9 +337,43 @@ local config = {
end,
helptag_fmt = function(name)
if name:lower() == 'treesitter' then
- return '*lua-treesitter-core*'
+ return 'lua-treesitter-core'
end
- return '*lua-treesitter-' .. name:lower() .. '*'
+ return 'lua-treesitter-' .. name:lower()
+ end,
+ },
+ editorconfig = {
+ filename = 'editorconfig.txt',
+ files = {
+ 'runtime/lua/editorconfig.lua',
+ },
+ section_order = {
+ 'editorconfig.lua',
+ },
+ section_fmt = function(_name)
+ return 'EditorConfig integration'
+ end,
+ helptag_fmt = function(name)
+ return name:lower()
+ end,
+ fn_xform = function(fun)
+ fun.table = true
+ fun.name = vim.split(fun.name, '.', { plain = true })[2]
+ end,
+ },
+ health = {
+ filename = 'health.txt',
+ files = {
+ 'runtime/lua/vim/health.lua',
+ },
+ section_order = {
+ 'health.lua',
+ },
+ section_fmt = function(_name)
+ return 'Checkhealth'
+ end,
+ helptag_fmt = function(name)
+ return name:lower()
end,
},
}
@@ -469,10 +503,12 @@ local function inline_type(obj, classes)
local desc_append = {}
for _, f in ipairs(cls.fields) do
- local fdesc, default = get_default(f.desc)
- local fty = render_type(f.type, nil, default)
- local fnm = fmt_field_name(f.name)
- table.insert(desc_append, table.concat({ '-', fnm, fty, fdesc }, ' '))
+ if not f.access then
+ local fdesc, default = get_default(f.desc)
+ local fty = render_type(f.type, nil, default)
+ local fnm = fmt_field_name(f.name)
+ table.insert(desc_append, table.concat({ '-', fnm, fty, fdesc }, ' '))
+ end
end
desc = desc .. '\n' .. table.concat(desc_append, '\n')
@@ -593,6 +629,12 @@ local function render_fun_header(fun, cfg)
if fun.classvar then
nm = fmt('%s:%s', fun.classvar, nm)
end
+ if nm == 'vim.bo' then
+ nm = 'vim.bo[{bufnr}]'
+ end
+ if nm == 'vim.wo' then
+ nm = 'vim.wo[{winid}][{bufnr}]'
+ end
local proto = fun.table and nm or nm .. '(' .. table.concat(args, ', ') .. ')'
@@ -600,7 +642,7 @@ local function render_fun_header(fun, cfg)
cfg.fn_helptag_fmt = fn_helptag_fmt_common
end
- local tag = cfg.fn_helptag_fmt(fun)
+ local tag = '*' .. cfg.fn_helptag_fmt(fun) .. '*'
if #proto + #tag > TEXT_WIDTH - 8 then
table.insert(ret, fmt('%78s\n', tag))
@@ -747,10 +789,17 @@ local function render_funs(funs, classes, cfg)
ret[#ret + 1] = render_fun(f, classes, cfg)
end
- -- Sort via prototype
+ -- Sort via prototype. Experimental API functions ("nvim__") sort last.
table.sort(ret, function(a, b)
local a1 = ('\n' .. a):match('\n[a-zA-Z_][^\n]+\n')
local b1 = ('\n' .. b):match('\n[a-zA-Z_][^\n]+\n')
+
+ local a1__ = a1:find('^%s*nvim__') and 1 or 0
+ local b1__ = b1:find('^%s*nvim__') and 1 or 0
+ if a1__ ~= b1__ then
+ return a1__ < b1__
+ end
+
return a1:lower() < b1:lower()
end)
@@ -816,7 +865,7 @@ local function make_section(filename, cfg, section_docs, funs_txt)
local sectname = cfg.section_name and cfg.section_name[filename] or mktitle(name)
-- section tag: e.g., "*api-autocmd*"
- local help_tag = cfg.helptag_fmt(sectname)
+ local help_tag = '*' .. cfg.helptag_fmt(sectname) .. '*'
if funs_txt == '' and #section_docs == 0 then
return
@@ -845,9 +894,9 @@ local function render_section(section, add_header)
})
end
- if section.doc and #section.doc > 0 then
- table.insert(doc, '\n\n')
- vim.list_extend(doc, section.doc)
+ local sdoc = '\n\n' .. table.concat(section.doc or {}, '\n')
+ if sdoc:find('[^%s]') then
+ doc[#doc + 1] = sdoc
end
if section.funs_txt then
@@ -880,6 +929,7 @@ end
--- @param cfg nvim.gen_vimdoc.Config
local function gen_target(cfg)
+ print('Target:', cfg.filename)
local sections = {} --- @type table<string,nvim.gen_vimdoc.Section>
expand_files(cfg.files)
@@ -891,7 +941,7 @@ local function gen_target(cfg)
local all_classes = {}
--- First pass so we can collect all classes
- for _, f in pairs(cfg.files) do
+ for _, f in vim.spairs(cfg.files) do
local ext = assert(f:match('%.([^.]+)$')) --[[@as 'h'|'c'|'lua']]
local parser = assert(parsers[ext])
local classes, funs, briefs = parser(f)
@@ -899,13 +949,14 @@ local function gen_target(cfg)
all_classes = vim.tbl_extend('error', all_classes, classes)
end
- for f, r in pairs(file_results) do
+ for f, r in vim.spairs(file_results) do
local classes, funs, briefs = r[1], r[2], r[3]
local briefs_txt = {} --- @type string[]
for _, b in ipairs(briefs) do
briefs_txt[#briefs_txt + 1] = md_to_vimdoc(b, 0, 0, TEXT_WIDTH)
end
+ print(' Processing file:', f)
local funs_txt = render_funs(funs, all_classes, cfg)
if next(classes) then
local classes_txt = render_classes(classes)
@@ -923,8 +974,9 @@ local function gen_target(cfg)
for _, f in ipairs(cfg.section_order) do
local section = sections[f]
if section then
+ print(string.format(" Rendering section: '%s'", section.title))
local add_sep_and_header = not vim.tbl_contains(cfg.append_only or {}, f)
- table.insert(docs, render_section(section, add_sep_and_header))
+ docs[#docs + 1] = render_section(section, add_sep_and_header)
end
end
@@ -945,7 +997,7 @@ local function gen_target(cfg)
end
local function run()
- for _, cfg in pairs(config) do
+ for _, cfg in vim.spairs(config) do
gen_target(cfg)
end
end