Skip to content

Commit 8f30a4a

Browse files
authored
docs(#3088): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute (#3260)
* docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute * docs(#3241): unify help generation and lint into vimdoc.sh, generation uses nvim source build to execute
1 parent b63b467 commit 8f30a4a

File tree

7 files changed

+108
-141
lines changed

7 files changed

+108
-141
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
mkdir -p "${DIR_NVIM_SRC}"
8383
curl -L "https://github.com/neovim/neovim/archive/refs/tags/${{ matrix.nvim_version }}.tar.gz" | tar zx --directory "${DIR_NVIM_SRC}/.."
8484
cd "${DIR_NVIM_SRC}"
85+
make doc
8586
make lintdoc
8687
8788
- run: make help-check

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Help is generated for:
136136

137137
Please add or update documentation when you make changes, see `:help dev-lua-doc` for docstring format.
138138

139-
`scripts/gen_vimdoc_config.lua` contains the manifest of help sources.
139+
`scripts/vimdoc_config.lua` contains the manifest of help sources.
140140

141141
### Config And Mappings
142142

@@ -160,7 +160,7 @@ make help-update
160160
- `*nvim-tree-mappings-default*`
161161
- `*nvim-tree-quickstart-help*`
162162

163-
- `scripts/gen_vimdoc.sh`
163+
- `scripts/vimdoc.sh doc`
164164
- Remove content starting at `*nvim-tree-config*`
165165
- Generate config classes `*nvim-tree-config*`
166166
- Generate API `*nvim-tree-api*`
@@ -175,7 +175,7 @@ make help-check
175175

176176
- Re-runs `make help-update`
177177
- Checks that `git diff` is empty, to ensure that all content has been generated. This is why a stage or commit is necessary.
178-
- Lints `doc/nvim-tree-lua.txt` using `scripts/lintdoc.sh` to check for no broken links etc.
178+
- Lints `doc/nvim-tree-lua.txt` using `scripts/vimdoc.sh lintdoc` to check for no broken links etc.
179179

180180
# Windows
181181

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ style-fix:
3434
# utility
3535
#
3636
help-update:
37-
scripts/gen_vimdoc.sh
37+
scripts/vimdoc.sh doc
3838
scripts/help-defaults.sh
3939

4040
#
4141
# CI
4242
# --ignore-blank-lines is used as nightly has removed unnecessary blank lines that stable (0.11.5) currently inserts
4343
#
4444
help-check: help-update
45-
scripts/lintdoc.sh
45+
scripts/vimdoc.sh lintdoc
4646
git diff --ignore-blank-lines --exit-code doc/nvim-tree-lua.txt
4747

4848

scripts/gen_vimdoc.sh

Lines changed: 0 additions & 74 deletions
This file was deleted.

scripts/lintdoc.sh

Lines changed: 0 additions & 61 deletions
This file was deleted.

scripts/vimdoc.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env sh
2+
3+
# Wrapper around Nvim make targets:
4+
#
5+
# make doc - gen_vimdoc.lua
6+
# Generates doc/nvim-tree-lua.txt
7+
# Uses nvim-tree sources defined in scripts/vimdoc_config.lua
8+
# Shims above into src/gen/gen_vimdoc.lua, replacing Nvim's config.
9+
#
10+
# make lintdoc - lintdoc.lua
11+
# Validates doc/nvim-tree-lua.txt
12+
# Desired:
13+
# - tags valid
14+
# - links valid
15+
# Also:
16+
# - brand spelling, notably Nvim and Lua
17+
#
18+
# There are some hardcoded expectations which we work around as commented.
19+
20+
set -e
21+
22+
if [ $# -ne 1 ] || [ "${1}" != "doc" ] && [ "${1}" != "lintdoc" ]; then
23+
echo "usage: ${0} <doc|lintdoc>" 1>&2
24+
exit 1
25+
fi
26+
27+
DIR_NVIM_SRC_DEF="/tmp/src/neovim-stable"
28+
29+
if [ ! -d "lua/nvim-tree" ]; then
30+
echo "Must be run from nvim-tree root" 1>&2
31+
exit 1
32+
fi
33+
34+
if [ -z "${DIR_NVIM_SRC}" ] && [ -d "${DIR_NVIM_SRC_DEF}" ]; then
35+
export DIR_NVIM_SRC="${DIR_NVIM_SRC_DEF}"
36+
fi
37+
38+
if [ ! -d "${DIR_NVIM_SRC}" ]; then
39+
cat << EOM
40+
41+
Nvim source v0.11+ is required to run ${0}
42+
43+
Unavailable: ${DIR_NVIM_SRC_DEF} or \$DIR_NVIM_SRC=${DIR_NVIM_SRC}
44+
45+
Please:
46+
mkdir -p ${DIR_NVIM_SRC_DEF}
47+
curl -L 'https://github.com/neovim/neovim/archive/refs/tags/stable.tar.gz' | tar zx --directory $(dirname "${DIR_NVIM_SRC_DEF}")
48+
or use your own e.g.
49+
export DIR_NVIM_SRC="\${HOME}/src/neovim"
50+
51+
EOM
52+
exit 1
53+
fi
54+
55+
cleanup() {
56+
# remove source link
57+
rm -fv "${DIR_NVIM_SRC}/runtime/lua/nvim_tree"
58+
59+
# remove our config
60+
rm -fv "${DIR_NVIM_SRC}/src/gen/vimdoc_config.lua"
61+
62+
# remove generated help
63+
rm -fv "${DIR_NVIM_SRC}/runtime/doc/nvim-tree-lua.txt"
64+
65+
# revert generator if present
66+
if [ -f "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org" ]; then
67+
mv -v "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org" "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua"
68+
fi
69+
}
70+
71+
# clean up any previous failed runs
72+
cleanup
73+
74+
# runtime/doc is hardcoded, copy the help in
75+
cp -v "doc/nvim-tree-lua.txt" "${DIR_NVIM_SRC}/runtime/doc"
76+
77+
# setup doc generation
78+
if [ "${1}" = "doc" ]; then
79+
# runtime/lua is available, link our sources in there
80+
# gen_vimdoc.lua doesn't like dashes in lua module names
81+
# -> use nvim_tree instead of nvim-tree
82+
ln -sv "${PWD}/lua/nvim-tree" "${DIR_NVIM_SRC}/runtime/lua/nvim_tree"
83+
84+
# modify gen_vimdoc.lua to use our config, backing up original
85+
cp "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua" "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua.org"
86+
sed -i -E 's/spairs\(config\)/spairs\(require("gen.vimdoc_config")\)/g' "${DIR_NVIM_SRC}/src/gen/gen_vimdoc.lua"
87+
88+
# copy our config
89+
cp -v "scripts/vimdoc_config.lua" "${DIR_NVIM_SRC}/src/gen"
90+
fi
91+
92+
# run from within Nvim source
93+
cd "${DIR_NVIM_SRC}"
94+
make "${1}"
95+
cd -
96+
97+
# copy the generated help out
98+
cp -v "${DIR_NVIM_SRC}/runtime/doc/nvim-tree-lua.txt" "doc"
99+
100+
# cleanup as everything succeeded
101+
cleanup
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--nvim-tree configuration for Nvim's gen_vimdoc.lua
22
--Returned config is injected into the above.
3-
--See gen_vimdoc.sh
3+
--Execute with `make doc`, see scripts/vimdoc.sh for details.
44

55
--gen_vimdoc keys by filename: -- FIXME: Using f_base will confuse `_meta/protocol.lua` with `protocol.lua`
66
--Hence we must ensure that filenames are unique within each nvim.gen_vimdoc.Config[]

0 commit comments

Comments
 (0)