Skip to content

Commit 6a99f5a

Browse files
authored
ci: lua language server and Makefile (#2546)
* ci: add lls-check * ci: add lls-check to ci.yml * ci: download lua-language-server binary * ci: download lua-language-server binary * ci: dummy failure to test * Revert "ci: dummy failure to test" This reverts commit 2bc43ba. * ci: ignore lls-out * ci: better name * ci: shellcheck nits * ci: add luals libs and tidy * ci: tidy * ci: add neovim 0.9.4 * ci: add ci neovim 0.9.4 to lib path * ci: dummy failure to test * Revert "ci: dummy failure to test" This reverts commit 4598733. * Revert "ci: add ci neovim 0.9.4 to lib path" This reverts commit 4f397d6. * Revert "ci: add neovim 0.9.4" This reverts commit 46fd1b3. * ci: action downloads and installs luals * ci: remove workspaces from luals * ci: consistent script naming * ci: add quality to contributing * ci: consistent script naming * ci: add lsp to diagnostics * ci: temporary find to enumerate home * ci: add VIMRUNTIME for lls * ci: temporary find to enumerate home * ci: temporary find to enumerate home * ci: remove temporary find to enumerate home * ci: correct VIMRUNTIME * ci: add ${3rd}/luv/library * ci: note VIMRUNTIME override * ci: add Makefile * ci: add Makefile * ci: add Makefile * ci: add Makefile * ci: document checks and fixes * ci: add help check * ci: add help check * ci: dummy help failure * Revert "ci: dummy help failure" This reverts commit c50ccea. * ci: document checks and fixes * ci: document checks and fixes * ci: matrix nvim version * ci: matrix nvim version * Revert "ci: matrix nvim version" This reverts commit fcef6a1. * Revert "ci: matrix nvim version" This reverts commit a8cb50d. * ci: matrix nvim version from env * ci: matrix nvim version from env * ci: matrix nvim version from env * ci: matrix nvim version * ci: matrix nvim version * ci: matrix per job * ci: matrix per job * ci: many lua versions * ci: move doc to style * ci: tidy ci and contributing
1 parent f1b3e6a commit 6a99f5a

File tree

11 files changed

+203
-37
lines changed

11 files changed

+203
-37
lines changed

.github/workflows/ci.yml

+42-8
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,65 @@ permissions:
1414
jobs:
1515
lint:
1616
runs-on: ubuntu-latest
17+
18+
strategy:
19+
matrix:
20+
lua_version: [ 5.1 ]
21+
1722
steps:
1823
- uses: actions/checkout@v4
1924

2025
- uses: leafo/gh-actions-lua@v10
2126
with:
22-
luaVersion: "5.1"
27+
luaVersion: ${{ matrix.lua_version }}
2328

2429
- uses: leafo/gh-actions-luarocks@v4
2530

26-
- name: luacheck
27-
run: |
28-
luarocks install luacheck 1.1.1
29-
luacheck lua
31+
- run: luarocks install luacheck 1.1.1
32+
33+
- run: make lint
3034

3135
style:
3236
runs-on: ubuntu-latest
37+
38+
strategy:
39+
matrix:
40+
stylua_version: [ 0.19.1 ]
41+
3342
steps:
3443
- uses: actions/checkout@v4
3544

3645
- name: stylua
3746
uses: JohnnyMorganz/stylua-action@v3
3847
with:
3948
token: ${{ secrets.GITHUB_TOKEN }}
40-
version: "0.19"
49+
version: ${{ matrix.stylua_version }}
4150
args: --check lua
4251

43-
- name: doc-comments
44-
run: ./scripts/doc-comments.sh
52+
- run: make style-doc
53+
54+
check:
55+
runs-on: ubuntu-latest
56+
57+
strategy:
58+
matrix:
59+
nvim_version: [ v0.9.4 ]
60+
luals_version: [ 3.7.3 ]
61+
62+
steps:
63+
- uses: actions/checkout@v3
64+
65+
- uses: rhysd/action-setup-vim@v1
66+
with:
67+
neovim: true
68+
version: ${{ matrix.nvim_version }}
69+
70+
- name: install luals
71+
run: |
72+
mkdir -p luals
73+
curl -L "https://github.com/LuaLS/lua-language-server/releases/download/${{ matrix.luals_version }}/lua-language-server-${{ matrix.luals_version }}-linux-x64.tar.gz" | tar zx --directory luals
74+
75+
- name: make check
76+
run: VIMRUNTIME=/home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime PATH="luals/bin:${PATH}" make check
77+
78+
- run: make help-check

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/luals-out/
2+
/luals/

.hooks/pre-commit.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
stylua . --check || exit 1
4-
luacheck . || exit 1
3+
make

.luarc.json

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
33
"runtime.version" : "Lua 5.1",
4+
"workspace": {
5+
"library": [
6+
"$VIMRUNTIME/lua/vim/lsp",
7+
"${3rd}/luv/library"
8+
]
9+
},
410
"diagnostics": {
11+
"libraryFiles": "Disable",
512
"globals": [
613
"vim"
714
],

CONTRIBUTING.md

+57-12
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,76 @@ Thank you for contributing.
44

55
See [Development](https://github.com/nvim-tree/nvim-tree.lua/wiki/Development) for environment setup, tips and tools.
66

7-
## Styling and formatting
7+
# Tools
88

9-
Code is formatted using luacheck, and linted using stylua.
10-
You can install these with:
9+
Following are used during CI and strongly recommended during local development.
1110

12-
```bash
13-
luarocks install luacheck
14-
cargo install stylua
11+
Lint: [luacheck](https://github.com/lunarmodules/luacheck/)
12+
13+
Style: [StyLua](https://github.com/JohnnyMorganz/StyLua)
14+
15+
Language server: [luals](https://luals.github.io)
16+
17+
You can install them via you OS package manager e.g. `pacman`, `brew` or other via other package managers such as `cargo` or `luarocks`
18+
19+
# Quality
20+
21+
The following quality checks are mandatory and are performed during CI. They run on the entire `lua` directory and return 1 on any failure.
22+
23+
You can run them all via `make` or `make all`
24+
25+
You can setup git hooks to run all checks by running `scripts/setup-hooks.sh`
26+
27+
## lint
28+
29+
1. Runs luacheck quietly using `.luacheck` settings
30+
31+
```sh
32+
make lint
33+
```
34+
35+
## style
36+
37+
1. Runs stylua using `.stylua.toml` settings
38+
1. Runs `scripts/doc-comments.sh` to validate annotated documentation
39+
40+
```sh
41+
make style
42+
```
43+
44+
You can automatically fix stylua issues via:
45+
46+
```sh
47+
make style-fix
48+
```
49+
50+
## check
51+
52+
1. Runs the checks that the LSP lua language server runs inside nvim using `.luarc.json` via `scripts/luals-check.sh`
53+
54+
```sh
55+
make check
1556
```
1657

17-
You can setup the git hooks by running `scripts/setup-hooks.sh`.
58+
Assumes `$VIMRUNTIME` is `/usr/share/nvim/runtime`. Adjust as necessary e.g.
1859

19-
## Adding new actions
60+
```sh
61+
VIMRUNTIME="/my/path/to/runtime" make check
62+
```
63+
64+
# Adding New Actions
2065

2166
To add a new action, add a file in `actions/name-of-the-action.lua`. You should export a `setup` function if some configuration is needed.
22-
Once you did, you should run the `scripts/update-help.sh`.
2367

24-
## Documentation
68+
Once you did, you should run `make help-update`
69+
70+
# Documentation
2571

2672
When adding new options, you should declare the defaults in the main `nvim-tree.lua` file.
27-
Once you did, you should run the `scripts/update-help.sh`.
2873

2974
Documentation for options should also be added to `nvim-tree-opts` in `doc/nvim-tree-lua.txt`
3075

31-
## Pull Request
76+
# Pull Request
3277

3378
Please reference any issues in the description e.g. "resolves #1234".
3479

Makefile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
all: lint style check
2+
3+
#
4+
# mandatory checks
5+
#
6+
lint: luacheck
7+
8+
style: stylua style-doc
9+
10+
check: luals
11+
12+
#
13+
# subtasks
14+
#
15+
luacheck:
16+
luacheck -q lua
17+
18+
stylua:
19+
stylua lua --check
20+
21+
style-doc:
22+
scripts/doc-comments.sh
23+
24+
luals:
25+
scripts/luals-check.sh
26+
27+
#
28+
# fixes
29+
#
30+
style-fix:
31+
stylua lua
32+
33+
#
34+
# utility
35+
#
36+
help-update:
37+
scripts/help-update.sh
38+
39+
#
40+
# CI
41+
#
42+
help-check: help-update
43+
git diff --exit-code doc/nvim-tree-lua.txt
44+
45+
46+
.PHONY: all lint style check luacheck stylua style-doc luals style-fix help-update help-check
47+

lua/nvim-tree/diagnostics.lua

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ local log = require "nvim-tree.log"
44

55
local M = {}
66

7-
---TODO add "$VIMRUNTIME" to "workspace.library" and use the @enum instead of this integer
8-
---@alias lsp.DiagnosticSeverity integer
9-
107
---COC severity level strings to LSP severity levels
118
---@enum COC_SEVERITY_LEVELS
129
local COC_SEVERITY_LEVELS = {

lua/nvim-tree/git/runner.lua

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ local log = require "nvim-tree.log"
22
local utils = require "nvim-tree.utils"
33
local notify = require "nvim-tree.notify"
44

5-
-- TODO add "${3rd}/luv/library" to "workspace.library"
6-
---@class uv.uv_handle_t: table
7-
---@class uv.uv_stream_t: uv.uv_handle_t
8-
---@class uv.uv_pipe_t: uv.uv_stream_t
9-
105
---@class Runner
116
local Runner = {}
127
Runner.__index = Runner

lua/nvim-tree/node.lua

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
---@meta
22

3-
-- TODO add "${3rd}/luv/library" to "workspace.library"
4-
---@class uv.uv_req_t: table
5-
---@class uv.uv_fs_t: uv.uv_req_t
6-
73
---@class ParentNode
84
---@field name string
95

scripts/update-help.sh renamed to scripts/help-update.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# run after changing nvim-tree.lua DEFAULT_OPTS or keymap.lua M.default_on_attach
44
# scrapes and updates nvim-tree-lua.txt
5-
# run from repository root: scripts/update-help.sh
5+
# run from repository root: scripts/help-update.sh OR make help-update
66

77

88
#
@@ -38,7 +38,7 @@ sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_ON_ATTACH.lua
3838
# help human
3939
echo > /tmp/DEFAULT_ON_ATTACH.help
4040
sed -E "s/^ *vim.keymap.set\('n', '(.*)',.*api(.*),.*opts\('(.*)'.*$/'\`\1\`' '\3' '|nvim-tree-api\2()|'/g
41-
" /tmp/DEFAULT_ON_ATTACH.lua | while read line
41+
" /tmp/DEFAULT_ON_ATTACH.lua | while read -r line
4242
do
4343
eval "printf '%-17.17s %-26.26s %s\n' ${line}" >> /tmp/DEFAULT_ON_ATTACH.help
4444
done

scripts/luals-check.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
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.
6+
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.
7+
8+
if [ -z "${VIMRUNTIME}" ]; then
9+
export VIMRUNTIME="/usr/share/nvim/runtime"
10+
fi
11+
12+
DIR_SRC="lua"
13+
DIR_OUT="luals-out"
14+
15+
# clear output
16+
rm -rf "${DIR_OUT}"
17+
mkdir "${DIR_OUT}"
18+
19+
# execute inside lua to prevent luals itself from being checked
20+
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${PWD}/.luarc.json" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
21+
RC=$?
22+
23+
echo "${OUT}" >&2
24+
25+
if [ $RC -ne 0 ]; then
26+
echo "failed with RC=$RC"
27+
exit $RC
28+
fi
29+
30+
# any output is a fail
31+
case "${OUT}" in
32+
*Diagnosis\ complete*)
33+
if [ -f "${DIR_OUT}/check.json" ]; then
34+
cat "${DIR_OUT}/check.json"
35+
exit 1
36+
else
37+
exit 0
38+
fi
39+
;;
40+
*)
41+
exit 1
42+
;;
43+
esac
44+

0 commit comments

Comments
 (0)