aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen_eval_files.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-10-06 09:12:35 -0700
committerGitHub <noreply@github.com>2024-10-06 09:12:35 -0700
commit6628741ada73bcf60dd1cb249178aa18e60dbebc (patch)
treefa36b7069875b62d5e532b531b52e1e33a5a9b9e /scripts/gen_eval_files.lua
parent00d1078ede9e0f03dd5eecbc9599d39c913ab953 (diff)
downloadrneovim-6628741ada73bcf60dd1cb249178aa18e60dbebc.tar.gz
rneovim-6628741ada73bcf60dd1cb249178aa18e60dbebc.tar.bz2
rneovim-6628741ada73bcf60dd1cb249178aa18e60dbebc.zip
feat(docs): improve `@see` meta docstrings #30693
Diffstat (limited to 'scripts/gen_eval_files.lua')
-rwxr-xr-xscripts/gen_eval_files.lua23
1 files changed, 13 insertions, 10 deletions
diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua
index 6aa8ee0112..25f3e30b74 100755
--- a/scripts/gen_eval_files.lua
+++ b/scripts/gen_eval_files.lua
@@ -199,14 +199,6 @@ local function process_params(params)
return params
end
---- @class vim.gen_vim_doc_fun
---- @field signature string
---- @field doc string[]
---- @field parameters_doc table<string,string>
---- @field return string[]
---- @field seealso string[]
---- @field annotations string[]
-
--- @return table<string, vim.EvalFn>
local function get_api_meta()
local ret = {} --- @type table<string, vim.EvalFn>
@@ -290,8 +282,19 @@ end
--- Ensure code blocks have one empty line before the start fence and after the closing fence.
---
--- @param x string
+--- @param special string?
+--- | 'see-api-meta' Normalize `@see` for API meta docstrings.
--- @return string
-local function norm_text(x)
+local function norm_text(x, special)
+ if special == 'see-api-meta' then
+ -- Try to guess a symbol that actually works in @see.
+ -- "nvim_xx()" => "vim.api.nvim_xx"
+ x = x:gsub([=[%|?(nvim_[^.()| ]+)%(?%)?%|?]=], 'vim.api.%1')
+ -- TODO: Remove backticks when LuaLS resolves: https://github.com/LuaLS/lua-language-server/issues/2889
+ -- "|foo|" => "`:help foo`"
+ x = x:gsub([=[|([^ ]+)|]=], '`:help %1`')
+ end
+
return (
x:gsub('|([^ ]+)|', '`%1`')
:gsub('\n*>lua', '\n\n```lua')
@@ -332,7 +335,7 @@ local function render_api_meta(_f, fun, write)
end
for _, see in ipairs(fun.see or {}) do
- write(util.prefix_lines('--- @see ', norm_text(see)))
+ write(util.prefix_lines('--- @see ', norm_text(see, 'see-api-meta')))
end
local param_names = {} --- @type string[]