Skip to content

Commit 6d6addc

Browse files
fidgetingbitspokey
andauthored
feat: Add lua-language-server to CI (#2611)
- Implement lua-language-server linter in pre-commit - Install via Nix due to lack of Ubuntu package - Apply patch for --check CLI bug using Nix overlay - Centralize linting config for VSCode, pre-commit, and CI Fixes #2576 ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet --------- Co-authored-by: Pokey Rule <[email protected]>
1 parent 94e9fd0 commit 6d6addc

File tree

7 files changed

+91
-6
lines changed

7 files changed

+91
-6
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: "Lua Language Server Lint"
2+
description: "Lints all lua files with lua-language-server"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- uses: cachix/install-nix-action@v27
7+
with:
8+
nix_path: nixpkgs=channel:nixos-unstable
9+
- uses: DeterminateSystems/magic-nix-cache-action@v2
10+
- run: nix profile install --accept-flake-config .#lua-language-server
11+
shell: bash
12+
- run: scripts/lint-lua-ls.sh
13+
shell: bash

.github/workflows/pre-commit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ on:
88
types: [opened, synchronize, reopened]
99
merge_group:
1010
branches: [main]
11+
workflow_dispatch:
1112

1213
jobs:
1314
pre-commit:
1415
name: Pre-commit
1516
runs-on: ubuntu-latest
17+
env:
18+
CURSORLESS_REPO_ROOT: ${{ github.workspace }}
1619
steps:
1720
- uses: actions/checkout@v4
1821
- uses: actions/setup-python@v5

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
NEOVIM_PATH: ${{ steps.vim.outputs.executable }}
6767
- uses: ./.github/actions/test-neovim-lua/
6868
if: runner.os == 'Linux' && matrix.app_version == 'stable'
69+
- uses: ./.github/actions/lint-lua-ls/
70+
if: runner.os == 'Linux' && matrix.app_version == 'stable'
6971
- name: Create vscode dist that can be installed locally
7072
run: pnpm -F @cursorless/cursorless-vscode populate-dist --local-install
7173
if: runner.os == 'Linux' && matrix.app_version == 'stable'

.luarc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"runtime.version": "Lua 5.1",
3+
"diagnostics.ignoredFiles": "Disable",
4+
"diagnostics.globals": ["vim", "talon", "it", "describe"],
5+
"workspace.ignoreDir": ["data/playground/lua/", ".luarocks", ".lua"]
6+
}

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
"typescript.enablePromptUseWorkspaceTsdk": true,
2727
"typescript.tsdk": "node_modules/typescript/lib",
2828
"eslint.workingDirectories": [{ "pattern": "packages/*/" }],
29-
"Lua.runtime.version": "Lua 5.1",
30-
"Lua.diagnostics.globals": ["vim", "talon", "it", "describe"],
31-
"Lua.diagnostics.ignoredFiles": "Disable",
32-
"Lua.workspace.ignoreDir": ["data/playground/lua/"],
3329
"[lua]": {
3430
"editor.defaultFormatter": "JohnnyMorganz.stylua"
3531
},

flake.nix

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
pkgs = import nixpkgs {
2323
inherit system;
2424
overlays = [
25+
# Updated neovim-node-client is pending merge:
2526
# https://github.com/NixOS/nixpkgs/pull/317333
2627
(final: prev: {
2728
nodePackages = prev.nodePackages // {
@@ -45,7 +46,21 @@
4546
};
4647
};
4748
neovim = prev.neovim.override { withNodeJs = true; };
48-
49+
# There is a recent bug that prevents cli --check invocation:
50+
# See #2613
51+
lua-language-server = prev.lua-language-server.overrideAttrs {
52+
postPatch =
53+
let
54+
patch = prev.fetchurl {
55+
url = "https://github.com/LuaLS/lua-language-server/pull/2775.patch";
56+
sha256 = "sha256-5hjuNzBHLp9kiD6O8jTL5YlvaqR8IuJPHchIZE2/p/Q=";
57+
};
58+
in
59+
''
60+
patch -p1 < ${patch}
61+
''
62+
+ prev.lua-language-server.postPatch;
63+
};
4964
})
5065

5166
];
@@ -57,6 +72,12 @@
5772
] (nixpkgs.lib.importTOML ./pyproject.toml).tool.ruff.target-version;
5873
in
5974
{
75+
packages = forEachSupportedSystem (
76+
{ pkgs }:
77+
{
78+
lua-language-server = pkgs.lua-language-server;
79+
}
80+
);
6081
devShells = forEachSupportedSystem (
6182
{ pkgs }:
6283
{
@@ -69,19 +90,21 @@
6990
[
7091
pkgs.corepack
7192
pkgs.vsce
93+
pkgs.nodejs
94+
7295
# https://github.com/NixOS/nixpkgs/pull/251418
7396
(pkgs.pre-commit.overrideAttrs (previousAttrs: {
7497
makeWrapperArgs = ''
7598
--set PYTHONPATH $PYTHONPATH
7699
'';
77100
}))
78101
python
102+
pkgs.lua-language-server # language server used by pre-commit hooks
79103

80104
pkgs.neovim
81105
pkgs.luajitPackages.busted # for lua testing
82106
pkgs.luarocks # pre-commit doesn't auto-install luarocks
83107
pkgs.ps
84-
pkgs.nodejs
85108
];
86109
# To prevent weird broken non-interactive bash terminal
87110
buildInputs = [ pkgs.bashInteractive ];

scripts/lint-lua-ls.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# lua-language-server should be installed automatically by the flake.nix dev shell
5+
# or .github/workflows/pre-commit.yml
6+
if ! type lua-language-server &>/dev/null; then
7+
echo "ERROR: lua-language-server is not installed. Please run 'nix develop' or install it manually."
8+
exit 1
9+
fi
10+
11+
if [ ! -e "${CURSORLESS_REPO_ROOT-nonexistent}" ]; then
12+
CURSORLESS_REPO_ROOT=$(git rev-parse --show-toplevel)
13+
fi
14+
15+
function check_file() {
16+
local file="$1"
17+
logpath="$(mktemp -d)"
18+
rm -rf "$logpath/check.json"
19+
result=$(lua-language-server --check "$file" \
20+
--checklevel="Warning" \
21+
--configpath="${CURSORLESS_REPO_ROOT}/.luarc.json" \
22+
--logpath="$logpath")
23+
if [[ ! "$result" == *"no problems found"* ]]; then
24+
if [ -e "$logpath/check.json" ]; then
25+
cat "$logpath/check.json"
26+
else
27+
echo "ERROR: lua-language-server failed to run."
28+
echo "$result"
29+
fi
30+
return 1
31+
32+
fi
33+
return 0
34+
}
35+
36+
# lua-language-server doesn't support single file parsing, so check entire folder
37+
exit_code=0
38+
if ! check_file "${CURSORLESS_REPO_ROOT}"; then
39+
exit_code=1
40+
fi
41+
42+
exit $exit_code

0 commit comments

Comments
 (0)