forked from cursorless-dev/cursorless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add lua language server to pre-commit
Fixes cursorless-dev#2576. Adds lua-language-server linter to pre-commit. There is no existing pre-commit hook, and also no Ubuntu package for this linter. I install it using nix package manager, as nixpkgs is one of the only places with a package. However, there is also a recent bug that prevents --check invocation of the cli. I have patched this in the lua-language-server using a nix overlay, until the PR is merged. This also moves the linting configuration to a single source of true, that vscode, pre-commit, CI can all use.
- Loading branch information
1 parent
a3982a9
commit 5b1abfc
Showing
7 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ jobs: | |
pre-commit: | ||
name: Pre-commit | ||
runs-on: ubuntu-latest | ||
env: | ||
CURSORLESS_REPO_ROOT: ${{ github.workspace }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
|
@@ -26,6 +28,11 @@ jobs: | |
- run: pnpm --color install | ||
- uses: leafo/gh-actions-lua@v9 | ||
- uses: leafo/gh-actions-luarocks@v4 | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- run: nix profile install --quiet --accept-flake-config nixpkgs#lua-language-server --override-input nixpkgs path:$PWD/patches/lua-language-server.nix | ||
shell: bash | ||
- uses: pre-commit/[email protected] | ||
- uses: pre-commit-ci/[email protected] | ||
if: always() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"runtime.version": "Lua 5.1", | ||
"diagnostics.ignoredFiles": "Disable", | ||
"diagnostics.globals": ["vim", "talon", "it", "describe"], | ||
"workspace.ignoreDir": ["data/playground/lua/"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(final: prev: { | ||
# There is a recent bug that prevents cli invocation: | ||
# See: https://github.com/LuaLS/lua-language-server/pull/2775 | ||
lua-language-server = prev.lua-language-server.overrideAttrs { | ||
postPatch = | ||
let | ||
patch = prev.fetchurl { | ||
url = "https://github.com/LuaLS/lua-language-server/pull/2775.patch"; | ||
sha256 = "sha256-5hjuNzBHLp9kiD6O8jTL5YlvaqR8IuJPHchIZE2/p/Q="; | ||
}; | ||
in | ||
'' | ||
patch -p1 < ${patch} | ||
'' | ||
+ prev.lua-language-server.postPatch; | ||
}; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# lua-language-server should be installed automatically by the flake.nix dev shell | ||
# or .github/workflows/pre-commit.yml | ||
if ! type lua-language-server &>/dev/null; then | ||
echo "ERROR: lua-ls is not installed. Please run 'nix develop' or install it manually." | ||
exit 1 | ||
fi | ||
|
||
if [ ! -e "${CURSORLESS_REPO_ROOT-nonexistent}" ]; then | ||
CURSORLESS_REPO_ROOT=$(git rev-parse --show-toplevel) | ||
fi | ||
|
||
logpath="$(mktemp -d)" | ||
rm -rf "$logpath/check.json" | ||
result=$(lua-language-server --check "${CURSORLESS_REPO_ROOT}" \ | ||
--checklevel="Warning" \ | ||
--configpath="${CURSORLESS_REPO_ROOT}/.luarc.json" \ | ||
--logpath="$logpath") | ||
if [[ ! "$result" == *"no problems found"* ]]; then | ||
cat "$logpath/check.json" | ||
exit 1 | ||
fi | ||
|
||
exit 0 |