diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml index 751837d0c2..be5c02c446 100644 --- a/.github/workflows/docgen.yml +++ b/.github/workflows/docgen.yml @@ -18,7 +18,7 @@ jobs: version: nightly - name: Run docgen run: | - scripts/docgen.sh + scripts/docgen.lua - name: Commit changes env: COMMIT_MSG: | diff --git a/scripts/docgen.lua b/scripts/docgen.lua old mode 100644 new mode 100755 index c1302bb53a..538ed2adf4 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -1,3 +1,7 @@ +#!/usr/bin/env -S nvim -l +local root = vim.trim(vim.system({ 'git', 'rev-parse', '--show-toplevel' }):wait().stdout) +vim.opt.rtp:append(root) + require 'lspconfig' local configs = require 'lspconfig.configs' local util = require 'lspconfig.util' @@ -89,7 +93,7 @@ local function require_all_configs() vim.env.XDG_CACHE_HOME = '/home/user/.cache' -- Configs are lazy-loaded, tickle them to populate the `configs` singleton. - for _, v in ipairs(vim.fn.glob('lua/lspconfig/configs/*.lua', true, true)) do + for _, v in ipairs(vim.fn.glob(vim.fs.joinpath(root, 'lua/lspconfig/configs/*.lua'), true, true)) do local module_name = v:gsub('.*/', ''):gsub('%.lua$', '') configs[module_name] = require('lspconfig.configs.' .. module_name) end @@ -107,7 +111,7 @@ local function make_lsp_sections() 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 config_file = (vim.fs.joinpath(root, 'lua/lspconfig/configs/%s.lua')):format(config_name) local params = { config_name = config_name, @@ -155,13 +159,14 @@ local function make_lsp_sections() end end io.close(file) + local config_relpath = vim.fs.relpath(root, config_file) -- XXX: "../" because the path is outside of the doc/ dir. return ('- `%s` source (use "gF" to visit): [../%s:%d](../%s#L%d)'):format( k, - config_file, + config_relpath, linenr, - config_file, + config_relpath, linenr ) end), @@ -284,14 +289,17 @@ local function generate_readme(template_file, params) local input_template = readfile(template_file) local readme_data = template(input_template, params) - local writer = assert(io.open('doc/configs.md', 'w')) + local conf_md = vim.fs.joinpath(root, 'doc/configs.md') + local conf_txt = vim.fs.joinpath(root, 'doc/configs.txt') + + local writer = assert(io.open(conf_md, 'w')) writer:write(readme_data) writer:close() - vim.loop.fs_copyfile('doc/configs.md', 'doc/configs.txt') + vim.loop.fs_copyfile(conf_md, conf_txt) end require_all_configs() -generate_readme('scripts/docs_template.md', { +generate_readme(vim.fs.joinpath(root, 'scripts/docs_template.md'), { implemented_servers_list = make_implemented_servers_list(), lsp_server_details = make_lsp_sections(), }) diff --git a/scripts/docgen.sh b/scripts/docgen.sh deleted file mode 100755 index 288465430c..0000000000 --- a/scripts/docgen.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec nvim -u NONE -E -R --headless +'set rtp+=$PWD' +'luafile scripts/docgen.lua' +q