|
1 | 1 | #!/usr/bin/env sh |
2 | 2 |
|
3 | | -# Performs a lua-language-server check on all files. |
4 | | -# luals-out/check.json will be produced on any issues, returning 1. |
5 | | -# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc. |
| 3 | +# Performs a lua-language-server check on all lua files. |
6 | 4 | # $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset. |
7 | 5 | # |
8 | 6 | # Call with codestyle-check param to enable only codestyle-check |
| 7 | +# |
| 8 | +# lua-language-server is inconsisent about which parameters must be absolute paths therefore we pass every path as absolute |
| 9 | + |
| 10 | +if [ $# -eq 1 ] && [ "${1}" != "codestyle-check" ] || [ $# -gt 1 ] ; then |
| 11 | + echo "usage: ${0} [codestyle-check]" 1>&2 |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +DIR_NVT="${PWD}" |
| 16 | + |
| 17 | +if [ ! -f "${DIR_NVT}/scripts/luals-check.sh" ]; then |
| 18 | + echo "Must be run from nvim-tree root" 1>&2 |
| 19 | + exit 1 |
| 20 | +fi |
9 | 21 |
|
10 | 22 | if [ -z "${VIMRUNTIME}" ]; then |
11 | 23 | export VIMRUNTIME="/usr/share/nvim/runtime" |
| 24 | + echo "Defaulting to VIMRUNTIME=${VIMRUNTIME}" |
| 25 | +fi |
| 26 | + |
| 27 | +if [ ! -d "${VIMRUNTIME}" ]; then |
| 28 | + echo "\$VIMRUNTIME=${VIMRUNTIME} not found" 1>&2 |
| 29 | + exit 1 |
12 | 30 | fi |
13 | 31 |
|
14 | | -DIR_SRC="${PWD}/lua" |
15 | | -DIR_OUT="${PWD}/luals-out" |
16 | | -FILE_LUARC="${DIR_OUT}/luarc.json" |
| 32 | +DIR_OUT="${DIR_NVT}/luals-out" |
| 33 | +LUARC="${DIR_OUT}/luarc.json" |
| 34 | +RC=0 |
17 | 35 |
|
18 | | -# clear output |
| 36 | +# clear previous output |
19 | 37 | rm -rf "${DIR_OUT}" |
20 | 38 | mkdir "${DIR_OUT}" |
21 | 39 |
|
| 40 | +# create the luarc.json for the requested check |
22 | 41 | case "${1}" in |
23 | 42 | "codestyle-check") |
24 | 43 | jq \ |
25 | 44 | '.diagnostics.neededFileStatus[] = "None" | .diagnostics.neededFileStatus."codestyle-check" = "Any"' \ |
26 | | - "${PWD}/.luarc.json" > "${FILE_LUARC}" |
| 45 | + "${DIR_NVT}/.luarc.json" > "${LUARC}" |
27 | 46 |
|
28 | 47 | ;; |
29 | 48 | *) |
30 | | - cp "${PWD}/.luarc.json" "${FILE_LUARC}" |
| 49 | + cp "${DIR_NVT}/.luarc.json" "${LUARC}" |
31 | 50 | ;; |
32 | 51 | esac |
33 | 52 |
|
34 | | -# execute inside lua directory to prevent luals itself from being checked |
35 | | -OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${FILE_LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error) |
36 | | -RC=$? |
37 | | - |
38 | | -echo "${OUT}" >&2 |
| 53 | +for SRC in lua scripts; do |
| 54 | + DIR_SRC="${DIR_NVT}/${SRC}" |
| 55 | + FILE_OUT="${DIR_OUT}/out.${SRC}.log" |
| 56 | + echo "Checking ${SRC}/" |
39 | 57 |
|
40 | | -if [ $RC -ne 0 ]; then |
41 | | - echo "failed with RC=$RC" |
42 | | - exit $RC |
43 | | -fi |
| 58 | + lua-language-server --check="${DIR_SRC}" --configpath="${LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error 2>&1 | tee "${FILE_OUT}" |
44 | 59 |
|
45 | | -# any output is a fail |
46 | | -case "${OUT}" in |
47 | | - *Diagnosis\ completed,\ no\ problems\ found*) |
48 | | - exit 0 |
49 | | - ;; |
50 | | - *) |
51 | | - cat "${DIR_OUT}/check.json" |
52 | | - exit 1 |
53 | | - ;; |
54 | | -esac |
| 60 | + if ! grep --quiet "Diagnosis completed, no problems found" "${FILE_OUT}"; then |
| 61 | + RC=1 |
| 62 | + fi |
| 63 | +done |
55 | 64 |
|
| 65 | +exit "${RC}" |
0 commit comments