diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2024-10-24 15:34:52 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2024-10-24 17:24:45 +0200 |
| commit | 9624fffcfa141335f772938d8c441bdb300e04e6 (patch) | |
| tree | bd6524e940d9294d48833f2a608a7aec2ebf37f5 /scripts/docgen.lua | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.tar nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.tar.gz nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.tar.bz2 nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.tar.lz nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.tar.xz nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.tar.zst nvim-lspconfig-9624fffcfa141335f772938d8c441bdb300e04e6.zip | |
feat(docs): autogenerate default_config docs
Problem:
Docs are manually maintained everywhere for no good reason.
Solution:
- revert commit 9dc02492c4a457479f8a0ec7a65aac1852ff59c0
- provide a "gF" friendly link to the source
Diffstat (limited to 'scripts/docgen.lua')
| -rw-r--r-- | scripts/docgen.lua | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 719e711c..4a62562d 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -9,6 +9,11 @@ local function template(s, params) return (s:gsub('{{([^{}]+)}}', params)) end +--- "@/.../nvim-lspconfig/lua/lspconfig/util.lua" => "./util.lua" +local function relpath(p) + return p:gsub([=[.*[/\\]lua[/\\]lspconfig[/\\]]=], '') +end + local function map_list(t, func) local res = {} for i, v in ipairs(t) do @@ -140,11 +145,29 @@ local function make_lsp_sections() end return make_section(0, '\n', { map_sorted(template_def.default_config, function(k, v) - local description = ((docs or {}).default_config or {})[k] - if description and type(description) ~= 'string' then - description = inspect(description) - elseif not description and type(v) == 'function' then - description = 'see source file' + local description = template_def.default_config[k] + if type(v) ~= 'function' then + description = inspect(v) + else + local info = debug.getinfo(v) + local relname = relpath(info.source) + local file = assert(io.open(string.sub(info.source, 2), 'r')) + + local fnbody = '' + local linenr = 0 + for line in file:lines() do + linenr = linenr + 1 + if linenr >= info.linedefined and linenr <= info.lastlinedefined then + fnbody = ('%s\n%s'):format(fnbody, line) + end + end + io.close(file) + + description = ('-- Source (use "gF" to visit): %s:%d\n'):format( + relname, + info.linedefined, + string.gsub(fnbody, '.*function', 'function') + ) end return string.format('- `%s` : \n```lua\n%s\n```', k, description or inspect(v)) end), @@ -245,7 +268,7 @@ local function make_lsp_sections() if #preamble_parts > 0 then table.insert(preamble_parts, '') end - params.preamble = table.concat(preamble_parts, '\n') + params.preamble = vim.trim(table.concat(preamble_parts, '\n')) end return template(lsp_section_template, params) |
