Skip to content

ci: lua language server and Makefile #2546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0d6b860
ci: add lls-check
alex-courtis Nov 21, 2023
a2902e5
ci: add lls-check to ci.yml
alex-courtis Nov 21, 2023
78bfdf8
ci: download lua-language-server binary
alex-courtis Nov 25, 2023
df807c4
ci: download lua-language-server binary
alex-courtis Nov 25, 2023
5a01aa8
ci: dummy failure to test
alex-courtis Nov 25, 2023
1f2e52c
Revert "ci: dummy failure to test"
alex-courtis Nov 25, 2023
04aa5a2
ci: ignore lls-out
alex-courtis Nov 25, 2023
8d9b108
ci: better name
alex-courtis Nov 25, 2023
eb856a5
ci: shellcheck nits
alex-courtis Nov 25, 2023
931efb3
ci: add luals libs and tidy
alex-courtis Nov 26, 2023
4e9ee61
ci: tidy
alex-courtis Nov 26, 2023
48494be
ci: add neovim 0.9.4
alex-courtis Nov 26, 2023
10de5c2
ci: add ci neovim 0.9.4 to lib path
alex-courtis Nov 26, 2023
fea0f04
ci: dummy failure to test
alex-courtis Nov 26, 2023
c12a3af
Revert "ci: dummy failure to test"
alex-courtis Nov 26, 2023
a1e293f
Revert "ci: add ci neovim 0.9.4 to lib path"
alex-courtis Nov 26, 2023
820b7b3
Revert "ci: add neovim 0.9.4"
alex-courtis Nov 26, 2023
b5de0c1
ci: action downloads and installs luals
alex-courtis Dec 9, 2023
b60ea9c
ci: remove workspaces from luals
alex-courtis Dec 9, 2023
edbf501
ci: consistent script naming
alex-courtis Dec 9, 2023
2356e3d
ci: add quality to contributing
alex-courtis Dec 9, 2023
747854a
ci: consistent script naming
alex-courtis Dec 9, 2023
240ef77
Merge branch 'master' into ci-lua-language-server
alex-courtis Dec 10, 2023
1532885
Merge branch 'master' into ci-lua-language-server
alex-courtis Dec 30, 2023
4d836e8
ci: add lsp to diagnostics
alex-courtis Dec 30, 2023
7e3caf9
ci: temporary find to enumerate home
alex-courtis Dec 30, 2023
00fe0a9
ci: add VIMRUNTIME for lls
alex-courtis Dec 30, 2023
7f94529
ci: temporary find to enumerate home
alex-courtis Dec 30, 2023
f6fe6b3
ci: temporary find to enumerate home
alex-courtis Dec 30, 2023
e51863e
ci: remove temporary find to enumerate home
alex-courtis Dec 30, 2023
4bd4717
ci: correct VIMRUNTIME
alex-courtis Dec 30, 2023
824d7e7
ci: add ${3rd}/luv/library
alex-courtis Dec 30, 2023
99d4fbf
ci: note VIMRUNTIME override
alex-courtis Dec 30, 2023
5e65115
Merge branch 'master' into ci-lua-language-server
alex-courtis Dec 31, 2023
95b9146
ci: add Makefile
alex-courtis Dec 31, 2023
d353323
ci: add Makefile
alex-courtis Dec 31, 2023
4198691
ci: add Makefile
alex-courtis Dec 31, 2023
e14aa5a
ci: add Makefile
alex-courtis Dec 31, 2023
eb9f7cd
ci: document checks and fixes
alex-courtis Dec 31, 2023
e1fae69
ci: add help check
alex-courtis Dec 31, 2023
5e62d1e
ci: add help check
alex-courtis Dec 31, 2023
c50ccea
ci: dummy help failure
alex-courtis Dec 31, 2023
ed0c82f
Revert "ci: dummy help failure"
alex-courtis Dec 31, 2023
828bbc8
ci: document checks and fixes
alex-courtis Dec 31, 2023
fa7ebc2
ci: document checks and fixes
alex-courtis Dec 31, 2023
a8cb50d
ci: matrix nvim version
alex-courtis Dec 31, 2023
fcef6a1
ci: matrix nvim version
alex-courtis Dec 31, 2023
1b509db
Revert "ci: matrix nvim version"
alex-courtis Dec 31, 2023
6b0fcc4
Revert "ci: matrix nvim version"
alex-courtis Dec 31, 2023
1a24ad8
ci: matrix nvim version from env
alex-courtis Dec 31, 2023
2ad6aa5
ci: matrix nvim version from env
alex-courtis Dec 31, 2023
b0f55dc
ci: matrix nvim version from env
alex-courtis Dec 31, 2023
995d3cb
ci: matrix nvim version
alex-courtis Dec 31, 2023
1aa2574
ci: matrix nvim version
alex-courtis Jan 1, 2024
9311fd8
ci: matrix per job
alex-courtis Jan 1, 2024
81b32ca
ci: matrix per job
alex-courtis Jan 1, 2024
003752c
ci: many lua versions
alex-courtis Jan 1, 2024
077d56e
ci: move doc to style
alex-courtis Jan 1, 2024
59b34b8
ci: tidy ci and contributing
alex-courtis Jan 1, 2024
d12dc49
Merge branch 'master' into ci-lua-language-server
alex-courtis Jan 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,65 @@ permissions:
jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
lua_version: [ 5.1 ]

