aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/docgen.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-10-24 17:05:21 +0200
committerJustin M. Keyes <justinkz@gmail.com>2024-10-24 17:24:48 +0200
commit903866024cd6c93a6acefd359329364234a65754 (patch)
treeb718eb4f88830d0843e45dc350ac7b5356f98d05 /scripts/docgen.lua
parentfeat(docs): autogenerate default_config docs (diff)
downloadnvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.tar
nvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.tar.gz
nvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.tar.bz2
nvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.tar.lz
nvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.tar.xz
nvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.tar.zst
nvim-lspconfig-903866024cd6c93a6acefd359329364234a65754.zip
feat(docs): autogenerate default_config docs
Problem: debug.info() is useless for some functions because they point to util.lua Solution: Provide a path to the source code instead of trying to inline the source code.
Diffstat (limited to 'scripts/docgen.lua')
-rw-r--r--scripts/docgen.lua44
1 files changed, 22 insertions, 22 deletions
diff --git a/scripts/docgen.lua b/scripts/docgen.lua
index 4a62562d..22abc294 100644
--- a/scripts/docgen.lua
+++ b/scripts/docgen.lua
@@ -83,7 +83,7 @@ require'lspconfig'.{{config_name}}.setup{}
```
{{commands}}
-**Default values:**
+**Default config:**
{{default_values}}
]]
@@ -113,6 +113,8 @@ local function make_lsp_sections()
map_sorted(configs, function(config_name, template_object)
local template_def = template_object.config_def
local docs = template_def.docs
+ -- "lua/lspconfig/configs/xx.lua"
+ local config_file = ('lua/lspconfig/configs/%s.lua'):format(config_name)
local params = {
config_name = config_name,
@@ -145,31 +147,29 @@ local function make_lsp_sections()
end
return make_section(0, '\n', {
map_sorted(template_def.default_config, function(k, v)
- 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'))
+ return ('- `%s` :\n```lua\n%s\n```'):format(k, inspect(v))
+ end
- 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
+ local file = assert(io.open(config_file, 'r'))
+ local linenr = 0
+ -- Find the line where `default_config` is defined.
+ for line in file:lines() do
+ linenr = linenr + 1
+ if line:find('%sdefault_config%s') then
+ break
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))
+ io.close(file)
+
+ -- XXX: "../" because the path is outside of the doc/ dir.
+ return ('- `%s` source (use "gF" to visit): [../%s:%d](../%s#L%d)\n'):format(
+ k,
+ config_file,
+ linenr,
+ config_file,
+ linenr
+ )
end),
})
end,