steps:
- uses: actions/checkout@v4

- uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.1"
luaVersion: ${{ matrix.lua_version }}

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

- name: luacheck
run: |
luarocks install luacheck 1.1.1
luacheck lua
- run: luarocks install luacheck 1.1.1

- run: make lint

style:
runs-on: ubuntu-latest

strategy:
matrix:
stylua_version: [ 0.19.1 ]

steps:
- uses: actions/checkout@v4

- name: stylua
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: "0.19"
version: ${{ matrix.stylua_version }}
args: --check lua

- name: doc-comments
run: ./scripts/doc-comments.sh
- run: make style-doc

check:
runs-on: ubuntu-latest

strategy:
matrix:
nvim_version: [ v0.9.4 ]
luals_version: [ 3.7.3 ]

steps:
- uses: actions/checkout@v3

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.nvim_version }}

- name: install luals
run: |
mkdir -p luals
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

- name: make check
run: VIMRUNTIME=/home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime PATH="luals/bin:${PATH}" make check

- run: make help-check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/luals-out/
/luals/
5 changes: 2 additions & 3 deletions .hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash
#!/bin/sh

stylua . --check || exit 1
luacheck . || exit 1
make
7 changes: 7 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"runtime.version" : "Lua 5.1",
"workspace": {
"library": [
"$VIMRUNTIME/lua/vim/lsp",
"${3rd}/luv/library"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Baby steps: just lsp and uv for now.

cmd, api and fn will take some time.

]
},
"diagnostics": {
"libraryFiles": "Disable",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many warnings in the libraries themselves.

"globals": [
"vim"
],
Expand Down
69 changes: 57 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,76 @@ Thank you for contributing.

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

## Styling and formatting
# Tools

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

```bash
luarocks install luacheck
cargo install stylua
Lint: [luacheck](https://github.com/lunarmodules/luacheck/)

Style: [StyLua](https://github.com/JohnnyMorganz/StyLua)

Language server: [luals](https://luals.github.io)

You can install them via you OS package manager e.g. `pacman`, `brew` or other via other package managers such as `cargo` or `luarocks`

# Quality

The following quality checks are mandatory and are performed during CI. They run on the entire `lua` directory and return 1 on any failure.

You can run them all via `make` or `make all`

You can setup git hooks to run all checks by running `scripts/setup-hooks.sh`

## lint

1. Runs luacheck quietly using `.luacheck` settings

```sh
make lint
```

## style

1. Runs stylua using `.stylua.toml` settings
1. Runs `scripts/doc-comments.sh` to validate annotated documentation

```sh
make style
```

You can automatically fix stylua issues via:

```sh
make style-fix
```

## check

1. Runs the checks that the LSP lua language server runs inside nvim using `.luarc.json` via `scripts/luals-check.sh`

```sh
make check
```

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

## Adding new actions
```sh
VIMRUNTIME="/my/path/to/runtime" make check
```

# Adding New Actions

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.
Once you did, you should run the `scripts/update-help.sh`.

## Documentation
Once you did, you should run `make help-update`

# Documentation

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

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

## Pull Request
# Pull Request

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

Expand Down
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
all: lint style check

#
# mandatory checks
#
lint: luacheck

style: stylua style-doc

check: luals

#
# subtasks
#
luacheck:
luacheck -q lua

stylua:
stylua lua --check

style-doc:
scripts/doc-comments.sh

luals:
scripts/luals-check.sh

#
# fixes
#
style-fix:
stylua lua

#
# utility
#
help-update:
scripts/help-update.sh

#
# CI
#
help-check: help-update
git diff --exit-code doc/nvim-tree-lua.txt


.PHONY: all lint style check luacheck stylua style-doc luals style-fix help-update help-check

3 changes: 0 additions & 3 deletions lua/nvim-tree/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ local log = require "nvim-tree.log"

local M = {}

---TODO add "$VIMRUNTIME" to "workspace.library" and use the @enum instead of this integer
---@alias lsp.DiagnosticSeverity integer

---COC severity level strings to LSP severity levels
---@enum COC_SEVERITY_LEVELS
local COC_SEVERITY_LEVELS = {
Expand Down
5 changes: 0 additions & 5 deletions lua/nvim-tree/git/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local notify = require "nvim-tree.notify"

-- TODO add "${3rd}/luv/library" to "workspace.library"
---@class uv.uv_handle_t: table
---@class uv.uv_stream_t: uv.uv_handle_t
---@class uv.uv_pipe_t: uv.uv_stream_t

---@class Runner
local Runner = {}
Runner.__index = Runner
Expand Down
4 changes: 0 additions & 4 deletions lua/nvim-tree/node.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
---@meta

-- TODO add "${3rd}/luv/library" to "workspace.library"
---@class uv.uv_req_t: table
---@class uv.uv_fs_t: uv.uv_req_t

---@class ParentNode
---@field name string

Expand Down
4 changes: 2 additions & 2 deletions scripts/update-help.sh → scripts/help-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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


#
Expand Down Expand Up @@ -38,7 +38,7 @@ sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_ON_ATTACH.lua
# help human
echo > /tmp/DEFAULT_ON_ATTACH.help
sed -E "s/^ *vim.keymap.set\('n', '(.*)',.*api(.*),.*opts\('(.*)'.*$/'\`\1\`' '\3' '|nvim-tree-api\2()|'/g
" /tmp/DEFAULT_ON_ATTACH.lua | while read line
" /tmp/DEFAULT_ON_ATTACH.lua | while read -r line
do
eval "printf '%-17.17s %-26.26s %s\n' ${line}" >> /tmp/DEFAULT_ON_ATTACH.help
done
Expand Down
44 changes: 44 additions & 0 deletions scripts/luals-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

# Performs a lua-language-server check on all files.
# luals-out/check.json will be produced on any issues, returning 1.
# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc.
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.

if [ -z "${VIMRUNTIME}" ]; then
export VIMRUNTIME="/usr/share/nvim/runtime"
fi

DIR_SRC="lua"
DIR_OUT="luals-out"

# clear output
rm -rf "${DIR_OUT}"
mkdir "${DIR_OUT}"

# execute inside lua to prevent luals itself from being checked
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${PWD}/.luarc.json" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
RC=$?

echo "${OUT}" >&2

if [ $RC -ne 0 ]; then
echo "failed with RC=$RC"
exit $RC
fi

# any output is a fail
case "${OUT}" in
*Diagnosis\ complete*)
if [ -f "${DIR_OUT}/check.json" ]; then
cat "${DIR_OUT}/check.json"
exit 1
else
exit 0
fi
;;
*)
exit 1
;;
esac